0

I have a need to generate the received data in excel, however I am facing the problem of accessing a static file on my server

I use NuxtJS + VUE a static Excel file is located in my /static folder

/static/Excel.xlsx
/static/Word.docx

If I try to access via FileReader () then I get the error

  var workBook = new Excel.Workbook();
  workBook.xlsx.readFile("/Excel.xlsx").then(function() {
    const ws = workbook.getWorksheet("Sheet1");
    cell = ws.getCell("A1").value;
    console.log(cell);
  });

Error:

TypeError: Cannot read property 'F_OK' of undefined

This error, as I understood from the discussions, is related to browser security. I would not want to violate the security of the browser and the application to access the file.

The option according to which the user loads the template himself is a little inconvenient, you have to do a lot of unnecessary actions

Link to solution on https://github.com/

at the same time I found a solution for Word using package: docxtemplater - it uses JSZipUtils and the example with Word works fine, however the module for xlsx is very expensive for me

loadFile(url, callback) {
  JSZipUtils.getBinaryContent(url, callback);
},

this.loadFile("/Word.docx", function(error, content) {
      if (error) {
        throw error;
      }
      var zip = new JSZip(content);
      var doc = new Docxtemplater();
      doc.loadZip(zip);
      //... getting data from the database and inserting it into the Word template
    });

Is it possible to somehow use the JSZipUtils package to implement access to Excel? or have another way is it different to get an instance of a static file without violating security?

0 Answers0