-
Notifications
You must be signed in to change notification settings - Fork 204
Zip file format not compatible with MS OFFICE xlsx #23
Comments
Could you please provide some details?
|
Simple Excel File: Unzip and re-zip with zip-rs: Code: `
` |
LibreOffice does not have a problem with your file, so I think it is mostly Excel for Mac being picky. However, I did find some differences.
It does not have any entries for the directories. |
It does not work. MS Excel said file needed to be repaired first either on MacOS or on Windows. After that , everything is ok. but the error dialog is annoying. Now I got this:
|
What does it say when you do not use compression on thumbnail.jpeg? |
I already did that. Now I'm trying to find some clue from jszip which is used in js-xlsx , but it takes time as I'm not familiar with zip file format.
|
@mvdnes is there a way to write ZIP files without the subdirectories? If you compare with vim, you'll see that the bad files have directory entries whereas the OPC says those should not be included in the file: Related discussion from jszip: Stuk/jszip#130 (comment) (got the vim check idea from @SheetJSDev's comment later in the thread) |
Is that what you are seeing? When I write using this library I don't see it adding subdirs unless I specifically add: let file = File::create(&output).unwrap();
let mut zip = zip::ZipWriter::new(file);
let walker = WalkDir::new(root).into_iter();
for entry in walker.filter_entry(|e| !should_ignore(e)) {
let entry = entry.unwrap();
let relative_path = entry.path().strip_prefix(root).unwrap();
let relative_string = relative_path.to_string_lossy();
// Ignore the entry to the rootdir itself.
if relative_string == "" {
continue;
}
println!("Adding: {}", relative_string);
let metadata = entry.metadata().unwrap();
if metadata.is_file() {
let mut buffer = String::new();
let mut f = File::open(entry.path())?;
// This will fail if something is not UTF-8 encoded.
try!(f.read_to_string(&mut buffer));
let options = FileOptions::default()
.compression_method(zip::CompressionMethod::Deflated)
.unix_permissions(metadata.permissions().mode());
try!(zip.start_file(relative_string, options));
try!(zip.write_all(buffer.as_bytes()));
} else if metadata.is_dir() {
// Do nothing for directories.
// If I uncomment the next line, I will have directory entries. Otherwise only files.
// try!(zip.add_directory(format!("{}/", relative_string), FileOptions::default()));
} else {
writeln!(
&mut std::io::stderr(),
"Error: cannot determine file type: {}", relative_path.display(),
).expect("failed printing error to stderr");
process::exit(1);
}
}
try!(zip.finish()); |
I actually haven't tried the code. I was looking for an semi-related issue for a different repo and this came up in the search. The displayed difference compares the results from the files prepared by @outersky . |
The error occurs because created zip file contains UNIX file system but Excel expects FAT |
@V-0-1-D: zip does not use a filesystem, it stores its files in a custom way. What does happen is that the zip-file has a number which indicates which version it is made by. |
On calamine side, everything was working fine until v0.2.8. v0.2.9 broke something, not sure what exactly. |
This is to work around zip 0.2.9 turning "deflate" into a feature and calamine disabling all features by default. See also zip-rs/zip-old#23
I'm not sure that this is related, but I was able to make calamine's tests run with zip 0.2.9 by turning on the new Compiling the example program without features:
and running:
gives
Full backtrace for completeness:
|
Ah I am sorry, this new change was indeed incompatible for people running |
This is to work around zip 0.2.9 turning "deflate" into a feature and calamine disabling all features by default. See also zip-rs/zip-old#23
Sorry about that. And thanks @laumann ! |
Closing because I think it is fixed. Feel free to re-open if this is not actually the case. |
unzip some.xlsx file, and re-zip them to another.xlsx with zip-rs, an error dialog will show up when it's opened by MS Office.
The text was updated successfully, but these errors were encountered: