TSV to Excel

Convert TSV to Excel in Java

A tab-separated values TSV file is a simple text format for storing data in a tabular structure, e.g., a database table or spreadsheet data, and a way of exchanging information between databases. Its also one of the popular file based structure for data storage other than CSV. However, we may have a requirement to convert TSV to Excel in bulk quantity so a programming API is always a viable solution. In this article, we are going to discuss the details on how to convert TSV to Excel using REST API.

TSV to Excel Conversion API

We are going to use Aspose.Cells Cloud SDK for Java which provides the capabilities to create, manipulate and transform the excel worksheets to other supported file formats within Java application. This SDK is developed on top of Aspose.Cells Cloud REST API. It also provides the capabilities to convert TSV to Excel. Now in order to get started, we need to add the following details in pom.xml of maven build type project.

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

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

Apart from JDK installation, we also need to create a free account over Aspose Cloud. Login using newly created account and lookup/create Client ID and Client Secret at Cloud Dashboard. These details are required in subsequent sections.

TSV to Excel using Java

In this section, we are going to discuss the details on how to convert TSV to Excel using Java code snippet. Please follow the steps given below to accomplish this requirement.

  • Firstly, create a CellsApi object while providing ClientID and Client secret details as arguments
  • Secondly, create a File instance to load input TSV
  • Thirdly, call the uploadFile(…) method to upload the source TSV to cloud storage
  • Now call the cellsWorkbookGetWorkbook(…) method requiring input TSV, resultant format and name of Excel workbook. The output is also stored in cloud storage
TSV to Excel preview

Image1:- TSV to XLS preview

The source TSV referenced in above example can be downloaded from TestCase.tsv and the resultant Excel from Resultant.xls

TSV to XLS using cURL Commands

Now we are going to discuss the details on how to convert TSV to XLS using cURL commands. So one of the pre-requisite for this approach is to first a JWT access token (based on client credentials) while executing the following command.

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"

Once we have the JWT token, we need to execute the following command to convert TSV to XLS. The resultant Excel will be available in cloud storage.

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>"

Conclusion

In this article, we have explored the options for converting TSV to Excel using Java Cloud SDK. So with simple steps, we can easily convert TSV to XLS, TSV to XLSX and other supported formats. Another easiest way of exploring the API within web browser is through swagger interface. Also, please note that all our Cloud SDKs are built under MIT license, so the complete source code can be downloaded from GitHub. You may consider approaching us for a quick resolution of issues via free product support forum.

We highly recommend visiting the following links to learn more about: