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?
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.
You don't say! I will definitely check that later, there is a good chance I had it open when running the process!
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"
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.
@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!
@SheetJSDev Would Buffer.isBuffer work on augmented Buffers?
@Mithgol That's one approach, but I'm leaning towards tweaking the CFB parser to add a unique field and check for that.
@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