You can easily convert Text to Excel programmatically in an efficient way. It is a widespread scenario in which you have a vast amount of data and you need to export it to Excel sheets. Fortunately, you will come across this JS library for Excel with which you can automate Text to Excel conversion easily. In this article, you will see converting text to Excel file in Node.js with this library’s help is no longer a difficult task. However, make sure you have installed Node.js on your machine.
You will go through the following sections:
JS library for Excel installation
The installation procedure of any library matters when it comes to rapid development. Therefore, you may install it by downloading the API package or running the following commands in the terminal.
npm install java npm install aspose.cells
Converting Text to Excel File in Node.js
Now, you are all set to start using the methods exposed by this enterprise-level library. Please follow the steps and the code snippet to implement text to Excel conversion programmatically.
- Instantiating an object of the Workbook class.
- Access the first worksheet by calling the get(index) method.
- Invoke the putValue method to add people’s names in column A. First name and Last name are separated by space.
- Create an instance of the TxtLoadOptions class that represents the options for the loading text file.
- Call the setSeparatorString method to set a string value as a separator.
- Split the column A into two columns using TextToColumns() method.
- Save the workbook in XLSX format by calling the save method.
Copy & paste the following code into your main file:
You can see the output in the image below:
Get a Free License
You can avail a free temporary license to try the API without evaluation limitations.
We are ending this blog post here with the hope you have learned how to achieve text to Excel conversion programmatically. Converting text to Excel file in Node.js is a lightweight task due to this JS library for Excel. However, you can build a module to convert text to columns robustly. Further, please visit the documentation to know the other rich features of this library.
Moreover, we suggest you follow our Getting Started guide.
Finally, conholdate.com is writing new blog posts. Therefore, please stay in touch for regular updates.
Ask a question
You can let us know about your questions or queries on our forum.
How do I write data into an Excel spreadsheet using Node.js?
Please visit this link to know the code snippet that writes text data into the columns of the spreadsheet.