jeudi 27 octobre 2016

Xlsx file gives error on MS Excel once it is zipped using rubyzip and unzipped on windows

Actually my requirement is to zip some files in some folders. I have already many files saved on my server and associated with some objects. So I have to zip all the files related to one object somewhat like this:

  • Main Folder
    • Sub Folder
      • Another Folder
        • XLSX File

This is an example of my hierarchy. What I did is I created these folders copied the files in those folders and the create a zip using this code:

http://ift.tt/29BiZxu

found on the rubyzip library itself. But when I unzip this file on windows and open it in Microsoft Excel then I get the following error:

We found a problem with some content in 'FileName.xlsx'.Do you want us to try to recover as much as we can? If you trust the source of this workbook, Click Yes

Pressing Yes recovers the file but I don't have any idea why this error is coming. I have tried opening the excel file when it is copied on the server that is working fine, but once it is zipped and unzipped then the error comes. I have seen some various issues for this topic like:

xlsx compressed by rubyzip not readable by Excel

but got no help.

What I tried to do more is like stting the compression level and I tried setting it to Zlib::DEFAULT_COMPRESSION for rubyzip but in spite of that I had the same issue. Also at some places and even in the readme if rubyzip I found that we may use:

Use write_buffer instead open

And I tried it using on this line (the best I could find):

http://ift.tt/2eUwjgQ

But it threw me a different exception so if this is the solution I am not sure how to use it.

Aucun commentaire:

Enregistrer un commentaire