简体   繁体   中英

how to insert a data to a cell of excel sheet from nodejs

I tried the below code for updating a data in a cell of excel sheet. The json is getting updated but the cell of that excel sheet is not getting updated with the new value. Should we do some write to excel file some codes. Can someone help me for the same

const XLSX = require('xlsx');
let workbook = XLSX.readFile('test1.xlsx');
let sheetName = workbook.SheetNames[0];
//console.log(sheetName+'    sheetName')
let worksheet = workbook.Sheets[sheetName];
console.log(JSON.stringify(worksheet['A2']))
var status =worksheet['A2'].v;
worksheet['A2'].v = 'test'
worksheet['A2'].r = 'test'
worksheet['A2'].h = 'test'
worksheet['A2'].w = 'test'
console.log(worksheet['A2'].v)
console.log(JSON.stringify(worksheet['A2']))

If you want your excel file to be updated, you need to update it. I would recommend reading the documentation .

Although, you are looking for writeFile .

XLSX.writeFile(workbook, 'out.xlsb');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM