Giter Site home page Giter Site logo

Comments (3)

zph avatar zph commented on September 24, 2024

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

from simple_xlsx_writer.

zph avatar zph commented on September 24, 2024

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.

from simple_xlsx_writer.

zph avatar zph commented on September 24, 2024

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.

from simple_xlsx_writer.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.