我试图用https://github.com/randym/axlsx和https://github.com/straydogstudio/axlsx_rails将简单的Excel文件下载添加到我的Rails应用程序中,但我似乎无法理清依赖关系。
这是我从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的1.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'这里有什么想法或建议吗?
发布于 2018-11-13 19:37:29
ruby Rails 5.2.1 / 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'
发布于 2017-02-23 21:49:07
我看到了同样的错误,NoMethodError - undefined method 'reopen' for "streamed":String:虽然我没有active_admin_import依赖,但在https://github.com/straydogstudio/axlsx_rails/issues/18#issuecomment-162934108上描述的gem版本的选择为我解决了这个问题。
https://stackoverflow.com/questions/38025219
复制相似问题