Convert CSV into Excel using Node.js

CSV to Excel Node.js

Recently, we have published a blog post that is about how to import XML into Excel programmatically using Node.js. However, in this article, we will learn how to convert CSV into Excel using an enterprise-level Node.js library. A CSV(comma separated values) format represents a plain text file that maintains content with comma-separated values. Moreover, Excel comes with rich data storage, and management features and is backed by Microsoft. So, we will learn how to convert CSV into Excel using Node.js by covering the following points:

How to convert CSV to XLSX

In this section, we will go through the pre-requisites, classes, and member functions exposed by Aspose.Cells for Node.js application.

Please visit our previous tutorial blog post in which we have mentioned the setting up process of Aspose.Cells on the local machine.

We will follow the following steps to complete the workflow:

  1. Create an object of the Cells class.
  2. Require the fs module to create a read stream of the source file.
  3. Create an object of the Workbook class that generates an Excel spreadsheet.
  4. Get the cells object of a particular worksheet using the getCells() method.
  5. Then we will call this method importCSVFromStream(cells, stream, spliter, convertNumericData, firstRow, firstColumn, callback) that accepts file data stream along with other options to convert CSV file to Excel.
  6. Finally, save(fileName) will save the file into the root directory.

Node.js library to convert CSV into Excel

Now, open your main server file and paste the following code. You need to place your source CSV file as I have the source file ‘sample.csv’ placed in the root directory.

After that, start your server and you will find an Excel file named ‘result.xlsx’ saved in the root of your directory. However, you can see the output in the image below.

Import XML into Excel in Node.js

Import XML data into Excel Spreadsheet

Get a Free License

You always have the chance to use a free temporary license to use Aspose.Cells for Node.js without evaluation limitations.

Conclusion

This is the end of this blog post. We have gone through the steps and code sample to convert CSV into Excel using Node.js programmatically. In addition, you can further explore the classes and methods used to convert CSV to XLSX. Moreover, there are some relevant links mentioned in the ‘See Also’ section below. Therefore, it is high time to opt for Aspose.cells if you are looking to install a CSV to Excel Node.js library for your business application. Further, conholdate.com is continuously writing on new interesting topics. Therefore, please stay connected for regular updates.

Ask a question

Feel free to visit our forum which is very active to respond to questions and queries/discussions.

See Also