caxlsx / caxlsx_rails

A Rails plugin to provide templates for the axlsx gem
MIT License
744 stars 84 forks source link

uninitialized constant Zip::OutputStream #170

Closed simicvm closed 11 months ago

simicvm commented 1 year ago

I am getting an error when trying to write xlsx file, and can't figure out the issue.

My gem file contains:

gem 'caxlsx'
gem 'caxlsx_rails'
gem 'rubyzip', require: 'zip'

my controller has:

  def export_xlsx
    @users = User.all
    p = Axlsx::Package.new
    wb = p.workbook

    wb.add_worksheet(name: "Document Information") do |sheet|
      sheet.add_row ["ID", "Name", "Email"]
      @users.each do |user|
        sheet.add_row [user.id, user.name, user.email]
      end
    end

    send_data p.to_stream.read, filename: "doc_data.xlsx", type: "application/xlsx"
  end

I get the following error on the send_data method:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

caused by:

uninitialized constant Zip::OutputStream
Did you mean?  Zip::ZipOutputStream

Ruby version: 2.7.3 Rails versions: 6.0.6.1 Bundler version: 2.1.4 platform: macOS 13.5.2

Any thoughts?

kiskoza commented 1 year ago

hi, thanks for reporting this issue. Could you give us the gem versions as well (caxlsx, caxlsx_rails and rubyzip)? Are you using the rubyzip in any other places? You don't need to add it to the gemfile anymore as it's a dependency of caxlsx recently

simicvm commented 1 year ago

hi, thanks for reporting this issue. Could you give us the gem versions as well (caxlsx, caxlsx_rails and rubyzip)? Are you using the rubyzip in any other places? You don't need to add it to the gemfile anymore as it's a dependency of caxlsx recently

Gem versions: caxlsx = 3.4.1 caxlsx_rails = 0.6.3 rubyzip = 2.3.2

I temporarily solved this issue by removing selenium and selenium-webdriver gems. However, I need those gems for testing, so I will need to put them back in.

straydogstudio commented 1 year ago

What versions of selenium and selenium-webdriver are you using? They must be changing the effective rubyzip.

You might post the output of "gem dependency -R zip" here

simicvm commented 1 year ago

We are using:

selenium (0.2.11)
selenium-webdriver (4.3.0)

This is the output of the command:

Gem rubyzip-2.3.2
  coveralls (~> 0.7, development)
  minitest (~> 5.4, development)
  pry (~> 0.10, development)
  rake (~> 12.3, >= 12.3.3, development)
  rubocop (~> 0.79, development)
  Used by
    caxlsx-3.4.1 (rubyzip (>= 1.3.0, < 3))
kiskoza commented 1 year ago

I'm going to try to reproduce this. Btw, I found an old issue with the same errors and gems: https://github.com/randym/axlsx/issues/312

kiskoza commented 1 year ago

It looks like selenium 0.2.11 depends on jar_wrapper 0.1.8 (>0) which dependes on zip 2.0.2 (>0), but it's not the same as rubyzip.

Unfortunately the github repo / homepage seems to be missing for zip and its last version came out in 2010, so though the problem is definitely a conflict in between these gems, it's hard to track down and fix the issue.

I'm not sure how your project looks like and how you're using the selenium gem, but I would check if you still need it - as far as I know, selenium-webdriver could do the browser automation alone without the other gem.

straydogstudio commented 1 year ago

The selenium gem was last released in 2013. I expect there is an alternate way to make sure the server is running.

Selenium-webdriver is current.