Class: HTOTConv::Generator::XlsxType1

Inherits:
XlsxBase show all
Defined in:
lib/htot_conv/generator/xlsx_type1.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XlsxBase

#output

Methods inherited from Base

#initialize, #output

Constructor Details

This class inherits a constructor from HTOTConv::Generator::Base

Class Method Details

.option_helpObject



8
9
10
11
12
13
14
15
16
# File 'lib/htot_conv/generator/xlsx_type1.rb', line 8

def self.option_help
  {
    :outline_rows => {
      :default => false,
      :pat => FalseClass,
      :desc => "group rows (default: no)",
    },
  }
end

Instance Method Details

#output_to_worksheet(ws) ⇒ Object



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
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/htot_conv/generator/xlsx_type1.rb', line 18

def output_to_worksheet(ws)
  row_index = 0
  max_value_length = @data.max_value_length

  [@data.key_header[0]].concat(
    HTOTConv::Util.pad_array(@data.value_header, max_value_length)
  ).each_with_index do |v, col_index|
    ws.add_cell(row_index, col_index, v)
    [:top, :bottom, :left, :right].each do |edge|
      ws[row_index][col_index].change_border(edge, "thin")
    end
  end
  row_index = row_index.succ

  @data.item.each do |item|
    ([item.key].concat(
      HTOTConv::Util.pad_array(item.value, max_value_length))
    ).each_with_index do |v, col_index|
      ws.add_cell(row_index, col_index, v)
      [:top, :bottom, :left, :right].each do |edge|
        ws[row_index][col_index].change_border(edge, "thin")
      end
    end
    row_index = row_index.succ
  end

  if @option[:outline_rows]
    @data.item.each_with_index do |item, item_index|
      ws[item_index + 1].outline_level = (item.level > 1)? (item.level - 1) : nil
    end

    ws.sheet_pr ||= RubyXL::WorksheetProperties.new
    ws.sheet_pr.outline_pr ||= RubyXL::OutlineProperties.new
    ws.sheet_pr.outline_pr.summary_below = false
  end
end