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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.