write_xlsx 0.62.0 → 0.64.0

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.
Files changed (107) hide show
  1. data/README.rdoc +14 -1
  2. data/examples/chart_data_tools.rb +215 -0
  3. data/examples/chart_pie.rb +36 -5
  4. data/examples/sparklines2.rb +1 -1
  5. data/examples/tab_colors.rb +3 -3
  6. data/lib/write_xlsx/chart.rb +559 -516
  7. data/lib/write_xlsx/chart/area.rb +4 -1
  8. data/lib/write_xlsx/chart/axis.rb +132 -0
  9. data/lib/write_xlsx/chart/bar.rb +17 -9
  10. data/lib/write_xlsx/chart/column.rb +9 -1
  11. data/lib/write_xlsx/chart/line.rb +24 -0
  12. data/lib/write_xlsx/chart/radar.rb +2 -2
  13. data/lib/write_xlsx/chart/scatter.rb +19 -0
  14. data/lib/write_xlsx/chart/stock.rb +10 -3
  15. data/lib/write_xlsx/drawing.rb +43 -44
  16. data/lib/write_xlsx/package/vml.rb +21 -14
  17. data/lib/write_xlsx/shape.rb +173 -22
  18. data/lib/write_xlsx/sparkline.rb +524 -0
  19. data/lib/write_xlsx/version.rb +1 -1
  20. data/lib/write_xlsx/workbook.rb +183 -115
  21. data/lib/write_xlsx/worksheet.rb +821 -1073
  22. data/lib/write_xlsx/worksheet/cell_data.rb +132 -0
  23. data/lib/write_xlsx/worksheet/print_style.rb +51 -0
  24. data/test/chart/test_add_series.rb +31 -6
  25. data/test/chart/test_write_d_lbls.rb +18 -18
  26. data/test/chart/test_write_number_format.rb +20 -24
  27. data/test/drawing/test_drawing_shape_01.rb +1 -1
  28. data/test/drawing/test_drawing_shape_02.rb +2 -2
  29. data/test/drawing/test_drawing_shape_03.rb +5 -5
  30. data/test/drawing/test_drawing_shape_04.rb +3 -3
  31. data/test/drawing/test_drawing_shape_05.rb +4 -4
  32. data/test/drawing/test_drawing_shape_07.rb +2 -2
  33. data/test/perl_output/chart_data_tools.xlsx +0 -0
  34. data/test/perl_output/chart_pie.xlsx +0 -0
  35. data/test/regression/disabled_test_vml04.rb +2 -2
  36. data/test/regression/test_chart_drop_lines01.rb +46 -0
  37. data/test/regression/test_chart_drop_lines02.rb +51 -0
  38. data/test/regression/test_chart_drop_lines03.rb +46 -0
  39. data/test/regression/test_chart_drop_lines04.rb +64 -0
  40. data/test/regression/test_chart_errorbars01.rb +47 -0
  41. data/test/regression/test_chart_errorbars02.rb +57 -0
  42. data/test/regression/test_chart_errorbars03.rb +53 -0
  43. data/test/regression/test_chart_errorbars04.rb +48 -0
  44. data/test/regression/test_chart_errorbars05.rb +47 -0
  45. data/test/regression/test_chart_errorbars06.rb +47 -0
  46. data/test/regression/test_chart_errorbars07.rb +66 -0
  47. data/test/regression/test_chart_font02.rb +1 -1
  48. data/test/regression/test_chart_font06.rb +1 -1
  49. data/test/regression/test_chart_gridlines04.rb +2 -1
  50. data/test/regression/test_chart_gridlines08.rb +2 -1
  51. data/test/regression/test_chart_points01.rb +37 -0
  52. data/test/regression/test_chart_points02.rb +40 -0
  53. data/test/regression/test_chart_points03.rb +42 -0
  54. data/test/regression/test_chart_points04.rb +52 -0
  55. data/test/regression/test_chart_points05.rb +49 -0
  56. data/test/regression/test_chart_points06.rb +49 -0
  57. data/test/regression/test_chartsheet05.rb +1 -1
  58. data/test/regression/test_chartsheet06.rb +1 -1
  59. data/test/regression/test_comment01.rb +1 -1
  60. data/test/regression/test_comment02.rb +1 -1
  61. data/test/regression/test_comment03.rb +1 -1
  62. data/test/regression/test_comment04.rb +2 -2
  63. data/test/regression/test_comment06.rb +1 -1
  64. data/test/regression/test_comment07.rb +1 -1
  65. data/test/regression/test_comment08.rb +1 -1
  66. data/test/regression/test_comment09.rb +1 -1
  67. data/test/regression/test_comment10.rb +1 -1
  68. data/test/regression/test_default_row04.rb +1 -1
  69. data/test/regression/test_escapes02.rb +1 -1
  70. data/test/regression/test_hyperlink15.rb +2 -2
  71. data/test/regression/test_shape_connect01.rb +6 -6
  72. data/test/regression/test_shape_connect02.rb +6 -6
  73. data/test/regression/test_shape_connect03.rb +11 -11
  74. data/test/regression/test_shape_connect04.rb +10 -10
  75. data/test/regression/test_shape_scale01.rb +2 -2
  76. data/test/regression/test_shape_stencil01.rb +3 -3
  77. data/test/regression/test_tab_color01.rb +1 -1
  78. data/test/regression/test_table04.rb +1 -1
  79. data/test/regression/test_table05.rb +1 -1
  80. data/test/regression/test_table06.rb +1 -1
  81. data/test/regression/test_vml01.rb +1 -1
  82. data/test/regression/test_vml02.rb +1 -1
  83. data/test/regression/test_vml03.rb +2 -2
  84. data/test/regression/xlsx_files/chart_drop_lines01.xlsx +0 -0
  85. data/test/regression/xlsx_files/chart_drop_lines02.xlsx +0 -0
  86. data/test/regression/xlsx_files/chart_drop_lines03.xlsx +0 -0
  87. data/test/regression/xlsx_files/chart_drop_lines04.xlsx +0 -0
  88. data/test/regression/xlsx_files/chart_errorbars01.xlsx +0 -0
  89. data/test/regression/xlsx_files/chart_errorbars02.xlsx +0 -0
  90. data/test/regression/xlsx_files/chart_errorbars03.xlsx +0 -0
  91. data/test/regression/xlsx_files/chart_errorbars04.xlsx +0 -0
  92. data/test/regression/xlsx_files/chart_errorbars05.xlsx +0 -0
  93. data/test/regression/xlsx_files/chart_errorbars06.xlsx +0 -0
  94. data/test/regression/xlsx_files/chart_errorbars07.xlsx +0 -0
  95. data/test/regression/xlsx_files/chart_points01.xlsx +0 -0
  96. data/test/regression/xlsx_files/chart_points02.xlsx +0 -0
  97. data/test/regression/xlsx_files/chart_points03.xlsx +0 -0
  98. data/test/regression/xlsx_files/chart_points04.xlsx +0 -0
  99. data/test/regression/xlsx_files/chart_points05.xlsx +0 -0
  100. data/test/regression/xlsx_files/chart_points06.xlsx +0 -0
  101. data/test/regression/xlsx_files/chart_stock02.xlsx +0 -0
  102. data/test/test_example_match.rb +278 -57
  103. data/test/worksheet/test_convert_date_time_02.rb +427 -433
  104. data/test/worksheet/test_convert_date_time_03.rb +1 -1
  105. data/test/worksheet/test_write_sheet_pr.rb +2 -2
  106. data/test/worksheet/test_write_sheet_view1.rb +2 -2
  107. metadata +80 -10
@@ -1,5 +1,5 @@
1
1
  require 'write_xlsx/workbook'
2
2
 
3
3
  class WriteXLSX < Writexlsx::Workbook
4
- VERSION = "0.62.0"
4
+ VERSION = "0.64.0"
5
5
  end
@@ -13,36 +13,55 @@
13
13
  require 'digest/md5'
14
14
 
15
15
  module Writexlsx
16
+
17
+ # The WriteXLSX provides an object oriented interface to a new Excel workbook.
18
+ # The following methods are available through a new workbook.
19
+ #
20
+ # * new[#method-c-new]
21
+ # * add_worksheet[#method-i-add_worksheet]
22
+ # * add_format[#method-i-add_format]
23
+ # * add_chart[#method-i-add_chart]
24
+ # * add_shape[#method-i-add_shape]
25
+ # * add_vba_project[#method-i-add_vba_project]
26
+ # * close[#method-i-close]
27
+ # * set_properties[#method-i-set_properties]
28
+ # * define_name[#method-i-define_name]
29
+ # * set_custom_color[#method-i-set_custom_color]
30
+ # * sheets[#method-i-sheets]
31
+ # * set_1904[#method-i-set_1904]
32
+ #
16
33
  class Workbook
17
34
 
18
35
  include Writexlsx::Utility
19
36
 
20
- attr_writer :firstsheet
21
- attr_reader :palette
22
- attr_reader :font_count, :num_format_count, :border_count, :fill_count, :custom_colors
23
- attr_reader :worksheets, :sheetnames, :charts, :drawings
24
- attr_reader :num_comment_files, :num_vml_files, :named_ranges
25
- attr_reader :doc_properties
26
- attr_reader :image_types, :images
27
- attr_reader :shared_strings
28
- attr_accessor :table_count
29
- attr_reader :vba_project
30
- #
31
- # A new Excel workbook is created using the new() constructor
37
+ BASE_NAME = { :sheet => 'Sheet', :chart => 'Chart'} # :nodoc:
38
+
39
+ attr_writer :firstsheet # :nodoc:
40
+ attr_reader :palette # :nodoc:
41
+ attr_reader :font_count, :num_format_count, :border_count, :fill_count, :custom_colors # :nodoc:
42
+ attr_reader :worksheets, :sheetnames, :charts, :drawings # :nodoc:
43
+ attr_reader :num_comment_files, :num_vml_files, :named_ranges # :nodoc:
44
+ attr_reader :doc_properties # :nodoc:
45
+ attr_reader :image_types, :images # :nodoc:
46
+ attr_reader :shared_strings # :nodoc:
47
+ attr_accessor :table_count # :nodoc:
48
+ attr_reader :vba_project # :nodoc:
49
+ #
50
+ # A new Excel workbook is created using the +new+ constructor
32
51
  # which accepts either a filename or an IO object as a parameter.
33
52
  # The following example creates a new Excel file based on a filename:
34
53
  #
35
- # workbook = WriteXLSX.new('filename.xlsx')
36
- # worksheet = workbook.add_worksheet
37
- # worksheet.write(0, 0, 'Hi Excel!')
38
- # workbook.close
54
+ # workbook = WriteXLSX.new('filename.xlsx')
55
+ # worksheet = workbook.add_worksheet
56
+ # worksheet.write(0, 0, 'Hi Excel!')
57
+ # workbook.close
39
58
  #
40
- # Here are some other examples of using new() with filenames:
59
+ # Here are some other examples of using +new+ with filenames:
41
60
  #
42
- # workbook1 = WriteXLSX.new(filename)
43
- # workbook2 = WriteXLSX.new('/tmp/filename.xlsx')
44
- # workbook3 = WriteXLSX.new("c:\\tmp\\filename.xlsx")
45
- # workbook4 = WriteXLSX.new('c:\tmp\filename.xlsx')
61
+ # workbook1 = WriteXLSX.new(filename)
62
+ # workbook2 = WriteXLSX.new('/tmp/filename.xlsx')
63
+ # workbook3 = WriteXLSX.new("c:\\tmp\\filename.xlsx")
64
+ # workbook4 = WriteXLSX.new('c:\tmp\filename.xlsx')
46
65
  #
47
66
  # The last two examples demonstrates how to create a file on DOS or Windows
48
67
  # where it is necessary to either escape the directory separator \
@@ -52,24 +71,21 @@ class Workbook
52
71
  # rather than .xls since the latter causes an Excel warning
53
72
  # when used with the XLSX format.
54
73
  #
55
- # The new() constructor returns a WriteXLSX object that you can use to
74
+ # The +new+ constructor returns a WriteXLSX object that you can use to
56
75
  # add worksheets and store data.
57
76
  #
58
- # You can also pass a valid IO object to the new() constructor.
77
+ # You can also pass a valid IO object to the +new+ constructor.
59
78
  #
60
- # xlsx = StringIO.new
61
- # workbook = WriteXLSX.new(xlsx)
62
- # ....
63
- # workbook.close
64
- # # you can get XLSX binary data as xlsx.string
79
+ # xlsx = StringIO.new
80
+ # workbook = WriteXLSX.new(xlsx)
81
+ # ....
82
+ # workbook.close
83
+ # # you can get XLSX binary data as xlsx.string
65
84
  #
66
85
  # And you can pass default_formats parameter like this:
67
86
  #
68
- # formats = {
69
- # :font => 'Arial',
70
- # :size => 10.5
71
- # }
72
- # workbook = WriteXLSX.new('file.xlsx', formats)
87
+ # formats = { :font => 'Arial', :size => 10.5 }
88
+ # workbook = WriteXLSX.new('file.xlsx', formats)
73
89
  #
74
90
  def initialize(file, default_formats = {})
75
91
  @writer = Package::XMLWriterSimple.new
@@ -122,23 +138,31 @@ def initialize(file, default_formats = {})
122
138
  end
123
139
 
124
140
  #
125
- # write XLSX data to file or IO object.
141
+ # The close method is used to close an Excel file.
142
+ #
143
+ # An explicit close is required if the file must be closed prior to performing
144
+ # some external action on it such as copying it, reading its size or attaching
145
+ # it to an email.
146
+ #
147
+ # In general, if you create a file with a size of 0 bytes or you fail to create
148
+ # a file you need to call close.
126
149
  #
127
150
  def close
128
- # In case close() is called twice, by user and by DESTROY.
151
+ # In case close() is called twice.
129
152
  return if @fileclosed
130
153
 
131
154
  @fileclosed = true
132
155
  store_workbook
133
156
  end
134
157
 
158
+ #
135
159
  # get array of Worksheet objects
136
160
  #
137
161
  # :call-seq:
138
162
  # sheets -> array of all Wordsheet object
139
163
  # sheets(1, 3, 4) -> array of spcified Worksheet object.
140
164
  #
141
- # The sheets() method returns a array, or a sliced array, of the worksheets
165
+ # The sheets method returns a array, or a sliced array, of the worksheets
142
166
  # in a workbook.
143
167
  #
144
168
  # If no arguments are passed the method returns a list of all the worksheets
@@ -183,11 +207,11 @@ def sheets(*args)
183
207
  # one system and the other.
184
208
  #
185
209
  # WriteXLSX stores dates in the 1900 format by default. If you wish to
186
- # change this you can call the set_1904() workbook method.
187
- # You can query the current value by calling the get_1904() workbook method.
188
- # This returns 0 for 1900 and 1 for 1904.
210
+ # change this you can call the set_1904 workbook method.
211
+ # You can query the current value by calling the get_1904 workbook method.
212
+ # This returns false for 1900 and true for 1904.
189
213
  #
190
- # In general you probably won't need to use set_1904().
214
+ # In general you probably won't need to use set_1904.
191
215
  #
192
216
  def set_1904(mode = true)
193
217
  unless sheets.empty?
@@ -196,6 +220,9 @@ def set_1904(mode = true)
196
220
  @date_1904 = ptrue?(mode)
197
221
  end
198
222
 
223
+ #
224
+ # return date system. false = 1900, true = 1904
225
+ #
199
226
  def get_1904
200
227
  @date_1904
201
228
  end
@@ -285,7 +312,8 @@ def add_worksheet(name = '')
285
312
  #
286
313
  # This method is use to create a new chart either as a standalone worksheet
287
314
  # (the default) or as an embeddable object that can be inserted into
288
- # a worksheet via the Worksheet#insert_chart method.
315
+ # a worksheet via the
316
+ # {Worksheet#insert_chart}[Worksheet.html#method-i-insert_chart] method.
289
317
  #
290
318
  # chart = workbook.add_chart(:type => 'column')
291
319
  #
@@ -296,7 +324,7 @@ def add_worksheet(name = '')
296
324
  # :name (optional)
297
325
  # :embedded (optional)
298
326
  #
299
- # :type
327
+ # === :type
300
328
  #
301
329
  # This is a required parameter.
302
330
  # It defines the type of chart that will be created.
@@ -313,7 +341,7 @@ def add_worksheet(name = '')
313
341
  # scatter
314
342
  # stock
315
343
  #
316
- # :subtype
344
+ # === :subtype
317
345
  #
318
346
  # Used to define a chart subtype where available.
319
347
  #
@@ -323,7 +351,7 @@ def add_worksheet(name = '')
323
351
  # (stacked and percent_stacked). See the documentation for those chart
324
352
  # types.
325
353
  #
326
- # :name
354
+ # === :name
327
355
  #
328
356
  # Set the name for the chart sheet. The name property is optional and
329
357
  # if it isn't supplied will default to Chart1 .. n. The name must be
@@ -333,11 +361,11 @@ def add_worksheet(name = '')
333
361
  #
334
362
  # chart = workbook.add_chart(:type => 'line', :name => 'Results Chart')
335
363
  #
336
- # :embedded
364
+ # === :embedded
337
365
  #
338
366
  # Specifies that the Chart object will be inserted in a worksheet
339
- # via the Worksheet#insert_chart method. It is an error to try insert
340
- # a Chart that doesn't have this flag set.
367
+ # via the {Worksheet#insert_chart}[Worksheet.html#insert_chart] method.
368
+ # It is an error to try insert a Chart that doesn't have this flag set.
341
369
  #
342
370
  # chart = workbook.add_chart(:type => 'line', :embedded => 1)
343
371
  #
@@ -347,8 +375,8 @@ def add_worksheet(name = '')
347
375
  # # Insert the chart into the a worksheet.
348
376
  # worksheet.insert_chart('E2', chart)
349
377
  #
350
- # See Chart for details on how to configure the chart object
351
- # once it is created. See also the chart_*.pl programs in the examples
378
+ # See Chart[Chart.html] for details on how to configure the chart object
379
+ # once it is created. See also the chart_*.rb programs in the examples
352
380
  # directory of the distro.
353
381
  #
354
382
  def add_chart(params = {})
@@ -382,7 +410,7 @@ def add_chart(params = {})
382
410
  end
383
411
 
384
412
  #
385
- # The add_format method can be used to create new Format objects
413
+ # The +add_format+ method can be used to create new Format objects
386
414
  # which are used to apply formatting to a cell. You can either define
387
415
  # the properties at creation time via a hash of property values
388
416
  # or later via method calls.
@@ -390,7 +418,8 @@ def add_chart(params = {})
390
418
  # format1 = workbook.add_format(property_hash) # Set properties at creation
391
419
  # format2 = workbook.add_format # Set properties later
392
420
  #
393
- # See the Format Class's rdoc for more details about Format properties and how to set them.
421
+ # See the {Format Class's rdoc}[Format.html] for more details about
422
+ # Format properties and how to set them.
394
423
  #
395
424
  def add_format(properties = {})
396
425
  init_data = [
@@ -407,28 +436,28 @@ def add_format(properties = {})
407
436
  end
408
437
 
409
438
  #
410
- # The add_shape() method can be used to create new shapes that may be
439
+ # The +add_shape+ method can be used to create new shapes that may be
411
440
  # inserted into a worksheet.
412
441
  #
413
442
  # You can either define the properties at creation time via a hash of
414
443
  # property values or later via method calls.
415
444
  #
416
- # # Set properties at creation.
417
- # plus = workbook.add_shape(
418
- # :type => 'plus',
419
- # :id => 3,
420
- # :width => pw,
421
- # :height => ph
422
- # )
445
+ # # Set properties at creation.
446
+ # plus = workbook.add_shape(
447
+ # :type => 'plus',
448
+ # :id => 3,
449
+ # :width => pw,
450
+ # :height => ph
451
+ # )
423
452
  #
424
- # # Default rectangle shape. Set properties later.
425
- # rect = workbook.add_shape
453
+ # # Default rectangle shape. Set properties later.
454
+ # rect = workbook.add_shape
426
455
  #
427
456
  # See also the shape*.rb programs in the examples directory of the distro.
428
457
  #
429
458
  # === Shape Properties
430
459
  #
431
- # Any shape property can be queried or modified by [] like hash.
460
+ # Any shape property can be queried or modified by [ ] like hash.
432
461
  #
433
462
  # ellipse = workbook.add_shape(properties)
434
463
  # ellipse[:type] = 'cross' # No longer an ellipse !
@@ -437,19 +466,19 @@ def add_format(properties = {})
437
466
  # The properties of a shape object that can be defined via add_shape are
438
467
  # shown below.
439
468
  #
440
- # ====:name
469
+ # ===:name
441
470
  #
442
471
  # Defines the name of the shape. This is an optional property and the shape
443
472
  # will be given a default name if not supplied. The name is generally only
444
473
  # used by Excel Macros to refer to the object.
445
474
  #
446
- # ====:type
475
+ # ===:type
447
476
  #
448
- # Defines the type of the object such as :rect, :ellipse OR :triangle.
477
+ # Defines the type of the object such as +:rect+, +:ellipse+ OR +:triangle+.
449
478
  #
450
479
  # ellipse = workbook.add_shape(:type => :ellipse)
451
480
  #
452
- # The default type is :rect.
481
+ # The default type is +:rect+.
453
482
  #
454
483
  # The full list of available shapes is shown below.
455
484
  #
@@ -457,7 +486,7 @@ def add_format(properties = {})
457
486
  # It creates an example workbook with all supported shapes labelled with
458
487
  # their shape names.
459
488
  #
460
- # ===== Basic Shapes
489
+ # === Basic Shapes
461
490
  #
462
491
  # blockArc can chevron cube decagon
463
492
  # diamond dodecagon donut ellipse funnel
@@ -471,7 +500,7 @@ def add_format(properties = {})
471
500
  # star5 star6 star7 star8 sun
472
501
  # teardrop trapezoid triangle
473
502
  #
474
- # ===== Arrow Shapes
503
+ # === Arrow Shapes
475
504
  #
476
505
  # bentArrow bentUpArrow circularArrow curvedDownArrow
477
506
  # curvedLeftArrow curvedRightArrow curvedUpArrow downArrow
@@ -480,13 +509,13 @@ def add_format(properties = {})
480
509
  # rightArrow stripedRightArrow swooshArrow upArrow
481
510
  # upDownArrow uturnArrow
482
511
  #
483
- # ===== Connector Shapes
512
+ # === Connector Shapes
484
513
  #
485
514
  # bentConnector2 bentConnector3 bentConnector4
486
515
  # bentConnector5 curvedConnector2 curvedConnector3
487
516
  # curvedConnector4 curvedConnector5 straightConnector1
488
517
  #
489
- # ===== Callout Shapes
518
+ # === Callout Shapes
490
519
  #
491
520
  # accentBorderCallout1 accentBorderCallout2 accentBorderCallout3
492
521
  # accentCallout1 accentCallout2 accentCallout3
@@ -497,7 +526,7 @@ def add_format(properties = {})
497
526
  # upArrowCallout upDownArrowCallout wedgeEllipseCallout
498
527
  # wedgeRectCallout wedgeRoundRectCallout
499
528
  #
500
- # ===== Flow Chart Shapes
529
+ # === Flow Chart Shapes
501
530
  #
502
531
  # flowChartAlternateProcess flowChartCollate flowChartConnector
503
532
  # flowChartDecision flowChartDelay flowChartDisplay
@@ -510,24 +539,24 @@ def add_format(properties = {})
510
539
  # flowChartPunchedCard flowChartPunchedTape flowChartSort
511
540
  # flowChartSummingJunction flowChartTerminator
512
541
  #
513
- # ===== Action Shapes
542
+ # === Action Shapes
514
543
  #
515
544
  # actionButtonBackPrevious actionButtonBeginning actionButtonBlank
516
545
  # actionButtonDocument actionButtonEnd actionButtonForwardNext
517
546
  # actionButtonHelp actionButtonHome actionButtonInformation
518
547
  # actionButtonMovie actionButtonReturn actionButtonSound
519
548
  #
520
- # ===== Chart Shapes
549
+ # === Chart Shapes
521
550
  #
522
551
  # Not to be confused with Excel Charts.
523
552
  #
524
553
  # chartPlus chartStar chartX
525
554
  #
526
- # ===== Math Shapes
555
+ # === Math Shapes
527
556
  #
528
557
  # mathDivide mathEqual mathMinus mathMultiply mathNotEqual mathPlus
529
558
  #
530
- # ===== Starts and Banners
559
+ # === Starts and Banners
531
560
  #
532
561
  # arc bevel bracePair bracketPair chord
533
562
  # cloud corner diagStripe doubleWave ellipseRibbon
@@ -536,11 +565,11 @@ def add_format(properties = {})
536
565
  # plus ribbon ribbon2 rightBrace rightBracket
537
566
  # verticalScroll wave
538
567
  #
539
- # ===== Tab Shapes
568
+ # === Tab Shapes
540
569
  #
541
570
  # cornerTabs plaqueTabs squareTabs
542
571
  #
543
- # ==== :text
572
+ # === :text
544
573
  #
545
574
  # This property is used to make the shape act like a text box.
546
575
  #
@@ -549,32 +578,34 @@ def add_format(properties = {})
549
578
  # The Text is super-imposed over the shape. The text can be wrapped using
550
579
  # the newline character \n.
551
580
  #
552
- # ==== :id
581
+ # === :id
553
582
  #
554
583
  # Identification number for internal identification. This number will be
555
584
  # auto-assigned, if not assigned, or if it is a duplicate.
556
585
  #
557
- # ==== :format
586
+ # === :format
558
587
  #
559
588
  # Workbook format for decorating the shape horizontally and/or vertically.
560
589
  #
561
- # ==== :rotation
590
+ # === :rotation
562
591
  #
563
592
  # Shape rotation, in degrees, from 0 to 360
564
593
  #
565
- # ==== :line, :fill
594
+ # === :line, :fill
566
595
  #
567
596
  # Shape color for the outline and fill.
568
597
  # Colors may be specified as a color index, or in RGB format, i.e. AA00FF.
569
598
  #
570
- # ==== :link_type
599
+ # See COULOURS IN EXCEL in the main documentation for more information.
600
+ #
601
+ # === :link_type
571
602
  #
572
603
  # Line type for shape outline. The default is solid.
573
604
  # The list of possible values is:
574
605
  #
575
606
  # dash, sysDot, dashDot, lgDash, lgDashDot, lgDashDotDot, solid
576
607
  #
577
- # ==== :valign, :align
608
+ # === :valign, :align
578
609
  #
579
610
  # Text alignment within the shape.
580
611
  #
@@ -584,18 +615,27 @@ def add_format(properties = {})
584
615
  # ======= =======
585
616
  # t Top
586
617
  # ctr Centre
587
- # b Bottom def add_shape(properties)
618
+ # b Bottom
588
619
  #
589
- # The default is to center both horizontally and vertically.
620
+ # Horizontal alignment can be:
621
+ #
622
+ # Setting Meaning
623
+ # ======= =======
624
+ # l Left
625
+ # r Right
626
+ # ctr Centre
627
+ # just Justified
590
628
  #
591
- # ==== :scale_x, :scale_y
629
+ # The default is to center both horizontally and vertically.
592
630
  #
631
+ # === :scale_x, :scale_y
593
632
  #
594
- # Scale factor in x and y dimension, for scaling the shape width and height. The default value is 1.
633
+ # Scale factor in x and y dimension, for scaling the shape width and
634
+ # height. The default value is 1.
595
635
  #
596
- # Scaling may be set on the shape object or via insert_shape().
636
+ # Scaling may be set on the shape object or via insert_shape.
597
637
  #
598
- # ==== :adjustments
638
+ # === :adjustments
599
639
  #
600
640
  # Adjustment of shape vertices. Most shapes do not use this. For some
601
641
  # shapes, there is a single adjustment to modify the geometry.
@@ -609,7 +649,7 @@ def add_format(properties = {})
609
649
  # dimension. Adjustments may be negative, to route the shape away
610
650
  # from the endpoint.
611
651
  #
612
- # ==== :stencil
652
+ # === :stencil
613
653
  #
614
654
  # Shapes work in stencil mode by default. That is, once a shape is
615
655
  # inserted, its connection is separated from its master.
@@ -620,7 +660,7 @@ def add_format(properties = {})
620
660
  # created once, and then the text of the shape is modified for each
621
661
  # employee.
622
662
  #
623
- # The insert_shape() method returns a reference to the inserted
663
+ # The insert_shape method returns a reference to the inserted
624
664
  # shape (the child).
625
665
  #
626
666
  # Stencil mode can be turned off, allowing for shape(s) to be
@@ -631,7 +671,7 @@ def add_format(properties = {})
631
671
  #
632
672
  def add_shape(properties)
633
673
  shape = Shape.new(properties)
634
- shape[:palette] = @palette
674
+ shape.palette = @palette
635
675
 
636
676
  @shapes ||= []
637
677
  @shapes << shape #Store shape reference.
@@ -652,7 +692,7 @@ def add_shape(properties)
652
692
  # workbook.define_name('Sales', '=Sheet1!$G$1:$H$10')
653
693
  #
654
694
  # It is also possible to define a local/worksheet name by prefixing the name
655
- # with the sheet name using the syntax sheetname!definedname:
695
+ # with the sheet name using the syntax +sheetname!definedname+:
656
696
  #
657
697
  # # Local/worksheet name.
658
698
  # workbook.define_name('Sheet2!Sales', '=Sheet2!$G$1:$G$10')
@@ -760,7 +800,30 @@ def set_properties(params)
760
800
  end
761
801
 
762
802
  #
763
- # Add a vbaProject binary to the XLSX file.
803
+ # The add_vba_project method can be used to add macros or functions to an
804
+ # WriteXLSX file using a binary VBA project file that has been extracted
805
+ # from an existing Excel xlsm file.
806
+ #
807
+ # workbook = WriteXLSX.new('file.xlsm')
808
+ #
809
+ # workbook.add_vba_project('./vbaProject.bin')
810
+ #
811
+ # The supplied +extract_vba+ utility can be used to extract the required
812
+ # +vbaProject.bin+ file from an existing Excel file:
813
+ #
814
+ # $ extract_vba file.xlsm
815
+ # Extracted 'vbaProject.bin' successfully
816
+ #
817
+ # Macros can be tied to buttons using the worksheet
818
+ # {insert_button}[Worksheet.html#method-i-insert_button] method
819
+ # (see the "WORKSHEET METHODS" section for details):
820
+ #
821
+ # worksheet.insert_button('C2', { :macro => 'my_macro' })
822
+ #
823
+ # Note, Excel uses the file extension xlsm instead of xlsx for files that
824
+ # contain macros. It is advisable to follow the same convention.
825
+ #
826
+ # See also the macros.rb example file.
764
827
  #
765
828
  def add_vba_project(vba_project)
766
829
  @vba_project = vba_project
@@ -769,10 +832,10 @@ def add_vba_project(vba_project)
769
832
  #
770
833
  # Change the RGB components of the elements in the colour palette.
771
834
  #
772
- # The set_custom_color() method can be used to override one of the built-in
835
+ # The set_custom_color method can be used to override one of the built-in
773
836
  # palette values with a more suitable colour.
774
837
  #
775
- # The value for _index_ should be in the range 8..63,
838
+ # The value for +index+ should be in the range 8..63,
776
839
  # see "COLOURS IN EXCEL".
777
840
  #
778
841
  # The default named colours use the following indices:
@@ -794,12 +857,13 @@ def add_vba_project(vba_project)
794
857
  # 33 => pink
795
858
  # 53 => orange
796
859
  #
797
- # A new colour is set using its RGB (red green blue) components. The red,
798
- # green and blue values must be in the range 0..255. You can determine the
799
- # required values in Excel using the Tools->Options->Colors->Modify dialog.
860
+ # A new colour is set using its RGB (red green blue) components. The +red+,
861
+ # +green+ and +blue+ values must be in the range 0..255. You can determine
862
+ # the required values in Excel using the Tools->Options->Colors->Modify
863
+ # dialog.
800
864
  #
801
- # The set_custom_color() workbook method can also be used with a HTML style
802
- # #rrggbb hex value:
865
+ # The set_custom_color workbook method can also be used with a HTML style
866
+ # +#rrggbb+ hex value:
803
867
  #
804
868
  # workbook.set_custom_color(40, 255, 102, 0 ) # Orange
805
869
  # workbook.set_custom_color(40, 0xFF, 0x66, 0x00) # Same thing
@@ -874,11 +938,11 @@ def shared_string_index(str, params = {}) #:nodoc:
874
938
  @shared_strings.index(str, params)
875
939
  end
876
940
 
877
- def str_unique
941
+ def str_unique # :nodoc:
878
942
  @shared_strings.unique_count
879
943
  end
880
944
 
881
- def shared_strings_empty?
945
+ def shared_strings_empty? # :nodoc:
882
946
  @shared_strings.empty?
883
947
  end
884
948
 
@@ -973,24 +1037,28 @@ def set_color_palette #:nodoc:
973
1037
  # invalid characters and if the name is unique in the workbook.
974
1038
  #
975
1039
  def check_sheetname(name) #:nodoc:
976
- # Increment the Sheet/Chart number used for default sheet names below.
977
- @sheetname_count += 1
1040
+ make_and_check_sheet_chart_name(:sheet, name)
1041
+ end
1042
+
1043
+ def check_chart_sheetname(name)
1044
+ make_and_check_sheet_chart_name(:chart, name)
1045
+ end
1046
+
1047
+ def make_and_check_sheet_chart_name(type, name)
1048
+ count = sheet_chart_count_increment(type)
1049
+ name = "#{BASE_NAME[type]}#{count}" unless ptrue?(name)
978
1050
 
979
- # Supply default Sheet/Chart name if none has been defined.
980
- if name.nil? || name == ''
981
- name = "#{@sheet_name}#{@sheetname_count}"
982
- end
983
1051
  check_valid_sheetname(name)
984
1052
  name
985
1053
  end
986
1054
 
987
- def check_chart_sheetname(name)
988
- @chartname_count += 1
989
- if name.nil? || name == ''
990
- name = "#{@chart_name}#{@chartname_count}"
1055
+ def sheet_chart_count_increment(type)
1056
+ case type
1057
+ when :sheet
1058
+ @sheetname_count += 1
1059
+ when :chart
1060
+ @chartname_count += 1
991
1061
  end
992
- check_valid_sheetname(name)
993
- name
994
1062
  end
995
1063
 
996
1064
  def check_valid_sheetname(name)