核心源码
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)