write_xlsx 1.10.0 → 1.10.2

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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -0
  3. data/Changes +9 -0
  4. data/README.md +2 -2
  5. data/examples/autofilter.rb +1 -1
  6. data/examples/chart_area.rb +12 -12
  7. data/examples/chart_bar.rb +12 -12
  8. data/examples/chart_clustered.rb +12 -12
  9. data/examples/chart_column.rb +12 -12
  10. data/examples/chart_combined.rb +25 -25
  11. data/examples/chart_data_labels.rb +99 -99
  12. data/examples/chart_data_table.rb +25 -25
  13. data/examples/chart_data_tools.rb +50 -50
  14. data/examples/chart_doughnut.rb +29 -29
  15. data/examples/chart_gauge.rb +18 -18
  16. data/examples/chart_line.rb +32 -32
  17. data/examples/chart_pareto.rb +16 -16
  18. data/examples/chart_pie.rb +17 -17
  19. data/examples/chart_radar.rb +38 -38
  20. data/examples/chart_scatter.rb +12 -12
  21. data/examples/chart_secondary_axis.rb +13 -13
  22. data/examples/chart_stock.rb +12 -12
  23. data/examples/chart_styles.rb +5 -5
  24. data/examples/colors.rb +11 -11
  25. data/examples/comments2.rb +15 -15
  26. data/examples/conditional_format.rb +74 -74
  27. data/examples/data_validate.rb +64 -64
  28. data/examples/date_time.rb +3 -3
  29. data/examples/demo.rb +14 -14
  30. data/examples/diag_border.rb +6 -6
  31. data/examples/dynamic_arrays.rb +2 -2
  32. data/examples/formats.rb +10 -10
  33. data/examples/hyperlink1.rb +4 -4
  34. data/examples/ignore_errors.rb +2 -2
  35. data/examples/indent.rb +2 -2
  36. data/examples/macros.rb +4 -4
  37. data/examples/merge1.rb +1 -1
  38. data/examples/merge2.rb +9 -9
  39. data/examples/merge3.rb +5 -5
  40. data/examples/merge4.rb +20 -20
  41. data/examples/merge5.rb +18 -18
  42. data/examples/merge6.rb +7 -7
  43. data/examples/outline.rb +1 -1
  44. data/examples/outline_collapsed.rb +1 -1
  45. data/examples/panes.rb +4 -4
  46. data/examples/properties.rb +9 -9
  47. data/examples/protection.rb +2 -2
  48. data/examples/rich_strings.rb +6 -6
  49. data/examples/shape1.rb +7 -7
  50. data/examples/shape2.rb +16 -16
  51. data/examples/shape3.rb +5 -5
  52. data/examples/shape4.rb +7 -7
  53. data/examples/shape5.rb +7 -7
  54. data/examples/shape6.rb +7 -7
  55. data/examples/shape7.rb +10 -10
  56. data/examples/shape8.rb +10 -10
  57. data/examples/shape_all.rb +4 -4
  58. data/examples/sparklines1.rb +11 -11
  59. data/examples/sparklines2.rb +76 -76
  60. data/examples/tables.rb +87 -87
  61. data/examples/watermark.rb +1 -1
  62. data/lib/write_xlsx/chart/bar.rb +4 -4
  63. data/lib/write_xlsx/chart/line.rb +1 -1
  64. data/lib/write_xlsx/chart/radar.rb +2 -2
  65. data/lib/write_xlsx/chart/scatter.rb +4 -4
  66. data/lib/write_xlsx/chart/series.rb +27 -27
  67. data/lib/write_xlsx/chart/stock.rb +5 -5
  68. data/lib/write_xlsx/chart.rb +30 -30
  69. data/lib/write_xlsx/colors.rb +19 -19
  70. data/lib/write_xlsx/package/conditional_format.rb +18 -7
  71. data/lib/write_xlsx/package/table.rb +33 -24
  72. data/lib/write_xlsx/shape.rb +5 -5
  73. data/lib/write_xlsx/sheets.rb +1 -1
  74. data/lib/write_xlsx/sparkline.rb +286 -286
  75. data/lib/write_xlsx/utility.rb +32 -31
  76. data/lib/write_xlsx/version.rb +1 -1
  77. data/lib/write_xlsx/workbook.rb +20 -20
  78. data/lib/write_xlsx/worksheet/cell_data.rb +1 -1
  79. data/lib/write_xlsx/worksheet/data_validation.rb +13 -1
  80. data/lib/write_xlsx/worksheet.rb +486 -246
  81. metadata +3 -3
@@ -18,7 +18,7 @@ require 'write_xlsx'
18
18
  # Create a new workbook called simple.xls and add a worksheet
19
19
  workbook = WriteXLSX.new('chart_data_tools.xlsx')
20
20
  worksheet = workbook.add_worksheet
21
- bold = workbook.add_format(:bold => 1)
21
+ bold = workbook.add_format(bold: 1)
22
22
 
23
23
  # Add the worksheet data that the charts will refer to.
24
24
  headings = ['Number', 'Data 1', 'Data 2']
@@ -38,32 +38,32 @@ worksheet.write('A2', data)
38
38
  #
39
39
 
40
40
  # Create a Line chart.
41
- chart1 = workbook.add_chart(:type => 'line', :embedded => 1)
41
+ chart1 = workbook.add_chart(type: 'line', embedded: 1)
42
42
 
43
43
  # Configure the first series with a polynomial trendline.
44
44
  chart1.add_series(
45
- :categories => '=Sheet1!$A$2:$A$7',
46
- :values => '=Sheet1!$B$2:$B$7',
47
- :trendline => {
48
- :type => 'polynomial',
49
- :order => 3
45
+ categories: '=Sheet1!$A$2:$A$7',
46
+ values: '=Sheet1!$B$2:$B$7',
47
+ trendline: {
48
+ type: 'polynomial',
49
+ order: 3
50
50
  }
51
51
  )
52
52
 
53
53
  # Configure the second series with a moving average trendline.
54
54
  chart1.add_series(
55
- :categories => '=Sheet1!$A$2:$A$7',
56
- :values => '=Sheet1!$C$2:$C$7',
57
- :trendline => { :type => 'linear' }
55
+ categories: '=Sheet1!$A$2:$A$7',
56
+ values: '=Sheet1!$C$2:$C$7',
57
+ trendline: { type: 'linear' }
58
58
  )
59
59
 
60
60
  # Add a chart title. and some axis labels.
61
- chart1.set_title(:name => 'Chart with Trendlines')
61
+ chart1.set_title(name: 'Chart with Trendlines')
62
62
 
63
63
  # Insert the chart into the worksheet (with an offset).
64
64
  worksheet.insert_chart(
65
65
  'D2', chart1,
66
- :x_offset => 25, :y_offset => 10
66
+ x_offset: 25, y_offset: 10
67
67
  )
68
68
 
69
69
  #######################################################################
@@ -72,29 +72,29 @@ worksheet.insert_chart(
72
72
  #
73
73
 
74
74
  # Create a Line chart.
75
- chart2 = workbook.add_chart(:type => 'line', :embedded => 1)
75
+ chart2 = workbook.add_chart(type: 'line', embedded: 1)
76
76
 
77
77
  # Configure the first series.
78
78
  chart2.add_series(
79
- :categories => '=Sheet1!$A$2:$A$7',
80
- :values => '=Sheet1!$B$2:$B$7',
81
- :data_labels => { :value => 1 },
82
- :marker => { :type => 'automatic' }
79
+ categories: '=Sheet1!$A$2:$A$7',
80
+ values: '=Sheet1!$B$2:$B$7',
81
+ data_labels: { value: 1 },
82
+ marker: { type: 'automatic' }
83
83
  )
84
84
 
85
85
  # Configure the second series.
86
86
  chart2.add_series(
87
- :categories => '=Sheet1!$A$2:$A$7',
88
- :values => '=Sheet1!$C$2:$C$7'
87
+ categories: '=Sheet1!$A$2:$A$7',
88
+ values: '=Sheet1!$C$2:$C$7'
89
89
  )
90
90
 
91
91
  # Add a chart title. and some axis labels.
92
- chart2.set_title(:name => 'Chart with Data Labels and Markers')
92
+ chart2.set_title(name: 'Chart with Data Labels and Markers')
93
93
 
94
94
  # Insert the chart into the worksheet (with an offset).
95
95
  worksheet.insert_chart(
96
96
  'D18', chart2,
97
- :x_offset => 25, :y_offset => 10
97
+ x_offset: 25, y_offset: 10
98
98
  )
99
99
 
100
100
  #######################################################################
@@ -103,28 +103,28 @@ worksheet.insert_chart(
103
103
  #
104
104
 
105
105
  # Create a Line chart.
106
- chart3 = workbook.add_chart(:type => 'line', :embedded => 1)
106
+ chart3 = workbook.add_chart(type: 'line', embedded: 1)
107
107
 
108
108
  # Configure the first series.
109
109
  chart3.add_series(
110
- :categories => '=Sheet1!$A$2:$A$7',
111
- :values => '=Sheet1!$B$2:$B$7',
112
- :y_error_bars => { :type => 'standard_error' }
110
+ categories: '=Sheet1!$A$2:$A$7',
111
+ values: '=Sheet1!$B$2:$B$7',
112
+ y_error_bars: { type: 'standard_error' }
113
113
  )
114
114
 
115
115
  # Configure the second series.
116
116
  chart3.add_series(
117
- :categories => '=Sheet1!$A$2:$A$7',
118
- :values => '=Sheet1!$C$2:$C$7'
117
+ categories: '=Sheet1!$A$2:$A$7',
118
+ values: '=Sheet1!$C$2:$C$7'
119
119
  )
120
120
 
121
121
  # Add a chart title. and some axis labels.
122
- chart3.set_title(:name => 'Chart with Error Bars')
122
+ chart3.set_title(name: 'Chart with Error Bars')
123
123
 
124
124
  # Insert the chart into the worksheet (with an offset).
125
125
  worksheet.insert_chart(
126
126
  'D34', chart3,
127
- :x_offset => 25, :y_offset => 10
127
+ x_offset: 25, y_offset: 10
128
128
  )
129
129
 
130
130
  #######################################################################
@@ -133,30 +133,30 @@ worksheet.insert_chart(
133
133
  #
134
134
 
135
135
  # Create a Line chart.
136
- chart4 = workbook.add_chart(:type => 'line', :embedded => 1)
136
+ chart4 = workbook.add_chart(type: 'line', embedded: 1)
137
137
 
138
138
  # Add the Up-Down Bars.
139
139
  chart4.set_up_down_bars
140
140
 
141
141
  # Configure the first series.
142
142
  chart4.add_series(
143
- :categories => '=Sheet1!$A$2:$A$7',
144
- :values => '=Sheet1!$B$2:$B$7'
143
+ categories: '=Sheet1!$A$2:$A$7',
144
+ values: '=Sheet1!$B$2:$B$7'
145
145
  )
146
146
 
147
147
  # Configure the second series.
148
148
  chart4.add_series(
149
- :categories => '=Sheet1!$A$2:$A$7',
150
- :values => '=Sheet1!$C$2:$C$7'
149
+ categories: '=Sheet1!$A$2:$A$7',
150
+ values: '=Sheet1!$C$2:$C$7'
151
151
  )
152
152
 
153
153
  # Add a chart title. and some axis labels.
154
- chart4.set_title(:name => 'Chart with Up-Down Bars')
154
+ chart4.set_title(name: 'Chart with Up-Down Bars')
155
155
 
156
156
  # Insert the chart into the worksheet (with an offset).
157
157
  worksheet.insert_chart(
158
158
  'D50', chart4,
159
- :x_offset => 25, :y_offset => 10
159
+ x_offset: 25, y_offset: 10
160
160
  )
161
161
 
162
162
  #######################################################################
@@ -165,30 +165,30 @@ worksheet.insert_chart(
165
165
  #
166
166
 
167
167
  # Create a Line chart.
168
- chart5 = workbook.add_chart(:type => 'line', :embedded => 1)
168
+ chart5 = workbook.add_chart(type: 'line', embedded: 1)
169
169
 
170
170
  # Add the High-Low lines.
171
171
  chart5.set_high_low_lines
172
172
 
173
173
  # Configure the first series.
174
174
  chart5.add_series(
175
- :categories => '=Sheet1!$A$2:$A$7',
176
- :values => '=Sheet1!$B$2:$B$7'
175
+ categories: '=Sheet1!$A$2:$A$7',
176
+ values: '=Sheet1!$B$2:$B$7'
177
177
  )
178
178
 
179
179
  # Configure the second series.
180
180
  chart5.add_series(
181
- :categories => '=Sheet1!$A$2:$A$7',
182
- :values => '=Sheet1!$C$2:$C$7'
181
+ categories: '=Sheet1!$A$2:$A$7',
182
+ values: '=Sheet1!$C$2:$C$7'
183
183
  )
184
184
 
185
185
  # Add a chart title. and some axis labels.
186
- chart5.set_title(:name => 'Chart with High-Low Lines')
186
+ chart5.set_title(name: 'Chart with High-Low Lines')
187
187
 
188
188
  # Insert the chart into the worksheet (with an offset).
189
189
  worksheet.insert_chart(
190
190
  'D66', chart5,
191
- :x_offset => 25, :y_offset => 10
191
+ x_offset: 25, y_offset: 10
192
192
  )
193
193
 
194
194
  #######################################################################
@@ -197,30 +197,30 @@ worksheet.insert_chart(
197
197
  #
198
198
 
199
199
  # Create a Line chart.
200
- chart6 = workbook.add_chart(:type => 'line', :embedded => 1)
200
+ chart6 = workbook.add_chart(type: 'line', embedded: 1)
201
201
 
202
202
  # Add Drop Lines.
203
203
  chart6.set_drop_lines
204
204
 
205
205
  # Configure the first series.
206
206
  chart6.add_series(
207
- :categories => '=Sheet1!$A$2:$A$7',
208
- :values => '=Sheet1!$B$2:$B$7'
207
+ categories: '=Sheet1!$A$2:$A$7',
208
+ values: '=Sheet1!$B$2:$B$7'
209
209
  )
210
210
 
211
211
  # Configure the second series.
212
212
  chart6.add_series(
213
- :categories => '=Sheet1!$A$2:$A$7',
214
- :values => '=Sheet1!$C$2:$C$7'
213
+ categories: '=Sheet1!$A$2:$A$7',
214
+ values: '=Sheet1!$C$2:$C$7'
215
215
  )
216
216
 
217
217
  # Add a chart title. and some axis labels.
218
- chart6.set_title(:name => 'Chart with Drop Lines')
218
+ chart6.set_title(name: 'Chart with Drop Lines')
219
219
 
220
220
  # Insert the chart into the worksheet (with an offset).
221
221
  worksheet.insert_chart(
222
222
  'D82', chart6,
223
- :x_offset => 25, :y_offset => 10
223
+ x_offset: 25, y_offset: 10
224
224
  )
225
225
 
226
226
  workbook.close
@@ -19,7 +19,7 @@ require 'write_xlsx'
19
19
 
20
20
  workbook = WriteXLSX.new('chart_doughnut.xlsx')
21
21
  worksheet = workbook.add_worksheet
22
- bold = workbook.add_format(:bold => 1)
22
+ bold = workbook.add_format(bold: 1)
23
23
 
24
24
  # Add the worksheet data that the charts will refer to.
25
25
  headings = %w[Category Values]
@@ -32,19 +32,19 @@ worksheet.write('A1', headings, bold)
32
32
  worksheet.write('A2', data)
33
33
 
34
34
  # Create a new chart object. In this case an embedded chart.
35
- chart1 = workbook.add_chart(:type => 'doughnut', :embedded => 1)
35
+ chart1 = workbook.add_chart(type: 'doughnut', embedded: 1)
36
36
 
37
37
  # Configure the series. Note the use of the array ref to define ranges:
38
38
  # [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
39
39
  # See below for an alternative syntax.
40
40
  chart1.add_series(
41
- :name => 'Doughnut sales data',
42
- :categories => ['Sheet1', 1, 3, 0, 0],
43
- :values => ['Sheet1', 1, 3, 1, 1]
41
+ name: 'Doughnut sales data',
42
+ categories: ['Sheet1', 1, 3, 0, 0],
43
+ values: ['Sheet1', 1, 3, 1, 1]
44
44
  )
45
45
 
46
46
  # Add a title.
47
- chart1.set_title(:name => 'Popular Doughnut Types')
47
+ chart1.set_title(name: 'Popular Doughnut Types')
48
48
 
49
49
  # Set an Excel chart style. Colors with white outline and shadow.
50
50
  chart1.set_style(10)
@@ -52,7 +52,7 @@ chart1.set_style(10)
52
52
  # Insert the chart into the worksheet (with an offset).
53
53
  worksheet.insert_chart(
54
54
  'C2', chart1,
55
- :x_offset => 25, :y_offset => 10
55
+ x_offset: 25, y_offset: 10
56
56
  )
57
57
 
58
58
  #
@@ -60,27 +60,27 @@ worksheet.insert_chart(
60
60
  #
61
61
 
62
62
  # Create an example Doughnut chart like above.
63
- chart2 = workbook.add_chart(:type => 'doughnut', :embedded => 1)
63
+ chart2 = workbook.add_chart(type: 'doughnut', embedded: 1)
64
64
 
65
65
  # Configure the series and add user defined segment colours.
66
66
  chart2.add_series(
67
- :name => 'Doughnut sales data',
68
- :categories => '=Sheet1!$A$2:$A$4',
69
- :values => '=Sheet1!$B$2:$B$4',
70
- :points => [
71
- { :fill => { :color => '#FA58D0' } },
72
- { :fill => { :color => '#61210B' } },
73
- { :fill => { :color => '#F5F6CE' } }
67
+ name: 'Doughnut sales data',
68
+ categories: '=Sheet1!$A$2:$A$4',
69
+ values: '=Sheet1!$B$2:$B$4',
70
+ points: [
71
+ { fill: { color: '#FA58D0' } },
72
+ { fill: { color: '#61210B' } },
73
+ { fill: { color: '#F5F6CE' } }
74
74
  ]
75
75
  )
76
76
 
77
77
  # Add a title.
78
- chart2.set_title(:name => 'Doughnut Chart with user defined colors')
78
+ chart2.set_title(name: 'Doughnut Chart with user defined colors')
79
79
 
80
80
  # Insert the chart into the worksheet (with an offset).
81
81
  worksheet.insert_chart(
82
82
  'C18', chart2,
83
- :x_offset => 25, :y_offset => 10
83
+ x_offset: 25, y_offset: 10
84
84
  )
85
85
 
86
86
  #
@@ -88,17 +88,17 @@ worksheet.insert_chart(
88
88
  #
89
89
 
90
90
  # Create an example Doughnut chart like above.
91
- chart3 = workbook.add_chart(:type => 'doughnut', :embedded => 1)
91
+ chart3 = workbook.add_chart(type: 'doughnut', embedded: 1)
92
92
 
93
93
  # Configure the series.
94
94
  chart3.add_series(
95
- :name => 'Doughnut sales data',
96
- :categories => '=Sheet1!$A$2:$A$4',
97
- :values => '=Sheet1!$B$2:$B$4'
95
+ name: 'Doughnut sales data',
96
+ categories: '=Sheet1!$A$2:$A$4',
97
+ values: '=Sheet1!$B$2:$B$4'
98
98
  )
99
99
 
100
100
  # Add a title.
101
- chart3.set_title(:name => 'Doughnut Chart with segment rotation')
101
+ chart3.set_title(name: 'Doughnut Chart with segment rotation')
102
102
 
103
103
  # Change the angle/rotation of the first segment.
104
104
  chart3.set_rotation(90)
@@ -106,7 +106,7 @@ chart3.set_rotation(90)
106
106
  # Insert the chart into the worksheet (with an offset).
107
107
  worksheet.insert_chart(
108
108
  'C34', chart3,
109
- :x_offset => 25, :y_offset => 10
109
+ x_offset: 25, y_offset: 10
110
110
  )
111
111
 
112
112
  #
@@ -114,17 +114,17 @@ worksheet.insert_chart(
114
114
  #
115
115
 
116
116
  # Create an example Doughnut chart like above.
117
- chart4 = workbook.add_chart(:type => 'doughnut', :embedded => 1)
117
+ chart4 = workbook.add_chart(type: 'doughnut', embedded: 1)
118
118
 
119
119
  # Configure the series.
120
120
  chart4.add_series(
121
- :name => 'Doughnut sales data',
122
- :categories => '=Sheet1!$A$2:$A$4',
123
- :values => '=Sheet1!$B$2:$B$4'
121
+ name: 'Doughnut sales data',
122
+ categories: '=Sheet1!$A$2:$A$4',
123
+ values: '=Sheet1!$B$2:$B$4'
124
124
  )
125
125
 
126
126
  # Add a title.
127
- chart4.set_title(:name => 'Doughnut Chart with user defined hole size')
127
+ chart4.set_title(name: 'Doughnut Chart with user defined hole size')
128
128
 
129
129
  # Change the hole size.
130
130
  chart4.set_hole_size(33)
@@ -132,7 +132,7 @@ chart4.set_hole_size(33)
132
132
  # Insert the chart into the worksheet (with an offset).
133
133
  worksheet.insert_chart(
134
134
  'C50', chart4,
135
- :x_offset => 25, :y_offset => 10
135
+ x_offset: 25, y_offset: 10
136
136
  )
137
137
 
138
138
  workbook.close
@@ -18,8 +18,8 @@ require 'write_xlsx'
18
18
  workbook = WriteXLSX.new('chart_gauge.xlsx')
19
19
  worksheet = workbook.add_worksheet
20
20
 
21
- chart_doughnut = workbook.add_chart(:type => 'doughnut', :embedded => 1)
22
- chart_pie = workbook.add_chart(:type => 'pie', :embedded => 1)
21
+ chart_doughnut = workbook.add_chart(type: 'doughnut', embedded: 1)
22
+ chart_pie = workbook.add_chart(type: 'pie', embedded: 1)
23
23
 
24
24
  # Add some data for the Doughnut and Pie charts. This is set up so the
25
25
  # gauge goes from 0-100. It is initially set at 75%.
@@ -28,13 +28,13 @@ worksheet.write_col('I2', ['Pie', 75, 1, '=200-I4-I3'])
28
28
 
29
29
  # Configure the doughnut chart as the background for the gauge.
30
30
  chart_doughnut.add_series(
31
- :name => '=Sheet1!$H$2',
32
- :values => '=Sheet1!$H$3:$H$6',
33
- :points => [
34
- { :fill => { :color => 'green' } },
35
- { :fill => { :color => 'yellow' } },
36
- { :fill => { :color => 'red' } },
37
- { :fill => { :none => 1 } }
31
+ name: '=Sheet1!$H$2',
32
+ values: '=Sheet1!$H$3:$H$6',
33
+ points: [
34
+ { fill: { color: 'green' } },
35
+ { fill: { color: 'yellow' } },
36
+ { fill: { color: 'red' } },
37
+ { fill: { none: 1 } }
38
38
  ]
39
39
  )
40
40
 
@@ -42,22 +42,22 @@ chart_doughnut.add_series(
42
42
  chart_doughnut.set_rotation(270)
43
43
 
44
44
  # Turn off the chart legend.
45
- chart_doughnut.set_legend(:none => 1)
45
+ chart_doughnut.set_legend(none: 1)
46
46
 
47
47
  # Turn off the chart fill and border.
48
48
  chart_doughnut.set_chartarea(
49
- :border => { :none => 1 },
50
- :fill => { :none => 1 }
49
+ border: { none: 1 },
50
+ fill: { none: 1 }
51
51
  )
52
52
 
53
53
  # Configure the pie chart as the needle for the gauge.
54
54
  chart_pie.add_series(
55
- :name => '=Sheet1!$I$2',
56
- :values => '=Sheet1!$I$3:$I$6',
57
- :points => [
58
- { :fill => { :none => 1 } },
59
- { :fill => { :color => 'black' } },
60
- { :fill => { :none => 1 } }
55
+ name: '=Sheet1!$I$2',
56
+ values: '=Sheet1!$I$3:$I$6',
57
+ points: [
58
+ { fill: { none: 1 } },
59
+ { fill: { color: 'black' } },
60
+ { fill: { none: 1 } }
61
61
  ]
62
62
  )
63
63
 
@@ -13,7 +13,7 @@ require 'write_xlsx'
13
13
 
14
14
  workbook = WriteXLSX.new('chart_line.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 => 'line', :embedded => 1)
30
+ chart = workbook.add_chart(type: 'line', 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(10)
@@ -55,30 +55,30 @@ chart.set_style(10)
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
  #
62
62
  # Create a stacked chart sub-type
63
63
  #
64
64
  chart2 = workbook.add_chart(
65
- :type => 'line',
66
- :embedded => 1,
67
- :subtype => 'stacked'
65
+ type: 'line',
66
+ embedded: 1,
67
+ subtype: 'stacked'
68
68
  )
69
69
 
70
70
  # Configure the first series.
71
71
  chart2.add_series(
72
- :name => '=Sheet1!$B$1',
73
- :categories => '=Sheet1!$A$2:$A$7',
74
- :values => '=Sheet1!$B$2:$B$7'
72
+ name: '=Sheet1!$B$1',
73
+ categories: '=Sheet1!$A$2:$A$7',
74
+ values: '=Sheet1!$B$2:$B$7'
75
75
  )
76
76
 
77
77
  # Configure second series.
78
78
  chart2.add_series(
79
- :name => '=Sheet1!$C$1',
80
- :categories => ['Sheet1', 1, 6, 0, 0],
81
- :values => ['Sheet1', 1, 6, 2, 2]
79
+ name: '=Sheet1!$C$1',
80
+ categories: ['Sheet1', 1, 6, 0, 0],
81
+ values: ['Sheet1', 1, 6, 2, 2]
82
82
  )
83
83
 
84
84
  # Add a chart title and some axis labels.
@@ -92,30 +92,30 @@ chart2.set_style(12)
92
92
  # Insert the chart into the worksheet (with an offset).
93
93
  worksheet.insert_chart(
94
94
  'D18', chart2,
95
- { :x_offset => 25, :y_offset => 10 }
95
+ { x_offset: 25, y_offset: 10 }
96
96
  )
97
97
 
98
98
  #
99
99
  # Create a percent stacked chart sub-type
100
100
  #
101
101
  chart3 = workbook.add_chart(
102
- :type => 'line',
103
- :embedded => 1,
104
- :subtype => 'percent_stacked'
102
+ type: 'line',
103
+ embedded: 1,
104
+ subtype: 'percent_stacked'
105
105
  )
106
106
 
107
107
  # Configure the first series.
108
108
  chart3.add_series(
109
- :name => '=Sheet1!$B$1',
110
- :categories => '=Sheet1!$A$2:$A$7',
111
- :values => '=Sheet1!$B$2:$B$7'
109
+ name: '=Sheet1!$B$1',
110
+ categories: '=Sheet1!$A$2:$A$7',
111
+ values: '=Sheet1!$B$2:$B$7'
112
112
  )
113
113
 
114
114
  # Configure second series.
115
115
  chart3.add_series(
116
- :name => '=Sheet1!$C$1',
117
- :categories => ['Sheet1', 1, 6, 0, 0],
118
- :values => ['Sheet1', 1, 6, 2, 2]
116
+ name: '=Sheet1!$C$1',
117
+ categories: ['Sheet1', 1, 6, 0, 0],
118
+ values: ['Sheet1', 1, 6, 2, 2]
119
119
  )
120
120
 
121
121
  # Add a chart title and some axis labels.
@@ -129,7 +129,7 @@ chart3.set_style(13)
129
129
  # Insert the chart into the worksheet (with an offset).
130
130
  worksheet.insert_chart(
131
131
  'D34', chart3,
132
- { :x_offset => 25, :y_offset => 10 }
132
+ { x_offset: 25, y_offset: 10 }
133
133
  )
134
134
 
135
135
  workbook.close
@@ -15,8 +15,8 @@ workbook = WriteXLSX.new('chart_pareto.xlsx')
15
15
  worksheet = workbook.add_worksheet
16
16
 
17
17
  # Formats used in the workbook.
18
- bold = workbook.add_format(:bold => 1)
19
- percent_format = workbook.add_format(:num_format => '0.0%')
18
+ bold = workbook.add_format(bold: 1)
19
+ percent_format = workbook.add_format(num_format: '0.0%')
20
20
 
21
21
  # Widen the columns for visibility.
22
22
  worksheet.set_column('A:A', 15)
@@ -39,38 +39,38 @@ worksheet.write_col('B2', numbers)
39
39
  worksheet.write_col('C2', percents, percent_format)
40
40
 
41
41
  # Create a new column chart. This will be the primary chart.
42
- column_chart = workbook.add_chart(:type => 'column', :embedded => 1)
42
+ column_chart = workbook.add_chart(type: 'column', embedded: 1)
43
43
 
44
44
  # Add a series
45
45
  column_chart.add_series(
46
- :categories => 'Sheet1!$A$2:$A$7',
47
- :values => 'Sheet1!$B$2:$B$7'
46
+ categories: 'Sheet1!$A$2:$A$7',
47
+ values: 'Sheet1!$B$2:$B$7'
48
48
  )
49
49
 
50
50
  # Add a chart title.
51
- column_chart.set_title(:name => 'Reasons for lateness')
51
+ column_chart.set_title(name: 'Reasons for lateness')
52
52
 
53
53
  # Turn off the chart legend.
54
- column_chart.set_legend(:position => 'none')
54
+ column_chart.set_legend(position: 'none')
55
55
 
56
56
  # Set the title and scale of the Y axes. Note, the secondary axis is set from
57
57
  # the primary chart.
58
58
  column_chart.set_y_axis(
59
- :name => 'Respondents (number)',
60
- :min => 0,
61
- :max => 120
59
+ name: 'Respondents (number)',
60
+ min: 0,
61
+ max: 120
62
62
  )
63
- column_chart.set_y2_axis(:max => 1)
63
+ column_chart.set_y2_axis(max: 1)
64
64
 
65
65
  # Create a new line chart. This will be the secondary chart.
66
- line_chart = workbook.add_chart(:type => 'line', :embedded => 1)
66
+ line_chart = workbook.add_chart(type: 'line', embedded: 1)
67
67
 
68
68
  # Add a series, on the secondary axis.
69
69
  line_chart.add_series(
70
- :categories => '=Sheet1!$A$2:$A$7',
71
- :values => '=Sheet1!$C$2:$C$7',
72
- :marker => { :type => 'automatic' },
73
- :y2_axis => 1
70
+ categories: '=Sheet1!$A$2:$A$7',
71
+ values: '=Sheet1!$C$2:$C$7',
72
+ marker: { type: 'automatic' },
73
+ y2_axis: 1
74
74
  )
75
75
 
76
76
  # Combine the charts.