How to Make Charts in Excel using Node.js

How to Make Charts in Excel using Node.js

Excel file manipulation and conversion to other file formats programmatically offer a competitive edge to business applications. In fact, you can add charts, font styles, and other graphical elements to the XLS/XLSX files using a few lines of source code in any programming language. However, we will use this XLSX JS library to automate this process. In this blog post, we will learn how to make charts in Excel using Node.js programmatically.

We will cover the following points:

XLSX JS library installation

This XLSX JS library can be installed easily without any third-party dependency. However, it lets you either download the API package or install it by running the following commands:

npm install java
npm install aspose.cells

How to Make Charts in Excel using Node.js

Once API is installed, we can move to the next step. Let’s write steps and the code snippet to make charts in Excel using Node.js.

You may follow the following steps:

  1. Create an instance of the Workbook class.
  2. Obtaining the reference of the first worksheet by calling the get(index) method.
  3. Adding sample values to cells by calling the putValue method.
  4. Invoke the add method to add a chart to the worksheet.
  5. Access the instance of the newly added chart by calling the get(index) method.
  6. Call the setChartDataRange method to set the chart data source as the range “A1:C4”.
  7. The save method will save the file in XLSX format.

Copy & paste the following code into your main file:

You can see the output in the image below:

create charts in excel file

Get a Free License

You can avail a free temporary license to try the API without evaluation limitations.

Summing up

We can end this blog post here. We have demonstrated how to make Charts in Excel using Node.js programmatically. In addition, you may navigate to the documentation of this XLSX JS library to know the other provisions & methods. In the coming days, we will come up with other blog posts to create pivot chart in Excel files programmatically. Therefore, please visit conholdate.com for the latest updates.

Ask a question

You can let us know about your questions or queries on our forum.

FAQs

How do I create a Node.js Excel spreadsheet?

You may install this XLSX JS library to create, and process spreadsheets programmatically.

How do I make Excel charts automatically?

Please follow this link to learn how to write the code snippet to create charts in Excel files in Node.js.

See Also