我正在尝试使用https://github.com/randym/axlsx和https://github.com/straydogstudio/axlsx_rails向我的Rails应用添加简单的Excel文件下载,但我似乎无法将依赖性整理出来。
这是我开始使用我的gem文件的地方:
gem 'zip-zip'
gem 'axlsx'
gem 'axlsx_rails'
gem 'activeadmin-axlsx'
和一个简单的索引模板:
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
抛出这个:
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'
这个问题似乎试图解决它:
https://github.com/straydogstudio/axlsx_rails/issues/18
它专注于axlsx gem的v2.x,我似乎无法加载尝试这个:
gem 'zip-zip'
gem 'axlsx', '2.1.0.pre'
gem 'axlsx_rails', '>=0.4'
gem 'activeadmin-axlsx'
但是打破了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
我没有得到好像我读到它们,他们应该对rubyzip的v1.2都没问题。
它还会中断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
如果我禁用active_admin_import
axlsx
效果很好,但这很糟糕,因为我放松了光滑的管理员导入。
降级似乎有效,但这似乎不是一个长期的解决方案:
gem 'active_admin_import', '2.1.2'
此处有任何想法或建议吗?
答案 0 :(得分:1)
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'