Class: Xport::RubyXL::Formatter
- Inherits:
-
Object
- Object
- Xport::RubyXL::Formatter
- Defined in:
- lib/xport/formatters/rubyxl.rb
Instance Attribute Summary collapse
-
#export ⇒ Object
readonly
Returns the value of attribute export.
-
#workbook ⇒ Object
readonly
Returns the value of attribute workbook.
Instance Method Summary collapse
- #add_header_row(worksheet, row) ⇒ Object
- #add_row(worksheet, row) ⇒ Object
- #add_worksheet {|worksheet| ... } ⇒ Object
- #column_widths(worksheet, *widths) ⇒ Object
-
#initialize(export) ⇒ Formatter
constructor
A new instance of Formatter.
- #merge_header_cells(worksheet, range) ⇒ Object
- #to_file ⇒ Object
Constructor Details
#initialize(export) ⇒ Formatter
Returns a new instance of Formatter.
21 22 23 24 25 |
# File 'lib/xport/formatters/rubyxl.rb', line 21 def initialize(export) @export = export @workbook = ::RubyXL::Workbook.new @i = 0 end |
Instance Attribute Details
#export ⇒ Object (readonly)
Returns the value of attribute export.
17 18 19 |
# File 'lib/xport/formatters/rubyxl.rb', line 17 def export @export end |
#workbook ⇒ Object (readonly)
Returns the value of attribute workbook.
17 18 19 |
# File 'lib/xport/formatters/rubyxl.rb', line 17 def workbook @workbook end |
Instance Method Details
#add_header_row(worksheet, row) ⇒ Object
36 37 38 39 |
# File 'lib/xport/formatters/rubyxl.rb', line 36 def add_header_row(worksheet, row) worksheet.change_row_bold(@i, true) add_row(worksheet, row) end |
#add_row(worksheet, row) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/xport/formatters/rubyxl.rb', line 41 def add_row(worksheet, row) row.each.with_index do |v, j| value = v.is_a?(Xport::Cell) ? v.value : v worksheet.add_cell(@i, j, value) end @i += 1 end |
#add_worksheet {|worksheet| ... } ⇒ Object
31 32 33 34 |
# File 'lib/xport/formatters/rubyxl.rb', line 31 def add_worksheet worksheet = workbook.worksheets[0] yield worksheet end |
#column_widths(worksheet, *widths) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/xport/formatters/rubyxl.rb', line 53 def column_widths(worksheet, *widths) widths.each.with_index do |width, i| next unless width worksheet.change_column_width(i, width) end end |
#merge_header_cells(worksheet, range) ⇒ Object
49 50 51 |
# File 'lib/xport/formatters/rubyxl.rb', line 49 def merge_header_cells(worksheet, range) worksheet.merge_cells(0, range.first, 0, range.last) end |
#to_file ⇒ Object
27 28 29 |
# File 'lib/xport/formatters/rubyxl.rb', line 27 def to_file workbook.stream end |