Excel file with multiple tabs
3 answers
If you understood correctly - by multiple tabs, you mean multiple "worksheets" in a book. Apache POI provides this functionality (check links below). Please note that I'm not a Ruby person (at least not yet) and these links are for Java use, but I'm sure YAJB-like bridges can help you with that:
+2
a source to share
I am using ruby gem "spreadsheet-excel" for this kind of function
#!/usr/bin/env ruby
RAILS_ENV = 'production'
require File.dirname(__FILE__) + '/../config/environment'
require "spreadsheet/excel"
file = "name_of_your_excel_file.xls"
workbook = Spreadsheet::Excel.new("#{RAILS_ROOT}/#{file}")
# First Sheet
worksheet = workbook.add_worksheet("Sheet No. 1")
worksheet.write(0, 0, "Timestamp")
worksheet.write(0, 1, "Type")
worksheet.write(0, 2, "Text")
# ...and whatever you want to do here
# Second Sheet
worksheet_2 = workbook.add_worksheet("Sheet No. 2")
#... and so on
This works great in both Ruby and Ruby-on-Rails.
To install a spreadsheet or Excel just type
ruby gem install "spreadsheet-excel"
Hope this helps you.
0
a source to share