Insert Shapes in Excel using Node.js

Insert Shapes in Excel using Node.js

The JavaScript API for Excel lets you add shapes—stars, lines, rectangles, arrows, and more—to worksheets programmatically. This library offers methods to automate shape creation, fill colors, and set sizes. This post provides code snippets to insert shapes in Excel using Node.js.

The following points will be covered in this guide:

Insert shapes in Excel using Node.js - API installation

Installing the library is simple. You can either download the API package or run these commands in the terminal:

npm install java
npm install aspose.cells

Insert a Line shape into Worksheet

Follow these steps and use the code snippet to add a line shape to an Excel file programmatically:

  1. Instantiate an instance of the Workbook class.
  2. Access the first worksheet from the collection by calling the get(index) method.
  3. Invoke the addShape method to add the line to the worksheet.
  4. Call the save method to save the file.

Copy & paste the following code into your main file:

You may see the output in the image below:

line shape

Add Rectangle in an Excel file

Similarly, add a rectangle shape using this code snippet:

You may see the output in the image below:

rectangle shape

Insert a Star shape into Worksheet

Use the following snippet to add a star shape with the JavaScript API for Excel:

You may see the output in the image below:

star shape

Add multiplication sign

Use this snippet to add a multiplication sign with the JavaScript API for Excel:

You may see the output in the image below:

multiplication shape

Get a Free License

You can obtain a free temporary license to try the API without evaluation limits.

Summing up

This guide shows how to insert shapes in Excel using the Node.js Excel library and highlights key features of the JavaScript API for Excel. Use this knowledge to automate shape insertion. For more details, see the documentation.

Moreover, we suggest you follow our Getting Started guide.

Finally, visit conholdate.com for new blog posts and 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.

See Also