Class: Dumpster::Excel::Writer
- Inherits:
-
Object
- Object
- Dumpster::Excel::Writer
- Defined in:
- lib/dumpster/excel.rb
Instance Method Summary collapse
-
#initialize(model) ⇒ Writer
constructor
A new instance of Writer.
- #write_to_file(path) ⇒ Object
- #write_to_string ⇒ Object
Constructor Details
#initialize(model) ⇒ Writer
Returns a new instance of Writer.
7 8 9 |
# File 'lib/dumpster/excel.rb', line 7 def initialize(model) @model = model end |
Instance Method Details
#write_to_file(path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dumpster/excel.rb', line 17 def write_to_file(path) package = Axlsx::Package.new workbook = package.workbook workbook.add_worksheet(:name => "Worksheet 1") do |sheet| @model.each do |row| sheet.add_row(row) end end package.serialize(path) end |
#write_to_string ⇒ Object
11 12 13 14 15 |
# File 'lib/dumpster/excel.rb', line 11 def write_to_string file = Tempfile.new('dumpster_excel_export.xlsx') write_to_file(file.path) File.read(file.path) end |