In this article, I’ll show you how to implement Excel automation and create Excel XLSX or XLS files in Node.js applications.

create excel file in nodejs - logo

Microsoft Excel is a powerful tool for working with data, and it’s often used for various tasks, such as data analysis, reporting, and data visualization. However, there may be scenarios where you need to generate Excel files programmatically, especially when you’re dealing with large datasets or creating dynamic reports. In this blog post, we’ll explore how to create Excel files in Node.js using Aspose.Cells, a versatile and feature-rich library for working with Excel documents.

Node.js Excel Library

Aspose.Cells for Node.js is a popular library for working with Excel files in Node.js. It provides a comprehensive set of features for creating, editing, and manipulating Excel spreadsheets. With the API, you can generate Excel files with a wide range of formatting options, charts, tables, and more. It’s a valuable tool for automating Excel-related tasks and generating dynamic reports.

You can download the library’s package and integrate it into your Node.js application. For more details, you can visit the Installation and Usage guide.

Create Excel File in Node.js

The following are steps to create a simple Excel file in Node.js:

  • Create an instance of Workbook class.
  • Access the desired worksheet from the workbook using Workbook.getWorksheets.get() method.
  • Put the value in the desired cell in the worksheet using the cell’s identifier, such as A1, B3, etc.
  • Save the workbook as an Excel file using Workbook.save() method.

The following code sample shows how to create an Excel file in Node.js.

create excel file in node.js

Update an Excel File in Node.js

You can also load an existing Excel file to update its content. The only thing you’ll have to do is provide the Excel file’s path in the Workbook constructor.

The following code sample shows how to modify the content of an existing Excel file in Node.js.

Insert an Image in Excel Sheet in Node.js

The following are the steps to insert an image in an Excel XLSX/XLS in Node.js.

The following code sample shows how to insert an image in the Excel XLS/XLSX in Node.js.

Insert image in Excel in node.js

Insert Charts in an Excel Sheet

Charts and graphs are important components of Excel files that are used to visually represent the data. Aspose.Cells for Node.js via Java lets you draw and manipulate a variety of charts including sunburst, treemap, histogram, pyramid, etc. The following are the simple steps to draw a chart in the Excel worksheet.

  • Create a new Excel file or load an existing one using Workbook class.
  • Add data to the worksheet as a data source for charts.
  • Access the chart collection of the worksheet using Worksheet.getCharts() method.
  • Add a new chart using Worksheet.getCharts().add() method.
  • Access the newly created chart from the collection in a new variable.
  • Specify the cells’ range to set NSeries for the chart.
  • Save the workbook as an Excel .xlsx file.

The following code sample shows how to create charts in Excel files in Node.js.

insert chart in excel in node.js

Create a Pivot Table in Excel Sheet

Excel files also allow you to create pivot tables based on a range of cells to summarize a large amount of data. The following are the steps to create a pivot table within an Excel worksheet.

  • Create a new Workbook or load an existing excel file.
  • Insert data into the worksheet (optional).
  • Access the pivot table collection using Worksheet.getPivotTables() method.
  • Add a new pivot table in the worksheet using Worksheet.getPivotTables().add() method.
  • Provide data to the pivot table.
  • Save the workbook as Excel file.

The following code sample shows how to create a pivot table in Excel in Node.js.

create pivot table in excel in node.js

Online Excel Editor

We also provide an online Excel editor for you to create and edit Excel files. You can use this powerful spreadsheet editor without creating an account.

Get Free Node.js Excel Library

You can generate Excel files in Node.js for free without evaluation limitations using a free temporary license.

Conclusion

Aspose.Cells is a powerful library for creating and working with Excel files in Node.js. Whether you’re generating reports, automating data processing, or creating dynamic spreadsheets, Aspose.Cells provides the tools you need. This blog post has given you a basic introduction to creating Excel files in Node.js, but there’s much more you can explore and achieve with the Node.js Excel library. You can learn more about the advanced features of Aspose.Cells for Node.js using the documentation.

See Also