Sha256: de04bd5b6f1ccacfe5e36a22c3067c32057127b885512a3ce1015ac1da9e1027
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
require 'fileutils' class Report class Xlsx include Utils attr_reader :report def initialize(report) @report = report end def path return @path if defined?(@path) require 'xlsx_writer' tmp_path = tmp_path(:extname => '.xlsx') workbook = XlsxWriter::Document.new if f = report.class.xlsx_format f.call workbook end report.class.tables.each do |table| sheet = workbook.add_sheet table.name cursor = 1 # excel row numbers start at 1 if table._head table._head.each(report) do |row| sheet.add_row row.to_a cursor += 1 end sheet.add_row [] cursor += 1 end if table._body sheet.add_row table._body.columns.map(&:name) table._body.each(report) do |row| sheet.add_row row.to_hash end sheet.add_autofilter calculate_autofilter(table, cursor) end end FileUtils.mv workbook.path, tmp_path workbook.cleanup @path = tmp_path end private def calculate_autofilter(table, cursor) [ 'A', cursor, ':', XlsxWriter::Cell.excel_column_letter(table._body.columns.length-1), cursor ].join end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
report-0.0.2 | lib/report/xlsx.rb |
report-0.0.1 | lib/report/xlsx.rb |