write_xlsx 1.09.5 → 1.10.1

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '080f089bfba0e7182c26bb8fab6d08f7515cbf828bbd358c5166b6fcf3fc689f'
4
- data.tar.gz: 074e380eeace6467f5ab04fa18ad032452b61c82013f3ae5e2254d5eb068c86e
3
+ metadata.gz: 66e9354b51872770af7121d5581615b53c0cb3b7e86c221b0ecee60fe54dae4b
4
+ data.tar.gz: 97d6ae9ed6dee9e57e98981e105da155ef405fd5ea40ea17e8057871f02d90d9
5
5
  SHA512:
6
- metadata.gz: d17f85e3491ed06d5dd39e94c11cdcb6b1abfeda6124143575da1e839d8ca88b8d4bcb06c51a7a94a813c06439c395e209424cf7fd0e1dd9616ed769a3538fc9
7
- data.tar.gz: 112c2336c1bde5435637c6b68e8ae9af98062bc884c1a82b378e8bd0e5d8c5733a23b261a10c8fd5654c4b66ac8bcf765a8ccf1a23887bd70f25634d24d10e17
6
+ metadata.gz: a86f539563acd7da100be9fb11e1e3da99c1985200e21eaa91ca9db3f69ea130038f0ecead40ea0ba6efcc5b4f433dcd4acf039006faa65adb60ed88d0d5f005
7
+ data.tar.gz: f98a3ac1110600e8e2c578127f85a804c1237d44069481f6c0baacc27ff6f21eddbb96f063c544239730ba059a16f7637f39ebfd902f3cc87be4995401bf303b
data/.rubocop.yml CHANGED
@@ -59,6 +59,7 @@ Metrics/MethodLength:
59
59
 
60
60
  Metrics/ParameterLists:
61
61
  Max: 12
62
+ MaxOptionalParameters: 6
62
63
 
63
64
  Metrics/PerceivedComplexity:
64
65
  Max: 50
@@ -89,7 +90,8 @@ Style/FormatStringToken:
89
90
  EnforcedStyle: unannotated
90
91
 
91
92
  Style/HashSyntax:
92
- Enabled: false
93
+ EnforceStyle: ruby19_no_mixed_keys
94
+ EnforcedShorthandSyntax: either
93
95
 
94
96
  Style/NumericLiterals:
95
97
  MinDigits: 10
@@ -100,6 +102,9 @@ Style/OptionalBooleanParameter:
100
102
  Style/RaiseArgs:
101
103
  Enabled: false
102
104
 
105
+ Style/SlicingWithRange:
106
+ Enabled: false
107
+
103
108
  Style/StringLiterals:
104
109
  Enabled: false
105
110
 
data/Changes CHANGED
@@ -1,5 +1,13 @@
1
1
  Change history of write_xlsx rubygem.
2
2
 
3
+ 2023-01-31 v1.10.1
4
+ Fixed PR #99. Remove range [1..] style to work on Ruby 2.5.
5
+
6
+ 2023-01-29 v.1.10.0
7
+ Ruby version 2.5.0 or later are required.
8
+
9
+ Added support for new Excel 365 dynamic functions.
10
+
3
11
  2023-01-18 v1.09.5
4
12
  Fixed issue #92. Worksheet#write raises with Time instance token.
5
13
 
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2022 Hideo NAKAMURA
1
+ Copyright (c) 2012-2023 Hideo NAKAMURA
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  gem to create a new file in the Excel 2007+ XLSX format, and you can use the
7
7
  same interface as writeexcel gem. write_xlsx is converted from Perl's module
8
- [Excel::Writer::XLSX-1.09](https://github.com/jmcnamara/excel-writer-xlsx/tree/CPAN_1.09)
8
+ [Excel::Writer::XLSX](https://github.com/jmcnamara/excel-writer-xlsx)
9
9
 
10
10
  ## Description
11
11
 
@@ -22,8 +22,9 @@ worksheet3 = workbook.add_worksheet
22
22
  worksheet4 = workbook.add_worksheet
23
23
  worksheet5 = workbook.add_worksheet
24
24
  worksheet6 = workbook.add_worksheet
25
+ worksheet7 = workbook.add_worksheet
25
26
 
26
- bold = workbook.add_format(:bold => 1)
27
+ bold = workbook.add_format(bold: 1)
27
28
 
28
29
  # Extract the data embedded at the end of this file.
29
30
  headings = DATA.gets.split
@@ -127,14 +128,12 @@ end
127
128
  ###############################################################################
128
129
  #
129
130
  #
130
- # Example 5. Autofilter with filter for blanks.
131
+ # Example 5. Autofilter with filter list condition in one of the columns.
131
132
  #
132
133
 
133
- # Create a blank cell in our test data.
134
- data[5][0] = ''
135
-
136
134
  worksheet5.autofilter('A1:D51')
137
- worksheet5.filter_column('A', 'x eq Blanks')
135
+
136
+ worksheet5.filter_column_list('A', %w[East North South])
138
137
 
139
138
  #
140
139
  # Hide the rows that don't match the filter criteria.
@@ -144,7 +143,7 @@ row = 1
144
143
  data.each do |row_data|
145
144
  region = row_data[0]
146
145
 
147
- worksheet5.set_row(row, nil, nil, 1) unless region == ''
146
+ worksheet5.set_row(row, nil, nil, 1) unless %w[East North South].include?(region)
148
147
 
149
148
  worksheet5.write(row, 0, row_data)
150
149
  row += 1
@@ -153,11 +152,14 @@ end
153
152
  ###############################################################################
154
153
  #
155
154
  #
156
- # Example 6. Autofilter with filter for non-blanks.
155
+ # Example 6. Autofilter with filter for blanks.
157
156
  #
158
157
 
158
+ # Create a blank cell in our test data.
159
+ data[5][0] = ''
160
+
159
161
  worksheet6.autofilter('A1:D51')
160
- worksheet6.filter_column('A', 'x eq NonBlanks')
162
+ worksheet6.filter_column('A', 'x == Blanks')
161
163
 
162
164
  #
163
165
  # Hide the rows that don't match the filter criteria.
@@ -167,7 +169,7 @@ row = 1
167
169
  data.each do |row_data|
168
170
  region = row_data[0]
169
171
 
170
- worksheet6.set_row(row, nil, nil, 1) unless region != ''
172
+ worksheet6.set_row(row, nil, nil, 1) unless region == ''
171
173
 
172
174
  worksheet6.write(row, 0, row_data)
173
175
  row += 1
@@ -175,6 +177,33 @@ end
175
177
 
176
178
  workbook.close
177
179
 
180
+ ###############################################################################
181
+ #
182
+ #
183
+ # Example 7. Autofilter with filter for non-blanks.
184
+ #
185
+
186
+ worksheet7.autofilter('A1:D51')
187
+ worksheet7.filter_column('A', 'x == NonBlanks')
188
+
189
+ #
190
+ # Hide the rows that don't match the filter criteria.
191
+ #
192
+ row = 1
193
+
194
+ data.each do |row_data|
195
+ region = row_data[0]
196
+
197
+ worksheet7.set_row(row, nil, nil, 1) unless region != ''
198
+
199
+ worksheet7.write(row, 0, row_data)
200
+ row += 1
201
+ end
202
+
203
+ workbook.close
204
+
205
+
206
+
178
207
  __END__
179
208
  Region Item Volume Month
180
209
  East Apple 9000 July
@@ -13,7 +13,7 @@ require 'write_xlsx'
13
13
 
14
14
  workbook = WriteXLSX.new('chart_area.xlsx')
15
15
  worksheet = workbook.add_worksheet
16
- bold = workbook.add_format(:bold => 1)
16
+ bold = workbook.add_format(bold: 1)
17
17
 
18
18
  # Add the worksheet data that the charts will refer to.
19
19
  headings = ['Number', 'Batch 1', 'Batch 2']
@@ -27,27 +27,27 @@ worksheet.write('A1', headings, bold)
27
27
  worksheet.write('A2', data)
28
28
 
29
29
  # Create a new chart object. In this case an embedded chart.
30
- chart = workbook.add_chart(:type => 'area', :embedded => 1)
30
+ chart = workbook.add_chart(type: 'area', embedded: 1)
31
31
 
32
32
  # Configure the first series.
33
33
  chart.add_series(
34
- :name => '=Sheet1!$B$1',
35
- :categories => '=Sheet1!$A$2:$A$7',
36
- :values => '=Sheet1!$B$2:$B$7'
34
+ name: '=Sheet1!$B$1',
35
+ categories: '=Sheet1!$A$2:$A$7',
36
+ values: '=Sheet1!$B$2:$B$7'
37
37
  )
38
38
 
39
39
  # Configure second series. Note alternative use of array ref to define
40
40
  # ranges: [ sheetname, row_start, row_end, col_start, col_end ].
41
41
  chart.add_series(
42
- :name => '=Sheet1!$C$1',
43
- :categories => ['Sheet1', 1, 6, 0, 0],
44
- :values => ['Sheet1', 1, 6, 2, 2]
42
+ name: '=Sheet1!$C$1',
43
+ categories: ['Sheet1', 1, 6, 0, 0],
44
+ values: ['Sheet1', 1, 6, 2, 2]
45
45
  )
46
46
 
47
47
  # Add a chart title and some axis labels.
48
- chart.set_title(:name => 'Results of sample analysis')
49
- chart.set_x_axis(:name => 'Test number')
50
- chart.set_y_axis(:name => 'Sample length (mm)')
48
+ chart.set_title(name: 'Results of sample analysis')
49
+ chart.set_x_axis(name: 'Test number')
50
+ chart.set_y_axis(name: 'Sample length (mm)')
51
51
 
52
52
  # Set an Excel chart style. Blue colors with white outline and shadow.
53
53
  chart.set_style(11)
@@ -55,7 +55,7 @@ chart.set_style(11)
55
55
  # Insert the chart into the worksheet (with an offset).
56
56
  worksheet.insert_chart(
57
57
  'D2', chart,
58
- :x_offset => 25, :y_offset => 10
58
+ x_offset: 25, y_offset: 10
59
59
  )
60
60
 
61
61
  workbook.close
@@ -13,7 +13,7 @@ require 'write_xlsx'
13
13
 
14
14
  workbook = WriteXLSX.new('chart_bar.xlsx')
15
15
  worksheet = workbook.add_worksheet
16
- bold = workbook.add_format(:bold => 1)
16
+ bold = workbook.add_format(bold: 1)
17
17
 
18
18
  # Add the worksheet data that the charts will refer to.
19
19
  headings = ['Number', 'Batch 1', 'Batch 2']
@@ -27,27 +27,27 @@ worksheet.write('A1', headings, bold)
27
27
  worksheet.write('A2', data)
28
28
 
29
29
  # Create a new chart object. In this case an embedded chart.
30
- chart = workbook.add_chart(:type => 'bar', :embedded => 1)
30
+ chart = workbook.add_chart(type: 'bar', embedded: 1)
31
31
 
32
32
  # Configure the first series.
33
33
  chart.add_series(
34
- :name => '=Sheet1!$B$1',
35
- :categories => '=Sheet1!$A$2:$A$7',
36
- :values => '=Sheet1!$B$2:$B$7'
34
+ name: '=Sheet1!$B$1',
35
+ categories: '=Sheet1!$A$2:$A$7',
36
+ values: '=Sheet1!$B$2:$B$7'
37
37
  )
38
38
 
39
39
  # Configure second series. Note alternative use of array ref to define
40
40
  # ranges: [ sheetname, row_start, row_end, col_start, col_end ].
41
41
  chart.add_series(
42
- :name => '=Sheet1!$C$1',
43
- :categories => ['Sheet1', 1, 6, 0, 0],
44
- :values => ['Sheet1', 1, 6, 2, 2]
42
+ name: '=Sheet1!$C$1',
43
+ categories: ['Sheet1', 1, 6, 0, 0],
44
+ values: ['Sheet1', 1, 6, 2, 2]
45
45
  )
46
46
 
47
47
  # Add a chart title and some axis labels.
48
- chart.set_title(:name => 'Results of sample analysis')
49
- chart.set_x_axis(:name => 'Test number')
50
- chart.set_y_axis(:name => 'Sample length (mm)')
48
+ chart.set_title(name: 'Results of sample analysis')
49
+ chart.set_x_axis(name: 'Test number')
50
+ chart.set_y_axis(name: 'Sample length (mm)')
51
51
 
52
52
  # Set an Excel chart style. Blue colors with white outline and shadow.
53
53
  chart.set_style(11)
@@ -55,7 +55,7 @@ chart.set_style(11)
55
55
  # Insert the chart into the worksheet (with an offset).
56
56
  worksheet.insert_chart(
57
57
  'D2', chart,
58
- :x_offset => 25, :y_offset => 10
58
+ x_offset: 25, y_offset: 10
59
59
  )
60
60
 
61
61
  workbook.close
@@ -12,7 +12,7 @@ require 'write_xlsx'
12
12
 
13
13
  workbook = WriteXLSX.new('chart_clustered.xlsx')
14
14
  worksheet = workbook.add_worksheet
15
- bold = workbook.add_format(:bold => 1)
15
+ bold = workbook.add_format(bold: 1)
16
16
 
17
17
  # Add the worksheet data that the charts will refer to.
18
18
  headings = ['Types', 'Sub Type', 'Value 1', 'Value 2', 'Value 3']
@@ -28,34 +28,34 @@ worksheet.write('A1', headings, bold)
28
28
  worksheet.write_col('A2', data)
29
29
 
30
30
  # Create a new chart object. In this case an embedded chart.
31
- chart = workbook.add_chart(:type => 'column', :embedded => 1)
31
+ chart = workbook.add_chart(type: 'column', embedded: 1)
32
32
 
33
33
  # Configure the series. Note, that the categories are 2D ranges (from column A
34
34
  # to column B). This creates the clusters. The series are shown as formula
35
35
  # strings for clarity but you can also use the array syntax. See the docs.
36
36
  chart.add_series(
37
- :name => '=Sheet1!$C$1',
38
- :categories => '=Sheet1!$A$2:$B$6',
39
- :values => '=Sheet1!$C$2:$C$6'
37
+ name: '=Sheet1!$C$1',
38
+ categories: '=Sheet1!$A$2:$B$6',
39
+ values: '=Sheet1!$C$2:$C$6'
40
40
  )
41
41
 
42
42
  chart.add_series(
43
- :name => '=Sheet1!$D$1',
44
- :categories => '=Sheet1!$A$2:$B$6',
45
- :values => '=Sheet1!$D$2:$D$6'
43
+ name: '=Sheet1!$D$1',
44
+ categories: '=Sheet1!$A$2:$B$6',
45
+ values: '=Sheet1!$D$2:$D$6'
46
46
  )
47
47
 
48
48
  chart.add_series(
49
- :name => '=Sheet1!$E$1',
50
- :categories => '=Sheet1!$A$2:$B$6',
51
- :values => '=Sheet1!$E$2:$E$6'
49
+ name: '=Sheet1!$E$1',
50
+ categories: '=Sheet1!$A$2:$B$6',
51
+ values: '=Sheet1!$E$2:$E$6'
52
52
  )
53
53
 
54
54
  # Set the Excel chart style.
55
55
  chart.set_style(37)
56
56
 
57
57
  # Turn off the legend.
58
- chart.set_legend(:position => 'none')
58
+ chart.set_legend(position: 'none')
59
59
 
60
60
  # Insert the chart into the worksheet.
61
61
  worksheet.insert_chart('G3', chart)
@@ -13,7 +13,7 @@ require 'write_xlsx'
13
13
 
14
14
  workbook = WriteXLSX.new('chart_column.xlsx')
15
15
  worksheet = workbook.add_worksheet
16
- bold = workbook.add_format(:bold => 1)
16
+ bold = workbook.add_format(bold: 1)
17
17
 
18
18
  # Add the worksheet data that the charts will refer to.
19
19
  headings = ['Number', 'Batch 1', 'Batch 2']
@@ -27,27 +27,27 @@ worksheet.write('A1', headings, bold)
27
27
  worksheet.write('A2', data)
28
28
 
29
29
  # Create a new chart object. In this case an embedded chart.
30
- chart = workbook.add_chart(:type => 'column', :embedded => 1)
30
+ chart = workbook.add_chart(type: 'column', embedded: 1)
31
31
 
32
32
  # Configure the first series.
33
33
  chart.add_series(
34
- :name => '=Sheet1!$B$1',
35
- :categories => '=Sheet1!$A$2:$A$7',
36
- :values => '=Sheet1!$B$2:$B$7'
34
+ name: '=Sheet1!$B$1',
35
+ categories: '=Sheet1!$A$2:$A$7',
36
+ values: '=Sheet1!$B$2:$B$7'
37
37
  )
38
38
 
39
39
  # Configure second series. Note alternative use of array ref to define
40
40
  # ranges: [ sheetname, row_start, row_end, col_start, col_end ].
41
41
  chart.add_series(
42
- :name => '=Sheet1!$C$1',
43
- :categories => ['Sheet1', 1, 6, 0, 0],
44
- :values => ['Sheet1', 1, 6, 2, 2]
42
+ name: '=Sheet1!$C$1',
43
+ categories: ['Sheet1', 1, 6, 0, 0],
44
+ values: ['Sheet1', 1, 6, 2, 2]
45
45
  )
46
46
 
47
47
  # Add a chart title and some axis labels.
48
- chart.set_title(:name => 'Results of sample analysis')
49
- chart.set_x_axis(:name => 'Test number')
50
- chart.set_y_axis(:name => 'Sample length (mm)')
48
+ chart.set_title(name: 'Results of sample analysis')
49
+ chart.set_x_axis(name: 'Test number')
50
+ chart.set_y_axis(name: 'Sample length (mm)')
51
51
 
52
52
  # Set an Excel chart style. Blue colors with white outline and shadow.
53
53
  chart.set_style(11)
@@ -55,7 +55,7 @@ chart.set_style(11)
55
55
  # Insert the chart into the worksheet (with an offset).
56
56
  worksheet.insert_chart(
57
57
  'D2', chart,
58
- :x_offset => 25, :y_offset => 10
58
+ x_offset: 25, y_offset: 10
59
59
  )
60
60
 
61
61
  workbook.close
@@ -13,7 +13,7 @@ require 'write_xlsx'
13
13
 
14
14
  workbook = WriteXLSX.new('chart_combined.xlsx')
15
15
  worksheet = workbook.add_worksheet
16
- bold = workbook.add_format(:bold => 1)
16
+ bold = workbook.add_format(bold: 1)
17
17
 
18
18
  # Add the worksheet data that the charts will refer to.
19
19
  headings = ['Number', 'Batch 1', 'Batch 2']
@@ -32,23 +32,23 @@ worksheet.write('A2', data)
32
32
  #
33
33
 
34
34
  # Create a new column chart. This will use this as the primary chart.
35
- column_chart1 = workbook.add_chart(:type => 'column', :embedded => 1)
35
+ column_chart1 = workbook.add_chart(type: 'column', embedded: 1)
36
36
 
37
37
  # Configure the data series for the primary chart.
38
38
  column_chart1.add_series(
39
- :name => '=Sheet1!$B$1',
40
- :categories => '=Sheet1!$A$2:$A$7',
41
- :values => '=Sheet1!$B$2:$B$7'
39
+ name: '=Sheet1!$B$1',
40
+ categories: '=Sheet1!$A$2:$A$7',
41
+ values: '=Sheet1!$B$2:$B$7'
42
42
  )
43
43
 
44
44
  # Create a new column chart. This will use this as the secondary chart.
45
- line_chart1 = workbook.add_chart(:type => 'line', :embedded => 1)
45
+ line_chart1 = workbook.add_chart(type: 'line', embedded: 1)
46
46
 
47
47
  # Configure the data series for the secondary chart.
48
48
  line_chart1.add_series(
49
- :name => '=Sheet1!$C$1',
50
- :categories => '=Sheet1!$A$2:$A$7',
51
- :values => '=Sheet1!$C$2:$C$7'
49
+ name: '=Sheet1!$C$1',
50
+ categories: '=Sheet1!$A$2:$A$7',
51
+ values: '=Sheet1!$C$2:$C$7'
52
52
  )
53
53
 
54
54
  # Combine the charts.
@@ -56,9 +56,9 @@ column_chart1.combine(line_chart1)
56
56
 
57
57
  # Add a chart title and some axis labels. Note, this is done via the
58
58
  # primary chart.
59
- column_chart1.set_title(:name => 'Combined chart - same Y axis')
60
- column_chart1.set_x_axis(:name => 'Test number')
61
- column_chart1.set_y_axis(:name => 'Sample length (mm)')
59
+ column_chart1.set_title(name: 'Combined chart - same Y axis')
60
+ column_chart1.set_x_axis(name: 'Test number')
61
+ column_chart1.set_y_axis(name: 'Sample length (mm)')
62
62
 
63
63
  # Insert the chart into the worksheet
64
64
  worksheet.insert_chart('E2', column_chart1)
@@ -69,38 +69,38 @@ worksheet.insert_chart('E2', column_chart1)
69
69
  #
70
70
 
71
71
  # Create a new column chart. This will use this as the primary chart.
72
- column_chart2 = workbook.add_chart(:type => 'column', :embedded => 1)
72
+ column_chart2 = workbook.add_chart(type: 'column', embedded: 1)
73
73
 
74
74
  # Configure the data series for the primary chart.
75
75
  column_chart2.add_series(
76
- :name => '=Sheet1!$B$1',
77
- :categories => '=Sheet1!$A$2:$A$7',
78
- :values => '=Sheet1!$B$2:$B$7'
76
+ name: '=Sheet1!$B$1',
77
+ categories: '=Sheet1!$A$2:$A$7',
78
+ values: '=Sheet1!$B$2:$B$7'
79
79
  )
80
80
 
81
81
  # Create a new column chart. This will use this as the secondary chart.
82
- line_chart2 = workbook.add_chart(:type => 'line', :embedded => 1)
82
+ line_chart2 = workbook.add_chart(type: 'line', embedded: 1)
83
83
 
84
84
  # Configure the data series for the secondary chart. We also set a
85
85
  # secondary Y axis via (y2_axis). This is the only difference between
86
86
  # this and the first example, apart from the axis label below.
87
87
  line_chart2.add_series(
88
- :name => '=Sheet1!$C$1',
89
- :categories => '=Sheet1!$A$2:$A$7',
90
- :values => '=Sheet1!$C$2:$C$7',
91
- :y2_axis => 1
88
+ name: '=Sheet1!$C$1',
89
+ categories: '=Sheet1!$A$2:$A$7',
90
+ values: '=Sheet1!$C$2:$C$7',
91
+ y2_axis: 1
92
92
  )
93
93
 
94
94
  # Combine the charts.
95
95
  column_chart2.combine(line_chart2)
96
96
 
97
97
  # Add a chart title and some axis labels.
98
- column_chart2.set_title(:name => 'Combine chart - secondary Y axis')
99
- column_chart2.set_x_axis(:name => 'Test number')
100
- column_chart2.set_y_axis(:name => 'Sample length (mm)')
98
+ column_chart2.set_title(name: 'Combine chart - secondary Y axis')
99
+ column_chart2.set_x_axis(name: 'Test number')
100
+ column_chart2.set_y_axis(name: 'Sample length (mm)')
101
101
 
102
102
  # NOTE: the y2 properties are on the secondary chart.
103
- line_chart2.set_y_axis(:name => 'Target length (mm)')
103
+ line_chart2.set_y_axis(name: 'Target length (mm)')
104
104
 
105
105
  # Insert the chart into the worksheet
106
106
  worksheet.insert_chart('E18', column_chart2)