Module: Spreadsheetable
- Defined in:
- lib/spreadsheetable.rb,
lib/spreadsheetable/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#sheet_columns ⇒ Object
Returns the value of attribute sheet_columns.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#sheet_columns ⇒ Object
Returns the value of attribute sheet_columns.
5 6 7 |
# File 'lib/spreadsheetable.rb', line 5 def sheet_columns @sheet_columns end |
Class Method Details
.extend_object(base) ⇒ Object
7 8 9 10 11 |
# File 'lib/spreadsheetable.rb', line 7 def self.extend_object(base) raise TypeError.new unless base.is_a?(ActiveRecord::Relation) || (base.is_a?(Array) && base.first.is_a?(ActiveRecord::Base)) base.instance_variable_set(:@sheet_columns, []) super end |
Instance Method Details
#to_spreadsheet ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/spreadsheetable.rb', line 18 def to_spreadsheet book = ::Spreadsheet::Workbook.new sheet = book.create_worksheet() rows = [_sheet_header] rows += self.collect{|_row| _to_row(_row)} rows.each_with_index do |_row, i| sheet.row(i).concat _row end tmpfile = Tempfile.new ["excel_tmp", ".xls"] book.write tmpfile tmpfile end |
#xls ⇒ Object
34 35 36 |
# File 'lib/spreadsheetable.rb', line 34 def xls to_spreadsheet end |