generating xls file using axlsx

元气小坏坏 提交于 2019-12-10 18:27:25

问题


is there a way to generate XLS file using 'axlsx' gem? I'm already using this gem to generate xlsx files, and don't want to move it all to a different gem, especially since axlsx is much easier to work with.


回答1:


Axlsx only generates xlsx files (it does not read them.) You'll have to use spreadsheet or roo or something else to directly create them.

I rely on the downloadable Microsoft converter to change from xlsx to xls. I only generate one file, and as long as the xlsx file is not too complicated there are no errors. It depends on your needs, of course.

If you are generating xlsx with Rails, consider using axlsx_rails. I wrote it, and it lets you put all Axlsx code into view templates.




回答2:


I generate my XLS files using the Ruby built-in class CSV:

file = CSV.generate do |csv|
  results.each do |r|
    csv << r
  end
end
mime_type = selected_format.downcase # can be either `xls` or `csv`
send_data file, type: mime_type, filename: filename, disposition: 'attachment'

This Railscast can also help you: http://railscasts.com/episodes/362-exporting-csv-and-excel?view=asciicast



来源:https://stackoverflow.com/questions/24146095/generating-xls-file-using-axlsx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!