【发布时间】:2018-12-04 23:48:59
【问题描述】:
尝试使用 Ruby Sinatra 和 AXLSX gem 提示下载窗口并流式传输 XLSX 文件,我的 excel 文件成功序列化到本地文件,所以我知道它是一个有效的 excel 文档,但我需要它来传输内容到最后用户。没有任何在线文档包含 AXLS 和 Sinatra 一起使用的示例,只有导轨。感谢您的帮助!
class Downloads < Sinatra::Base
get '/downloads/report' do
## ...
Axlsx::Package.new do |p|
p.workbook.add_worksheet(name: 'tab name') do |sheet|
## ...
end
content_type 'application/xlsx'
attachment 'cost-code-dashboard.xlsx'
p.to_stream # unsuccessful
# p.to_stream.read # unsuccessful as well
end
end
end
我也试过下面的sn-p不成功
Axlsx::Package.new do |p|
## ...
send_file p.to_stream.read, type: "application/xlsx", filename: "cost-code-dashboard.xlsx"
end
【问题讨论】: