Search code examples
meteorxlsx

meteor, write to xlsx-file using xlsx-populate


I am using xlsx-populate to manipulate my files on serverside of my meteor application. The code below is how I try to do it however it gives an error.

writeFile : function(dict){
    XlsxPopulate.fromFileAsync("assets/app/PlanningTemplate.xlsx").
    then(workbook => {
        const sheet = workbook.sheet("Sheet1");
        Object.keys(dict).forEach(function(key) {
            sheet.cell(key).value(dict[key]);
        });
        workbook.toFileAsync("assets/app/PlanningTemplate.xlsx");
    })                  
}

The error is something like this:

unhandledPromiseRejectionWarning: unhandled promise rejection <rejection id: 1>: Error: EPERM: operation not permitted open C:\.....

However I wrote code that reads the file, that works fine, but I can't seem to make it work for writing to the same file.


Solution

  • Basically you shouldn't be trying to write to the file system. When you deploy it to docker image, the file system will be read only, so you have to add a writable volume. It's easier to use a package like Ostrio:files to do file access.

    If you still want to write to your file system, you have to remember that meteor builds the image and runs the server somewhere in .meteor/local... so you should use absolute file paths instead of relative ones.