0

I am having trouble trying to read an .xlsx file in my meteor application with xlsx. I tried to do this:

const XLSX = require('xlsx');

/* Makes it possible to use the codes!*/
Template.Planning.onCreated(function() {
    var workbook = XLSX.read('planning.xlsx', {type:'binary'});
    var first_sheet_name = workbook.SheetNames[0];
    var address_of_cell = 'A22';
    /* Get worksheet */
    var worksheet = workbook.Sheets[first_sheet_name];
    /* Find desired cell */
    var desired_cell = worksheet[address_of_cell];
    /* Get the value */
    var desired_value = (desired_cell ? desired_cell.v : undefined);
    console.log(desired_value);
});

The file planning.xlsx is located in the same folder as my Planning.js file. However this code returns undefined, but when I open planning.xlsx, the cell A22 contains the name Dave. What am I doing wrong?

fangio
  • 1,746
  • 5
  • 28
  • 52
  • 1
    As your `Template` indicated you are on the client. The `.xlsx` file should therefore exist in the `public/` directory in order to be a resource, that is made available to the client. See: https://guide.meteor.com/structure.html#special-directories – Jankapunkt Jul 12 '18 at 12:39
  • @fangio Did you solve this? – Cos Mar 10 '19 at 10:32

0 Answers0