write_xlsx 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -0
- data/VERSION +1 -1
- data/lib/write_xlsx/chart.rb +421 -604
- data/lib/write_xlsx/chart/area.rb +6 -9
- data/lib/write_xlsx/chart/bar.rb +1 -44
- data/lib/write_xlsx/chart/column.rb +1 -46
- data/lib/write_xlsx/chart/line.rb +6 -9
- data/lib/write_xlsx/chart/pie.rb +42 -63
- data/lib/write_xlsx/chart/scatter.rb +42 -96
- data/lib/write_xlsx/chart/stock.rb +14 -21
- data/lib/write_xlsx/chartsheet.rb +4 -4
- data/lib/write_xlsx/drawing.rb +112 -163
- data/lib/write_xlsx/format.rb +62 -47
- data/lib/write_xlsx/package/app.rb +14 -19
- data/lib/write_xlsx/package/comments.rb +37 -48
- data/lib/write_xlsx/package/core.rb +12 -34
- data/lib/write_xlsx/package/packager.rb +10 -15
- data/lib/write_xlsx/package/relationships.rb +3 -5
- data/lib/write_xlsx/package/shared_strings.rb +7 -9
- data/lib/write_xlsx/package/styles.rb +148 -172
- data/lib/write_xlsx/package/vml.rb +43 -65
- data/lib/write_xlsx/package/xml_writer_simple.rb +7 -3
- data/lib/write_xlsx/workbook.rb +30 -67
- data/lib/write_xlsx/worksheet.rb +189 -239
- data/test/chart/test_write_format_code.rb +2 -1
- data/test/helper.rb +9 -0
- data/test/perl_output/chart_scatter06.xlsx +0 -0
- data/test/test_example_match.rb +37 -0
- data/test/test_xml_writer_simple.rb +9 -8
- data/test/worksheet/test_write_cell.rb +10 -10
- data/write_xlsx.gemspec +3 -2
- metadata +12 -11
@@ -37,15 +37,12 @@ def write_chart_type
|
|
37
37
|
# Write the <c:areaChart> element.
|
38
38
|
#
|
39
39
|
def write_area_chart
|
40
|
-
@writer.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
write_series
|
47
|
-
|
48
|
-
@writer.end_tag('c:areaChart')
|
40
|
+
@writer.tag_elements('c:areaChart') do
|
41
|
+
# Write the c:grouping element.
|
42
|
+
write_grouping('standard')
|
43
|
+
# Write the series elements.
|
44
|
+
write_series
|
45
|
+
end
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
data/lib/write_xlsx/chart/bar.rb
CHANGED
@@ -39,29 +39,6 @@ def write_chart_type
|
|
39
39
|
write_bar_chart
|
40
40
|
end
|
41
41
|
|
42
|
-
#
|
43
|
-
# Write the <c:barChart> element.
|
44
|
-
#
|
45
|
-
def write_bar_chart
|
46
|
-
subtype = @subtype
|
47
|
-
|
48
|
-
subtype = 'percentStacked' if subtype == 'percent_stacked'
|
49
|
-
|
50
|
-
@writer.start_tag('c:barChart')
|
51
|
-
|
52
|
-
# Write the c:barDir element.
|
53
|
-
write_bar_dir
|
54
|
-
|
55
|
-
# Write the c:grouping element.
|
56
|
-
write_grouping(subtype)
|
57
|
-
|
58
|
-
# Write the series elements.
|
59
|
-
write_series
|
60
|
-
|
61
|
-
@writer.end_tag('c:barChart')
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
42
|
#
|
66
43
|
# Write the <c:barDir> element.
|
67
44
|
#
|
@@ -79,27 +56,7 @@ def write_bar_dir
|
|
79
56
|
# Write the series elements.
|
80
57
|
#
|
81
58
|
def write_series
|
82
|
-
|
83
|
-
index = 0
|
84
|
-
@series.each do |series|
|
85
|
-
write_ser(index, series)
|
86
|
-
index += 1
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
# Write the c:marker element.
|
91
|
-
write_marker_value
|
92
|
-
|
93
|
-
# Write the c:overlap element.
|
94
|
-
write_overlap if @subtype =~ /stacked/
|
95
|
-
|
96
|
-
# Generate the axis ids.
|
97
|
-
add_axis_id
|
98
|
-
add_axis_id
|
99
|
-
|
100
|
-
# Write the c:axId element.
|
101
|
-
write_axis_id(@axis_ids[0])
|
102
|
-
write_axis_id(@axis_ids[1])
|
59
|
+
write_series_base {write_overlap if @subtype =~ /stacked/}
|
103
60
|
end
|
104
61
|
|
105
62
|
|
@@ -42,32 +42,6 @@ def write_chart_type
|
|
42
42
|
write_bar_chart
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
##############################################################################
|
47
|
-
#
|
48
|
-
# _write_bar_chart
|
49
|
-
#
|
50
|
-
# Write the <c:barChart> element.
|
51
|
-
#
|
52
|
-
def write_bar_chart
|
53
|
-
subtype = @subtype
|
54
|
-
|
55
|
-
subtype = 'percentStacked' if subtype == 'percent_stacked'
|
56
|
-
|
57
|
-
@writer.start_tag('c:barChart')
|
58
|
-
|
59
|
-
# Write the c:barDir element.
|
60
|
-
write_bar_dir
|
61
|
-
|
62
|
-
# Write the c:grouping element.
|
63
|
-
write_grouping(subtype)
|
64
|
-
|
65
|
-
# Write the series elements.
|
66
|
-
write_series
|
67
|
-
|
68
|
-
@writer.end_tag('c:barChart')
|
69
|
-
end
|
70
|
-
|
71
45
|
#
|
72
46
|
# Write the <c:barDir> element.
|
73
47
|
#
|
@@ -86,26 +60,7 @@ def write_bar_dir
|
|
86
60
|
# Write the series elements.
|
87
61
|
#
|
88
62
|
def write_series
|
89
|
-
|
90
|
-
index = 0
|
91
|
-
@series.each do |series|
|
92
|
-
write_ser(index, series)
|
93
|
-
index += 1
|
94
|
-
end
|
95
|
-
|
96
|
-
# Write the c:marker element.
|
97
|
-
write_marker_value
|
98
|
-
|
99
|
-
# Write the c:overlap element.
|
100
|
-
write_overlap if @subtype =~ /stacked/
|
101
|
-
|
102
|
-
# Generate the axis ids.
|
103
|
-
add_axis_id
|
104
|
-
add_axis_id
|
105
|
-
|
106
|
-
# Write the c:axId element.
|
107
|
-
write_axis_id(@axis_ids[0])
|
108
|
-
write_axis_id(@axis_ids[1])
|
63
|
+
write_series_base {write_overlap if @subtype =~ /stacked/}
|
109
64
|
end
|
110
65
|
|
111
66
|
#
|
@@ -36,15 +36,12 @@ def write_chart_type
|
|
36
36
|
# Write the <c:lineChart> element.
|
37
37
|
#
|
38
38
|
def write_line_chart
|
39
|
-
@writer.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
write_series
|
46
|
-
|
47
|
-
@writer.end_tag('c:lineChart')
|
39
|
+
@writer.tag_elements('c:lineChart') do
|
40
|
+
# Write the c:grouping element.
|
41
|
+
write_grouping('standard')
|
42
|
+
# Write the series elements.
|
43
|
+
write_series
|
44
|
+
end
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
data/lib/write_xlsx/chart/pie.rb
CHANGED
@@ -43,18 +43,14 @@ def write_chart_type
|
|
43
43
|
# Write the <c:pieChart> element.
|
44
44
|
#
|
45
45
|
def write_pie_chart
|
46
|
-
@writer.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# Write the c:firstSliceAng element.
|
55
|
-
write_first_slice_ang
|
56
|
-
|
57
|
-
@writer.end_tag('c:pieChart')
|
46
|
+
@writer.tag_elements('c:pieChart') do
|
47
|
+
# Write the c:varyColors element.
|
48
|
+
write_vary_colors
|
49
|
+
# Write the series elements.
|
50
|
+
write_series
|
51
|
+
# Write the c:firstSliceAng element.
|
52
|
+
write_first_slice_ang
|
53
|
+
end
|
58
54
|
end
|
59
55
|
|
60
56
|
#
|
@@ -64,15 +60,12 @@ def write_pie_chart
|
|
64
60
|
# Write the <c:plotArea> element.
|
65
61
|
#
|
66
62
|
def write_plot_area
|
67
|
-
@writer.
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
write_chart_type
|
74
|
-
|
75
|
-
@writer.end_tag('c:plotArea')
|
63
|
+
@writer.tag_elements('c:plotArea') do
|
64
|
+
# Write the c:layout element.
|
65
|
+
write_layout
|
66
|
+
# Write the subclass chart type element.
|
67
|
+
write_chart_type
|
68
|
+
end
|
76
69
|
end
|
77
70
|
|
78
71
|
#
|
@@ -116,21 +109,16 @@ def write_legend
|
|
116
109
|
|
117
110
|
position = allowed[position]
|
118
111
|
|
119
|
-
@writer.
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
# Write the c:txPr element. Over-ridden.
|
131
|
-
write_tx_pr_legend
|
132
|
-
|
133
|
-
@writer.end_tag('c:legend')
|
112
|
+
@writer.tag_elements('c:legend') do
|
113
|
+
# Write the c:legendPos element.
|
114
|
+
write_legend_pos(position)
|
115
|
+
# Write the c:layout element.
|
116
|
+
write_layout
|
117
|
+
# Write the c:overlay element.
|
118
|
+
write_overlay if overlay != 0
|
119
|
+
# Write the c:txPr element. Over-ridden.
|
120
|
+
write_tx_pr_legend
|
121
|
+
end
|
134
122
|
end
|
135
123
|
|
136
124
|
#
|
@@ -139,33 +127,26 @@ def write_legend
|
|
139
127
|
def write_tx_pr_legend
|
140
128
|
horiz = 0
|
141
129
|
|
142
|
-
@writer.
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
# Write the a:p element.
|
151
|
-
write_a_p_legend
|
152
|
-
|
153
|
-
@writer.end_tag('c:txPr')
|
130
|
+
@writer.tag_elements('c:txPr') do
|
131
|
+
# Write the a:bodyPr element.
|
132
|
+
write_a_body_pr(horiz)
|
133
|
+
# Write the a:lstStyle element.
|
134
|
+
write_a_lst_style
|
135
|
+
# Write the a:p element.
|
136
|
+
write_a_p_legend
|
137
|
+
end
|
154
138
|
end
|
155
139
|
|
156
140
|
#
|
157
141
|
# Write the <a:p> element for legends.
|
158
142
|
#
|
159
143
|
def write_a_p_legend
|
160
|
-
@writer.
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
write_a_end_para_rpr
|
167
|
-
|
168
|
-
@writer.end_tag('a:p')
|
144
|
+
@writer.tag_elements('a:p') do
|
145
|
+
# Write the a:pPr element.
|
146
|
+
write_a_p_pr_legend
|
147
|
+
# Write the a:endParaRPr element.
|
148
|
+
write_a_end_para_rpr
|
149
|
+
end
|
169
150
|
end
|
170
151
|
|
171
152
|
#
|
@@ -176,12 +157,10 @@ def write_a_p_pr_legend
|
|
176
157
|
|
177
158
|
attributes = ['rtl', rtl]
|
178
159
|
|
179
|
-
@writer.
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
@writer.end_tag('a:pPr')
|
160
|
+
@writer.tag_elements('a:pPr', attributes) do
|
161
|
+
# Write the a:defRPr element.
|
162
|
+
write_a_def_rpr
|
163
|
+
end
|
185
164
|
end
|
186
165
|
|
187
166
|
#
|
@@ -68,15 +68,12 @@ def write_scatter_chart
|
|
68
68
|
# Add default formatting to the series data.
|
69
69
|
modify_series_formatting
|
70
70
|
|
71
|
-
@writer.
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
write_series
|
78
|
-
|
79
|
-
@writer.end_tag('c:scatterChart')
|
71
|
+
@writer.tag_elements('c:scatterChart') do
|
72
|
+
# Write the c:scatterStyle element.
|
73
|
+
write_scatter_style(style)
|
74
|
+
# Write the series elements.
|
75
|
+
write_series
|
76
|
+
end
|
80
77
|
end
|
81
78
|
|
82
79
|
#
|
@@ -85,39 +82,28 @@ def write_scatter_chart
|
|
85
82
|
# Write the <c:ser> element.
|
86
83
|
#
|
87
84
|
def write_ser(index, series)
|
88
|
-
@writer.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
# Write the c:xVal element.
|
112
|
-
write_x_val(series)
|
113
|
-
|
114
|
-
# Write the c:yVal element.
|
115
|
-
write_y_val(series)
|
116
|
-
|
117
|
-
# Write the c:smooth element.
|
118
|
-
write_c_smooth
|
119
|
-
|
120
|
-
@writer.end_tag('c:ser')
|
85
|
+
@writer.tag_elements('c:ser') do
|
86
|
+
# Write the c:idx element.
|
87
|
+
write_idx(index)
|
88
|
+
# Write the c:order element.
|
89
|
+
write_order(index)
|
90
|
+
# Write the series name.
|
91
|
+
write_series_name(series)
|
92
|
+
# Write the c:spPr element.
|
93
|
+
write_sp_pr(series)
|
94
|
+
# Write the c:marker element.
|
95
|
+
write_marker(series[:_marker])
|
96
|
+
# Write the c:dLbls element.
|
97
|
+
write_d_lbls(series[:_labels])
|
98
|
+
# Write the c:trendline element.
|
99
|
+
write_trendline(series[:_trendline])
|
100
|
+
# Write the c:xVal element.
|
101
|
+
write_x_val(series)
|
102
|
+
# Write the c:yVal element.
|
103
|
+
write_y_val(series)
|
104
|
+
# Write the c:smooth element.
|
105
|
+
write_c_smooth
|
106
|
+
end
|
121
107
|
end
|
122
108
|
|
123
109
|
#
|
@@ -127,72 +113,32 @@ def write_ser(index, series)
|
|
127
113
|
# Write the <c:plotArea> element.
|
128
114
|
#
|
129
115
|
def write_plot_area
|
130
|
-
@writer.
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
@horiz_val_axis = 1
|
143
|
-
write_val_axis('l')
|
144
|
-
|
145
|
-
@writer.end_tag('c:plotArea')
|
116
|
+
@writer.tag_elements('c:plotArea') do
|
117
|
+
# Write the c:layout element.
|
118
|
+
write_layout
|
119
|
+
# Write the subclass chart type element.
|
120
|
+
write_chart_type
|
121
|
+
# Write the c:catAx element.
|
122
|
+
write_cat_val_axis('b', 1)
|
123
|
+
# Write the c:catAx element.
|
124
|
+
@horiz_val_axis = 1
|
125
|
+
|
126
|
+
write_val_axis('l')
|
127
|
+
end
|
146
128
|
end
|
147
129
|
|
148
130
|
#
|
149
131
|
# Write the <c:xVal> element.
|
150
132
|
#
|
151
133
|
def write_x_val(series)
|
152
|
-
|
153
|
-
data_id = series[:_cat_data_id]
|
154
|
-
data = @formula_data[data_id]
|
155
|
-
|
156
|
-
@writer.start_tag('c:xVal')
|
157
|
-
|
158
|
-
# Check the type of cached data.
|
159
|
-
type = get_data_type(data)
|
160
|
-
|
161
|
-
# TODO. Can a scatter plot have non-numeric data.
|
162
|
-
|
163
|
-
if type == 'str'
|
164
|
-
# Write the c:numRef element.
|
165
|
-
write_str_ref(formula, data, type)
|
166
|
-
else
|
167
|
-
# Write the c:numRef element.
|
168
|
-
write_num_ref(formula, data, type)
|
169
|
-
end
|
170
|
-
|
171
|
-
@writer.end_tag('c:xVal')
|
134
|
+
write_val_base(series[:_categories], series[:_cat_data_id], 'c:xVal')
|
172
135
|
end
|
173
136
|
|
174
137
|
#
|
175
138
|
# Write the <c:yVal> element.
|
176
139
|
#
|
177
140
|
def write_y_val(series)
|
178
|
-
|
179
|
-
data_id = series[:_val_data_id]
|
180
|
-
data = @formula_data[data_id]
|
181
|
-
|
182
|
-
@writer.start_tag('c:yVal')
|
183
|
-
|
184
|
-
# Check the type of cached data.
|
185
|
-
type = get_data_type(data)
|
186
|
-
|
187
|
-
if type == 'str'
|
188
|
-
# Write the c:numRef element.
|
189
|
-
write_str_ref(formula, data, type)
|
190
|
-
else
|
191
|
-
# Write the c:numRef element.
|
192
|
-
write_num_ref(formula, data, type)
|
193
|
-
end
|
194
|
-
|
195
|
-
@writer.end_tag('c:yVal')
|
141
|
+
write_val_base(series[:_values], series[:_val_data_id], 'c:yVal')
|
196
142
|
end
|
197
143
|
|
198
144
|
#
|