Class: Daru::IO::Exporters::Excel
- Defined in:
- lib/daru/io/exporters/excel.rb
Overview
Excel Exporter Class, that extends to_excel_string
and write_excel
methods to
Daru::DataFrame
instance variables
Instance Method Summary collapse
-
#initialize(dataframe, header: true, data: true, index: true) ⇒ Excel
constructor
Initializes an Excel Exporter instance.
-
#to_s ⇒ String
Exports an Excel Exporter instance to a file-writable String.
-
#write(path) ⇒ Object
Exports an Excel Exporter instance to an xls file.
Methods inherited from Base
Constructor Details
#initialize(dataframe, header: true, data: true, index: true) ⇒ Excel
Note:
For giving formatting options as hashes to the :data
, :index
or header
keyword argument(s), please have a look at the
Spreadsheet::Font
and
Spreadsheet::Format
pages.
Initializes an Excel Exporter instance.
51 52 53 54 55 56 57 58 |
# File 'lib/daru/io/exporters/excel.rb', line 51 def initialize(dataframe, header: true, data: true, index: true) optional_gem 'spreadsheet', '~> 1.1.1' super(dataframe) @data = data @index = index @header = header end |
Instance Method Details
#to_s ⇒ String
Exports an Excel Exporter instance to a file-writable String.
72 73 74 |
# File 'lib/daru/io/exporters/excel.rb', line 72 def to_s super end |
#write(path) ⇒ Object
Exports an Excel Exporter instance to an xls file.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/daru/io/exporters/excel.rb', line 82 def write(path) @book = Spreadsheet::Workbook.new @sheet = @book.create_worksheet process_offsets write_headers @dataframe.each_row_with_index.with_index do |(row, idx), r| write_index(idx, r+@row_offset) write_data(row, r+@row_offset) end @book.write(path) end |