Insert Shapes in Excel using Node.js

Insert Shapes in Excel using Node.js

The JavaScript API for Excel lets you add multiple shapes—stars, lines, rectangles, arrows, and more—to worksheets programmatically. This library provides many methods to automate the process, including filling shapes with color and setting their size. In this post we show 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

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

Follow these steps and 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 avail a free temporary license to try the API without evaluation limitations.

Summing up

This concludes the guide. You now know how to insert shapes in Excel using the Node.js Excel library and have seen key features of the JavaScript API for Excel. Use this information to automate shape insertion programmatically. For more details, visit the documentation.

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.

See Also