Class: Xport::Axlsx::Formatter
- Inherits:
-
Object
- Object
- Xport::Axlsx::Formatter
- Defined in:
- lib/xport/formatters/axlsx.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 26 27 28 29 |
# File 'lib/xport/formatters/axlsx.rb', line 21 def initialize(export) @export = export @package = ::Axlsx::Package.new @workbook = @package.workbook # Support Numbers and multiline strings in Excel Mac 2011 # https://github.com/randym/axlsx/issues/252 @package.use_shared_strings = true end |
Instance Attribute Details
#export ⇒ Object (readonly)
Returns the value of attribute export.
17 18 19 |
# File 'lib/xport/formatters/axlsx.rb', line 17 def export @export end |
#workbook ⇒ Object (readonly)
Returns the value of attribute workbook.
17 18 19 |
# File 'lib/xport/formatters/axlsx.rb', line 17 def workbook @workbook end |
Instance Method Details
#add_header_row(worksheet, row) ⇒ Object
40 41 42 |
# File 'lib/xport/formatters/axlsx.rb', line 40 def add_header_row(worksheet, row) worksheet.add_row row, style: header_style end |
#add_row(worksheet, row) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/xport/formatters/axlsx.rb', line 44 def add_row(worksheet, row) values = row.map { |v| v.is_a?(Xport::Cell) ? v.value : v } axlsx_row = worksheet.add_row(values, style: styles, types: builder.types) row.each.with_index do |cell, i| next unless cell.is_a?(Xport::Cell) axlsx_cell = axlsx_row.cells[i] axlsx_cell.color = cell.color if cell.comment worksheet.add_comment( ref: axlsx_cell.reference(false), author: 'Conditions', text: cell.comment, visible: false ) end end end |
#add_worksheet {|worksheet| ... } ⇒ Object
35 36 37 38 |
# File 'lib/xport/formatters/axlsx.rb', line 35 def add_worksheet worksheet = @workbook.add_worksheet yield worksheet end |
#column_widths(worksheet, *widths) ⇒ Object
66 67 68 |
# File 'lib/xport/formatters/axlsx.rb', line 66 def column_widths(worksheet, *widths) worksheet.column_widths(*widths) end |
#merge_header_cells(worksheet, range) ⇒ Object
62 63 64 |
# File 'lib/xport/formatters/axlsx.rb', line 62 def merge_header_cells(worksheet, range) worksheet.merge_cells worksheet.rows.first.cells[range] end |
#to_file ⇒ Object
31 32 33 |
# File 'lib/xport/formatters/axlsx.rb', line 31 def to_file @package.to_stream end |