write_xlsx 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -109,24 +109,19 @@ def write_scale_crop
|
|
109
109
|
# Write the <HeadingPairs> element.
|
110
110
|
#
|
111
111
|
def write_heading_pairs
|
112
|
-
|
113
|
-
|
112
|
+
@writer.tag_elements('HeadingPairs') do
|
114
113
|
write_vt_vector('variant', @heading_pairs)
|
115
|
-
|
116
|
-
@writer.end_tag('HeadingPairs')
|
114
|
+
end
|
117
115
|
end
|
118
116
|
|
119
117
|
#
|
120
118
|
# Write the <TitlesOfParts> element.
|
121
119
|
#
|
122
120
|
def write_titles_of_parts
|
123
|
-
@writer.
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
write_vt_vector('lpstr', parts_data)
|
128
|
-
|
129
|
-
@writer.end_tag('TitlesOfParts')
|
121
|
+
@writer.tag_elements('TitlesOfParts') do
|
122
|
+
parts_data = @part_names.collect { |part_name| ['lpstr', part_name] }
|
123
|
+
write_vt_vector('lpstr', parts_data)
|
124
|
+
end
|
130
125
|
end
|
131
126
|
|
132
127
|
#
|
@@ -140,15 +135,15 @@ def write_vt_vector(base_type, data)
|
|
140
135
|
'baseType', base_type
|
141
136
|
]
|
142
137
|
|
143
|
-
@writer.
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
138
|
+
@writer.tag_elements('vt:vector', attributes) do
|
139
|
+
data.each do |a|
|
140
|
+
if base_type == 'variant'
|
141
|
+
@writer.tag_elements('vt:variant') { write_vt_data(*a) }
|
142
|
+
else
|
143
|
+
write_vt_data(*a)
|
144
|
+
end
|
145
|
+
end
|
149
146
|
end
|
150
|
-
|
151
|
-
@writer.end_tag('vt:vector')
|
152
147
|
end
|
153
148
|
|
154
149
|
#
|
@@ -211,20 +211,19 @@ def write_comments
|
|
211
211
|
def write_authors(comment_data)
|
212
212
|
author_count = 0
|
213
213
|
|
214
|
-
@writer.
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
214
|
+
@writer.tag_elements('authors') do
|
215
|
+
comment_data.each do |comment|
|
216
|
+
author = comment.author || ''
|
217
|
+
if author && !@author_ids[author]
|
218
|
+
# Store the author id.
|
219
|
+
@author_ids[author] = author_count
|
220
|
+
author_count += 1
|
221
|
+
|
222
|
+
# Write the author element.
|
223
|
+
write_author(author)
|
224
|
+
end
|
224
225
|
end
|
225
226
|
end
|
226
|
-
|
227
|
-
@writer.end_tag('authors')
|
228
227
|
end
|
229
228
|
|
230
229
|
#
|
@@ -238,9 +237,9 @@ def write_author(data)
|
|
238
237
|
# Write the <commentList> element.
|
239
238
|
#
|
240
239
|
def write_comment_list(comment_data)
|
241
|
-
@writer.
|
242
|
-
|
243
|
-
|
240
|
+
@writer.tag_elements('commentList') do
|
241
|
+
comment_data.each { |comment| write_comment(comment) }
|
242
|
+
end
|
244
243
|
end
|
245
244
|
|
246
245
|
#
|
@@ -253,36 +252,31 @@ def write_comment(comment)
|
|
253
252
|
author_id = (@author_ids[comment.author] if comment.author) || 0
|
254
253
|
attributes << 'authorId' << author_id
|
255
254
|
|
256
|
-
@writer.
|
257
|
-
|
258
|
-
|
255
|
+
@writer.tag_elements('comment', attributes) do
|
256
|
+
write_text(comment.string)
|
257
|
+
end
|
259
258
|
end
|
260
259
|
|
261
260
|
#
|
262
261
|
# Write the <text> element.
|
263
262
|
#
|
264
263
|
def write_text(text)
|
265
|
-
@writer.
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
@writer.end_tag('text')
|
264
|
+
@writer.tag_elements('text') do
|
265
|
+
# Write the text r element.
|
266
|
+
write_text_r(text)
|
267
|
+
end
|
271
268
|
end
|
272
269
|
|
273
270
|
#
|
274
271
|
# Write the <r> element.
|
275
272
|
#
|
276
273
|
def write_text_r(text)
|
277
|
-
@writer.
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
write_text_t(text)
|
284
|
-
|
285
|
-
@writer.end_tag('r')
|
274
|
+
@writer.tag_elements('r') do
|
275
|
+
# Write the rPr element.
|
276
|
+
write_r_pr
|
277
|
+
# Write the text r element.
|
278
|
+
write_text_t(text)
|
279
|
+
end
|
286
280
|
end
|
287
281
|
|
288
282
|
#
|
@@ -300,21 +294,16 @@ def write_text_t(text)
|
|
300
294
|
# Write the <rPr> element.
|
301
295
|
#
|
302
296
|
def write_r_pr
|
303
|
-
@writer.
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
# Write the family element.
|
315
|
-
write_family
|
316
|
-
|
317
|
-
@writer.end_tag('rPr')
|
297
|
+
@writer.tag_elements('rPr') do
|
298
|
+
# Write the sz element.
|
299
|
+
write_sz
|
300
|
+
# Write the color element.
|
301
|
+
write_color
|
302
|
+
# Write the rFont element.
|
303
|
+
write_r_font
|
304
|
+
# Write the family element.
|
305
|
+
write_family
|
306
|
+
end
|
318
307
|
end
|
319
308
|
|
320
309
|
#
|
@@ -84,18 +84,14 @@ def write_cp_core_properties
|
|
84
84
|
# Write the <dc:creator> element.
|
85
85
|
#
|
86
86
|
def write_dc_creator
|
87
|
-
|
88
|
-
|
89
|
-
@writer.data_element('dc:creator', data)
|
87
|
+
write_base(:author, 'dc:creator', '')
|
90
88
|
end
|
91
89
|
|
92
90
|
#
|
93
91
|
# Write the <cp:lastModifiedBy> element.
|
94
92
|
#
|
95
93
|
def write_cp_last_modified_by
|
96
|
-
|
97
|
-
|
98
|
-
@writer.data_element('cp:lastModifiedBy', data)
|
94
|
+
write_base(:author, 'cp:lastModifiedBy', '')
|
99
95
|
end
|
100
96
|
|
101
97
|
#
|
@@ -130,66 +126,48 @@ def write_dcterms_modified
|
|
130
126
|
# Write the <dc:title> element.
|
131
127
|
#
|
132
128
|
def write_dc_title
|
133
|
-
|
134
|
-
|
135
|
-
return unless data
|
136
|
-
|
137
|
-
@writer.data_element('dc:title', data)
|
129
|
+
write_base(:title, 'dc:title')
|
138
130
|
end
|
139
131
|
|
140
132
|
#
|
141
133
|
# Write the <dc:subject> element.
|
142
134
|
#
|
143
135
|
def write_dc_subject
|
144
|
-
|
145
|
-
|
146
|
-
return unless data
|
147
|
-
|
148
|
-
@writer.data_element('dc:subject', data)
|
136
|
+
write_base(:subject, 'dc:subject')
|
149
137
|
end
|
150
138
|
|
151
139
|
#
|
152
140
|
# Write the <cp:keywords> element.
|
153
141
|
#
|
154
142
|
def write_cp_keywords
|
155
|
-
|
156
|
-
|
157
|
-
return unless data
|
158
|
-
|
159
|
-
@writer.data_element('cp:keywords', data)
|
143
|
+
write_base(:keywords, 'cp:keywords')
|
160
144
|
end
|
161
145
|
|
162
146
|
#
|
163
147
|
# Write the <dc:description> element.
|
164
148
|
#
|
165
149
|
def write_dc_description
|
166
|
-
|
167
|
-
|
168
|
-
return unless data
|
169
|
-
|
170
|
-
@writer.data_element('dc:description', data)
|
150
|
+
write_base(:comments, 'dc:description')
|
171
151
|
end
|
172
152
|
|
173
153
|
#
|
174
154
|
# Write the <cp:category> element.
|
175
155
|
#
|
176
156
|
def write_cp_category
|
177
|
-
|
178
|
-
|
179
|
-
return unless data
|
180
|
-
|
181
|
-
@writer.data_element('cp:category', data)
|
157
|
+
write_base(:category, 'cp:category')
|
182
158
|
end
|
183
159
|
|
184
160
|
#
|
185
161
|
# Write the <cp:contentStatus> element.
|
186
162
|
#
|
187
163
|
def write_cp_content_status
|
188
|
-
|
164
|
+
write_base(:status, 'cp:contentStatus')
|
165
|
+
end
|
189
166
|
|
167
|
+
def write_base(key, tag, default = nil)
|
168
|
+
data = @properties[key] || default
|
190
169
|
return unless data
|
191
|
-
|
192
|
-
@writer.data_element('cp:contentStatus', data)
|
170
|
+
@writer.data_element(tag, data)
|
193
171
|
end
|
194
172
|
end
|
195
173
|
end
|
@@ -120,31 +120,26 @@ def write_chartsheet_files
|
|
120
120
|
# Write the chart files.
|
121
121
|
#
|
122
122
|
def write_chart_files
|
123
|
-
|
124
|
-
|
125
|
-
FileUtils.mkdir_p("#{@package_dir}/xl/charts")
|
126
|
-
|
127
|
-
index = 1
|
128
|
-
@workbook.charts.each do |chart|
|
129
|
-
chart.set_xml_writer("#{@package_dir}/xl/charts/chart#{index}.xml")
|
130
|
-
index += 1
|
131
|
-
chart.assemble_xml_file
|
132
|
-
end
|
123
|
+
write_chart_or_drawing_files(@workbook.charts, 'chart')
|
133
124
|
end
|
134
125
|
|
135
126
|
#
|
136
127
|
# Write the drawing files.
|
137
128
|
#
|
138
129
|
def write_drawing_files
|
139
|
-
|
130
|
+
write_chart_or_drawing_files(@workbook.drawings, 'drawing')
|
131
|
+
end
|
132
|
+
|
133
|
+
def write_chart_or_drawing_files(objects, filename)
|
134
|
+
return if objects.empty?
|
140
135
|
|
141
|
-
FileUtils.mkdir_p("#{@package_dir}/xl
|
136
|
+
FileUtils.mkdir_p("#{@package_dir}/xl/#{filename}s")
|
142
137
|
|
143
138
|
index = 1
|
144
|
-
|
145
|
-
|
139
|
+
objects.each do |object|
|
140
|
+
object.set_xml_writer("#{@package_dir}/xl/#{filename}s/#{filename}#{index}.xml")
|
146
141
|
index += 1
|
147
|
-
|
142
|
+
object.assemble_xml_file
|
148
143
|
end
|
149
144
|
end
|
150
145
|
|
@@ -71,11 +71,9 @@ def write_xml_declaration
|
|
71
71
|
def write_relationships
|
72
72
|
attributes = ['xmlns', Package_schema]
|
73
73
|
|
74
|
-
@writer.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
@writer.end_tag('Relationships')
|
74
|
+
@writer.tag_elements('Relationships', attributes) do
|
75
|
+
@rels.each { |rel| write_relationship(*rel) }
|
76
|
+
end
|
79
77
|
end
|
80
78
|
|
81
79
|
#
|
@@ -93,16 +93,14 @@ def write_si(string)
|
|
93
93
|
|
94
94
|
attributes << 'xml:space' << 'preserve' if string =~ /^[ \t]/ || string =~ /[ \t]$/
|
95
95
|
|
96
|
-
@writer.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
96
|
+
@writer.tag_elements('si') do
|
97
|
+
# Write any rich strings without further tags.
|
98
|
+
if string =~ %r{^<r>} && string =~ %r{</r>$}
|
99
|
+
@writer.io_write(string)
|
100
|
+
else
|
101
|
+
@writer.data_element('t', string, attributes)
|
102
|
+
end
|
103
103
|
end
|
104
|
-
|
105
|
-
@writer.end_tag('si')
|
106
104
|
end
|
107
105
|
|
108
106
|
def total_count
|
@@ -96,16 +96,14 @@ def write_num_fmts
|
|
96
96
|
|
97
97
|
attributes = ['count', count]
|
98
98
|
|
99
|
-
@writer.
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
@writer.tag_elements('numFmts', attributes) do
|
100
|
+
# Write the numFmts elements.
|
101
|
+
@xf_formats.each do |format|
|
102
|
+
# Ignore built-in number formats, i.e., < 164.
|
103
|
+
next unless format.num_format_index >= 164
|
104
|
+
write_num_fmt(format.num_format_index, format.num_format)
|
105
|
+
end
|
106
106
|
end
|
107
|
-
|
108
|
-
@writer.end_tag('numFmts')
|
109
107
|
end
|
110
108
|
|
111
109
|
#
|
@@ -172,64 +170,57 @@ def write_num_fmt(num_fmt_id, format_code)
|
|
172
170
|
# Write the <fonts> element.
|
173
171
|
#
|
174
172
|
def write_fonts
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
# Write the font elements for format objects that have them.
|
182
|
-
@xf_formats.each { |format| write_font(format) unless format.has_font == 0 }
|
183
|
-
|
184
|
-
@writer.end_tag('fonts')
|
173
|
+
write_format_elements('fonts', @font_count) do
|
174
|
+
@xf_formats.each do |format|
|
175
|
+
write_font(format) if format.has_font?
|
176
|
+
end
|
177
|
+
end
|
185
178
|
end
|
186
179
|
|
187
180
|
#
|
188
181
|
# Write the <font> element.
|
189
182
|
#
|
190
183
|
def write_font(format, dxf_format = nil)
|
191
|
-
@writer.
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
end
|
184
|
+
@writer.tag_elements('font') do
|
185
|
+
# The condense and extend elements are mainly used in dxf formats.
|
186
|
+
write_condense unless format.font_condense == 0
|
187
|
+
write_extend unless format.font_extend == 0
|
188
|
+
|
189
|
+
@writer.empty_tag('b') if format.bold?
|
190
|
+
@writer.empty_tag('i') if format.italic?
|
191
|
+
@writer.empty_tag('strike') if format.strikeout?
|
192
|
+
@writer.empty_tag('outline') if format.outline?
|
193
|
+
@writer.empty_tag('shadow') if format.shadow?
|
194
|
+
|
195
|
+
# Handle the underline variants.
|
196
|
+
write_underline( format.underline ) if format.underline?
|
197
|
+
|
198
|
+
write_vert_align('superscript') if format.font_script == 1
|
199
|
+
write_vert_align('subscript') if format.font_script == 2
|
200
|
+
|
201
|
+
@writer.empty_tag('sz', ['val', format.size]) if !dxf_format
|
202
|
+
|
203
|
+
theme = format.theme
|
204
|
+
if theme != 0
|
205
|
+
write_color('theme', theme)
|
206
|
+
elsif format.color_indexed != 0
|
207
|
+
write_color('indexed', format.color_indexed)
|
208
|
+
elsif format.color != 0
|
209
|
+
color = get_palette_color(format.color)
|
210
|
+
write_color('rgb', color)
|
211
|
+
elsif !dxf_format
|
212
|
+
write_color('theme', 1)
|
213
|
+
end
|
222
214
|
|
223
|
-
|
224
|
-
|
225
|
-
|
215
|
+
if !dxf_format
|
216
|
+
@writer.empty_tag('name', ['val', format.font])
|
217
|
+
@writer.empty_tag('family', ['val', format.font_family])
|
226
218
|
|
227
|
-
|
228
|
-
|
219
|
+
if format.font == 'Calibri' && format.hyperlink == 0
|
220
|
+
@writer.empty_tag('scheme', ['val', format.font_scheme])
|
221
|
+
end
|
229
222
|
end
|
230
223
|
end
|
231
|
-
|
232
|
-
@writer.end_tag('font')
|
233
224
|
end
|
234
225
|
|
235
226
|
#
|
@@ -259,27 +250,25 @@ def write_fills
|
|
259
250
|
|
260
251
|
attributes = ['count', count]
|
261
252
|
|
262
|
-
@writer.
|
253
|
+
@writer.tag_elements('fills', attributes) do
|
254
|
+
# Write the default fill element.
|
255
|
+
write_default_fill('none')
|
256
|
+
write_default_fill('gray125')
|
263
257
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
# Write the fill elements for format objects that have them.
|
269
|
-
@xf_formats.each do |format|
|
270
|
-
write_fill(format) unless format.has_fill == 0
|
258
|
+
# Write the fill elements for format objects that have them.
|
259
|
+
@xf_formats.each do |format|
|
260
|
+
write_fill(format) if format.has_fill?
|
261
|
+
end
|
271
262
|
end
|
272
|
-
|
273
|
-
@writer.end_tag( 'fills' )
|
274
263
|
end
|
275
264
|
|
276
265
|
#
|
277
266
|
# Write the <fill> element for the default fills.
|
278
267
|
#
|
279
268
|
def write_default_fill(pattern_type)
|
280
|
-
@writer.
|
281
|
-
|
282
|
-
|
269
|
+
@writer.tag_elements('fill') do
|
270
|
+
@writer.empty_tag('patternFill', ['patternType', pattern_type])
|
271
|
+
end
|
283
272
|
end
|
284
273
|
|
285
274
|
#
|
@@ -312,47 +301,48 @@ def write_fill(format, dxf_format = nil)
|
|
312
301
|
gray0625
|
313
302
|
)
|
314
303
|
|
315
|
-
@writer.
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
304
|
+
@writer.tag_elements('fill' ) do
|
305
|
+
# The "none" pattern is handled differently for dxf formats.
|
306
|
+
if dxf_format && format.pattern <= 1
|
307
|
+
attributes = []
|
308
|
+
else
|
309
|
+
attributes = ['patternType', patterns[format.pattern]]
|
310
|
+
end
|
311
|
+
|
312
|
+
@writer.tag_elements('patternFill', attributes) do
|
313
|
+
unless fg_color == 0
|
314
|
+
fg_color = get_palette_color(fg_color)
|
315
|
+
@writer.empty_tag('fgColor', ['rgb', fg_color])
|
316
|
+
end
|
328
317
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
318
|
+
if bg_color != 0
|
319
|
+
bg_color = get_palette_color(bg_color)
|
320
|
+
@writer.empty_tag('bgColor', ['rgb', bg_color])
|
321
|
+
else
|
322
|
+
@writer.empty_tag('bgColor', ['indexed', 64]) if !dxf_format
|
323
|
+
end
|
324
|
+
end
|
334
325
|
end
|
335
|
-
|
336
|
-
@writer.end_tag('patternFill')
|
337
|
-
@writer.end_tag('fill')
|
338
326
|
end
|
339
327
|
|
340
328
|
#
|
341
329
|
# Write the <borders> element.
|
342
330
|
#
|
343
331
|
def write_borders
|
344
|
-
|
332
|
+
write_format_elements('borders', @border_count) do
|
333
|
+
@xf_formats.each do |format|
|
334
|
+
write_border(format) if format.has_border?
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
345
338
|
|
339
|
+
def write_format_elements(elements, count)
|
346
340
|
attributes = ['count', count]
|
347
341
|
|
348
|
-
@writer.
|
349
|
-
|
350
|
-
|
351
|
-
@xf_formats.each do |format|
|
352
|
-
write_border(format) unless format.has_border == 0
|
342
|
+
@writer.tag_elements(elements, attributes) do
|
343
|
+
# Write the border elements for format objects that have them.
|
344
|
+
yield
|
353
345
|
end
|
354
|
-
|
355
|
-
@writer.end_tag('borders')
|
356
346
|
end
|
357
347
|
|
358
348
|
#
|
@@ -375,25 +365,23 @@ def write_border(format, dxf_format = nil)
|
|
375
365
|
format.diag_border = 1 if format.diag_type != 0 && format.diag_border == 0
|
376
366
|
|
377
367
|
# Write the start border tag.
|
378
|
-
@writer.
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
end
|
368
|
+
@writer.tag_elements('border', attributes) do
|
369
|
+
# Write the <border> sub elements.
|
370
|
+
write_sub_border('left', format.left, format.left_color)
|
371
|
+
write_sub_border('right', format.right, format.right_color)
|
372
|
+
write_sub_border('top', format.top, format.top_color)
|
373
|
+
write_sub_border('bottom', format.bottom, format.bottom_color)
|
374
|
+
|
375
|
+
# Condition DXF formats don't allow diagonal borders
|
376
|
+
if !dxf_format
|
377
|
+
write_sub_border('diagonal', format.diag_border, format.diag_color)
|
378
|
+
end
|
390
379
|
|
391
|
-
|
392
|
-
|
393
|
-
|
380
|
+
if dxf_format
|
381
|
+
write_sub_border('vertical')
|
382
|
+
write_sub_border('horizontal')
|
383
|
+
end
|
394
384
|
end
|
395
|
-
|
396
|
-
@writer.end_tag('border')
|
397
385
|
end
|
398
386
|
|
399
387
|
#
|
@@ -424,16 +412,14 @@ def write_sub_border(type, style = 0, color = nil)
|
|
424
412
|
|
425
413
|
attributes = [:style, border_styles[style]]
|
426
414
|
|
427
|
-
@writer.
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
415
|
+
@writer.tag_elements(type, attributes) do
|
416
|
+
if color != 0
|
417
|
+
color = get_palette_color(color)
|
418
|
+
@writer.empty_tag('color', ['rgb', color])
|
419
|
+
else
|
420
|
+
@writer.empty_tag('color', ['auto', 1])
|
421
|
+
end
|
434
422
|
end
|
435
|
-
|
436
|
-
@writer.end_tag(type)
|
437
423
|
end
|
438
424
|
|
439
425
|
#
|
@@ -444,12 +430,10 @@ def write_cell_style_xfs
|
|
444
430
|
|
445
431
|
attributes = ['count', count]
|
446
432
|
|
447
|
-
@writer.
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
@writer.end_tag('cellStyleXfs')
|
433
|
+
@writer.tag_elements('cellStyleXfs', attributes) do
|
434
|
+
# Write the style_xf element.
|
435
|
+
write_style_xf
|
436
|
+
end
|
453
437
|
end
|
454
438
|
|
455
439
|
#
|
@@ -466,12 +450,10 @@ def write_cell_xfs
|
|
466
450
|
|
467
451
|
attributes = ['count', formats.size]
|
468
452
|
|
469
|
-
@writer.
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
@writer.end_tag('cellXfs')
|
453
|
+
@writer.tag_elements('cellXfs', attributes) do
|
454
|
+
# Write the xf elements.
|
455
|
+
formats.each { |format| write_xf(format) }
|
456
|
+
end
|
475
457
|
end
|
476
458
|
|
477
459
|
#
|
@@ -540,10 +522,10 @@ def write_xf(format)
|
|
540
522
|
|
541
523
|
# Write XF with sub-elements if required.
|
542
524
|
if has_align || has_protect
|
543
|
-
@writer.
|
544
|
-
|
545
|
-
|
546
|
-
|
525
|
+
@writer.tag_elements('xf', attributes) do
|
526
|
+
@writer.empty_tag('alignment', align) if has_align
|
527
|
+
@writer.empty_tag('protection', protection) if has_protect
|
528
|
+
end
|
547
529
|
else
|
548
530
|
@writer.empty_tag('xf', attributes)
|
549
531
|
end
|
@@ -557,12 +539,10 @@ def write_cell_styles
|
|
557
539
|
|
558
540
|
attributes = ['count', count]
|
559
541
|
|
560
|
-
@writer.
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
@writer.end_tag('cellStyles')
|
542
|
+
@writer.tag_elements('cellStyles', attributes) do
|
543
|
+
# Write the cellStyle element.
|
544
|
+
write_cell_style
|
545
|
+
end
|
566
546
|
end
|
567
547
|
|
568
548
|
#
|
@@ -593,23 +573,21 @@ def write_dxfs
|
|
593
573
|
attributes = ['count', count]
|
594
574
|
|
595
575
|
if !formats.empty?
|
596
|
-
@writer.
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
576
|
+
@writer.tag_elements('dxfs', attributes) do
|
577
|
+
# Write the font elements for format objects that have them.
|
578
|
+
@dxf_formats.each do |format|
|
579
|
+
@writer.tag_elements('dxf') do
|
580
|
+
write_font(format, 1) if format.has_dxf_font?
|
581
|
+
|
582
|
+
if format.num_format_index != 0
|
583
|
+
write_num_fmt(format.num_format_index, format.num_format)
|
584
|
+
end
|
585
|
+
|
586
|
+
write_fill(format, 1) if format.has_dxf_fill?
|
587
|
+
write_border(format, 1) if format.has_dxf_border?
|
588
|
+
end
|
605
589
|
end
|
606
|
-
|
607
|
-
write_fill(format, 1) if format.has_dxf_fill != 0
|
608
|
-
write_border(format, 1) if format.has_dxf_border != 0
|
609
|
-
@writer.end_tag('dxf')
|
610
590
|
end
|
611
|
-
|
612
|
-
@writer.end_tag('dxfs')
|
613
591
|
else
|
614
592
|
@writer.empty_tag('dxfs', attributes)
|
615
593
|
end
|
@@ -640,9 +618,9 @@ def write_colors
|
|
640
618
|
|
641
619
|
return if @custom_colors.empty?
|
642
620
|
|
643
|
-
@writer.
|
644
|
-
|
645
|
-
|
621
|
+
@writer.tag_elements( 'colors' ) do
|
622
|
+
write_mru_colors(@custom_colors)
|
623
|
+
end
|
646
624
|
end
|
647
625
|
|
648
626
|
#
|
@@ -655,14 +633,12 @@ def write_mru_colors(*args)
|
|
655
633
|
count = custom_colors.size
|
656
634
|
custom_colors = custom_colors[-10, 10] if count > 10
|
657
635
|
|
658
|
-
@writer.
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
636
|
+
@writer.tag_elements('mruColors') do
|
637
|
+
# Write the custom colors in reverse order.
|
638
|
+
@custom_colors.reverse.each do |color|
|
639
|
+
write_color('rgb', color)
|
640
|
+
end
|
663
641
|
end
|
664
|
-
|
665
|
-
@writer.end_tag('mruColors')
|
666
642
|
end
|
667
643
|
|
668
644
|
def write_xml_declaration
|