Sha256: 27ec8a4e6a22c1eb0a1baab59d6a971dede737b4916b31be0b85b2e9442216ce
Contents?: true
Size: 1.13 KB
Versions: 5
Compression:
Stored size: 1.13 KB
Contents
module Tableview::Output class XLS require 'spreadsheet' HEADER_STYLE = {:align => :center, :weight => :bold} FOOTER_STYLE = {:weight => :bold } def process(tv) @table = Spreadsheet::Workbook.new tv.subtables.each do |sub| sheet1 = @table.create_worksheet :name => sub.title offset = 0 sub.parts.each do |part| p_style = case part.class.to_s when "Tableview::ViewHandler::Header" HEADER_STYLE.dup when "Tableview::ViewHandler::Footer" FOOTER_STYLE.dup else {} end.merge part.options part.rows.each do |row| style = p_style.merge row.options row.cells.each_with_index do |cell, i| format = Spreadsheet::Format.new style.merge(cell.options) sheet1[offset, i] = cell.contents sheet1.row(offset).set_format i, format end offset += 1 end end end end def to_s io = StringIO.new @table.write(io) io.rewind string = io.read end end end
Version data entries
5 entries across 5 versions & 1 rubygems