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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/htot_conv/generator/xlsx_type2.rb', line 24
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.[l - 1] || nil }).concat(
HTOTConv::Util.pad_array(@data., max_value_length)),
:style => Axlsx::STYLE_THIN_BORDER)
@data.item.each_with_index do |item, item_index|
key_cell = Array.new(max_level, nil)
key_cell[item.level - 1] = item.key
value_cell = HTOTConv::Util.pad_array(item.value, max_value_length)
ws.add_row(key_cell.concat(value_cell),
:style => Axlsx::STYLE_THIN_BORDER)
(1..max_level).each do |level|
edges = []
edges << :left if (level <= item.level)
edges << :right if ((level < item.level) || (level == max_level))
edges << :top if ((level >= item.level) || (item_index == 0))
edges << :bottom if ((level > item.level) || (item_index == @data.item.length - 1))
ws.rows.last.cells[level - 1].style = ws.styles.add_style(
:border => { :style => :thin, :color => "00", :edges => edges })
end
end
if @option[:outline_rows]
outline_begin = Array.new(max_level, nil)
dummy_end_item = HTOTConv::Outline::Item.new(nil, 1, nil)
@data.item.concat([dummy_end_item]).each_with_index do |item, item_index|
(item.level..max_level).each do |level|
if outline_begin[level - 1]
if outline_begin[level - 1] < item_index - 1
ws.outline_level_rows((outline_begin[level - 1] + 1) + 1, (item_index - 1) + 1, level, false)
end
outline_begin[level - 1] = nil
end
end
outline_begin[item.level - 1] = item_index
end
if defined? ws.sheet_pr.outline_pr
ws.sheet_pr.outline_pr.summary_below = false
else
class << ws.sheet_pr def to_xml_string(str="".dup)
tmp_str = "".dup
super(tmp_str)
str << tmp_str.sub('<pageSetUpPr', '<outlinePr summaryBelow="0" /><pageSetUpPr')
end
end
end
end
case @option[:integrate_cells]
when :colspan
@data.item.each_with_index do |item, item_index|
if item.level < max_level
ws.merge_cells(ws.rows[item_index + 1].cells[((item.level - 1)..(max_level - 1))])
end
end
when :rowspan
@data.item.each_with_index do |item, item_index|
cells = [ws.rows[item_index + 1].cells[item.level - 1]]
((item_index + 1)..(@data.item.length - 1)).each do |i|
break if @data.item[i].level <= item.level
cells << ws.rows[i + 1].cells[item.level - 1]
end
ws.merge_cells(cells) if cells.length > 1
end
end
end
|