Excel to JSON

Canza Excel zuwa JSON ta amfani da Java

Excel galibi ana amfani da kasuwanci ta hanyar kasuwanci don tantance bayanan su yadda ya kamata. Wani dalili na shahararsa shi ne cewa yana goyan bayan ƙirƙirar sigogi, jadawali, da abubuwan gani daban-daban waɗanda ke taimakawa wajen fahimtar bayanan ta hanya mafi inganci. Koyaya, idan muna buƙatar raba bayanan takaddun aikin Excel tare da wasu aikace-aikacen, muna buƙatar rarraba abubuwan da ke cikinsa kuma mu raba su cikin tsari gama gari. Don haka, ƙila mu yi la’akari da zaɓi don fitarwa Excel zuwa tsarin JSON, kamar yadda aka saba amfani da shi don adanawa da musayar bayanai akan intanit. A cikin wannan labarin, za mu bincika cikakkun bayanai game da fassarar Excel zuwa JSON.

API ɗin Canjin Excel zuwa JSON

Aspose.Cells Cloud SDK don Java an haɓaka shi da farko don tallafawa ikon ƙirƙirar littafin aikin Excel, magudi da canzawa zuwa tsari kamar HTML, PDF, JPG ] da sauran tsare-tsare. Yanzu don farawa, mataki na farko shine ƙara waɗannan cikakkun bayanai a cikin pom.xml na aikin ginin maven.

<repositories> 
    <repository>
        <id>aspose-cloud</id>
        <name>artifact.aspose-cloud-releases</name>
        <url>https://artifact.aspose.cloud/repo</url>
    </repository>   
</repositories>

<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-cells-cloud</artifactId>
        <version>22.8</version>
    </dependency>
</dependencies>

Da zarar an ƙara bayanin SDK, muna buƙatar ƙirƙirar asusun kyauta akan Aspose Cloud. Shiga ta amfani da sabon asusun da aka ƙirƙira kuma bincika/ƙirƙiri ID na abokin ciniki da Sirrin Abokin ciniki a Cloud Dashboard. Ana buƙatar waɗannan cikakkun bayanai a cikin sassan da ke gaba.

Canza Excel zuwa JSON ta amfani da Java

Za mu tattauna cikakkun bayanai na Excel zuwa jujjuya JSON ta amfani da snippet code na Java. Don haka da fatan za a bi umarnin da aka kayyade a ƙasa don cika wannan buƙatu.

  • Da farko, ƙirƙiri abin CellsApi yayin samar da ClientID da bayanan sirri na Abokin ciniki azaman muhawara
  • Na biyu, ƙirƙiri misalin Fayil don loda littafin aiki na Excel
  • Na uku, kira hanyar uploadFile(…) don loda littafin aikin Excel zuwa ma’ajiyar girgije
  • Yanzu kira hanyar selWorkbookGetWorkbook(…) da ke buƙatar shigar da sunan Excel, tsarin sakamako azaman Json da sunan fayil ɗin fitarwa. Bayan nasarar yin nasara, ana adana fayil ɗin JSON a cikin ma’ajin gajimare
// don ƙarin misalai, da fatan za a ziyarci https://github.com/aspose-cells-cloud/aspose-cells-cloud-java

try
    {
    // Samu ClientID da ClientSecret daga https://dashboard.aspose.cloud/
    String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
    String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
  
    // ƙirƙiri misali na CellsApi ta amfani da takaddun shaidar abokin ciniki
    CellsApi api = new CellsApi(clientId,clientSecret);
    		
    // sunan shigar da littafin aikin Excel
    String fileName = "TestCase.xlsx";
    
    // bayanan sirri idan littafin aiki a rufaffen
    String password = null;
    
    // Yana ƙayyade ko saita layuka na littafin aiki don zama autofit.
    Boolean isAutoFit = true;
    // Yana ƙayyade ko ajiye bayanan tebur kawai. Yi amfani da pdf kawai don Excel.
    Boolean onlySaveTable = true;
    // resultant fayil format
    String format = "JSON";
    		
    // loda fayil daga tsarin gida
    File file = new File("c://Users/nayyer/"+fileName);	
    
    // loda shigarwar Excel zuwa ma'ajiyar girgije
    api.uploadFile("source.xlsx", file, "default");

    // yi aikin canza takarda
    File response = api.cellsWorkbookGetWorkbook("source.xlsx", password, format, 
    			            isAutoFit, onlySaveTable, null,"default", "Resultant.json","default", null);        
            
    // buga sakon nasara
    System.out.println("Successsul conversion of Excel to JSON !");
    }catch(Exception ex)
    {
        System.out.println(ex);
    }

Fitar da Excel zuwa JSON ba tare da Loda ba

A cikin wannan sashe, za mu tattauna cikakkun bayanai kan yadda ake canza Excel zuwa JSON ba tare da fara loda shigarwar Excel zuwa ajiyar girgije ba. Koyaya, sakamakon JSON za a adana shi a cikin ma’ajin gajimare.

  • Da farko, ƙirƙiri abin CellsApi yayin samar da ClientID da bayanan sirri na Abokin ciniki azaman muhawara
  • Na biyu, ƙirƙiri misalin Fayil don loda littafin aiki na Excel
  • Na uku, kira hanyar selWorkbookPutConvertWorkbook(…) da ke buƙatar shigar da sunan Excel, tsarin sakamako azaman Json da sunan fayil ɗin fitarwa. Bayan nasarar yin nasara, ana adana fayil ɗin JSON a cikin ma’ajin gajimare
// don ƙarin misalai, da fatan za a ziyarci https://github.com/aspose-cells-cloud/aspose-cells-cloud-java

try
    {
    // Samu ClientID da ClientSecret daga https://dashboard.aspose.cloud/
    String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
    String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
  
    // ƙirƙiri misali na CellsApi ta amfani da takaddun shaidar abokin ciniki
    CellsApi api = new CellsApi(clientId,clientSecret);
    		
    // sunan shigar da littafin aikin Excel
    String fileName = "TestCase.xlsx";
    
    // bayanan sirri idan littafin aiki a rufaffen
    String password = null;
    
    // resultant fayil format
    String format = "JSON";
    		
    // loda fayil daga tsarin gida
    File file = new File("c://Users/nayyer/"+fileName);	
    
    // yi aikin canza takarda
    File response = api.cellsWorkbookPutConvertWorkbook(file, format, password, "output.json", "default", null);       
            
    // buga sakon nasara
    System.out.println("Successsul conversion of Excel to JSON !");
    
    }catch(Exception ex)
    {
        System.out.println(ex);
    }
Excel zuwa JSON preview

Hoto 1: - Tasirin Juyawar Excel zuwa JSON

Shigar da littafin aikin Excel da sakamakon Json fayil da aka samar a sama misali ana iya saukewa daga Testcase.xlsx da output.json

XLSX zuwa JSON ta amfani da Umarnin CURL

Tunda ana iya samun dama ga REST APIs ta hanyar umarnin cURL, don haka a cikin wannan sashe, za mu kira Aspose.Cells Cloud ta umarnin cURL don cika abin da muke bukata. Yanzu ɗayan abubuwan da ake buƙata don wannan aikin shine samar da alamar samun damar JWT (dangane da shaidar abokin ciniki) yayin aiwatar da umarni mai zuwa.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Yanzu da zarar muna da alamar JWT, muna buƙatar aiwatar da umarni mai zuwa don canza Excel zuwa JSON. Za a adana sakamakon JSON a cikin ma’ajin gajimare.

curl -v -X GET "https://api.aspose.cloud/v3.0/cells/TestCase-original.xlsx?format=JSON&isAutoFit=false&onlySaveTable=false&outPath=output.json&checkExcelRestriction=true" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Kammalawa

A cikin wannan labarin, mun koyi jujjuyawar Excel zuwa fayil JSON ta amfani da Java Cloud SDK. Don haka mun shaida cewa tare da ƙarancin layukan lamba, mun sami nasarar cika abin da muke buƙata A lokaci guda, mun bincika zaɓi don canza Excel zuwa JSON tare da umarnin cURL akan tashar. Baya ga waɗannan hanyoyin, wata hanya mafi sauƙi ta bincika API a cikin mai binciken gidan yanar gizo shine ta hanyar swagger interface. Hakanan, da fatan za a lura cewa duk Cloud SDK ɗin mu an gina su ƙarƙashin lasisin MIT, don haka ana iya saukar da cikakkiyar lambar tushe daga GitHub. Kuna iya la’akari da kusantar mu don saurin warware batutuwa ta hanyar kyauta Tallafin tallafin samfur.

Labarai masu alaka

Muna ba da shawarar ziyartar hanyoyin haɗin yanar gizo masu zuwa don ƙarin koyo game da: