jmcnamara / rust_xlsxwriter

A Rust library for creating Excel XLSX files.
https://crates.io/crates/rust_xlsxwriter
Apache License 2.0
250 stars 23 forks source link

question: The generated xlsx file with a large number of images cannot be opened properly with Excel #51

Closed wcshds closed 11 months ago

wcshds commented 11 months ago

Question

Hello, I tried to use this crate to generate a basic-full.xlsx file with a lot of images, but the file did not open properly with Excel. The Excel error message is "We found a problem with some content".

Then I tried to generate two files basic-1.xlsx and basic-2.xlsx, each containing half the number of images, which could be opened normally with Excel. I then manually merged the two separately generated files into a single file basic-merge.xlsx, which also opened normally.

I don't know why this crate doesn't generate basic-full.xlsx correctly, can you help me?

basic-full.xlsx basic-1.xlsx basic-2.xlsx basic-merge.xlsx

jmcnamara commented 11 months ago

Thanks for the report. I'll take a look.

jmcnamara commented 11 months ago

You may already know this but for context a xlsx file is a collection of XML files in a zip container.

I can't find any issue in the XML file structure (although it is hard to be 100% sure since the files are massive).

I think it may be a zipwriter/zip issue. I was able to open the file by unzipping it and then rezipping it. The file is too big to upload here but you can create a rezipped version for testing like this:

unzip basic-full.xlsx -d basic-full

cd basic-full
find . -type f | xargs zip ../basic-rezipped.xlsx
cd ..

ls basic-rezipped.xlsx

Can you try generate the file like that and then open it. I was able to open it successfully (although it takes a while since the file is huge).

screenshot

wcshds commented 11 months ago

Thanks for your help. After rezipping the file, I can successfully open it now.

jmcnamara commented 11 months ago

I think you should submit this as a bug to zip.rs: https://github.com/zip-rs/zip/issues

Attach the links to the basic-full.xlsx and basic-rezipped.xlsx files and add the commands to create one from the other.

Explain that Excel complains about the first file but not when it is rezipped.

The issue is possibly related to: https://github.com/zip-rs/zip/issues/23 (Update: it isn't)

jmcnamara commented 11 months ago

If you make the rezipped file available I can raise the bug report.

wcshds commented 11 months ago

Thanks! basic-rezip.xlsx

jmcnamara commented 11 months ago

I've opened an issue in zip.rs for this: https://github.com/zip-rs/zip/issues/388

I tried to do some analysis on the zip file but didn't get anywhere. Hopefully the zip.rs folk(s) will have a look.

I also noticed that there was a u32 overflow issue highlighted by your test program so I put a fix for that in v0.45.0 on crates.io.

jmcnamara commented 11 months ago

Closing in favour of https://github.com/zip-rs/zip/issues/388