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: Corrupted zip : can't find end of central directory #35

Closed
remotevision opened this issue Oct 21, 2013 · 38 comments
Closed

Error: Corrupted zip : can't find end of central directory #35

remotevision opened this issue Oct 21, 2013 · 38 comments

Comments

@remotevision
Copy link

remotevision commented Oct 21, 2013

EDIT: if you encounter this issue, confirm you are using the latest version and that you are using the correct input type! See https://github.com/sheetjs/sheetjs#input-type

For example, using a FileReader with readAsArrayBuffer will call the load event where the result is an ArrayBuffer, so type should be "array"

If data is received through an XHR or fetch, verify that the source data is not UTF8-encoded. Some platforms like AWS Gateway API do this automatically and require an override as explained in the function demo

--

I am trying to use this library to parse a base64 encoded .xslx file on the server using node.js. I have also removing the base64 header info and loading the data into a binary buffer, but I get the same error.

Here is my function to parse the file:

var parseFile = function(data){
  var xlsx = XLSX.read(data, {type: 'base64'});
  var sheet_name_list = xlsx.SheetNames;
  xlsx.SheetNames.forEach(function(y) {
    for (z in xlsx.Sheets[y]) {
      if(z[0] === '!') continue;
      console.log(y + "!" + z + "=" + JSON.stringify(xlsx.Sheets[y][z].v));
    }
  });
};

However, when I try to parse the data, I get the following error.

Error: Corrupted zip : can't find end of central directory
        at Object.ZipEntries.readEndOfCentral (/Users/.../node_modules/xlsx/jszip.js:2087:27)
        at Object.ZipEntries.load (/Users/.../node_modules/xlsx/jszip.js:2104:18)
        at Object.ZipEntries (/Users/.../node_modules/xlsx/jszip.js:2010:18)
        at Object.JSZip.load (/Users/.../node_modules/xlsx/jszip.js:2115:22)
        at Object.JSZip (/Users/.../node_modules/xlsx/jszip.js:5:14)
        at Object.readSync [as read] (/Users/.../node_modules/xlsx/xlsx.js:940:24)
        at parseFile (/Users/.../routes/tickets.js:35:19)

any thoughts as to why this might be happening? When I load my file into your demo site, it parses it to json just fine.

@SheetJSDev
Copy link
Contributor

@remotevision any updates?

@SheetJSDev
Copy link
Contributor

@remotevision I'm going to close this for now. If you can reproduce this problem, please comment and reopen the issue.

@nox0311
Copy link

nox0311 commented Feb 26, 2014

i too have the same issue

@SheetJSDev
Copy link
Contributor

@nox0311 can you share a file that triggers the error?

@SheetJSDev SheetJSDev reopened this Feb 26, 2014
@nox0311
Copy link

nox0311 commented Mar 3, 2014

hey i got a solution to this issue.....
we get this error if app uses excel file which are created by any other application other than Microsoft Excel...
for eg: if we create an excel file using .net applications the we encounter such erros since the header is different as to which is Set by MicrosoftExcel...
We wont get this error if excel files used are created by MS excel

@SheetJSDev
Copy link
Contributor

@nox0311 Excel really doesn't care about the file extension. It looks at the content to determine how to parse. To see this, you can take a CSV file, rename as XLSX, and try to open in excel.

Two things:

  1. Can you try with js-xls ( https://github.com/SheetJS/js-xls ) and see if it parses there?

  2. Can you open the file with wordpad or notepad and see if the file is actually a CSV?

@nox0311
Copy link

nox0311 commented Mar 5, 2014

i tried parsing that file using the js-xls module mentioned above and it gives an error as:
"unsupported file";
and that file can be opened with notepad and i can see the data clearly there

@SheetJSDev
Copy link
Contributor

@nox0311 Is it a CSV or TSV or HTML file? (also can you send me a copy?)

@nox0311
Copy link

nox0311 commented Mar 5, 2014

i tried another file which was created by c#.net application and still it was parsed properly. but when opened with notepad it gave random symbols.

@nox0311
Copy link

nox0311 commented Mar 5, 2014

@SheetJSDev the file i m using has some sensitive info of organisation i m working in so wont be able to send u a copy....
i m trying to figure out a way to parse these files and will let u know if i arrive at some solution

@SheetJSDev
Copy link
Contributor

@nox0311 I understand :) If you open the file in notepad, what are the first five characters?

  • If you see PK followed by some junk, then it's a zip file
  • If you see binary, it's likely to be an XLS file
  • If you see <? or <W then it's most likely a xml workbook
  • If you just see your data in plaintext, then it's most likely a CSV or TSV file. See if there are commas.

@nox0311
Copy link

nox0311 commented Mar 5, 2014

the file which i m using shows data as plaintext in notepad but gives error "Unsupported File" when used with xls module.
it has extension .xls and this file is created by an application other than MS Excel.

i created another file "demo.xls" in MS Excel and copied all the data from above file in demo.xls .
this file parses easily.

so the conclusion I come to is that Files which are created by MSExcel are parsed easily.

@SheetJSDev
Copy link
Contributor

@nox0311 re-read #35 (comment)

Excel really doesn't care about the file extension. It looks at the content to determine how to parse. To see this, you can take a CSV file, rename as XLSX, and try to open in excel.

You should use a CSV or TSV parser for the file.

There is an attempt at a unified parser https://github.com/SheetJS/j for all formats, but right now it only supports 5: http://sheetjs.com/status/

Since this doesn't directly relate to the XLSX or related formats, I'm going to close the issue here but open a related issue in the relevant project

@cristiandley
Copy link

Im having the same issue trying to parse a .xls file. It Promt

Error: Corrupted zip : can't find end of central directory

I download the file from a website made on .net (aspx)

frostfang referenced this issue in frostfang/gf-proxy Jul 2, 2015
@fitnr
Copy link

fitnr commented Nov 17, 2015

I'm getting this with xlsx@0.7.12 in node versions 0.12.4 and 4.2.1: Error: Corrupted zip : can't find end of central directory

The file I'm getting the error with is here: http://www1.nyc.gov/assets/finance/downloads/pdf/rolling_sales/neighborhood_sales/staten_island_sales_prices.xls

The file is binary, and works fine in Excel.

@stasyaner
Copy link

I'm getting this with xlsx with dates

@Raghavendra22g
Copy link

Hi I was also facing similar issue, while importing .xlsx file "Error: Corrupted zip : can't find end of central directory" .. I tried following which solved the issue. ''result'' is the file input and truncate the format.
var data = result.toString().replace("data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,", "");
data = data.toString().replace("data:text/xlsx;base64,", "");
$window.xlsx(data); // call the library now..

Since I used excel-builder.js to generate the file. I modified some part xlsx.js library to element styling.

Its working for me well .
Thank You

@jetpackdata
Copy link

anybody has a proper fix for this ? Any chance we could reopen this ticket ?

@cicerohen
Copy link

cicerohen commented Oct 25, 2016

@shankararul I'm having the same problem: Corrupted zip : can't find end of central directory

@jetpackdata
Copy link

Hey @cicerohen, i kind of figured out a workaround in this error - http://stackoverflow.com/a/36261090/786326 (Hope it helps)

@cicerohen
Copy link

@shankarul this error occurred for me why in my function I tried execute readFile(filePath) before the readStream(filePath) end.

@Mwaiwathu
Copy link

I have a similar issue but with parsing docx... Passing the same path by one method ie a string creates the error whilst using another drag drop API works weird

@SheetJSDev
Copy link
Contributor

The input type has to match the specified type, as explained in the input type table.

@FlyerJay
Copy link

i have got the same issue ,Corrupted zip : can't find end of central directory
im sure this file can open with ms excel

@SheetJSDev
Copy link
Contributor

@FlyerJay if you can reproduce the issue in the live demo then it's a bug in the parsing logic and we would love to see an offending file. You can email it to us or attach to a reply here.

If you cannot reproduce the issue in the demo, then there's an issue in your integration code and we would need to see a code snippet to advise further.

@FlyerJay
Copy link

error.xlsx

@SheetJSDev
Copy link
Contributor

@FlyerJay http://oss.sheetjs.com/js-xlsx/ reads the file:

screen shot 2017-04-20 at 00 01 02

This is the full output: https://hastebin.com/zopiresadu.http

My guess is that you are either using an older version or your integration code is not correct. Can you check if the version is 0.9.11? console.log(XLSX.version) somewhere in your code

@FlyerJay
Copy link

thank you!!i know where the problem is

@jeevanhr7
Copy link

i am also facing the same issue

@bennettluo
Copy link

@SheetJSDev Hey, I still have the same issue while reading extremely large excel (over than 20Mb, xlsx), I tried to use node stream to handle each chunk because it cannot figure out the sheet results by using XLSX.readFile directly, but it doens't work for that. Could you give me some advices?

@PedramMarandi
Copy link

PedramMarandi commented May 28, 2019

After 6 years there is no solution to this problem 👯
I'm facing with the same issue, I'm trying to read Buffer but I get the below exception

Error: Corrupted zip : can't find end of central directory",
            "    at ZipEntries.readEndOfCentral (/Users/pedromarandi/projects/replenishment/node_modules/xlsx/jszip.js:2281:19)",
            "    at ZipEntries.load (/Users/pedromarandi/projects/replenishment/node_modules/xlsx/jszip.js:2343:14)",
            "    at new ZipEntries (/Users/pedromarandi/projects/replenishment/node_modules/xlsx/jszip.js:2167:14)",
            "    at JSZipSync.module.exports [as load] (/Users/pedromarandi/projects/replenishment/node_modules/xlsx/jszip.js:580:18)",
            "    at new JSZipSync (/Users/pedromarandi/projects/replenishment/node_modules/xlsx/jszip.js:527:14)",
            "    at read_zip (/Users/pedromarandi/projects/replenishment/node_modules/xlsx/xlsx.js:20267:24)",
            "    at Object.readSync [as read] (/Users/pedromarandi/projects/replenishment/node_modules/xlsx/xlsx.js:20335:69)",
            "    at read (/Users/pedromarandi/projects/replenishment/src/lib/sheetUtils.js:23:15)",
            "    at _callee$ (/Users/pedromarandi/projects/replenishment/src/lib/validations/validatePurchaseOrderFile.js:28:21)",
            "    at tryCatch (/Users/pedromarandi/projects/replenishment/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)",
            "    at Generator.invoke [as _invoke] (/Users/pedromarandi/projects/replenishment/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:22)",
            "    at Generator.prototype.(anonymous function) [as next] (/Users/pedromarandi/projects/replenishment/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)",
            "    at asyncGeneratorStep (/Users/pedromarandi/projects/replenishment/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)",
            "    at _next (/Users/pedromarandi/projects/replenishment/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)",
            "    at process._tickCallback (internal/process/next_tick.js:68:7)"```

@hlynurl
Copy link

hlynurl commented Jun 23, 2019

I am having this problem. I cannot read any excel files from buffers anymore.

@SheetJSDev
Copy link
Contributor

@PedramMarandi @hlynurl at this point it's most likely a corruption issue somewhere else. To check:

  • Write the buffer to file and see if you can open it in Excel
  • actually log Buffer.isBuffer(data) and confirm you are dealing with a buffer

@hlynurl
Copy link

hlynurl commented Jun 24, 2019

@SheetJSDev thank you for your advice.

I have confirmed I am dealing with a buffer. This is not something that happened while writing new code. This is all of a sudden happening in my codebase which worked fine before on the exact same files. I even have an app in production working fine which was deployed from my last commit but if I clear all changes and revert back to that commit this still happens.

  • I suspect this has something to do with .DS_Store files on my mac so I have tried to delete them but this is still happening.
  • I have tried to remove all node modules and re-install few times.
  • ... do you have any other ideas?

@mwangiKibui
Copy link

i solved mine by changing the editor

@bertrandmartel
Copy link

For me I had the same error when the input file was protected by a password

@hutao96
Copy link

hutao96 commented Sep 14, 2021

can not work with xlsx, just xls can be use
Error: Corrupted zip : can't find end of central directory
at u.readEndOfCentral (xlsx.core.min.js:2)
at u.load (xlsx.core.min.js:2)
at new u (xlsx.core.min.js:2)
at n.r.exports [as load] (xlsx.core.min.js:2)
at new n (xlsx.core.min.js:2)

@SheetJSDev
Copy link
Contributor

@hutao96 please raise a new issue and include some details like the actual read call and how the data is obtained

@SheetJS SheetJS locked and limited conversation to collaborators Sep 14, 2021
@SheetJSDev SheetJSDev pinned this issue Sep 14, 2021
@reviewher reviewher unpinned this issue Sep 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests