Open showlovel opened 11 years ago
add : i try to read the file .
There is no information here to diagnose the issue. Are you reading, writing? What data?
I have this issue as well, with xlsx.js version 2.3.0, whenever I try to read any XLSX file, even those generated by the library itself. For example, I have a script that loads a template and attempts to replace some data by doing:
let inPath = path.resolve('template.xlsx'); console.log('Loading template from ' + inPath); let xlsbook = xlsx(inPath);
This errors with: Error: Corrupted zip : can't find end of central directory at Object.ZipEntries.readEndOfCentral (jszip/jszip-load.js:450:22) at Object.ZipEntries.load (jszip/jszip-load.js:507:15) at Object.ZipEntries (jszip/jszip-load.js:341:15) at Object.JSZip.load (jszip/jszip-load.js:528:20) at xlsx (xlsx.js:54:13)
@velvitonator the xlsx
function takes the content as parameter :
function xlsx(file) {
/// ...
zip = zip.load(file, { base64: true });
This project uses an old version of JSZip (disclaimer : I'm a JSZip contributor) and if you're using nodejs, the native support of Buffer comes with JSZip 2.0. With JSZip 1, you have to use a Uint8Array/ArrayBuffer or (with the base64 = true flag) a base64 encoded string.
Ah, loading the file myself with base64 encoding, then passing it to xlsx does it.
Thanks for the help! =)
@velvitonator could you post how you passed a base64 encoded string into xlsx. I'm fairly new to node.js and am having trouble.
Unfortunately, this was over six months ago and I wound up having to emit pure CSV because the XLSX library would cause the node script to run out of memory while trying to generate all the XML for all the data I had.
Looking back over the issue and jogging my memory, though, the core issue was that the xlsx function takes the file contents, not the path to the file. I believe I wound up doing something like the below, going off of the example I gave above:
let inPath = path.resolve('template.xlsx');
console.log('Loading template from', inPath);
let xlsxbook = xlsx(file.readSync(inPath, {encoding:'base64'}));
Thanks
@velvitonator let
does not work in node.js if not started with the harmony
flag. .resolve
also throws errors in above context if put directly into node.js code.
However using j worked for me. $ npm install j
var J = require('j');
var workbook = J.readFile(FileWithFullPath);
@nottinhill Yes, node needs to be started with --harmony for let. The above code ought to be fine in most contexts with just var, though.
The resolve is also more of a formality, so that the print statement is precise. It's not needed, but It should merely be a matter of require-ing the path module, i.e. require('path').
what can i do?