tafia / calamine

A pure Rust Excel/OpenDocument SpreadSheets file reader: rust on metal sheets
MIT License
1.69k stars 158 forks source link

xls error: Zip(InvalidArchive("Could not find central directory end"))' #366

Closed Xiaobaishushu25 closed 12 months ago

Xiaobaishushu25 commented 12 months ago

when i try to use open_workbook function to read a xls file,it report error:thread 'main' panicked at 'called Result::unwrap() on an Err value: Zip(InvalidArchive("Could not find central directory end"))', src\main.rs:30:106, i also try to read a xls file with small amounts of data in the same folder,it success. I can use Excel to open it normally. Is it because there are too many rows of data? (about 12000 row).

dimastbk commented 12 months ago

Xls is a binary format that does not use zip. Maybe you are trying to open an xlsx file with the annotation "Xls"?

Xiaobaishushu25 commented 12 months ago

Xls is a binary format that does not use zip. Maybe you are trying to open an xlsx file with the annotation "Xls"?

I'm also curious why zip is involved.The initial extension of the file is "xls",and can use Excel to open it normally, but if i chage the extension to xlsx, the excel will alert "Excel cannot open the file 'xx.xlsx' because the file format or file extension is invalid. Please ensure that the file is not damaged and that the file extension matches the format of the file". And both of them use calamine to read report the same error:

thread 'main' panicked at 'called Result::unwrap() on an Err value: Zip(InvalidArchive("Could not find central directory end"))',
Xiaobaishushu25 commented 12 months ago

Xls is a binary format that does not use zip. Maybe you are trying to open an xlsx file with the annotation "Xls"?

Sorry, I was too careless. i have found the reason, because i directly copied the sample code,One of the sentences is

let mut excel: Xlsx<_> = open_workbook("file.xlsx").unwrap();

it explicitly declared type is Xlsx<_> but i didnt notice it, i just change the file path, but my file is xls, so it wrong. now i have change the type to Xls<_>, it work well,this crate is very useful, and also thank you for your answer.

tafia commented 11 months ago

Awesome, there is also the open_workbook_auto function in case you want calamine to infer the workbook type from the file extension.