Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Follow up from closed Issue #1 #7

Open
zph opened this issue Oct 6, 2012 · 3 comments
Open

Follow up from closed Issue #1 #7

zph opened this issue Oct 6, 2012 · 3 comments

Comments

@zph
Copy link

zph commented Oct 6, 2012

Follow up from closed Issue #1

Thank you all for creating such an easy to use library. I wanted to follow up on this thread to report current findings on this issue.

Issue is present with Excel 2011 Mac as well as Excel 2013 (Win7). Both versions of Excel complain about corrupted files. After clicking on that error prompt, Excel goes through a recovery process and the file and content are available.

Issue probably stems from known issues with the Zip library. Here's a description of the issue on RubyZip's repo.

I'll see if it's an older gem issue and if there are available solutions. I'll report back here with what I find.

@zph
Copy link
Author

zph commented Oct 6, 2012

Interesting. It does not give this same issue when I did the following:

  1. Setup Gemfile that includes RubyZip, rake, and fast_xs. Ran bundle install.
  2. Then ran test suite and opened the test.xlsx file. No corruption errors.

So next I'll check if using this specific environment replicates my original file (including corruptions).

Update:
I required the most recent version of simple_xlsx_writer through Bundler (pulling directly from github). Issue is still present.

Here are the gem versions being used in the environment (just in case it's pertinent):

  • activemodel (3.2.6)
  • activesupport (3.2.6)
  • addressable (2.2.8)
  • builder (3.0.0)
  • bundler (1.2.1)
  • fast_xs (0.8.0)
  • i18n (0.6.0)
  • mime-types (1.19)
  • multi_json (1.3.6)
  • oauth (0.4.6)
  • rest-client (1.6.7)
  • ruby-trello (0.4.2)
  • rubyzip (0.9.9)
  • simple_xlsx_writer (0.5.3 bdc3575)

I've had this same experience with my own Ruby when trying to unzip and re-zip Docx and Xlsx files. It's reproducible in IRB or pry. Then the successful case of zipping a file back up and opening it can be shown when using a standard Linux/*nix zip library.

After more research, I came upon this description of the same basic issue: RubyZip Discussion Re Docx Corruption.

Here is a temporary solution posted in that same thread.... Gist

@zph
Copy link
Author

zph commented Oct 6, 2012

My next step in troubleshooting it was to implement the solution showing in the linked Gist. I swapped out the .write() method for .write_buffer() and brought the code back to a passing test state (less one test that I have yet to see pass).

This is available on my brach called zip_corruption . Attached below is the pertinent portion:

class Serializer

  def initialize to
    @to = to
    @zip = Zip::ZipFile.new(File.expand_path(to), Zip::ZipFile::CREATE)
    # Zip::ZipFile.open(to, Zip::ZipFile::CREATE) do |zip|
    buffer = Zip::ZipOutputStream.write_buffer do |out|
      # @zip = zip
      add_doc_props
      add_worksheets_directory
      add_relationship_part
      add_styles
      @doc = Document.new(self)
      yield @doc
      add_workbook_relationship_part
      add_content_types
      add_workbook_part
    end

  end
...

Unfortunately this is not working. Same corruption present after generating a new spreadsheet despite tests passing.

I'm not sure how to proceed with troubleshooting at this point. If anyone has feedback or ideas on what's going on, let me know.

@zph
Copy link
Author

zph commented Oct 13, 2012

Going on the assumption that something in the RubyZip gem was causing an issue that isn't present when using standard unix tools for the compression aspect, I re-wrote my program to use a fork that does just that https://github.com/seamusabshere/xlsx_writer.

Using the same starting data to form the xlsx and xlsx_writer did not solve the corruption issue.

If anyone has input over why the xlsx ends up corrupted, please let me know.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant