Class: HTOTConv::Generator::XlsxType5
- Defined in:
- lib/htot_conv/generator/xlsx_type5.rb
Instance Method Summary collapse
Methods inherited from XlsxBase
Methods inherited from Base
#initialize, option_help, #output
Constructor Details
This class inherits a constructor from HTOTConv::Generator::Base
Instance Method Details
#output_to_worksheet(ws) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/htot_conv/generator/xlsx_type5.rb', line 8 def output_to_worksheet(ws) max_level = @data.max_level max_value_length = @data.max_value_length ws.add_row(((1..max_level).map {|l| @data.key_header[l - 1] || nil }).concat( HTOTConv::Util.pad_array(@data.value_header, max_value_length)), :style => Axlsx::STYLE_THIN_BORDER) @data.to_tree.descendants.each do |node| if node.leaf? item = node.item key_cell = Array.new(max_level, nil) key_cell[node.item.level - 1] = item.key node.ancestors do |ancestor| key_cell[ancestor.item.level - 1] = ancestor.item.key if ancestor.item end value_cell = HTOTConv::Util.pad_array(item.value, max_value_length) ws.add_row(key_cell.concat(value_cell), :style => Axlsx::STYLE_THIN_BORDER) (item.level..max_level).each do |level| edges = [:top, :bottom] edges << :left if (level == item.level) edges << :right if (level == max_level) ws.rows.last.cells[level - 1].style = ws.styles.add_style( :border => { :style => :thin, :color => "00", :edges => edges }) end end end ws.auto_filter = "A1:#{ws.rows.last.cells[max_level + max_value_length - 1].r}" end |