Skip to content

Update an Excel file in node.js

In this post, you will learn how to update a Microsoft Excel spreadsheet in node.js.

Advertisements

We have already seen how to read an excel file in node.js using the npm package XLSX.

We’ve already learnt that each cell content is in json format. A typical cell content in JSON format would look like:

{ t: 'n', v: 0.624907407407407, w: '2:59:52 PM' }

..where t is the type, v is the value and w is the formatted value

To update a cell’s content you need to assign values in this JSON format. Please follow the steps below.

Assign an empty json object to a cell.

if (!sheet2['J2']) 
	sheet2['J2'] = {};

Assign type.

sheet2['J2'].t = "s"; //String
Advertisements

Assign value.

sheet2['J2'].v = "W178263127");

Write the file.

xlsx.writeFile(spreadsheet, "output.xlsx");

See also  How to configure npm with npmrc?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.