Convert CSV to Excel XLSX via Java using REST API

Convert CSV to Excel XLS or XLSX in Java using REST API.

CSV (Comma Separated Values) and Excel are two of the most widely used file formats for storing and managing data. CSV files are plain text files that contain comma-separated data. On the other hand, Excel files are more advanced and can contain multiple worksheets, formulas, charts, and other features. Converting CSV files to Excel files can be a time-consuming task, especially when dealing with large data sets. Fortunately, there is an easy and efficient way to convert CSV files to Excel files using GroupDocs.Conversion Cloud SDK for Java. In this article, we will discuss how to convert CSV to Excel XLS or XLSX in Java using REST API.

In this article we will cover the following topics:

CSV to Excel File Conversion REST API - Java SDK Installation

In order to convert CSV file to Excel using Java, I will be using GroupDocs.Conversion Cloud SDK for Java. This SDK for Java is a powerful and easy-to-use cloud-based software that allows users to convert documents from one format to another. It supports a wide range of file formats, including CSV, Excel, PDF, HTML, and more. GroupDocs.Conversion Cloud SDK for Java is built on top of the RESTful API, which allows developers to integrate the software into their applications seamlessly. It also provides advanced features like file encryption, compression, and password protection.

You can either download the API’s JAR file or install it using Maven by adding the following repository and dependency into your project’s pom.xml file:

Maven Repository:

<repository>
    <id>groupdocs-artifact-repository</id>
    <name>GroupDocs Artifact Repository</name>
    <url>https://repository.groupdocs.cloud/repo</url>
</repository>

Maven Dependency:

<dependency>
    <groupId>com.groupdocs</groupId
    <artifactId>groupdocs-conversion-cloud</artifactId>
    <version>23.4</version>
    <scope>compile</scope>
</dependency>

Now, you need to sign up for a free account on the GroupDocs website to use the GroupDocs.Conversion Cloud SDK for Java. Once you have created an account, you will be provided with a Client ID and Client Secret that you will use to authenticate API requests. Please add the code snippet shown below once you have your ID and Secret:

How to Convert CSV File to Excel XLSX in Java using REST API

Here are the steps to convert a CSV file to an Excel format using GroupDocs.Conversion Cloud SDK for Java:

  • Upload the CSV file to the Cloud
  • Convert a CSV file to an Excel file using Java
  • Download the converted file

Upload the File

Firstly, upload the CSV file to the cloud using the code snippet given below:

Hence, the uploaded CSV file will be available in the files section of your dashboard on the cloud.

Convert CSV to Excel Online in Java

In this section, we will show the steps and the code snippet needed to convert a CSV file to an Excel format programmatically in Java.

The steps are:

  • Firstly, import the required classes into your Java file.
  • Secondly, create an instance of the ConvertApi class.
  • Thirdly, create an instance of ConvertSettings class.
  • Next, provide your cloud storage name.
  • Now, set the source file path and the output format to “xlsx”.
  • After that, set the output file path.
  • Next, create an instance of the XlsxConvertOptions class.
  • Optionally, provide various convert options like setFromPage, setPagesCount, etc.
  • Then, create the ConvertDocumentRequest class instance and pass the settings parameter.
  • Finally, convert CSV to XLSX by calling the convert_document() method and passing the ConvertDocumentRequest parameter.

The following sample code snippet shows how to convert CSV to XLSX format programmatically in Java using REST API:

Finally, the above code snippet will save the Excel file in the cloud. You can see the output in the image below:

How to Convert CSV to Excel in Java using REST API.

Convert CSV to Excel online via Java.

Download the Converted File

The above code sample will save the converted CSV to an Excel file in the cloud. You can download it using the following code sample:

Free Online CSV to Excel Converter

How to convert CSV to Excel online for free? Please try an online CSV to Excel converter to create an Excel file from CSV. This converter is developed using the above-mentioned Groupdocs.Conversion Cloud APIs.

Conclusion

Finally, this brings us to the end of this blog post. The following is what you have learned from this article:

  • how to convert CSV to Excel format in Java programmatically, as well as additional customization options;
  • programmatically upload the CSV file to the cloud and then download the converted Excel file from the cloud;
  • and convert any CSV to Excel for free using a free online CSV to Excel converter.

Moreover, we also provide an API Reference section that lets you visualize and communicate with our APIs directly through the browser. Java SDK’s complete source code is freely available on Github. Please check the GroupDocs.Conversion Cloud SDK for Java Examples here.

Additionally, we suggest you follow our Getting Started guide for detailed steps and API usage.

Finally, we keep writing new blog articles on different file formats and conversions using REST API. So, please get in touch for the latest updates.

Ask a question

For any queries/discussions about CSV to Excel conversion API, please feel free to contact us via the forum.

FAQs

How do I convert a CSV to an Excel file online for free?

Please follow the step-by-step instructions to convert a CSV to Excel online for free:

  • Open online CSV to XLSX converter.
  • Now, click inside the file drop area to upload a CSV file or drag & drop a CSV file.
  • Next, click on the Convert Now button. Online CSV to Excel converter will change CSV into an Excel file.
  • The download link of the output file will be available instantly after conversion.

How do I convert CSV to Excel on Windows?

Please visit the download link to download the CSV to Excel offline converter for Windows. This free CSV to Excel converter can be used to convert CSV to Excel files on Windows quickly, with a single click.

Is GroupDocs.Conversion Cloud SDK for Java secure?

Yes, GroupDocs.Conversion Cloud SDK for Java is a secure way to convert files. The SDK uses the HTTPS protocol to ensure that all data transferred between your application and the GroupDocs.Conversion Cloud API is encrypted and secure. Moreover, the GroupDocs.Conversion Cloud SDK for Java is regularly updated and maintained by the development team

See Also

If you want to learn more about related topics, we recommend reading the articles listed below: