
Insert Shapes in Excel using Node.js
This JavaScript API for Excel enables you to add multiple shapes in Worksheets programmatically. Shapes such as stars, lines, rectangles, arrows, and many others. This library offers a wide range of methods to automate this whole process. In addition, you may fill the shapes with colors and configure their sizes depending upon your requirements. In this blog post, we will write the code snippets to insert shapes in Excel using Node.js Excel library.
The following points will be covered in this guide:
- Insert shapes in Excel using Node.js - API installation
- Insert a Line shape into Worksheet
- Add Rectangle in an Excel file
- Insert a Star shape into Worksheet
- Add multiplication sign
Insert shapes in Excel using Node.js - API installation
The installation process of this library is simple. You can either download the API package or install it by running the following commands into the terminal:
npm install java
npm install aspose.cells
Insert a Line shape into Worksheet
You may follow the steps and the code snippet to add a line shape into an Excel file programmatically:
- Instantiate an instance of the Workbook class.
- Access the first worksheet from the collection by calling the get(index) method.
- Invoke the addShape method to add the line to the worksheet.
- Call the save method to save the file.
Copy & paste the following code into your main file:
var fs = require('fs'); | |
var aspose = aspose || {}; | |
aspose.cells = require("aspose.cells"); | |
// Instantiate an instance of the Workbook class | |
var workbook = new aspose.cells.Workbook(); | |
// Access first worksheet from the collection by calling the get(index) method | |
var sheet = workbook.getWorksheets().get(0); | |
// Invoke the addShape method to add the line to the worksheet | |
sheet.getShapes().addShape(aspose.cells.MsoDrawingType.LINE, 2, 0, 2, 0, 100, 300);//method 1 | |
// Call the save method to save the file | |
workbook.save("sample2.xlsx", aspose.cells.SaveFormat.XLSX); |
You may see the output in the image below:

Add Rectangle in an Excel file
Similarly, we can add a rectangle shape by following the code snippet:
var fs = require('fs'); | |
var aspose = aspose || {}; | |
aspose.cells = require("aspose.cells"); | |
// Instantiate an instance of the Workbook class | |
var workbook = new aspose.cells.Workbook(); | |
// Access first worksheet from the collection by calling the get(index) method | |
var sheet = workbook.getWorksheets().get(0); | |
// Add the rectangle to the worksheet by calling the addShape method | |
var shapes = sheet.getShapes().addShape(aspose.cells.MsoDrawingType.RECTANGLE, 2, 0, 2, 0, 100, 300); | |
// Save the file. https://reference.aspose.com/cells/nodejs/Workbook#save | |
workbook.save("sample3.xlsx", aspose.cells.SaveFormat.XLSX); |
You may see the output in the image below:

Insert a Star shape into Worksheet
Follow the code snippet to add a star sign using this JavaScript API for Excel:
var fs = require('fs'); | |
var aspose = aspose || {}; | |
aspose.cells = require("aspose.cells"); | |
// Instantiate an instance of the Workbook class | |
var workbook = new aspose.cells.Workbook(); | |
// Access first worksheet from the collection by calling the get(index) method | |
var sheet = workbook.getWorksheets().get(0); | |
// Add the star shape to the worksheet by calling the addShape method | |
sheet.getShapes().addAutoShape(aspose.cells.AutoShapeType.STAR_5, 2, 0, 2, 0, 100, 100); | |
// Save the file. https://reference.aspose.com/cells/nodejs/Workbook#save | |
workbook.save("sample5.xlsx", aspose.cells.SaveFormat.XLSX); |
You may see the output in the image below:

Add multiplication sign
Follow the code snippet to add a star sign using this JavaScript API for Excel:
var fs = require('fs'); | |
var aspose = aspose || {}; | |
aspose.cells = require("aspose.cells"); | |
// Instantiate an instance of the Workbook class | |
var workbook = new aspose.cells.Workbook(); | |
// Access first worksheet from the collection by calling the get(index) | |
var sheet = workbook.getWorksheets().get(0); | |
// Add the multiplication shape to the worksheet by calling the addShape method | |
sheet.getShapes().addAutoShape(aspose.cells.AutoShapeType.MATH_MULTIPLY, 2, 0, 2, 0, 100, 100); | |
// Save the file. https://reference.aspose.com/cells/nodejs/Workbook#save | |
workbook.save("sample4.xlsx", aspose.cells.SaveFormat.XLSX); |
You may 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.
Summing up
This brings us to the end of this blog post. You have gone through how to insert shapes in Excel using Node.js Excel library. In addition, you have gone through some prominent features of this JavaScript API for Excel. Moreover, this blog post will really help you if you are looking to automate this process programmatically. However, do not forget to visit the documentation to know other features.
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.
FAQs
How do I insert multiple shapes into Excel?
Please follow this link to know the code snippet that helps you add various shapes in Excel files programmatically.