Menu

#18 Invalid zip file generated

open
nobody
None
5
2012-07-18
2006-12-13
No

I've some problems with rubyzip.
Here is the code I use:

require 'zip/zipfilesystem'
include Zip

File.unlink('tmp.xlsx') rescue nil
File.copy('test/openxml/excel_template.xlsx', 'tmp.xlsx')
ZipFile.open('tmp.xlsx') do |zip|
txt = nil
zip.file.open('xl/sharedStrings.xml', 'r') do |file|
txt = file.read
end
zip.file.open('xl/sharedStrings.xml', 'w') do |file|
file.write(txt)
end
end

After the script, the fil tmp.xlsx should contain
the same files as test/openxml/excel_template.xlsx.
It's right but I can't decompress it correctly.

Here is the output of zipinfo test.xlsx

Archive: tmp.xlsx 32133 bytes 18 files
-rw---- 4.5 fat 588 b- defN 1-Jan-80 00:00 _rels/.rels
-rw---- 4.5 fat 6614 b- defN 1-Jan-80 00:00 xl/theme/theme1.xml
-rw---- 4.5 fat 322 b- defN 1-Jan-80 00:00
xl/worksheets/_rels/sheet1.xml.rels
-rw---- 4.5 fat 494 b- defN 1-Jan-80 00:00
xl/worksheets/sheet4.xml
-rw---- 4.5 fat 554 b- defN 1-Jan-80 00:00 docProps/core.xml
-rw---- 4.5 fat 748 b- stor 1-Jan-80 00:00
xl/media/image2.jpeg
-rw---- 4.5 fat 429 b- defN 1-Jan-80 00:00
xl/theme/_rels/theme1.xml.rels
-rw---- 4.5 fat 442 b- defN 1-Jan-80 00:00
xl/worksheets/sheet2.xml
-rw-r--r-- 5.2 unx 836 t- defN 13-Dec-06 16:14
xl/sharedStrings.xml
-rw---- 4.5 fat 21922 b- stor 1-Jan-80 00:00
xl/media/image1.jpeg
-rw---- 4.5 fat 442 b- defN 1-Jan-80 00:00
xl/worksheets/sheet3.xml
-rw---- 4.5 fat 1744 b- defN 1-Jan-80 00:00 [Content_Types].xml
-rw---- 4.5 fat 660 b- defN 1-Jan-80 00:00 xl/workbook.xml
-rw---- 4.5 fat 1488 b- defN 1-Jan-80 00:00
xl/printerSettings/printerSettings1.bin
-rw---- 4.5 fat 866 b- defN 1-Jan-80 00:00 docProps/app.xml
-rw---- 4.5 fat 1121 b- defN 1-Jan-80 00:00
xl/_rels/workbook.xml.rels
-rw---- 4.5 fat 4599 b- defN 1-Jan-80 00:00 xl/styles.xml
-rw---- 4.5 fat 3586 b- defN 1-Jan-80 00:00
xl/worksheets/sheet1.xml
18 files, 47455 bytes uncompressed, 29951 bytes compressed: 36.9%

And here is the output of unzip test.xlsx

Archive: tmp.xlsx
inflating: tmp/_rels/.rels
error: invalid compressed data to inflate
inflating: tmp/xl/theme/theme1.xml
inflating: tmp/xl/worksheets/_rels/sheet1.xml.rels
inflating: tmp/xl/worksheets/sheet4.xml
inflating: tmp/docProps/core.xml
error: invalid compressed data to inflate
extracting: tmp/xl/media/image2.jpeg
inflating: tmp/xl/theme/_rels/theme1.xml.rels
inflating: tmp/xl/worksheets/sheet2.xml
inflating: tmp/xl/sharedStrings.xml
extracting: tmp/xl/media/image1.jpeg
inflating: tmp/xl/worksheets/sheet3.xml
inflating: tmp/[Content_Types].xml
error: invalid compressed data to inflate
inflating: tmp/xl/workbook.xml
inflating: tmp/xl/printerSettings/printerSettings1.bin
inflating: tmp/docProps/app.xml
error: invalid compressed data to inflate
inflating: tmp/xl/_rels/workbook.xml.rels
error: invalid compressed data to inflate
inflating: tmp/xl/styles.xml
inflating: tmp/xl/worksheets/sheet1.xml

DO you have any idea ?

In attachement, you'll find exel_template.xlsx I use for testing.

Discussion

  • Thomas Sondergaard

     
  • Nobody/Anonymous

    Logged In: NO

    I am having the same problem with a .pptx file I am generating. It looks like it is something related to Office 2007 files?

     
  • Chris Garrett

    Chris Garrett - 2007-08-31

    Logged In: YES
    user_id=1869552
    Originator: NO

    I just submitted a patch that will generate zip archives readable by Office 2007.

     
  • Olivier Capillon

    Logged In: YES
    user_id=812665
    Originator: NO

    I had compatibility issues between rubyzip and MS Office 2007 too. The patch of czgarrett did not work out for me. :(
    But I could resolve the problem by setting the versionNeededToExtract value to 20 (instead of 0) in the Zip::ZipEntry (zib.rb) methods write_local_entry (line 547) and write_c_dir_entry (line 696).
    MS Office 2007 seems to be happy with it so far ...

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.