We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(9)
对于编写/导出 xlsx 文件的任务,Axlsx 是我发现的功能最齐全的库。但它不支持读取/导入 xlsx 文件。
https://github.com/randym/axlsx
这是作者的描述:
For the task of writing/exporting xlsx files, Axlsx is the most feature complete library I've found. It does not support reading/importing xlsx files, though.
https://github.com/randym/axlsx
Here's the author's description:
你可以试试这个宝石
并且
You can try this gem
And
看来 RubyXL 两者兼而有之,读和写
https://github.com/gilt/rubyXL
虽然还没用过..
seems RubyXL does both, read AND write
https://github.com/gilt/rubyXL
haven't used it yet though..
XLSX 文件本质上是 XML 文件的压缩集合。如果您找不到合适的 gem,您可以尝试使用 Ruby 手动生成它们,可能使用从 Excel 保存的空模板。我们曾经这样做过,效果很好,不幸的是代码不是开源的。
但最终,我们需要对结果的外观有更多的控制,因此我们使用 Excel 自动化制作了基于 .NET 的解决方案。
An XLSX file is essentially a zipped collection of XML files. If you don't find suitable gem, you may try generating them manually using Ruby, possibly using an empty template saved from Excel. We used to do that, worked pretty well, unfortunately that code is not open-sourced.
But eventually, we needed more control over how the result looks so we made .NET based solution with Excel automation.
我发现在 excel 中使用 WIN32OLE 取得了很多成功。我总是发现自己回到 rubyonwindows.blogspot.com 获取示例。
I have found a lot of success utilizing WIN32OLE with excel. I always find myself back at rubyonwindows.blogspot.com for examples.
添加到上述宝石列表中,Roo(https://github.com/roo-rb/roo) 是一种流行的 ruby gem,用于管理和使用 excel 和 xlsx 文件。
Adding to the list of above gems, Roo(https://github.com/roo-rb/roo) is a popular ruby gem that is used to manage and work with excel and xlsx files.
我发现所有现有的 ruby excel 库的界面都非常不像 ruby,尤其是在读取文件时确定单元格类型时不准确。
因此,如果您正在寻找(IMO)更简单的东西,我已经成功地使用了 simple_xlsx_reader 和 simple_xlsx_writer。
我是 simple_xlsx_reader 的作者,截至撰写本文时,我没有在 simple_xlsx_reader 中进行测试来断言读取 simple_xlsx_writer 生成的文件的所有用例,所以我不能说它得到完全支持,但我可以说我已经部署了一个生产应用程序,它连续使用这两个库进行各种集成测试,没有出现任何问题。
I found the interfaces of all the existing ruby excel libraries to be very un-ruby-like, and especially inaccurate when determining cell types when reading files.
So, if you're looking for something that's (IMO) simpler, I've successfully used the combination of simple_xlsx_reader and simple_xlsx_writer.
I'm the author of simple_xlsx_reader, and as of the time of this writing I don't have tests in simple_xlsx_reader that assert all use cases for reading files generated by simple_xlsx_writer, so I can't say it's fully supported, but I can say I've deployed a production application that used both libraries back-to-back for various integration tests, without issue.
检查这个 gem,我对于生成任何困难的格式/布局非常有用
gem 'axlsx' ,github:'randym/axlsx',分支:'master'
并参考这些链接的文档axlsx-documentation
Check with this gem, i is very useful to generate any difficult format/layout
gem 'axlsx' , github: 'randym/axlsx', branch: 'master'
and refer these link's for Documentationaxlsx-documentation
要在没有任何 gem 的情况下导出(csv 和 xslx),我们可以使用 -
https://gorails.com /episodes/export-to-csv
这个链接展示了如何导出csv,下面是我们如何获取xlsx。
查找调用to_csv方法的方法,
send_data @models.to_csv, filename: "Contract-#{Date.today}.csv"
写为-
send_data @models.to_csv,文件名:“Contract-#{Date.today}.xlsx”
这对我有用!
To export (csv & xslx) without any gem we can use-
https://gorails.com/episodes/export-to-csv
This link shows how to export in csv, below is how we can get xlsx.
find method which calling to_csv method,
send_data @models.to_csv, filename: "Contract-#{Date.today}.csv"
write as-
send_data @models.to_csv, filename: "Contract-#{Date.today}.xlsx"
That worked for me!!!