开发者

Which gem support Import/Export to xlsx file in ruby [closed]

开发者 https://www.devze.com 2023-02-03 04:00 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 3 years ago.

Improve this question

I need to read and write to Excelx file with ruby code, Tried with sprea开发者_StackOverflow中文版dsheet it does not support xlsx format, Roo is also to read the file and not write to xlsx.

Is there any gem/plugin which will write to Excelx?


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.


You can try this gem

https://github.com/harvesthq/simple_xlsx_writer

And

https://github.com/cxn03651/writeexcel/


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


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.


I have found a lot of success utilizing WIN32OLE with excel. I always find myself back at rubyonwindows.blogspot.com for examples.


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.


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.


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


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!!!

0

精彩评论

暂无评论...
验证码 换一张
取 消