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?
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'
我看到同样的错误, NoMethodError - undefined method 'reopen' for "streamed":String:
虽然我没有active_admin_import
依赖,但是在https://github.com/straydogstudio/axlsx_rails/issues中描述了宝石版本的选择/ 18#issuecomment-162934108为我解决了这个问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.