While CSV (Comma-Separated Values) files are a popular choice for storing and exchanging tabular data due to their simplicity and compatibility, there are times when you may need to convert CSV files into Excel format. In such cases, an accurate and precise conversion is needed. Let us explore how to convert CSV and Excel in Java.

Java CSV to Excel Converter API

To convert these file formats, firstly you need to configure Aspose.Cells for Java API in your Java environment. This will let you achieve the requirements with only a couple of lines of code. The API will take care of the rest of the tasks and activities. You can set it up either by downloading the JAR file or by adding the following Maven Repository specifications:

Repository:

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

Dependency:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-cells</artifactId>
    <version>23.4</version>
</dependency>

After installing and configuring the API successfully, let us proceed to learn the conversion CSV and Excel (XLSX/XLS) file formats.

Convert CSV to Excel XLS in Java

One of the popular use cases for CSV to Excel conversion is when you need to populate some values into a Table in the Excel worksheet. Likewise, the are many possibilities and use cases where you might need to perform this conversion. To keep this simple and easy, let us consider a basic CSV file as an example:

My Data,,,,,,,

Items A,Items B,Items C,Items D,Items E,Items F,Items G,Items H
12,23,33,66,11,87,99,33
23,22,33,77,31,22,45,56
34,11,12,23,22,34,11,12
45,43,54,88,36,45,45,37
65,65,65,65,13,65,9,35
34,22,27,22,32,23,23,32
213,186,224,341,145,276,232,205

Let us follow the steps below to convert a CSV to Excel file:

  1. Initialize LoadOptions class object
  2. Specify FileFormatType as CSV
  3. Instantiate an object of Workbook class
  4. Save the output Excel file

The code snippet below shows how to convert CSV to Excel (XLSX/XLS) using Java:

The screenshot below shows the output Excel file generated with the above code snippet:

Convert Excel CSV

Convert CSV and Excel Online

We also provide an online tool to convert CSV to Excel, which is based on Aspose.Cells. This is a free tool and you can use it without signing up.

Conclusion

Aspose.Cells for Java simplifies the process of converting CSV files to Excel format in your Java applications. Whether you’re working on data manipulation or reporting, this library provides a powerful set of tools for Excel automation.

By following the steps outlined in this blog post, you can quickly integrate Aspose.Cells for Java into your project and perform CSV to Excel conversions effortlessly. This allows you to leverage the power of Excel in managing and presenting your data, making your applications even more versatile and efficient.

However, if you notice any problem with configuration or conversion then please feel free to reach out to us at Free Support Forum. We would love to help you out!

See Also