CSV file format is used to save comma-separated values. CSV to Excel conversion is helpful when there are numbers involved in the input data and you need to perform some calculations. Likewise, Excel to CSV conversion is helpful in some scenarios, like serialization of data in some cases. Let us explore the inter-conversion between CSV and Excel file format (XLS or XLSX) in detail using Aspose.Cells for Java API:

CSV to Excel and Excel to CSV Converter API – Installation

In order 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:


    <name>Aspose Java API</name>



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 (XLSX/XLS) using 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

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 Excel (XLSX/XLS) to CSV using Java

Excel (XLSX/XLS) to CSV conversion is also an important use case. As we have created an Excel file already, let us consider it as an input file to proceed with the conversion. This can explain the high fidelity between the conversion of CSV and Excel files that we have converted already. Let us follow the steps below for converting Excel (XLSX/XLS) to CSV using Java.

  1. Load the input Excel file with Workbook constructor
  2. Save output CSV file by specifying the CSV SaveFormat

Following code snippet shows how to convert Excel (XLSX/XLS) to CSV in Java:

After converting the input Excel file, you may compare the output CSV file with the file which was used above in the first example. You will notice the output files are identical to each other. This high fidelity speaks volumes about the efficiency of these file format conversions.


In a nutshell, we have learned how easily we can convert an Excel file to CSV and CSV to Excel with Java. 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