0

I have used axlsx gem for downloading data into excel. I have added worksheets with each sheet having 100 rows. In my data i have year column based on year i need to add sheets.

How can i do that?

Insane Skull
  • 9,220
  • 9
  • 44
  • 63
user2083041
  • 513
  • 1
  • 8
  • 32

1 Answers1

0

You would just sort your data by year (at least) and add a worksheet for each year:

data_by_year.each do |thing|
  wb.add_worksheet(:name => thing.year.to_s) do |sheet|
    sheet.add_row ["First Column", "Second", "Third"]
    sheet.add_row [thing.first, thing.second, thing.third]
  end
end

There is a workbook.worksheets instance attribute of the type SimpleTypedList, but this is not considered public API. With that you may have success adding to worksheets whether or not your data is in year order.

noel
  • 2,095
  • 14
  • 14