write_xlsx 1.09.5 → 1.10.1

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 (110) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -1
  3. data/Changes +8 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +1 -1
  6. data/examples/autofilter.rb +39 -10
  7. data/examples/chart_area.rb +12 -12
  8. data/examples/chart_bar.rb +12 -12
  9. data/examples/chart_clustered.rb +12 -12
  10. data/examples/chart_column.rb +12 -12
  11. data/examples/chart_combined.rb +25 -25
  12. data/examples/chart_data_labels.rb +99 -99
  13. data/examples/chart_data_table.rb +25 -25
  14. data/examples/chart_data_tools.rb +50 -50
  15. data/examples/chart_doughnut.rb +29 -29
  16. data/examples/chart_gauge.rb +18 -18
  17. data/examples/chart_line.rb +32 -32
  18. data/examples/chart_pareto.rb +16 -16
  19. data/examples/chart_pie.rb +17 -17
  20. data/examples/chart_radar.rb +38 -38
  21. data/examples/chart_scatter.rb +12 -12
  22. data/examples/chart_secondary_axis.rb +13 -13
  23. data/examples/chart_stock.rb +12 -12
  24. data/examples/chart_styles.rb +5 -5
  25. data/examples/colors.rb +11 -11
  26. data/examples/comments2.rb +15 -15
  27. data/examples/conditional_format.rb +74 -74
  28. data/examples/data_validate.rb +64 -64
  29. data/examples/date_time.rb +3 -3
  30. data/examples/demo.rb +14 -14
  31. data/examples/diag_border.rb +6 -6
  32. data/examples/dynamic_arrays.rb +247 -0
  33. data/examples/formats.rb +10 -10
  34. data/examples/hyperlink1.rb +4 -4
  35. data/examples/ignore_errors.rb +2 -2
  36. data/examples/indent.rb +2 -2
  37. data/examples/lambda.rb +43 -0
  38. data/examples/macros.rb +4 -4
  39. data/examples/merge1.rb +1 -1
  40. data/examples/merge2.rb +9 -9
  41. data/examples/merge3.rb +5 -5
  42. data/examples/merge4.rb +20 -20
  43. data/examples/merge5.rb +18 -18
  44. data/examples/merge6.rb +7 -7
  45. data/examples/outline.rb +1 -1
  46. data/examples/outline_collapsed.rb +1 -1
  47. data/examples/panes.rb +4 -4
  48. data/examples/properties.rb +9 -9
  49. data/examples/protection.rb +2 -2
  50. data/examples/rich_strings.rb +6 -6
  51. data/examples/shape1.rb +7 -7
  52. data/examples/shape2.rb +16 -16
  53. data/examples/shape3.rb +5 -5
  54. data/examples/shape4.rb +7 -7
  55. data/examples/shape5.rb +7 -7
  56. data/examples/shape6.rb +7 -7
  57. data/examples/shape7.rb +10 -10
  58. data/examples/shape8.rb +10 -10
  59. data/examples/shape_all.rb +4 -4
  60. data/examples/sparklines1.rb +11 -11
  61. data/examples/sparklines2.rb +76 -76
  62. data/examples/tables.rb +87 -87
  63. data/examples/watermark.png +0 -0
  64. data/examples/watermark.rb +26 -0
  65. data/lib/write_xlsx/chart/bar.rb +4 -4
  66. data/lib/write_xlsx/chart/line.rb +1 -1
  67. data/lib/write_xlsx/chart/radar.rb +2 -2
  68. data/lib/write_xlsx/chart/scatter.rb +4 -4
  69. data/lib/write_xlsx/chart/series.rb +27 -27
  70. data/lib/write_xlsx/chart/stock.rb +5 -5
  71. data/lib/write_xlsx/chart.rb +31 -30
  72. data/lib/write_xlsx/chartsheet.rb +1 -0
  73. data/lib/write_xlsx/col_name.rb +1 -0
  74. data/lib/write_xlsx/colors.rb +20 -19
  75. data/lib/write_xlsx/compatibility.rb +1 -0
  76. data/lib/write_xlsx/drawing.rb +20 -10
  77. data/lib/write_xlsx/format.rb +5 -0
  78. data/lib/write_xlsx/formats.rb +1 -0
  79. data/lib/write_xlsx/gradient.rb +2 -0
  80. data/lib/write_xlsx/package/app.rb +1 -0
  81. data/lib/write_xlsx/package/button.rb +6 -2
  82. data/lib/write_xlsx/package/comments.rb +3 -1
  83. data/lib/write_xlsx/package/conditional_format.rb +4 -3
  84. data/lib/write_xlsx/package/content_types.rb +1 -0
  85. data/lib/write_xlsx/package/core.rb +1 -0
  86. data/lib/write_xlsx/package/custom.rb +1 -0
  87. data/lib/write_xlsx/package/metadata.rb +1 -0
  88. data/lib/write_xlsx/package/packager.rb +1 -0
  89. data/lib/write_xlsx/package/relationships.rb +1 -0
  90. data/lib/write_xlsx/package/shared_strings.rb +1 -1
  91. data/lib/write_xlsx/package/styles.rb +1 -0
  92. data/lib/write_xlsx/package/table.rb +9 -8
  93. data/lib/write_xlsx/package/theme.rb +1 -0
  94. data/lib/write_xlsx/package/vml.rb +1 -0
  95. data/lib/write_xlsx/package/xml_writer_simple.rb +21 -2
  96. data/lib/write_xlsx/shape.rb +6 -5
  97. data/lib/write_xlsx/sheets.rb +2 -1
  98. data/lib/write_xlsx/sparkline.rb +287 -286
  99. data/lib/write_xlsx/utility.rb +25 -26
  100. data/lib/write_xlsx/version.rb +3 -1
  101. data/lib/write_xlsx/workbook.rb +20 -20
  102. data/lib/write_xlsx/worksheet/cell_data.rb +53 -63
  103. data/lib/write_xlsx/worksheet/data_validation.rb +1 -0
  104. data/lib/write_xlsx/worksheet/hyperlink.rb +3 -2
  105. data/lib/write_xlsx/worksheet/page_setup.rb +1 -0
  106. data/lib/write_xlsx/worksheet.rb +287 -74
  107. data/lib/write_xlsx/zip_file_utils.rb +1 -0
  108. data/lib/write_xlsx.rb +1 -0
  109. data/write_xlsx.gemspec +1 -0
  110. metadata +8 -4
@@ -1,27 +1,28 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Writexlsx
4
5
  class Colors
5
6
  COLORS = {
6
- :aqua => 0x0F,
7
- :cyan => 0x0F,
8
- :black => 0x08,
9
- :blue => 0x0C,
10
- :brown => 0x10,
11
- :magenta => 0x0E,
12
- :fuchsia => 0x0E,
13
- :gray => 0x17,
14
- :grey => 0x17,
15
- :green => 0x11,
16
- :lime => 0x0B,
17
- :navy => 0x12,
18
- :orange => 0x35,
19
- :pink => 0x21,
20
- :purple => 0x14,
21
- :red => 0x0A,
22
- :silver => 0x16,
23
- :white => 0x09,
24
- :yellow => 0x0D
7
+ aqua: 0x0F,
8
+ cyan: 0x0F,
9
+ black: 0x08,
10
+ blue: 0x0C,
11
+ brown: 0x10,
12
+ magenta: 0x0E,
13
+ fuchsia: 0x0E,
14
+ gray: 0x17,
15
+ grey: 0x17,
16
+ green: 0x11,
17
+ lime: 0x0B,
18
+ navy: 0x12,
19
+ orange: 0x35,
20
+ pink: 0x21,
21
+ purple: 0x14,
22
+ red: 0x0A,
23
+ silver: 0x16,
24
+ white: 0x09,
25
+ yellow: 0x0D
25
26
  } # :nodoc:
26
27
 
27
28
  ###############################################################################
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  #
4
5
  # Why would we ever use Ruby 1.8.7 when we can backport with something
@@ -1,24 +1,26 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
5
6
 
6
7
  module Writexlsx
7
8
  class Drawing
8
- attr_accessor :type, :dimensions, :width, :height, :description, :shape, :anchor, :rel_index, :url_rel_index
9
+ attr_accessor :type, :dimensions, :width, :height, :shape, :anchor, :rel_index, :url_rel_index, :name, :description
9
10
  attr_reader :tip, :decorative
10
11
 
11
- def initialize(type, dimensions, width, height, description, shape, anchor, rel_index = nil, url_rel_index = nil, tip = nil, decorative = nil)
12
+ def initialize(type, dimensions, width, height, shape, anchor, rel_index = nil, url_rel_index = nil, tip = nil, name = nil, description = nil, decorative = nil)
12
13
  @type = type
13
14
  @dimensions = dimensions
14
15
  @width = width
15
16
  @height = height
16
- @description = description
17
17
  @shape = shape
18
18
  @anchor = anchor
19
19
  @rel_index = rel_index
20
20
  @url_rel_index = url_rel_index
21
21
  @tip = tip
22
+ @name = name
23
+ @description = description
22
24
  @decorative = decorative
23
25
  end
24
26
  end
@@ -96,12 +98,13 @@ module Writexlsx
96
98
  type = drawing.type
97
99
  width = drawing.width
98
100
  height = drawing.height
99
- description = drawing.description
100
101
  shape = drawing.shape
101
102
  anchor = drawing.anchor
102
103
  rel_index = drawing.rel_index
103
104
  url_rel_index = drawing.url_rel_index
104
105
  tip = drawing.tip
106
+ name = drawing.name
107
+ description = drawing.description
105
108
  decorative = drawing.decorative
106
109
 
107
110
  col_from, row_from, col_from_offset, row_from_offset,
@@ -129,7 +132,7 @@ module Writexlsx
129
132
  # Graphic frame.
130
133
 
131
134
  # Write the xdr:graphicFrame element for charts.
132
- write_graphic_frame(index, rel_index, description)
135
+ write_graphic_frame(index, rel_index, name, description, decorative)
133
136
  elsif type == 2
134
137
  # Write the xdr:pic element.
135
138
  write_pic(
@@ -263,14 +266,17 @@ module Writexlsx
263
266
  #
264
267
  # Write the <xdr:graphicFrame> element.
265
268
  #
266
- def write_graphic_frame(index, rel_index, name = nil)
267
- macro = ''
269
+ def write_graphic_frame(
270
+ index, rel_index, name = nil,
271
+ description = nil, decorative = nil, macro = nil
272
+ )
273
+ macro ||= ''
268
274
 
269
275
  attributes = [['macro', macro]]
270
276
 
271
277
  @writer.tag_elements('xdr:graphicFrame', attributes) do
272
278
  # Write the xdr:nvGraphicFramePr element.
273
- write_nv_graphic_frame_pr(index, name)
279
+ write_nv_graphic_frame_pr(index, name, description, decorative)
274
280
  # Write the xdr:xfrm element.
275
281
  write_xfrm
276
282
  # Write the a:graphic element.
@@ -281,12 +287,16 @@ module Writexlsx
281
287
  #
282
288
  # Write the <xdr:nvGraphicFramePr> element.
283
289
  #
284
- def write_nv_graphic_frame_pr(index, name = nil)
290
+ def write_nv_graphic_frame_pr(
291
+ index, name = nil, description = nil, decorative = nil
292
+ )
293
+
285
294
  name = "Chart #{index}" unless ptrue?(name)
286
295
 
287
296
  @writer.tag_elements('xdr:nvGraphicFramePr') do
288
297
  # Write the xdr:cNvPr element.
289
- write_c_nv_pr(index + 1, name)
298
+ write_c_nv_pr(index + 1, name, description,
299
+ nil, nil, decorative)
290
300
  # Write the xdr:cNvGraphicFramePr element.
291
301
  write_c_nv_graphic_frame_pr
292
302
  end
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/utility'
4
5
 
@@ -658,6 +659,10 @@ module Writexlsx
658
659
  attributes
659
660
  end
660
661
 
662
+ def force_text_format?
663
+ @num_format == 49 # Text format ('@')
664
+ end
665
+
661
666
  private
662
667
 
663
668
  def write_font_shapes(writer)
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Writexlsx
2
4
  module Gradient
3
5
  def gradient_properties(args)
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/utility'
4
5
 
@@ -7,10 +8,13 @@ module Writexlsx
7
8
  class Button
8
9
  include Writexlsx::Utility
9
10
 
10
- attr_accessor :font, :macro, :vertices
11
+ attr_accessor :font, :macro, :vertices, :description
11
12
 
12
13
  def v_shape_attributes(id, z_index)
13
- attributes = v_shape_attributes_base(id, z_index)
14
+ attributes = v_shape_attributes_base(id)
15
+ attributes << ['alt', description] if description
16
+
17
+ attributes << ['style', (v_shape_style_base(z_index, vertices) + style_addition).join]
14
18
  attributes << ['o:button', 't']
15
19
  attributes << ['fillcolor', color]
16
20
  attributes << ['strokecolor', 'windowText [64]']
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/format'
4
5
  require 'write_xlsx/package/xml_writer_simple'
@@ -112,7 +113,8 @@ module Writexlsx
112
113
  end
113
114
 
114
115
  def v_shape_attributes(id, z_index)
115
- attr = v_shape_attributes_base(id, z_index)
116
+ attr = v_shape_attributes_base(id)
117
+ attr << ['style', (v_shape_style_base(z_index, vertices) + style_addition).join]
116
118
  attr << ['fillcolor', color]
117
119
  attr << ['o:insetmode', 'auto']
118
120
  attr
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Writexlsx
4
5
  module Package
@@ -657,9 +658,9 @@ module Writexlsx
657
658
  # Set the default icon properties.
658
659
  total_icons.times do
659
660
  props << {
660
- :criteria => 0,
661
- :value => 0,
662
- :type => 'percent'
661
+ criteria: 0,
662
+ value: 0,
663
+ type: 'percent'
663
664
  }
664
665
  end
665
666
 
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -27,7 +27,7 @@ module Writexlsx
27
27
  unless @strings_index[string]
28
28
  # Only first time the string will be append to list
29
29
  # next time we only check and not #dup it
30
- str = string.dup.freeze
30
+ str = string.frozen? ? string : string.freeze
31
31
  @strings << str
32
32
  @strings_index[str] = @strings.size - 1
33
33
  end
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -247,14 +248,14 @@ module Writexlsx
247
248
  .gsub(/\]/, "']")
248
249
 
249
250
  subtotals = {
250
- :average => 101,
251
- :countNums => 102,
252
- :count => 103,
253
- :max => 104,
254
- :min => 105,
255
- :stdDev => 107,
256
- :sum => 109,
257
- :var => 110
251
+ average: 101,
252
+ countNums: 102,
253
+ count: 103,
254
+ max: 104,
255
+ min: 105,
256
+ stdDev: 107,
257
+ sum: 109,
258
+ var: 110
258
259
  }
259
260
 
260
261
  unless (func_num = subtotals[function.to_sym])
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -13,6 +13,11 @@ module Writexlsx
13
13
 
14
14
  def initialize
15
15
  @io = StringIO.new
16
+ # Will allocate new string once, then use allocated string
17
+ # Key is tag name
18
+ # Only tags without attributes will be cached
19
+ @tag_start_cache = {}
20
+ @tag_end_cache = {}
16
21
  end
17
22
 
18
23
  def set_xml_writer(filename = nil)
@@ -41,7 +46,16 @@ module Writexlsx
41
46
  end
42
47
 
43
48
  def start_tag_str(tag, attr = [])
44
- "<#{tag}#{key_vals(attr)}>"
49
+ if attr.empty?
50
+ result = @tag_start_cache[tag]
51
+ unless result
52
+ result = "<#{tag}>"
53
+ @tag_start_cache[tag] = result
54
+ end
55
+ else
56
+ result = "<#{tag}#{key_vals(attr)}>"
57
+ end
58
+ result
45
59
  end
46
60
 
47
61
  def end_tag(tag)
@@ -49,7 +63,12 @@ module Writexlsx
49
63
  end
50
64
 
51
65
  def end_tag_str(tag)
52
- "</#{tag}>"
66
+ result = @tag_end_cache[tag]
67
+ unless result
68
+ result = "</#{tag}>"
69
+ @tag_end_cache[tag] = result
70
+ end
71
+ result
53
72
  end
54
73
 
55
74
  def empty_tag(tag, attr = [])
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Writexlsx
4
5
  ###############################################################################
@@ -203,11 +204,11 @@ module Writexlsx
203
204
  def auto_locate_connectors(shapes, shape_hash)
204
205
  # Valid connector shapes.
205
206
  connector_shapes = {
206
- :straightConnector => 1,
207
- :Connector => 1,
208
- :bentConnector => 1,
209
- :curvedConnector => 1,
210
- :line => 1
207
+ straightConnector: 1,
208
+ Connector: 1,
209
+ bentConnector: 1,
210
+ curvedConnector: 1,
211
+ line: 1
211
212
  }
212
213
 
213
214
  shape_base = @type.chop.to_sym # Remove the number of segments from end of type.
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'delegate'
4
5
  require 'write_xlsx/package/xml_writer_simple'
@@ -7,7 +8,7 @@ module Writexlsx
7
8
  class Sheets < DelegateClass(Array)
8
9
  include Writexlsx::Utility
9
10
 
10
- BASE_NAME = { :sheet => 'Sheet', :chart => 'Chart' } # :nodoc:
11
+ BASE_NAME = { sheet: 'Sheet', chart: 'Chart' } # :nodoc:
11
12
 
12
13
  def initialize
13
14
  super([])