Sim*_*zen 7 csv excel ruby-on-rails xlsx export-to-excel
我实现了一个 CSV 导出器,其工作方式如下:
CSV.generateStringIO)这个过程效果很好!
我只是尝试将文件的内容类型更改为 xlsx 格式,但是我收到了回形针的内容欺骗错误。我也在努力设置它在 Windows 和 Mac 机器上工作的内容类型。我研究了一下,发现了以下插件:
CSV.generate# data var filled up with with customers
CSV.generate(options) do |csv|
csv << [
'header 1',
'header 2'
]
data.each do |obj|
csv << [
obj.attr1,
obj.attr2,
]
end
end
file = StringIO.new(data) #mimic a real upload file
file.class.class_eval { attr_accessor :original_filename, :content_type } #add attr's that paperclip needs
file.original_filename = "customer-export.#{customer_export.params['format']}" #assign filename in way that paperclip likes
file.content_type = content_type # text/plain for CSV and ? for XLSX
# the file can be assigned to an paperclip attachment and this works for now perfect
Run Code Online (Sandbox Code Playgroud)
顺便说一句:Ruby 2.2,Rails 4.1
| 归档时间: |
|
| 查看次数: |
848 次 |
| 最近记录: |