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.
@@ -43,12 +43,10 @@ def write_stock_chart
43
43
  # Add default formatting to the series data.
44
44
  modify_series_formatting
45
45
 
46
- @writer.start_tag('c:stockChart')
47
-
48
- # Write the series elements.
49
- write_series
50
-
51
- @writer.end_tag('c:stockChart')
46
+ @writer.tag_elements('c:stockChart') do
47
+ # Write the series elements.
48
+ write_series
49
+ end
52
50
  end
53
51
 
54
52
  #
@@ -83,21 +81,16 @@ def write_series
83
81
  # Write the <c:plotArea> element.
84
82
  #
85
83
  def write_plot_area
86
- @writer.start_tag('c:plotArea')
87
-
88
- # Write the c:layout element.
89
- write_layout
90
-
91
- # Write the subclass chart type element.
92
- write_chart_type
93
-
94
- # Write the c:dateAx element.
95
- write_date_axis
96
-
97
- # Write the c:catAx element.
98
- write_val_axis
99
-
100
- @writer.end_tag('c:plotArea')
84
+ @writer.tag_elements('c:plotArea') do
85
+ # Write the c:layout element.
86
+ write_layout
87
+ # Write the subclass chart type element.
88
+ write_chart_type
89
+ # Write the c:dateAx element.
90
+ write_date_axis
91
+ # Write the c:catAx element.
92
+ write_val_axis
93
+ end
101
94
  end
102
95
 
103
96
  #
@@ -161,10 +161,10 @@ def _write_sheet_pr # :nodoc:
161
161
  attributes << {'filterMode' => 1} if @filter_on
162
162
 
163
163
  if @fit_page || @tab_color
164
- @writer.start_tag('sheetPr', attributes)
165
- write_tab_color
166
- write_page_set_up_pr
167
- @writer.end_tag('sheetPr')
164
+ @writer.tag_elements('sheetPr', attributes) do
165
+ write_tab_color
166
+ write_page_set_up_pr
167
+ end
168
168
  else
169
169
  @writer.empty_tag('sheetPr', attributes)
170
170
  end
@@ -88,68 +88,55 @@ def write_two_cell_anchor(*args)
88
88
  # Add attribute for images.
89
89
  attributes << :editAs << 'oneCell' if type == 2
90
90
 
91
- @writer.start_tag('xdr:twoCellAnchor', attributes)
92
-
93
- # Write the xdr:from element.
94
- write_from(col_from, row_from, col_from_offset, row_from_offset)
95
-
96
- # Write the xdr:from element.
97
- write_to(col_to, row_to, col_to_offset, row_to_offset)
98
-
99
- if type == 1
100
- # Write the xdr:graphicFrame element for charts.
101
- write_graphic_frame(index)
102
- else
103
- # Write the xdr:pic element.
104
- write_pic(index, col_absolute, row_absolute, width, height, description)
91
+ @writer.tag_elements('xdr:twoCellAnchor', attributes) do
92
+ # Write the xdr:from element.
93
+ write_from(col_from, row_from, col_from_offset, row_from_offset)
94
+ # Write the xdr:from element.
95
+ write_to(col_to, row_to, col_to_offset, row_to_offset)
96
+
97
+ if type == 1
98
+ # Write the xdr:graphicFrame element for charts.
99
+ write_graphic_frame(index)
100
+ else
101
+ # Write the xdr:pic element.
102
+ write_pic(index, col_absolute, row_absolute, width, height, description)
103
+ end
104
+
105
+ # Write the xdr:clientData element.
106
+ write_client_data
105
107
  end
106
-
107
- # Write the xdr:clientData element.
108
- write_client_data
109
-
110
- @writer.end_tag('xdr:twoCellAnchor')
111
108
  end
112
109
 
113
110
  #
114
111
  # Write the <xdr:from> element.
115
112
  #
116
113
  def write_from(col, row, col_offset, row_offset)
117
- @writer.start_tag('xdr:from')
118
-
119
- # Write the xdr:col element.
120
- write_col(col)
121
-
122
- # Write the xdr:colOff element.
123
- write_col_off(col_offset)
124
-
125
- # Write the xdr:row element.
126
- write_row(row)
127
-
128
- # Write the xdr:rowOff element.
129
- write_row_off(row_offset)
130
-
131
- @writer.end_tag('xdr:from')
114
+ @writer.tag_elements('xdr:from') do
115
+ # Write the xdr:col element.
116
+ write_col(col)
117
+ # Write the xdr:colOff element.
118
+ write_col_off(col_offset)
119
+ # Write the xdr:row element.
120
+ write_row(row)
121
+ # Write the xdr:rowOff element.
122
+ write_row_off(row_offset)
123
+ end
132
124
  end
133
125
 
134
126
  #
135
127
  # Write the <xdr:to> element.
136
128
  #
137
129
  def write_to(col, row, col_offset, row_offset)
138
- @writer.start_tag('xdr:to')
139
-
140
- # Write the xdr:col element.
141
- write_col(col)
142
-
143
- # Write the xdr:colOff element.
144
- write_col_off(col_offset)
145
-
146
- # Write the xdr:row element.
147
- write_row(row)
148
-
149
- # Write the xdr:rowOff element.
150
- write_row_off(row_offset)
151
-
152
- @writer.end_tag('xdr:to')
130
+ @writer.tag_elements('xdr:to') do
131
+ # Write the xdr:col element.
132
+ write_col(col)
133
+ # Write the xdr:colOff element.
134
+ write_col_off(col_offset)
135
+ # Write the xdr:row element.
136
+ write_row(row)
137
+ # Write the xdr:rowOff element.
138
+ write_row_off(row_offset)
139
+ end
153
140
  end
154
141
 
155
142
  #
@@ -190,33 +177,26 @@ def write_graphic_frame(index)
190
177
 
191
178
  attributes = ['macro', macro]
192
179
 
193
- @writer.start_tag('xdr:graphicFrame', attributes)
194
-
195
- # Write the xdr:nvGraphicFramePr element.
196
- write_nv_graphic_frame_pr(index)
197
-
198
- # Write the xdr:xfrm element.
199
- write_xfrm
200
-
201
- # Write the a:graphic element.
202
- write_atag_graphic(index)
203
-
204
- @writer.end_tag('xdr:graphicFrame')
180
+ @writer.tag_elements('xdr:graphicFrame', attributes) do
181
+ # Write the xdr:nvGraphicFramePr element.
182
+ write_nv_graphic_frame_pr(index)
183
+ # Write the xdr:xfrm element.
184
+ write_xfrm
185
+ # Write the a:graphic element.
186
+ write_atag_graphic(index)
187
+ end
205
188
  end
206
189
 
207
190
  #
208
191
  # Write the <xdr:nvGraphicFramePr> element.
209
192
  #
210
193
  def write_nv_graphic_frame_pr(index)
211
- @writer.start_tag('xdr:nvGraphicFramePr')
212
-
213
- # Write the xdr:cNvPr element.
214
- write_c_nv_pr( index + 1, "Chart #{index}" )
215
-
216
- # Write the xdr:cNvGraphicFramePr element.
217
- write_c_nv_graphic_frame_pr
218
-
219
- @writer.end_tag('xdr:nvGraphicFramePr')
194
+ @writer.tag_elements('xdr:nvGraphicFramePr') do
195
+ # Write the xdr:cNvPr element.
196
+ write_c_nv_pr( index + 1, "Chart #{index}" )
197
+ # Write the xdr:cNvGraphicFramePr element.
198
+ write_c_nv_graphic_frame_pr
199
+ end
220
200
  end
221
201
 
222
202
  #
@@ -242,12 +222,10 @@ def write_c_nv_graphic_frame_pr
242
222
  if @embedded
243
223
  @writer.empty_tag('xdr:cNvGraphicFramePr')
244
224
  else
245
- @writer.start_tag('xdr:cNvGraphicFramePr')
246
-
247
- # Write the a:graphicFrameLocks element.
248
- write_a_graphic_frame_locks
249
-
250
- @writer.end_tag('xdr:cNvGraphicFramePr')
225
+ @writer.tag_elements('xdr:cNvGraphicFramePr') do
226
+ # Write the a:graphicFrameLocks element.
227
+ write_a_graphic_frame_locks
228
+ end
251
229
  end
252
230
  end
253
231
 
@@ -266,15 +244,12 @@ def write_a_graphic_frame_locks
266
244
  # Write the <xdr:xfrm> element.
267
245
  #
268
246
  def write_xfrm
269
- @writer.start_tag('xdr:xfrm')
270
-
271
- # Write the xfrmOffset element.
272
- write_xfrm_offset
273
-
274
- # Write the xfrmOffset element.
275
- write_xfrm_extension
276
-
277
- @writer.end_tag('xdr:xfrm')
247
+ @writer.tag_elements('xdr:xfrm') do
248
+ # Write the xfrmOffset element.
249
+ write_xfrm_offset
250
+ # Write the xfrmOffset element.
251
+ write_xfrm_extension
252
+ end
278
253
  end
279
254
 
280
255
  #
@@ -311,12 +286,10 @@ def write_xfrm_extension
311
286
  # Write the <a:graphic> element.
312
287
  #
313
288
  def write_atag_graphic(index)
314
- @writer.start_tag('a:graphic')
315
-
316
- # Write the a:graphicData element.
317
- write_atag_graphic_data(index)
318
-
319
- @writer.end_tag('a:graphic')
289
+ @writer.tag_elements('a:graphic') do
290
+ # Write the a:graphicData element.
291
+ write_atag_graphic_data(index)
292
+ end
320
293
  end
321
294
 
322
295
  #
@@ -327,12 +300,10 @@ def write_atag_graphic_data(index)
327
300
 
328
301
  attributes = ['uri', uri]
329
302
 
330
- @writer.start_tag('a:graphicData', attributes)
331
-
332
- # Write the c:chart element.
333
- write_c_chart("rId#{index}")
334
-
335
- @writer.end_tag('a:graphicData')
303
+ @writer.tag_elements('a:graphicData', attributes) do
304
+ # Write the c:chart element.
305
+ write_c_chart("rId#{index}")
306
+ end
336
307
  end
337
308
 
338
309
  #
@@ -364,45 +335,36 @@ def write_client_data
364
335
  # Write the <xdr:pic> element.
365
336
  #
366
337
  def write_pic(index, col_absolute, row_absolute, width, height, description)
367
- @writer.start_tag('xdr:pic')
368
-
369
- # Write the xdr:nvPicPr element.
370
- write_nv_pic_pr(index, description)
371
-
372
- # Write the xdr:blipFill element.
373
- write_blip_fill(index)
374
-
375
- # Write the xdr:spPr element.
376
- write_sp_pr(col_absolute, row_absolute, width, height)
377
-
378
- @writer.end_tag('xdr:pic')
338
+ @writer.tag_elements('xdr:pic') do
339
+ # Write the xdr:nvPicPr element.
340
+ write_nv_pic_pr(index, description)
341
+ # Write the xdr:blipFill element.
342
+ write_blip_fill(index)
343
+ # Write the xdr:spPr element.
344
+ write_sp_pr(col_absolute, row_absolute, width, height)
345
+ end
379
346
  end
380
347
 
381
348
  #
382
349
  # Write the <xdr:nvPicPr> element.
383
350
  #
384
351
  def write_nv_pic_pr(index, description)
385
- @writer.start_tag('xdr:nvPicPr')
386
-
387
- # Write the xdr:cNvPr element.
388
- write_c_nv_pr( index + 1, "Picture #{index}", description )
389
-
390
- # Write the xdr:cNvPicPr element.
391
- write_c_nv_pic_pr
392
-
393
- @writer.end_tag('xdr:nvPicPr')
352
+ @writer.tag_elements('xdr:nvPicPr') do
353
+ # Write the xdr:cNvPr element.
354
+ write_c_nv_pr( index + 1, "Picture #{index}", description )
355
+ # Write the xdr:cNvPicPr element.
356
+ write_c_nv_pic_pr
357
+ end
394
358
  end
395
359
 
396
360
  #
397
361
  # Write the <xdr:cNvPicPr> element.
398
362
  #
399
363
  def write_c_nv_pic_pr
400
- @writer.start_tag('xdr:cNvPicPr')
401
-
402
- # Write the a:picLocks element.
403
- write_a_pic_locks
404
-
405
- @writer.end_tag('xdr:cNvPicPr')
364
+ @writer.tag_elements('xdr:cNvPicPr') do
365
+ # Write the a:picLocks element.
366
+ write_a_pic_locks
367
+ end
406
368
  end
407
369
 
408
370
  #
@@ -420,15 +382,12 @@ def write_a_pic_locks
420
382
  # Write the <xdr:blipFill> element.
421
383
  #
422
384
  def write_blip_fill(index)
423
- @writer.start_tag('xdr:blipFill')
424
-
425
- # Write the a:blip element.
426
- write_a_blip(index)
427
-
428
- # Write the a:stretch element.
429
- write_a_stretch
430
-
431
- @writer.end_tag('xdr:blipFill')
385
+ @writer.tag_elements('xdr:blipFill') do
386
+ # Write the a:blip element.
387
+ write_a_blip(index)
388
+ # Write the a:stretch element.
389
+ write_a_stretch
390
+ end
432
391
  end
433
392
 
434
393
  #
@@ -451,12 +410,10 @@ def write_a_blip(index)
451
410
  # Write the <a:stretch> element.
452
411
  #
453
412
  def write_a_stretch
454
- @writer.start_tag('a:stretch')
455
-
456
- # Write the a:fillRect element.
457
- write_a_fill_rect
458
-
459
- @writer.end_tag('a:stretch')
413
+ @writer.tag_elements('a:stretch') do
414
+ # Write the a:fillRect element.
415
+ write_a_fill_rect
416
+ end
460
417
  end
461
418
 
462
419
  #
@@ -470,30 +427,24 @@ def write_a_fill_rect
470
427
  # Write the <xdr:spPr> element.
471
428
  #
472
429
  def write_sp_pr(col_absolute, row_absolute, width, height)
473
- @writer.start_tag('xdr:spPr')
474
-
475
- # Write the a:xfrm element.
476
- write_a_xfrm(col_absolute, row_absolute, width, height)
477
-
478
- # Write the a:prstGeom element.
479
- write_a_prst_geom
480
-
481
- @writer.end_tag('xdr:spPr')
430
+ @writer.tag_elements('xdr:spPr') do
431
+ # Write the a:xfrm element.
432
+ write_a_xfrm(col_absolute, row_absolute, width, height)
433
+ # Write the a:prstGeom element.
434
+ write_a_prst_geom
435
+ end
482
436
  end
483
437
 
484
438
  #
485
439
  # Write the <a:xfrm> element.
486
440
  #
487
441
  def write_a_xfrm(col_absolute, row_absolute, width, height)
488
- @writer.start_tag('a:xfrm')
489
-
490
- # Write the a:off element.
491
- write_a_off( col_absolute, row_absolute )
492
-
493
- # Write the a:ext element.
494
- write_a_ext( width, height )
495
-
496
- @writer.end_tag('a:xfrm')
442
+ @writer.tag_elements('a:xfrm') do
443
+ # Write the a:off element.
444
+ write_a_off( col_absolute, row_absolute )
445
+ # Write the a:ext element.
446
+ write_a_ext( width, height )
447
+ end
497
448
  end
498
449
 
499
450
  #
@@ -529,12 +480,10 @@ def write_a_prst_geom
529
480
 
530
481
  attributes = ['prst', prst]
531
482
 
532
- @writer.start_tag('a:prstGeom', attributes)
533
-
534
- # Write the a:avLst element.
535
- write_a_av_lst
536
-
537
- @writer.end_tag('a:prstGeom')
483
+ @writer.tag_elements('a:prstGeom', attributes) do
484
+ # Write the a:avLst element.
485
+ write_a_av_lst
486
+ end
538
487
  end
539
488
 
540
489
  #
@@ -163,9 +163,8 @@ class Format
163
163
  attr_reader :diag_type, :diag_color, :font_only, :color, :color_indexed # :nodoc:
164
164
  attr_reader :left, :left_color, :right, :right_color, :top, :top_color, :bottom, :bottom_color # :nodoc:
165
165
  attr_reader :font_scheme # :nodoc:
166
- attr_accessor :font_index, :has_font, :has_dxf_font, :has_dxf_fill, :has_dxf_border # :nodoc:
167
- attr_accessor :num_format_index, :border_index, :has_border # :nodoc:
168
- attr_accessor :fill_index, :has_fill, :font_condense, :font_extend, :diag_border # :nodoc:
166
+ attr_accessor :num_format_index, :border_index, :font_index # :nodoc:
167
+ attr_accessor :fill_index, :font_condense, :font_extend, :diag_border # :nodoc:
169
168
  attr_accessor :bg_color, :fg_color, :pattern # :nodoc:
170
169
 
171
170
  def initialize(xf_format_indices = {}, dxf_format_indices = {}, params = {}) # :nodoc:
@@ -178,8 +177,6 @@ def initialize(xf_format_indices = {}, dxf_format_indices = {}, params = {}) #
178
177
  @num_format = 0
179
178
  @num_format_index = 0
180
179
  @font_index = 0
181
- @has_font = 0
182
- @has_dxf_font = 0
183
180
  @font = 'Calibri'
184
181
  @size = 11
185
182
  @bold = 0
@@ -210,14 +207,10 @@ def initialize(xf_format_indices = {}, dxf_format_indices = {}, params = {}) #
210
207
  @fg_color = 0x00
211
208
  @bg_color = 0x00
212
209
  @pattern = 0
213
- @has_fill = 0
214
- @has_dxf_fill = 0
215
210
  @fill_index = 0
216
211
  @fill_count = 0
217
212
 
218
213
  @border_index = 0
219
- @has_border = 0
220
- @has_dxf_border = 0
221
214
  @border_count = 0
222
215
 
223
216
  @bottom = 0
@@ -477,27 +470,7 @@ def get_color(color)
477
470
  #
478
471
  def self.get_color(color)
479
472
 
480
- colors = {
481
- :aqua => 0x0F,
482
- :cyan => 0x0F,
483
- :black => 0x08,
484
- :blue => 0x0C,
485
- :brown => 0x10,
486
- :magenta => 0x0E,
487
- :fuchsia => 0x0E,
488
- :gray => 0x17,
489
- :grey => 0x17,
490
- :green => 0x11,
491
- :lime => 0x0B,
492
- :navy => 0x12,
493
- :orange => 0x35,
494
- :pink => 0x21,
495
- :purple => 0x14,
496
- :red => 0x0A,
497
- :silver => 0x16,
498
- :white => 0x09,
499
- :yellow => 0x0D,
500
- }
473
+ colors = Colors::COLORS
501
474
 
502
475
  if color.respond_to?(:to_str)
503
476
  # Return RGB style colors for processing later.
@@ -652,39 +625,81 @@ def method_missing(name, *args) # :nodoc:
652
625
  end
653
626
 
654
627
  def bold?
655
- return false unless @bold
656
- return false if @bold == 0
657
- true
628
+ bool_both_ruby_and_perl?(@bold)
658
629
  end
659
630
 
660
631
  def italic?
661
- return false unless @italic
662
- return false if @italic == 0
663
- true
632
+ bool_both_ruby_and_perl?(@italic)
664
633
  end
665
634
 
666
635
  def strikeout?
667
- return false unless @font_strikeout
668
- return false if @font_strikeout == 0
669
- true
636
+ bool_both_ruby_and_perl?(@font_strikeout)
670
637
  end
671
638
 
672
639
  def outline?
673
- return false unless @font_outline
674
- return false if @font_outline == 0
675
- true
640
+ bool_both_ruby_and_perl?(@font_outline)
676
641
  end
677
642
 
678
643
  def shadow?
679
- return false unless @font_shadow
680
- return false if @font_shadow == 0
681
- true
644
+ bool_both_ruby_and_perl?(@font_shadow)
682
645
  end
683
646
 
684
647
  def underline?
685
- return false unless @underline
686
- return false if @underline == 0
648
+ bool_both_ruby_and_perl?(@underline)
649
+ end
650
+
651
+ def bool_both_ruby_and_perl?(val)
652
+ return false unless val
653
+ return false if val == 0
687
654
  true
688
655
  end
656
+
657
+ def has_border(flag)
658
+ @has_border = flag
659
+ end
660
+
661
+ def has_border? # :nodoc:
662
+ @has_border
663
+ end
664
+
665
+ def has_dxf_border(flag)
666
+ @has_dxf_border = flag
667
+ end
668
+
669
+ def has_dxf_border?
670
+ @has_dxf_border
671
+ end
672
+
673
+ def has_font(flag)
674
+ @has_font = flag
675
+ end
676
+
677
+ def has_font?
678
+ @has_font
679
+ end
680
+
681
+ def has_dxf_font(flag)
682
+ @has_dxf_font = flag
683
+ end
684
+
685
+ def has_dxf_font?
686
+ @has_dxf_font
687
+ end
688
+
689
+ def has_fill(flag)
690
+ @has_fill = flag
691
+ end
692
+
693
+ def has_fill?
694
+ @has_fill
695
+ end
696
+
697
+ def has_dxf_fill(flag)
698
+ @has_dxf_fill = flag
699
+ end
700
+
701
+ def has_dxf_fill?
702
+ @has_dxf_fill
703
+ end
689
704
  end
690
705
  end