How do you edit a specific cell in an excel file using JavaScript?
I am trying to do it using ExcelJS but having a hard time in writing to my excel file.
Thanks for the reply I got it working and here is my code.
var Excel = require('exceljs');
var workbook = new Excel.Workbook();
workbook.xlsx.readFile('file.xlsx')//Change file name here or give file path
.then(function() {
var worksheet = workbook.getWorksheet('sheet');
var i=1;
worksheet.eachRow({ includeEmpty: false }, function(row, rowNumber) {
r=worksheet.getRow(i).values;
r1=r[2];// Indexing a column
console.log(r1);
i++;
});
worksheet.getCell('B3').value = "abc";//Change the cell number here
return workbook.xlsx.writeFile('file.xlsx')//Change file name here or give file path
});
I was missing this return statement that saves my edited file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With