3

I am trying to add simple Excel file downloads to my Rails app with https://github.com/randym/axlsx and https://github.com/straydogstudio/axlsx_rails but I can't seem to get the dependancies sorted out.

Here is where I started out with my gem file:

gem 'zip-zip'
gem 'axlsx'
gem 'axlsx_rails'
gem 'activeadmin-axlsx'

and a simple index template:

wb = xlsx_package.workbook
wb.add_worksheet(name: "Areas") do |sheet|
  @areas.each do |area|
    sheet.add_row [area.name, area.user_id]
  end
end

throws this:

NoMethodError - undefined method `reopen' for "streamed":String:
  rubyzip (1.2.0) lib/zip/output_stream.rb:32:in `initialize'
  axlsx (1.3.6) lib/axlsx/package.rb:113:in `to_stream'
  app/views/areas/index.xlsx.axlsx:8:in `_app_views_areas_index_xlsx_axlsx___113759396792702403_70279795626520'

This issue seems to try to address it:

https://github.com/straydogstudio/axlsx_rails/issues/18

and it focuses on v2.x of the axlsx gem which I also can't seem to get to load trying this:

gem 'zip-zip'
gem 'axlsx', '2.1.0.pre'
gem 'axlsx_rails', '>=0.4' 
gem 'activeadmin-axlsx'

but that breaks active_admin_import:

Bundler could not find compatible versions for gem "rubyzip":
  In Gemfile:
    active_admin_import (>= 0) ruby depends on
      rubyzip (~> 1.2) ruby

    axlsx (= 2.1.0.pre) ruby depends on
      rubyzip (~> 1.1.7) ruby

which I don't get as if I read this they should both be ok with v1.2 of rubyzip.

It also breaks activeadmin-axlsx:

      # patching the index method to allow the xlsx format.
      def index_with_xlsx(options={}, &block)
        index_without_xlsx(options) do |format|  ### wrong number of arguments (1 for 0)
           format.xlsx do
            xlsx = active_admin_config.xlsx_builder.serialize(collection)
            send_data xlsx.to_stream.read, :filename => "#{xlsx_filename}", :type => Mime::Type.lookup_by_extension(:xlsx)
          end
        end

If I disable active_admin_import axlsx works great but that sucks because I loose the slick admin importing.

Downgrading seems to work but that does not seem like a long term solution:

gem 'active_admin_import', '2.1.2'

Any ideas here or suggestions?

Dan Tappin
  • 2,692
  • 3
  • 37
  • 77
  • 1
    You might try forking the axlsx repo, changing its dependencies, and pointing to your own github. I'm pretty sure it doesn't really care about rubyzip 1.1 vs. 1.2. But you'd have to find out. Axlsx_rails may then give dependency trouble, but may not. Unfortunately axlsx development has stalled over the last year or so, even though it's still a useful gem. – noel Jul 05 '16 at 16:11

2 Answers2

1

Working combination for Rails 5.2.1 / ruby 2.5.0:

gem 'rubyzip', '>= 1.2.1' gem 'axlsx', git: 'https://github.com/randym/axlsx.git', ref: 'c8ac844' gem 'axlsx_rails' gem 'zip-zip'

rusllonrails
  • 5,586
  • 3
  • 34
  • 27
0

I was seeing the same error, NoMethodError - undefined method 'reopen' for "streamed":String: Although I do not have the active_admin_import dependency, the selection of gem versions described at https://github.com/straydogstudio/axlsx_rails/issues/18#issuecomment-162934108 resolved the issue for me.

bhfailor
  • 175
  • 2
  • 6