exceljs: Corrupt xlsx after updating
Hello, great lib, I have an issue with the following code whereby the updated file become corrupt. The val you see in code is a string version of a bool so “true” or “false”, I did hardcode a string as val (“hello”), just to see if it was the bool that caused the issue, but the file still got corrupted. Can you please take a look and see what I may be doing wrong, thanks. If I am able to recover the file, it has the updated value, but my app is no longer able to read the file for subsequent parsing
function updateExcelEntry(inputPage,sheet,colKeyIndex,colIndexToUpdate,rowKey,val){
//console.log("in excel " + inputPage);
var workbook = new Excel.Workbook();
workbook.xlsx.readFile(inputPage).then(function() {
// use workbook
//console.log("getting sheet " + sheet);
var worksheet = workbook.getWorksheet(sheet);
//console.log("getting keyCol " + colKeyIndex);
var keyCol = worksheet.getColumn(colKeyIndex);
keyCol.key = "key";
var col = worksheet.getColumn(colIndexToUpdate);
col.key = "colToUpdate";
worksheet.eachRow(function(row, rowNumber) {
//console.log("checking key val " + row.getCell("key").value);
//console.log("vs rowKey " + rowKey);
if(rowNumber !== 1 && row.getCell("key").value === rowKey){
//console.log("Row " + rowNumber + " = " + JSON.stringify(row.values));
row.getCell("colToUpdate").value = val;
}
});
}).then(function() {
return workbook.xlsx.writeFile(inputPage)
}).then(function() {
console.log("workbook updated " + inputPage);
});
}
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 5
- Comments: 19
I solved the problem by using:
https://www.npmjs.com/package/xlsx-populate
All sorts of small formatting problems simply disappeared. I cannot recommend it enough.
I have same issue. After read the latest comments i make a test. Make a simple script that only read and write on different file.
First test:
Second test:
So something is different in LibreOffice/OpenOffice files.
Nothing here worked as an intended solution for me. Any updates?
Same issue here, using the last version:
I am using it to take an Excel sheet, use it as a template, and change some of the cells programmatically.
I can sadly confirm the problem. Wasted 6 hours on this…
I can confirm that this is happening for any libreoffice-generated xlsx I read and then write (even if no changes are made)
Libreoffice info: