Rails undefined method `reopen' for "streamed":String

Thomastar · 2018年06月22日 · 最后由 liukun_lk 回复于 2018年06月22日 · 201 次阅读

核心源码

exl = Axlsx::Package.new
exl.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
  sheet.add_row ["公司名称", "客户类型", "店铺联系人", "店铺联系人电话", "地址", "跟进状态", "备注", "业务员", "联系人名称", "联系人电话", "联系人手机"]
  @cards.each do |card|
    sheet.add_row [
      card.company_name, 
      card.customer_type,
      card.shop_contact,
      card.shop_phone,
      card.address,
      card.state,
      card.remark,
      card.salesmen,
      card.name,
      card.tel,
      card.phone
      ]
  end
end
exl.use_shared_strings = true
# exl.serialize('simple.xlsx')
send_data exl.to_stream.read, type: "application/xlsx", filename: "bussiness_card.xlsx"

错误: undefined method `reopen' for "streamed":String

初步原因判断是rubyzip 版本的问题,后面解决了还是报错

gemfile:
gem 'rubyzip', '>= 1.0.0'
gem 'zip-zip'
gem 'axlsx', '~> 2.0.1'
gem "roo"

gemfile.lock
    axlsx (2.0.1)
      htmlentities (~> 4.3.1)
      nokogiri (>= 1.4.1)
      rubyzip (~> 1.0.0)
    roo (1.13.2)
      nokogiri
      rubyzip
      spreadsheet (> 0.6.4)
共收到 4 条回复

你的文件开头是不是写了# frozen_string_literal: true

3楼 已删除
liukun_lk 回复

是写了

Thomastar 回复

那你可能需要把# frozen_string_literal: true改成 false

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册