CSV format is widely used to import or export large datasets from one application to another. However, in some cases, you may need to convert CSV files to Excel XLSX or XLS. Likewise, vice versa can also be required in certain scenarios. In accordance with that, this article covers how to convert CSV to Excel and Excel to CSV format programmatically in Node.js.
- Node.js CSV to Excel or Excel to CSV Converter
- Convert CSV to XLSX or XLS in Node.js
- Convert XLSX or XLS to CSV in Node.js
- Get a Free API Licence
Node.js CSV to Excel or Excel to CSV Converter
For back and forth conversion of CSV and Excel formats, we’ll use Aspose.Cells for Node.js via Java. It is a powerful and feature-rich API for the manipulation of spreadsheet formats from within the Node.js applications. You can either download the API’s package or install it using the following NPM command.
> npm install aspose.cells
Convert CSV to XLSX or XLS in Node.js
The following are the steps to convert a CSV file to Excel XLSX or XLS.
- Create an object of LoadOptions class and initialize it with FileFormatType.CSV.
- Create an object of the Workbook class to load the CSV file.
- Convert CSV to XLSX using Workbook.save(String , SaveFormat.XLSX) method.
The following code sample shows how to convert CSV to Excel XLSX in Node.js.
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
CSV to Excel
Convert XLSX or XLS to CSV in Node.js
The following are the steps to convert XLSX or XLS file to CSV in Node.js.
- Create an object of the Workbook class to load the XLSX file.
- Convert XLSX file to CSV using Workbook.save(String , SaveFormat.CSV) method.
The following code sample shows how to convert Excel XLSX or XLS to CSV.
Get a Free API License
In order to use the API without evaluation limitations, you can request a free temporary license.
In this article, you have learned how easy it is to convert CSV to Excel or Excel to CSV in Node.js applications. You can explore more about the Node.js Excel API using the documentation. In case you would have any queries, feel free to let us know via our forum.