stephen-hardy / xlsx.js

XLSX.js is a JavaScript library for converting the data in base64 XLSX files into JavaScript objects - and back! Please note that this library is licensed under the Microsoft Office Extensible File License - a license NOT approved by the OSI. While this license is based off of the MS-PL, which is OSI-approved, there are significant differences.
http://blog.innovatejs.com/?tag=xlsx-js
Other
575 stars 122 forks source link

Porblem with "Corrupted zip : can't find end of central directory " #11

Open showlovel opened 11 years ago

showlovel commented 11 years ago

what can i do?

showlovel commented 11 years ago

add : i try to read the file .

stephen-hardy commented 11 years ago

There is no information here to diagnose the issue. Are you reading, writing? What data?

velvitonator commented 10 years ago

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)

(I removed the path to xlsx.js on my machine from the message). I have tried with the template I want, a template with everything removed, the default workbook Excel gives when you make a new one, and a workbook generated by xlsx.js in another script of ours. Thoughts?
dduponchel commented 10 years ago

@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.

velvitonator commented 10 years ago

Ah, loading the file myself with base64 encoding, then passing it to xlsx does it.

Thanks for the help! =)

EasyTarget86 commented 9 years ago

@velvitonator could you post how you passed a base64 encoded string into xlsx. I'm fairly new to node.js and am having trouble.

velvitonator commented 9 years ago

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'}));
EasyTarget86 commented 9 years ago

Thanks

wethinkagile commented 9 years ago

@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);
velvitonator commented 9 years ago

@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').