I have a xlsm file with few data already in it and need to write some data and create a new xlsm file during automation. With below code the file gets created , but it becomes corrupt and unable to open. File size reduces, for ex from 8kb to 7kb. Not sure what is getting missed while writing the file.
var Excel = require('exceljs');
var workbook = new Excel.Workbook();
workbook.xlsx.readFile('Book.xlsm')
.then(function () {
var worksheet = workbook.getWorksheet(1);
var row = worksheet.getRow(1);
console.log(row.getCell(1).value + " - First value"); // Get A1 value
row.getCell(3).value = "c"; //Set value to A3
row.commit();
return workbook.xlsx.writeFile('new.xlsm');
})
Note : Just created Book.xlsm with some value columns a,b and values 1,2. Trying to set A3 with 'c' and save as new.xlsm
If there are any other npm package which doesn't have this problem also would be great.