Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while using xslx readFile method #163

Closed
ghost opened this issue Aug 3, 2016 · 4 comments
Closed

Error while using xslx readFile method #163

ghost opened this issue Aug 3, 2016 · 4 comments

Comments

@ghost
Copy link

ghost commented Aug 3, 2016

var spans = node.attributes.spans.split(':').map(function(span) { return parseInt(span); });
                                       ^

TypeError: Cannot read property 'split' of undefined
    at utils.inherits.parseOpen (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/lib/xlsx/xform/sheet/row-xform.js:97:40)
    at utils.inherits.parseOpen (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/lib/xlsx/xform/list-xform.js:71:31)
    at utils.inherits.parseOpen (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/lib/xlsx/xform/sheet/worksheet-xform.js:109:19)
    at SAXStream.<anonymous> (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/lib/xlsx/xform/base-xform.js:65:14)
    at emitOne (events.js:77:13)
    at SAXStream.emit (events.js:169:7)
    at Object.me._parser.(anonymous function) [as onopentag] (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/node_modules/sax/lib/sax.js:245:15)
    at emit (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/node_modules/sax/lib/sax.js:615:33)
    at emitNode (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/node_modules/sax/lib/sax.js:620:3)
    at openTag (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/node_modules/sax/lib/sax.js:801:3)
    at Object.write (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/node_modules/sax/lib/sax.js:1181:11)
    at SAXStream.write (/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/node_modules/sax/lib/sax.js:227:16)
    at Entry.ondata (_stream_readable.js:542:20)
    at emitOne (events.js:77:13)
    at Entry.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:153:18)

In node 6.3.1 I get an additional error:

(node:2898) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.

The error disappears if I use the LTS version (4.4.7)
This is my code:

var Excel = require('exceljs');

var workbook = new Excel.Workbook();
var filename = 'test.xlsx';

workbook.xlsx.readFile(filename).then(function () {

});

Is there a way to fix this?

@petitcl
Copy link

petitcl commented Aug 5, 2016

I had the same issue than you. I was able to 'fix' it by manually editing the /lib/xlsx/xform/sheet/row-xform.js file and replacing the line 95 with the following:
var spans = node.attributes.spans ? node.attributes.spans.split(':').map(function(span) { return parseInt(span); }) : [];

Unfortunately, the content of the variable spans is used several lines below and since it's empty, it might cause issues that I am not aware of.

@ghost
Copy link
Author

ghost commented Aug 6, 2016

Thanks for the workaround, apparently it is failing at the last element because it is always undefined (apparently). Istead of asigning it to an empty array, I assigned it to the last not-undefined value, which is just [57, 67]

      var spans = node.attributes.spans ? node.attributes.spans.split(':').map(function(span) { return parseInt(span); }) : [57, 67];

After doing that, another error appeared, which is this one:

/home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/lib/xlsx/xform/style/border-xform.js:101
          this.model.color = this.map.color.model;
                           ^

TypeError: Cannot set property 'color' of undefined

Fixed it with yet another workaround (damn it)...
Changed that part from this:

if (this.map.color.model) {
    this.model.color = this.map.color.model;
}

to this

if (this.map.color.model && this.model) {
    this.model.color = this.map.color.model;
}

But still, another error appeared sigh

Unhandled rejection TypeError: Cannot read property 'workbookViewId' of undefined
    at /home/carmelo12341/dev/nodejs/excel/node_modules/exceljs/lib/xlsx/xform/book/workbook-xform.js:184:41

After some console.logs, I discovered that those lines aren't important, simply commenting them or deleting them will fix that error. This ones (around line 181)

// reconcile bookViews
    _.each(model.worksheets, function(sheet) {
      _.each(sheet.views, function(view) {
        var bookView =  model.views[view.workbookViewId];
        _.extend(view, bookView);
        delete view.workbookViewId;
      });
    });

I don't like workarounds and maybe what I did broke something but for now, it works! Maybe it was just an additional loop somewhere in this code, but this code changes fixed all the issues (for now) and... I'm happy with it.
I would appreciate if guyonroche fix this, someday. And also add some more examples in the docs (just saying)
c:

guyonroche added a commit that referenced this issue Oct 24, 2016
Fix issue #163: the "spans" attribute of the row element is optional
@guyonroche
Copy link
Collaborator

Arturas' PR is now published in 0.2.31 - this should fix this issue.

@arturas-vitkauskas
Copy link

I believe the issue #186 should also be closed as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants