I was using spreadsheet gem for reading and writing data to xls file. It was kind of easy. Now I need to work on xlsx file and I guess spreadsheet doesn't support xlsx files.
I found roo gem supports xlsx.
For creating of xls file using spreadsheet, It was something like
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet
sheet.row(0).concat %w[col1 col2 col3 col4]
For reading
book1 = Spreadsheet.open('Data/CA.xls')
read_sheet = book1.worksheet('sheet')
How to create and read using roo.
Actually,
roosupports both, but the projects are now split.To have xlsx support you need to:
To have xls support you need to require both:
You can't create a spreadsheet excel file with
rooit specializes on reading such file.For reading then you need to:
For more information visit the roo's github pages
To create an excel file
To write an Excel file I would recommend Axlsx gem. I did not use it for some time now, but it used to be quite good.
There is whole buch of examples right at github - example.rb.
They are better than I would come up here so I'll post one of them:
Edit - missing output file