Microsoft Excel is one of the leading and most widely used software in this world of technology. Most organizations leverage this software for various purposes and maintain a huge amount of data in Excel files. In addition, modifying several data files manually is always a hassle. In this blog post, we will learn how to insert rows and columns in Excel files programmatically using Nodejs. However, automating this process will provide efficiency and a competitive edge to the business.
The following points will be covered in this blog post:
- Insert rows and columns in Excel files using Node.js - API installation
- Insert multiple rows in Excel Worksheets Code Example
- Node.js library to insert columns in Excel Sheets
Insert rows and columns in Excel files using Node.js - API installation
We will use a powerful Node.js Excel library to insert rows and columns in an Excel sheet programmatically. You can easily install by running the following commands in the terminal.
npm install java
npm install aspose.cells
You can visit this link to know further about the installation procedure.
Note: A source XLSX file in the project root directory should be placed to test the functionalities.
Insert multiple rows in Excel Worksheets Code Example
In this section, we will go through the following steps and the code snippet to insert rows in an Excel file using Node.js.
- Create an object of the Cells class.
- Load an Excel file(i.e. sample.xlsx) by initializing an object of the WorkBook child class.
- Call the insertRows(rowIndex, totalRows, options) method to insert as many rows as needed anywhere in the worksheet.
- Save the file using the save(fileName) method.
The following code snippet is to insert multiple rows in an Excel Worksheet programmatically.
The output can be seen in the image below.
Node.js library to insert columns in Excel Sheets
This Node.js Excel library offers the provision to add columns in Excel files using simple lines of code.
Following are the steps to insert columns in the Excel worksheet using Node.js.
- Import and create an object of the Cells class.
- Create an object of the WorkBook child class by initializing it with an Excel file.
- Now, invoke the insertColumns(columnIndex, totalColumns) method to insert columns into the Excel worksheet.
- Finally, the save(fileName) method saves the file into the root directory.
Copy and paste the code snippet mentioned below to insert columns in an Excel File programmatically using Node.js.
Now, start the server and you will see the output as shown below in the image.
Get a Free License
You may use a free temporary license to use Aspose.Cells for Node.js without evaluation limitations.
Conclusion
This blog post ends here. We have gone through how to insert rows and columns in Excel files using Node.js. In addition, you can explore the documentation to learn further about Aspose.Cells for Node.js. Moreover, conholdate.com will write on new engaging topics. Therefore, please stay in touch for the latest updates.
Ask a question
In case of any queries please feel free to write to us at the forum.