Excel files are excellent for storing and managing structured data, but their proprietary format can limit compatibility with certain applications, databases, or systems. CSV (Comma-Separated Values) files, on the other hand, are lightweight, universally accepted, and easy to parse, making them ideal for data exchange, integration, and analysis. By converting Excel to CSV, you simplify data processing, enable cross-platform accessibility, and streamline automated workflows. In this article, we’ll explore how to perform this conversion efficiently using a Java REST API, unlocking the full potential of your data.
Excel to CSV Conversion API
Aspose.Cells Cloud SDK for Java offers a powerful and efficient solution for converting Excel files to CSV format with minimal effort. The API supports a wide range of Excel formats, including XLS, XLSX, and CSV, ensuring seamless data handling. Furthermore, the conversion process retains the integrity of your data, enabling accurate and reliable results.
Installation
In order to use the Cloud SDK, we need to add the following Maven dependencies to our pom.xml file:.
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.cloud/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells-cloud</artifactId>
<version>24.9</version>
</dependency>
</dependencies>
- You can download the latest version from the Aspose Repository.
Secondly, we need to obtain our client credentials from cloud dashboard. If you do not have an existing account, simply create a free account by following the instructions specified in the quick start article.
Excel to Comma Delimited Files in Java
The following section explains the details on converting an Excel workbook to CSV format using Java code snippet:
CellsApi api = new CellsApi(clientId,clientSecret);
Create an instance of CellsApi while providing client credentials as input arguments.
api.uploadFile("input.xlsx", file, "basic");
Upload the input XLSX to cloud storage using uploadFile(…) method.
File response = api.cellsWorkbookGetWorkbook(name, password,format,
isAutoFit, onlySaveTable, null,"basic", "Resultant.csv","basic", null);
Finally, call the method cellsWorkbookGetWorkbook(…) to initiate the conversion operation.
The input Excel workbook used in above example can be downloaded from:
XLS to CSV using cURL Commands
Aspose.Cells Cloud simplifies the process of converting Excel files to CSV format using cURL commands, offering a straightforward solution for developers who prefer command-line tools. This method eliminates the need for complex installations or additional libraries, providing a secure, scalable, and efficient way to handle Excel-to-CSV conversions across platforms.
The first step in this method is to generate a JWT access token using the following command:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=XXXXXXX-b195-426c-85f7-XXXXXXXX&client_secret=XXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Now that we have the JWT token, we need to execute the following command to convert Excel workbook to comma separated values.
curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}/SaveAs?newfilename={myResultant}&isAutoFitRows=false&isAutoFitColumns=false&checkExcelRestriction=false" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"SaveFormat\": \"csv\",}"
Replace sourceFile
with the name of input excel file (available in the cloud storage), myResultant
with the name of resultant CSV file and accessToken
with JWT access token generated above.
Conclusion
In this article, we have learned that Aspose.Cells Cloud provides two versatile approaches to achieve this: through its intuitive Java SDK and via cURL commands. Both methods ensure high accuracy, customizable outputs, and a secure cloud-based environment for processing your data. Whether you prefer working with code or command-line tools, Aspose.Cells Cloud delivers a reliable and efficient solution to meet your needs. Try Aspose.Cells Cloud today to streamline your Excel-to-CSV conversions!
Useful Links
Related Articles
Please visit the following links to learn more about: