TypeError !CompObj is not a function #504

Closed
opened 2016-11-19 09:48:51 +00:00 by JanSchuermannPH · 8 comments
JanSchuermannPH commented 2016-11-19 09:48:51 +00:00 (Migrated from github.com)

Getting the above error with the following code:

Excel = require('xlsjs')
try
   workbook = Excel.readFile(uploadPath)
   console.log(workbook)
catch e
   console.log(e)

Also when I try the official demo with the same file, the error pops up in the console.
The file is not corrupted and it happens with all files of the same type.

Any ideas?

Getting the above error with the following code: ``` Excel = require('xlsjs') try workbook = Excel.readFile(uploadPath) console.log(workbook) catch e console.log(e) ``` Also when I try the official demo with the same file, the error pops up in the console. The file is not corrupted and it happens with all files of the same type. Any ideas?
chaostheory commented 2016-11-30 18:07:26 +00:00 (Migrated from github.com)

Is the file that you're trying to process with SheetsJS already opened in MS Excel? If so, close the file in Excel and try again. I only get that error if it's already open in Excel and I try doing something to the same excel file in SheetsJS.

Is the file that you're trying to process with SheetsJS already opened in MS Excel? If so, close the file in Excel and try again. I only get that error if it's already open in Excel and I try doing something to the same excel file in SheetsJS.
JanSchuermannPH commented 2016-11-30 18:08:45 +00:00 (Migrated from github.com)

You don't say! I will definitely check that later, there is a good chance I had it open when running the process!

You don't say! I will definitely check that later, there is a good chance I had it open when running the process!
chaostheory commented 2016-11-30 18:15:23 +00:00 (Migrated from github.com)

Probably should open a new request for an addition to the error message like "TypeError !CompObj is not a function. Is the file open by MS Excel"

Probably should open a new request for an addition to the error message like "TypeError !CompObj is not a function. Is the file open by MS Excel"
Mithgol commented 2017-01-23 16:46:03 +00:00 (Migrated from github.com)

Somehow TypeError !CompObj is not a function might also disappear if an Excel file is resaved by LibreOffice (File → Save a copy).

Here's a ZIP attachment containing Santek.xls (which causes such TypeError) and Santek_LO.xls (resaved from LibreOffice, does not cause any errors).

There's also a visible difference in size: Santek.xls is 5939 bytes while Santek_LO.xls is 17920 bytes.

That Santek.xls might serve as a sample for anyone willing to debug such TypeError's original cause.

Somehow `TypeError !CompObj is not a function` might also disappear if an Excel file is resaved by LibreOffice (File → Save a copy). Here's [a ZIP attachment](https://github.com/SheetJS/js-xlsx/files/724289/Santek.zip) containing `Santek.xls` (which causes such TypeError) and `Santek_LO.xls` (resaved from LibreOffice, does not cause any errors). There's also a visible difference in size: `Santek.xls` is 5939 bytes while `Santek_LO.xls` is 17920 bytes. That `Santek.xls` might serve as a sample for anyone willing to debug such TypeError's original cause.
SheetJSDev commented 2017-02-04 22:18:14 +00:00 (Migrated from github.com)

@JanSchuermannPH @chaostheory @Mithgol thanks for the followup!

This is a pre-BIFF5 XLS file. The error is coming because of a change in nodejs behavior :/

Long story short, in the actual parse_xlscfb function https://github.com/SheetJS/js-xlsx/blob/master/bits/81_xls.js#L630 the expected input data is either a CFB container or an augmented Buffer. The code checks if the data is a buffer by searching for the find key:

https://github.com/SheetJS/js-xlsx/blob/master/bits/81_xls.js#L635

As it turns out, node later added Buffer.find:

$ for i in 0.8 0.10 0.12 4. 5. 6. 7.; do sudo n $i; echo $(node --version) $(node -pe 'new Buffer(3).find'); done
v0.8.28 undefined
v0.10.48 undefined
v0.12.18 undefined
v4.7.3 [Function: find]
v5.12.0 [Function: find]
v6.9.5 [Function: find]
v7.5.0 [Function: find]

So the first fix is to change how the data is tested. There are probably more missing records that need to be supported, but thanks @Mithgol for providing a sample!

@JanSchuermannPH @chaostheory @Mithgol thanks for the followup! This is a pre-BIFF5 XLS file. The error is coming because of a change in nodejs behavior :/ Long story short, in the actual `parse_xlscfb` function https://github.com/SheetJS/js-xlsx/blob/master/bits/81_xls.js#L630 the expected input data is either a CFB container or an augmented Buffer. The code checks if the data is a buffer by searching for the `find` key: https://github.com/SheetJS/js-xlsx/blob/master/bits/81_xls.js#L635 As it turns out, node later added Buffer.find: ```sh $ for i in 0.8 0.10 0.12 4. 5. 6. 7.; do sudo n $i; echo $(node --version) $(node -pe 'new Buffer(3).find'); done v0.8.28 undefined v0.10.48 undefined v0.12.18 undefined v4.7.3 [Function: find] v5.12.0 [Function: find] v6.9.5 [Function: find] v7.5.0 [Function: find] ``` So the first fix is to change how the data is tested. There are probably more missing records that need to be supported, but thanks @Mithgol for providing a sample!
Mithgol commented 2017-02-04 23:18:12 +00:00 (Migrated from github.com)

@SheetJSDev Would Buffer.isBuffer work on augmented Buffers?

@SheetJSDev Would [`Buffer.isBuffer`](https://nodejs.org/docs/latest/api/buffer.html#buffer_class_method_buffer_isbuffer_obj) work on augmented Buffers?
SheetJSDev commented 2017-02-04 23:39:22 +00:00 (Migrated from github.com)

@Mithgol That's one approach, but I'm leaning towards tweaking the CFB parser to add a unique field and check for that.

@Mithgol That's one approach, but I'm leaning towards tweaking the CFB parser to add a unique field and check for that.
SheetJSDev commented 2017-02-10 19:46:23 +00:00 (Migrated from github.com)

@chaostheory newer versions of excel are not capable of generating BIFF2-4 files. They use a newer format (BIFF5 or BIFF8) which is why re-saving the file seems to fix the issue.

@JanSchuermannPH @Mithgol as part of this fix, we also added direct BIFF2 exports and filled some missing record types. The updated write script generates an xls file compatible with Excel 2.0

@chaostheory newer versions of excel are not capable of generating BIFF2-4 files. They use a newer format (BIFF5 or BIFF8) which is why re-saving the file seems to fix the issue. @JanSchuermannPH @Mithgol as part of this fix, we also added direct BIFF2 exports and filled some missing record types. The updated write script generates an xls file compatible with Excel 2.0
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#504
No description provided.