weshatheleopard / rubyXL

Ruby lib for reading/writing/modifying .xlsx and .xlsm files
MIT License
1.28k stars 255 forks source link

`NoMethodError` when parsing certain .xlsx files #463

Open wakasa51 opened 2 months ago

wakasa51 commented 2 months ago

First of all, thank you for creating such a wonderful gem.

I’m currently encountering an issue where a NoMethodError is raised when trying to parse certain .xlsx files. This error appears with files that were originally created as .numbers files on a Mac and then manually converted to .xlsx by simply changing the file extension. We understand that files manually converted from .numbers to .xlsx are technically invalid, but sometimes our users attempt to use such files in our product.

Steps to Reproduce:

  1. Attempt to parse a manually converted .xlsx file (for example, a .numbers file renamed to .xlsx) using the following code:
    File.open("./test.xlsx") { |f| RubyXL::Parser.parse_buffer(f.read) }
  2. The following error occurs:
    NoMethodError: undefined method `root=' for nil:NilClass
    from #{ruby_path}/versions/3.2.4/lib/ruby/gems/3.2.0/gems/rubyXL-3.4.27/lib/rubyXL/objects/root.rb:68:in `parse_zip_file'

Version: rubyXL version: 3.4.27 Ruby version: 3.2.4

Expected Behavior:

It would be greatly appreciated if, instead of a NoMethodError, the library could return a more descriptive error indicating that the parsing failed.

Thank you again for all your hard work on this gem!

weshatheleopard commented 2 months ago

Can you please provide a test file that exhibits this behavior?

wakasa51 commented 2 months ago

Thank you for your prompt response!

I’ve attached a sample .xlsx file that exhibits the behavior described in the issue. test.xlsx

Please let me know if there’s anything else I can provide or if you need further information.

Thank you again for your help!