TSV zuwa Excel

Canza TSV zuwa Excel a Java

Fayil ɗin da aka raba dabi’u TSV tsari ne mai sauƙi na rubutu don adana bayanai a cikin tsari na tebur, misali, tebur na bayanai ko bayanan maƙunsar bayanai, da hanyar musayar bayanai tsakanin ma’ajin bayanai. Hakanan ɗayan shahararrun tsarin tushen fayil don ajiyar bayanai ban da CSV. Koyaya, muna iya samun buƙatu don canza TSV zuwa Excel a cikin adadi mai yawa don haka API na shirye-shirye koyaushe shine mafita mai dacewa. A cikin wannan labarin, za mu tattauna cikakkun bayanai kan yadda ake canza TSV zuwa Excel ta amfani da REST API.

API ɗin Canjin TSV zuwa Excel

Za mu yi amfani da Aspose.Cells Cloud SDK don Java wanda ke ba da damar ƙirƙira, sarrafa da canza takaddun aikin Excel zuwa wasu tsararrun fayilolin da aka goyan baya a cikin aikace-aikacen Java. An haɓaka wannan SDK a saman Aspose.Cells Cloud REST API. Hakanan yana ba da damar canza TSV zuwa Excel. Yanzu don farawa, muna buƙatar ƙara cikakkun bayanai masu zuwa 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>

Baya ga shigarwar JDK, muna kuma 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.

TSV zuwa Excel ta amfani da Java

A cikin wannan sashe, zamu tattauna cikakkun bayanai kan yadda ake canza TSV zuwa Excel ta amfani da snippet code na Java. Da fatan za a bi matakan da aka bayar 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
  • Abu na biyu, ƙirƙirar misalin Fayil don loda shigar da TSV
  • Na uku, kira hanyar uploadFile(…) don loda tushen TSV zuwa ma’ajiyar girgije
  • Yanzu kira hanyar selWorkbookGetWorkbook(…) da ke buƙatar shigar da TSV, tsarin sakamako da sunan littafin aikin Excel. Ana kuma adana abubuwan da aka fitar a cikin ma’ajiyar girgije
// 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.tsv";
    
    // 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 = "XLS";
    		
    // loda fayil daga tsarin gida
    File file = new File("c://Users/nayyer/"+fileName);	
    
    // loda shigarwar TSV zuwa ma'ajiyar gajimare
    api.uploadFile("input.tsv", file, "default");

    // yi aikin canza takarda
    File response = api.cellsWorkbookGetWorkbook("input.tsv",  password,format, 
    			            isAutoFit, onlySaveTable, null,"default",  "Resultant.xls","default", null);        
            
    // buga sakon nasara
    System.out.println("TSV to Excel successfull !");
    }catch(Exception ex)
    {
        System.out.println(ex);
    }
TSV zuwa Excel preview

Hoto1: - TSV zuwa samfotin XLS

Ana iya saukar da tushen TSV da aka ambata a cikin misalin sama daga TestCase.tsv da sakamakon Excel daga Resultant.xls

TSV zuwa XLS ta amfani da Umarnin CURL

Yanzu za mu tattauna cikakkun bayanai kan yadda ake canza TSV zuwa XLS ta amfani da umarnin CURL. Don haka ɗayan abubuwan da ake buƙata don wannan hanyar ita ce fara alamar samun damar JWT (bisa ga 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"

Da zarar mun sami alamar JWT, muna buƙatar aiwatar da umarni mai zuwa don canza TSV zuwa XLS. Sakamakon Excel zai kasance a cikin ajiyar girgije.

curl -v -X GET "https://api.aspose.cloud/v3.0/cells/input.tsv?format=XLS&isAutoFit=false&onlySaveTable=false&outPath=Resultant.xls&checkExcelRestriction=true" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Kammalawa

A cikin wannan labarin, mun bincika zaɓuɓɓukan don canza TSV zuwa Excel ta amfani da Java Cloud SDK. Don haka tare da matakai masu sauƙi, za mu iya sauƙi canza TSV zuwa XLS, TSV zuwa XLSX da sauran nau’o’in tallafi. Wata hanya mafi sauƙi ta bincika API a cikin mai binciken gidan yanar gizo ita ce ta 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: