ruby 中哪些 gem 支持导入/导出到 xlsx 文件

发布于 2024-10-11 08:02:54 字数 1539 浏览 10 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

只为守护你 2024-10-18 08:02:54

对于编写/导出 xlsx 文件的任务,Axlsx 是我发现的功能最齐全的库。但它不支持读取/导入 xlsx 文件。

https://github.com/randym/axlsx

这是作者的描述:

xlsx 生成,包含图表、图像、自动列宽、
可定制的样式和完整的架构验证。 Axlsx 擅长
帮助您生成精美的 Office Open XML 电子表格文档
无需了解整个 ECMA 规范。查看
自述文件中提供了一些示例,说明它是多么简单。最重要的是,您可以
在序列化之前验证您的 xlsx 文件,以便您确定
生成的任何内容都将加载到您客户端的计算机上。

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:

xlsx generation with charts, images, automated column width,
customizable styles and full schema validation. Axlsx excels at
helping you generate beautiful Office Open XML Spreadsheet documents
without having to understand the entire ECMA specification. Check out
the README for some examples of how easy it is. Best of all, you can
validate your xlsx file before serialization so you know for sure that
anything generated is going to load on your client's machine.

千鲤 2024-10-18 08:02:54

看来 RubyXL 两者兼而有之,读和写
https://github.com/gilt/rubyXL
虽然还没用过..

seems RubyXL does both, read AND write
https://github.com/gilt/rubyXL
haven't used it yet though..

旧人 2024-10-18 08:02:54

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.

卸妝后依然美 2024-10-18 08:02:54

我发现在 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.

临走之时 2024-10-18 08:02:54

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.

死开点丶别碍眼 2024-10-18 08:02:54

我发现所有现有的 ruby​​ excel 库的界面都非常不像 ruby​​,尤其是在读取文件时确定单元格类型时不准确。

因此,如果您正在寻找(IMO)更简单的东西,我已经成功地使用了 simple_xlsx_readersimple_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.

给妤﹃绝世温柔 2024-10-18 08:02:54

检查这个 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

黯然 2024-10-18 08:02:54

要在没有任何 gem 的情况下导出(csv 和 xslx),我们可以使用 -

https://gorails.com /episodes/export-to-csv

这个链接展示了如何导出csv,下面是我们如何获取xlsx。

  1. 打开控制器
  2. 查找调用to_csv方法的方法,

    send_data @models.to_csv, filename: "Contract-#{Date.today}.csv"

  3. 写为-

    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.

  1. open controller
  2. find method which calling to_csv method,

    send_data @models.to_csv, filename: "Contract-#{Date.today}.csv"

  3. write as-

    send_data @models.to_csv, filename: "Contract-#{Date.today}.xlsx"

That worked for me!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文