Class: Sheets::Renderers::ExcelRenderer
- Defined in:
- lib/sheets/renderers/excel_renderer.rb
Instance Method Summary collapse
Methods inherited from Base
formats, formats=, #initialize, renders
Constructor Details
This class inherits a constructor from Sheets::Renderers::Base
Instance Method Details
#to_xls ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sheets/renderers/excel_renderer.rb', line 4 def to_xls workbook = Spreadsheet::Excel::Workbook.new worksheet = Spreadsheet::Excel::Worksheet.new workbook.add_worksheet(worksheet) @data.each_with_index do |row, row_index| row.each_with_index do |cell, col_index| worksheet[row_index, col_index] = cell end end # Tried to use StringIO here, but ran into encoding issues with Ruby 1.8.7. file_path = "tmp_excel_render_#{Time.now.to_i}" File.open(file_path, 'w+') {|file| workbook.write(file) } File.read(file_path) ensure File.delete( file_path ) if File.exists?( file_path ) end |