TLDR; I am trying to edit and save an existing excel(.xlsx) file from an electron app.
The app is using webpack so the answer to this question will not work (results in this issue).
Instead I try the following:
import * as exceljs from "exceljs/dist/exceljs.min.js"
import fs from 'fs'
export const openFile = () => {
let workbook = new exceljs.Workbook();
var stream = fs.createReadStream("./app/utils/some_file.xlsx");
stream.pipe(workbook.xlsx.createInputStream());
stream.on('end', function() {
console.log(workbook)
workbook.worksheets.forEach((worksheet, sheetId) => {
console.log(worksheet)
});
});
}
- Note line 1 is a fix for the issue lined above.
The output when console logging the workbook
variable is an object called b.exports
. It does have the structure of the workbook and all meta data (updater, date modified, array of named worksheets) - just no methods that are highlighted in the documentation.
For example the console.log in the workbook.worksheets.forEach
function never runs as there is no workbook.worksheets
!
The documentation on exceljs is not clear to me and issues are not being answered so I hope someone on here can help (that way I can update the documentation on the repo hopefully and help others in future).
So can anyone either explain how I can get the code in the answer to the question above (Modify existing Excel File using node.js) to work with webpack/electron or altenatively, how can I get the code I have to work.