excel to csv

Convert Excel to CSV in Java

In today’s data-driven world, the ability to convert Excel files to CSV (Comma-Separated Values) format has become essential. While Excel files are widely used for storing and analyzing data, CSV files offer a simpler and more versatile format that can be easily processed by various applications and programming languages. Converting Excel to CSV provides a way to streamline data integration, improve interoperability, and facilitate data exchange between different systems. In this article, we will explore how to accomplish this task using Java Cloud SDK, empowering you to effortlessly convert Excel files to CSV and unlock the full potential of your data.

Excel to CSV Conversion Cloud SDK

When it comes to converting Excel files to CSV using Java, the Aspose.Cells Cloud SDK for Java stands out as a powerful and efficient solution. Aspose.Cells Cloud is a feature-rich API that provides extensive support for Excel file manipulation, including the ability to convert Excel files to CSV format seamlessly. So, whether you’re working on a data migration project, data analysis, or any other scenario that requires Excel to CSV conversion, the Aspose.Cells Cloud SDK empowers you with the tools and flexibility to achieve your goals efficiently and accurately.

Now, please add the following details in pom.xml to add the Cloud SDK reference in your project.

<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>22.8</version>
    </dependency>
</dependencies>

Once the reference of Cloud SDK is added, please register an account over Cloud dashboard and lookup/create Client ID and Client Secret details.

Convert Excel to CSV in Java

Please follow the instructions given below to convert XLSX to CSV format.

  • Create an instance of CellsApi class while providing client credentials as input arguments.
  • Specify the name of input Excel, resultant format as CSV, and the name of output file.
  • Upload the input Excel workbook to cloud storage using the uploadFile(…) method.
  • Finally, call the method cellsWorkbookGetWorkbook(…) to initiate the XLSX to CSV conversion operation.
excel to csv file preview

image1:- Excel to CSV file preview

The sample files used in the above example can be downloaded from myDocument.xlsx and Resultant.csv.

Convert local XLSX to CSV

In this section, we are going to learn the steps on how to convert XLSX to CSV without uploading the input file to cloud storage. So please follow the instructions given below.

  • Create an instance of CellsApi while providing client credentials as input arguments.
  • Specify the name of input Excel, resultant format as CSV, and output file name.
  • Thirdly, call the method cellsWorkbookPutConvertWorkbook(…) to initiate the XLSX to CSV conversion.

XLSX to CSV using cURL Commands

Another powerful way to convert Excel files to CSV is through cURL commands and the Aspose.Cells Cloud REST API. With the Aspose.Cells Cloud REST API, you can perform various operations on Excel files, including conversion to CSV, using simple and straightforward cURL commands. By leveraging the power of cURL commands and the Aspose.Cells Cloud REST API, you can automate the conversion process, handle large Excel files, and achieve efficient and reliable results.

Now, execute the following command to generate JWT access token:

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once the JWT is generated, please execute the following command to convert XLSX to CSV and save the output in cloud storage. Please note that input XLSX is already available in cloud storage.

curl -v -X GET "https://api.aspose.cloud/v3.0/cells/myDocument(1).xlsx?format=CSV&isAutoFit=false&onlySaveTable=false&outPath=converted.csv&checkExcelRestriction=true" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Conclusion

Whether you choose to utilize the Aspose.Cells Cloud SDK for Java or leverage cURL commands with the Aspose.Cells Cloud REST API, you have powerful tools at your disposal for Excel to CSV conversion. These approaches offer flexibility, scalability, and ease of integration, allowing you to convert Excel files to CSV format effortlessly. Therefore, by leveraging these technologies, you can automate the conversion process, streamline your workflows, and extract valuable data from Excel files in a format that is widely compatible and easily accessible.

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