write_xlsx 1.04.0 → 1.08.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -1
  3. data/Changes +50 -0
  4. data/README.md +1 -1
  5. data/examples/chart_data_labels.rb +320 -0
  6. data/examples/ignore_errors.rb +39 -0
  7. data/ignore_errors.xlsx +0 -0
  8. data/lib/write_xlsx/chart/series.rb +100 -0
  9. data/lib/write_xlsx/chart.rb +155 -33
  10. data/lib/write_xlsx/drawing.rb +80 -17
  11. data/lib/write_xlsx/package/app.rb +3 -3
  12. data/lib/write_xlsx/package/conditional_format.rb +2 -8
  13. data/lib/write_xlsx/package/packager.rb +1 -0
  14. data/lib/write_xlsx/package/styles.rb +16 -3
  15. data/lib/write_xlsx/package/table.rb +8 -0
  16. data/lib/write_xlsx/utility.rb +9 -3
  17. data/lib/write_xlsx/version.rb +1 -1
  18. data/lib/write_xlsx/workbook.rb +23 -0
  19. data/lib/write_xlsx/worksheet/data_validation.rb +1 -6
  20. data/lib/write_xlsx/worksheet.rb +160 -37
  21. data/test/drawing/{test_write_ext.rb → test_write_xdr_ext.rb} +2 -2
  22. data/test/perl_output/chart_data_labels.xlsx +0 -0
  23. data/test/perl_output/ignore_errors.xlsx +0 -0
  24. data/test/regression/test_array_formula04.rb +31 -0
  25. data/test/regression/test_chart_crossing01.rb +1 -1
  26. data/test/regression/test_chart_crossing05.rb +46 -0
  27. data/test/regression/test_chart_crossing06.rb +46 -0
  28. data/test/regression/test_chart_data_labels26.rb +44 -0
  29. data/test/regression/test_chart_data_labels27.rb +44 -0
  30. data/test/regression/test_chart_data_labels28.rb +52 -0
  31. data/test/regression/test_chart_data_labels29.rb +43 -0
  32. data/test/regression/test_chart_data_labels30.rb +46 -0
  33. data/test/regression/test_chart_data_labels31.rb +49 -0
  34. data/test/regression/test_chart_data_labels32.rb +54 -0
  35. data/test/regression/test_chart_data_labels33.rb +52 -0
  36. data/test/regression/test_chart_data_labels34.rb +54 -0
  37. data/test/regression/test_chart_data_labels35.rb +46 -0
  38. data/test/regression/test_chart_data_labels36.rb +54 -0
  39. data/test/regression/test_chart_data_labels37.rb +51 -0
  40. data/test/regression/test_chart_data_labels38.rb +54 -0
  41. data/test/regression/test_chart_data_labels39.rb +53 -0
  42. data/test/regression/test_chart_data_labels40.rb +53 -0
  43. data/test/regression/test_chart_data_labels41.rb +54 -0
  44. data/test/regression/test_chart_data_labels42.rb +58 -0
  45. data/test/regression/test_chart_data_labels43.rb +58 -0
  46. data/test/regression/test_chart_data_labels44.rb +56 -0
  47. data/test/regression/test_chart_data_labels45.rb +57 -0
  48. data/test/regression/test_chart_data_labels46.rb +61 -0
  49. data/test/regression/test_chart_data_labels47.rb +61 -0
  50. data/test/regression/test_chart_data_labels48.rb +55 -0
  51. data/test/regression/test_chart_data_labels49.rb +55 -0
  52. data/test/regression/test_chart_data_labels50.rb +57 -0
  53. data/test/regression/test_format16.rb +24 -0
  54. data/test/regression/test_format17.rb +24 -0
  55. data/test/regression/test_header04.rb +30 -0
  56. data/test/regression/test_hyperlink50.rb +27 -0
  57. data/test/regression/test_hyperlink51.rb +27 -0
  58. data/test/regression/test_ignore_error01.rb +23 -0
  59. data/test/regression/test_ignore_error02.rb +24 -0
  60. data/test/regression/test_ignore_error03.rb +26 -0
  61. data/test/regression/test_ignore_error04.rb +26 -0
  62. data/test/regression/test_ignore_error05.rb +32 -0
  63. data/test/regression/test_ignore_error06.rb +32 -0
  64. data/test/regression/test_image52.rb +26 -0
  65. data/test/regression/test_image53.rb +26 -0
  66. data/test/regression/test_image54.rb +26 -0
  67. data/test/regression/test_image55.rb +27 -0
  68. data/test/regression/test_protect04.rb +32 -0
  69. data/test/regression/test_protect05.rb +35 -0
  70. data/test/regression/test_protect06.rb +35 -0
  71. data/test/regression/test_protect07.rb +23 -0
  72. data/test/regression/test_table26.rb +38 -0
  73. data/test/regression/xlsx_files/array_formula04.xlsx +0 -0
  74. data/test/regression/xlsx_files/chart_crossing05.xlsx +0 -0
  75. data/test/regression/xlsx_files/chart_crossing06.xlsx +0 -0
  76. data/test/regression/xlsx_files/chart_data_labels26.xlsx +0 -0
  77. data/test/regression/xlsx_files/chart_data_labels27.xlsx +0 -0
  78. data/test/regression/xlsx_files/chart_data_labels28.xlsx +0 -0
  79. data/test/regression/xlsx_files/chart_data_labels29.xlsx +0 -0
  80. data/test/regression/xlsx_files/chart_data_labels30.xlsx +0 -0
  81. data/test/regression/xlsx_files/chart_data_labels31.xlsx +0 -0
  82. data/test/regression/xlsx_files/chart_data_labels32.xlsx +0 -0
  83. data/test/regression/xlsx_files/chart_data_labels33.xlsx +0 -0
  84. data/test/regression/xlsx_files/chart_data_labels34.xlsx +0 -0
  85. data/test/regression/xlsx_files/chart_data_labels35.xlsx +0 -0
  86. data/test/regression/xlsx_files/chart_data_labels36.xlsx +0 -0
  87. data/test/regression/xlsx_files/chart_data_labels37.xlsx +0 -0
  88. data/test/regression/xlsx_files/chart_data_labels38.xlsx +0 -0
  89. data/test/regression/xlsx_files/chart_data_labels39.xlsx +0 -0
  90. data/test/regression/xlsx_files/chart_data_labels40.xlsx +0 -0
  91. data/test/regression/xlsx_files/chart_data_labels41.xlsx +0 -0
  92. data/test/regression/xlsx_files/chart_data_labels42.xlsx +0 -0
  93. data/test/regression/xlsx_files/chart_data_labels43.xlsx +0 -0
  94. data/test/regression/xlsx_files/chart_data_labels44.xlsx +0 -0
  95. data/test/regression/xlsx_files/chart_data_labels45.xlsx +0 -0
  96. data/test/regression/xlsx_files/chart_data_labels46.xlsx +0 -0
  97. data/test/regression/xlsx_files/chart_data_labels47.xlsx +0 -0
  98. data/test/regression/xlsx_files/chart_data_labels48.xlsx +0 -0
  99. data/test/regression/xlsx_files/chart_data_labels49.xlsx +0 -0
  100. data/test/regression/xlsx_files/chart_data_labels50.xlsx +0 -0
  101. data/test/regression/xlsx_files/format16.xlsx +0 -0
  102. data/test/regression/xlsx_files/format17.xlsx +0 -0
  103. data/test/regression/xlsx_files/header04.xlsx +0 -0
  104. data/test/regression/xlsx_files/hyperlink50.xlsx +0 -0
  105. data/test/regression/xlsx_files/hyperlink51.xlsx +0 -0
  106. data/test/regression/xlsx_files/ignore_error01.xlsx +0 -0
  107. data/test/regression/xlsx_files/ignore_error02.xlsx +0 -0
  108. data/test/regression/xlsx_files/ignore_error03.xlsx +0 -0
  109. data/test/regression/xlsx_files/ignore_error04.xlsx +0 -0
  110. data/test/regression/xlsx_files/ignore_error05.xlsx +0 -0
  111. data/test/regression/xlsx_files/ignore_error06.xlsx +0 -0
  112. data/test/regression/xlsx_files/image52.xlsx +0 -0
  113. data/test/regression/xlsx_files/image53.xlsx +0 -0
  114. data/test/regression/xlsx_files/image54.xlsx +0 -0
  115. data/test/regression/xlsx_files/image55.xlsx +0 -0
  116. data/test/regression/xlsx_files/protect04.xlsx +0 -0
  117. data/test/regression/xlsx_files/protect05.xlsx +0 -0
  118. data/test/regression/xlsx_files/protect06.xlsx +0 -0
  119. data/test/regression/xlsx_files/protect07.xlsx +0 -0
  120. data/test/regression/xlsx_files/table26.xlsx +0 -0
  121. data/test/test_example_match.rb +345 -1
  122. data/test/utility/test_range.rb +20 -0
  123. metadata +209 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c3893d317a3ab9f246b62c9d6b6b3a727abd9ab539da4edf52c4029f076d566
4
- data.tar.gz: 64861b9ce57ebd55ce67508b33be19705049a8db520edfacc1fd40d8547c2b9c
3
+ metadata.gz: 15cfe1d88bbb3b997322aa3d507a8e8960bacd75afd397699a34d71e84162ab8
4
+ data.tar.gz: 0d5500191ffb1e57645eb6162ae40cfbceddcfe6008704697645a4099da7ba1b
5
5
  SHA512:
6
- metadata.gz: c3870b13ed05dca60597ecc86662d15d2ec143667e6ff29349c4409d2dd7966eb9f7246f14071a06524a15f5039cb8ec2d4c6c4fb99206b1377f452abe94eddc
7
- data.tar.gz: b776541fecba7724e59e5742939e331944ea9a08d87eba2528d29404f9f34bbab8a8abe548fd52735a15c72e42e54c54cc73ad5c06765521647771178229fab0
6
+ metadata.gz: b5b8b723b22bab86ad2a1fe4527aa94ded8ff95661fc1b23098552774dc6f98cbaf80fdfca5be2e6422810fe9d0fc95748a329aa17770708f40e06112d507fec
7
+ data.tar.gz: 85f1ee5165c26ddd247b10b19de5ee6e2c07be360211c80316e9259dda928d7ff64052581bbbd8023c2965d8d2449daf1d4a7470c6a7e11d2b4f3f5b67fb4dc1
data/.travis.yml CHANGED
@@ -63,4 +63,3 @@ rvm:
63
63
  - 2.1.1
64
64
  - 2.1.0
65
65
  - 2.0.0
66
- - 1.9.3
data/Changes CHANGED
@@ -1,5 +1,55 @@
1
1
  Change history of write_xlsx rubygem.
2
2
 
3
+ 2021-11-19 v1.08.0
4
+
5
+ Added ability to add accessibility options "description" and
6
+ "decorative" to images via insert_image().
7
+
8
+ Added the workbook read_only_recommended() method to set the Excel
9
+ "Read-only Recommended" option that is available when saving a file.
10
+
11
+ Added option to set a chart crossing to 'min' as well as the existing
12
+ 'max' option. The 'min' option isn't available in the Excel interface
13
+ but can be enabled via VBA.
14
+
15
+ Added option to unprotect ranges in protected worksheets.
16
+
17
+ Added check, and warning, for worksheet tables with no data row. Either
18
+ with or without a header row.
19
+
20
+ Added ignore_errors() worksheet method to ignore Excel worksheet
21
+ errors/warnings in user defined ranges.
22
+
23
+ Fixed issue where pattern formats without colours where given a default
24
+ black fill colour.
25
+
26
+ Fix issue where custom chart data labels didn't inherit the position for
27
+ the data labels in the series.
28
+
29
+ Fixed issue with relative url links in images.
30
+
31
+ Fixed issue where headers/footers were restricted to 254 characters
32
+ instead of 255.
33
+
34
+ 2021-02-17 v1.07.0
35
+
36
+ Added support for Border, Fill, Pattern and Gradient formatting to chart
37
+ data labels and chart custom data labels.
38
+
39
+
40
+ 2021-02-15 v1.06.0
41
+
42
+ Fix for issue where array formulas weren't included in the output file
43
+ for certain ranges/conditions.
44
+
45
+
46
+ 2021-02-15 v1.05.0
47
+
48
+ Added support for custom data labels in charts.
49
+
50
+ Remove ruby-1.9.3 travil CI check.
51
+
52
+
3
53
  2021-02-14 v1.04.0
4
54
 
5
55
  Added support for "stacked" and "percent_stacked" Line charts.
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.04](https://github.com/jmcnamara/excel-writer-xlsx/tree/CPAN_1.04)
8
+ [Excel::Writer::XLSX-1.08](https://github.com/jmcnamara/excel-writer-xlsx/tree/CPAN_1.08)
9
9
 
10
10
  ## Description
11
11
 
@@ -0,0 +1,320 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # A demo of an various Excel chart data label features that are available
7
+ # via an WriteXLSX chart.
8
+ #
9
+ # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
11
+ #
12
+
13
+ require 'write_xlsx'
14
+
15
+ workbook = WriteXLSX.new('chart_data_labels.xlsx')
16
+ worksheet = workbook.add_worksheet
17
+ bold = workbook.add_format(:bold => 1)
18
+
19
+ # Add the worksheet data that the charts will refer to.
20
+ headings = ['Number', 'Data', 'Text']
21
+ data = [
22
+ [ 2, 3, 4, 5, 6, 7 ],
23
+ [20, 10, 20, 30, 40, 30 ],
24
+ ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
25
+ ]
26
+
27
+ worksheet.write('A1', headings, bold)
28
+ worksheet.write('A2', data)
29
+
30
+
31
+ #######################################################################
32
+ #
33
+ # Example with standard data labels.
34
+ #
35
+
36
+ # Create a Column chart.
37
+ chart1 = workbook.add_chart(:type => 'column', :embedded => 1)
38
+
39
+ # Configure the data series and add the data labels.
40
+ chart1.add_series(
41
+ :categories => '=Sheet1!$A$2:$A$7',
42
+ :values => '=Sheet1!$B$2:$B$7',
43
+ :data_labels => { :value => 1 }
44
+ )
45
+
46
+ # Add a chart title.
47
+ chart1.set_title(:name => 'Chart with standard data labels')
48
+
49
+ # Turn off the chart legend.
50
+ chart1.set_legend(:none => 1)
51
+
52
+ # Insert the chart into the worksheet (with an offset).
53
+ worksheet.insert_chart('D2', chart1, { :x_offset => 25, :y_offset => 10 })
54
+
55
+
56
+ #######################################################################
57
+ #
58
+ # Example with value and category data labels.
59
+ #
60
+
61
+ # Create a Column chart.
62
+ chart2 = workbook.add_chart(:type => 'column', :embedded => 1)
63
+
64
+ # Configure the data series and add the data labels.
65
+ chart2.add_series(
66
+ :categories => '=Sheet1!$A$2:$A$7',
67
+ :values => '=Sheet1!$B$2:$B$7',
68
+ :data_labels => { :value => 1, :category => 1 }
69
+ )
70
+
71
+ # Add a chart title.
72
+ chart2.set_title(:name => 'Category and Value data labels')
73
+
74
+ # Turn off the chart legend.
75
+ chart2.set_legend(:none => 1)
76
+
77
+ # Insert the chart into the worksheet (with an offset).
78
+ worksheet.insert_chart('D18', chart2, { :x_offset => 25, :y_offset => 10 })
79
+
80
+
81
+ #######################################################################
82
+ #
83
+ # Example with standard data labels with different font.
84
+ #
85
+
86
+ # Create a Column chart.
87
+ chart3 = workbook.add_chart(:type => 'column', :embedded => 1)
88
+
89
+ # Configure the data series and add the data labels.
90
+ chart3.add_series(
91
+ :categories => '=Sheet1!$A$2:$A$7',
92
+ :values => '=Sheet1!$B$2:$B$7',
93
+ :data_labels => { :value => 1,
94
+ :font => {:bold => 1,
95
+ :color => 'red',
96
+ :rotation => -30}
97
+ }
98
+ )
99
+
100
+ # Add a chart title.
101
+ chart3.set_title(:name => 'Data labels with user defined font')
102
+
103
+ # Turn off the chart legend.
104
+ chart3.set_legend(:none => 1)
105
+
106
+ # Insert the chart into the worksheet (with an offset).
107
+ worksheet.insert_chart('D34', chart3, { :x_offset => 25, :y_offset => 10 })
108
+
109
+
110
+ #######################################################################
111
+ #
112
+ # Example with custom string data labels.
113
+ #
114
+
115
+ # Create a Column chart.
116
+ chart4 = workbook.add_chart(:type => 'column', :embedded => 1)
117
+
118
+ # Configure the data series and add the data labels.
119
+ chart4.add_series(
120
+ :categories => '=Sheet1!$A$2:$A$7',
121
+ :values => '=Sheet1!$B$2:$B$7',
122
+ :data_labels => {
123
+ :value => 1,
124
+ :border => {:color => 'red'},
125
+ :fill => {:color => 'yellow'}
126
+ }
127
+ )
128
+
129
+ # Add a chart title.
130
+ chart4.set_title(:name => 'Data labels with formatting')
131
+
132
+ # Turn off the chart legend.
133
+ chart4.set_legend(:none => 1)
134
+
135
+ # Insert the chart into the worksheet (with an offset).
136
+ worksheet.insert_chart('D50', chart4, { :x_offset => 25, :y_offset => 10 })
137
+
138
+
139
+ #######################################################################
140
+ #
141
+ # Example with custom string data labels.
142
+ #
143
+
144
+ # Create a Column chart.
145
+ chart5 = workbook.add_chart( :type => 'column', :embedded => 1 )
146
+
147
+ # Some custom labels.
148
+ custom_labels = [
149
+ { :value => 'Amy' },
150
+ { :value => 'Bea' },
151
+ { :value => 'Eva' },
152
+ { :value => 'Fay' },
153
+ { :value => 'Liv' },
154
+ { :value => 'Una' }
155
+ ]
156
+
157
+ # Configure the data series and add the data labels.
158
+ chart5.add_series(
159
+ :categories => '=Sheet1!$A$2:$A$7',
160
+ :values => '=Sheet1!$B$2:$B$7',
161
+ :data_labels => { :value => 1, :custom => custom_labels }
162
+ )
163
+
164
+ # Add a chart title.
165
+ chart5.set_title(:name => 'Chart with custom string data labels')
166
+
167
+ # Turn off the chart legend.
168
+ chart5.set_legend(:none => 1)
169
+
170
+ # Insert the chart into the worksheet (with an offset).
171
+ worksheet.insert_chart('D66', chart5, { :x_offset => 25, :y_offset => 10 })
172
+
173
+
174
+ #######################################################################
175
+ #
176
+ # Example with custom data labels from cells.
177
+ #
178
+
179
+ # Create a Column chart.
180
+ chart6 = workbook.add_chart(:type => 'column', :embedded => 1)
181
+
182
+ # Some custom labels.
183
+ custom_labels = [
184
+ { :value => '=Sheet1!$C$2' },
185
+ { :value => '=Sheet1!$C$3' },
186
+ { :value => '=Sheet1!$C$4' },
187
+ { :value => '=Sheet1!$C$5' },
188
+ { :value => '=Sheet1!$C$6' },
189
+ { :value => '=Sheet1!$C$7' }
190
+ ]
191
+
192
+
193
+ # Configure the data series and add the data labels.
194
+ chart6.add_series(
195
+ :categories => '=Sheet1!$A$2:$A$7',
196
+ :values => '=Sheet1!$B$2:$B$7',
197
+ :data_labels => { :value => 1, :custom => custom_labels }
198
+ )
199
+
200
+ # Add a chart title.
201
+ chart6.set_title(:name => 'Chart with custom data labels from cells')
202
+
203
+ # Turn off the chart legend.
204
+ chart6.set_legend(:none => 1)
205
+
206
+ # Insert the chart into the worksheet (with an offset).
207
+ worksheet.insert_chart('D82', chart6, { :x_offset => 25, :y_offset => 10 })
208
+
209
+
210
+ #######################################################################
211
+ #
212
+ # Example with custom and default data labels.
213
+ #
214
+
215
+ # Create a Column chart.
216
+ chart7 = workbook.add_chart(:type => 'column', :embedded => 1)
217
+
218
+ # Some custom labels. The nil items will get the default value.
219
+ # We also set a font for the custom items as an extra example.
220
+ custom_labels = [
221
+ { :value => '=Sheet1!$C$2', :font => { :color => 'red' } },
222
+ nil,
223
+ { :value => '=Sheet1!$C$4', :font => { :color => 'red' } },
224
+ { :value => '=Sheet1!$C$5', :font => { :color => 'red' } }
225
+ ]
226
+
227
+
228
+ # Configure the data series and add the data labels.
229
+ chart7.add_series(
230
+ :categories => '=Sheet1!$A$2:$A$7',
231
+ :values => '=Sheet1!$B$2:$B$7',
232
+ :data_labels => { :value => 1, :custom => custom_labels }
233
+ )
234
+
235
+ # Add a chart title.
236
+ chart7.set_title(:name => 'Mixed custom and default data labels')
237
+
238
+ # Turn off the chart legend.
239
+ chart7.set_legend(:none => 1)
240
+
241
+ # Insert the chart into the worksheet (with an offset).
242
+ worksheet.insert_chart('D98', chart7, { :x_offset => 25, :y_offset => 10 })
243
+
244
+
245
+ #######################################################################
246
+ #
247
+ # Example with deleted custom data labels.
248
+ #
249
+
250
+ # Create a Column chart.
251
+ chart8 = workbook.add_chart(:type => 'column', :embedded => 1)
252
+
253
+ # Some deleted custom labels and defaults (nil). This allows us to
254
+ # highlight certain values such as the minimum and maximum.
255
+ custom_labels = [
256
+ { :delete => 1 },
257
+ nil,
258
+ { :delete => 1 },
259
+ { :delete => 1 },
260
+ nil,
261
+ { :delete => 1 }
262
+ ]
263
+
264
+ # Configure the data series and add the data labels.
265
+ chart8.add_series(
266
+ :categories => '=Sheet1!$A$2:$A$7',
267
+ :values => '=Sheet1!$B$2:$B$7',
268
+ :data_labels => { :value => 1, :custom => custom_labels }
269
+ )
270
+
271
+ # Add a chart title.
272
+ chart8.set_title(:name => 'Chart with deleted data labels')
273
+
274
+ # Turn off the chart legend.
275
+ chart8.set_legend(:none => 1)
276
+
277
+ # Insert the chart into the worksheet (with an offset).
278
+ worksheet.insert_chart('D114', chart8, { :x_offset => 25, :y_offset => 10 })
279
+
280
+ #######################################################################
281
+ #
282
+ # Example with custom string data labels and formatting.
283
+ #
284
+
285
+ # Create a Column chart.
286
+ chart9 = workbook.add_chart( :type => 'column', :embedded => 1 )
287
+
288
+ # Some custom labels.
289
+ custom_labels = [
290
+ { :value => 'Amy', :border => {:color => 'blue'} },
291
+ { :value => 'Bea' },
292
+ { :value => 'Eva' },
293
+ { :value => 'Fay' },
294
+ { :value => 'Liv' },
295
+ { :value => 'Una', :fill => {:color => 'green'} }
296
+ ]
297
+
298
+
299
+ # Configure the data series and add the data labels.
300
+ chart9.add_series(
301
+ :categories => '=Sheet1!$A$2:$A$7',
302
+ :values => '=Sheet1!$B$2:$B$7',
303
+ :data_labels => {
304
+ :value => 1,
305
+ :custom => custom_labels,
306
+ :border => {:color => 'red'},
307
+ :fill => {:color => 'yellow'}
308
+ }
309
+ )
310
+
311
+ # Add a chart title.
312
+ chart9.set_title( :name => 'Chart with custom labels and formatting' )
313
+
314
+ # Turn off the chart legend.
315
+ chart9.set_legend( :none => 1 )
316
+
317
+ # Insert the chart into the worksheet (with an offset).
318
+ worksheet.insert_chart( 'D130', chart9, { :x_offset => 25, :y_offset => 10 } )
319
+
320
+ workbook.close
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ##############################################################################
5
+ #
6
+ # An example of turning off worksheet cells errors/warnings using the
7
+ # Excel::Writer::XLSX module.
8
+ #
9
+ # Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
10
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
11
+ #
12
+
13
+ require 'write_xlsx'
14
+
15
+ workbook = WriteXLSX.new('ignore_errors.xlsx')
16
+ worksheet = workbook.add_worksheet
17
+
18
+ # Write strings that looks like numbers. This will cause an Excel warning.
19
+ worksheet.write_string('C2', '123')
20
+ worksheet.write_string('C3', '123')
21
+
22
+ # Write a divide by zero formula. This will also cause an Excel warning.
23
+ worksheet.write_formula('C5', '=1/0')
24
+ worksheet.write_formula('C6', '=1/0')
25
+
26
+ # Turn off some of the warnings:
27
+ worksheet.ignore_errors(
28
+ :number_stored_as_text => 'C3',
29
+ :eval_error => 'C6'
30
+ )
31
+
32
+ # Write some descriptions for the cells and make the column wider for clarity.
33
+ worksheet.set_column('B:B', 16)
34
+ worksheet.write('B2', 'Warning:')
35
+ worksheet.write('B3', 'Warning turned off:')
36
+ worksheet.write('B5', 'Warning:')
37
+ worksheet.write('B6', 'Warning turned off:')
38
+
39
+ workbook.close
Binary file
@@ -296,10 +296,110 @@ module Writexlsx
296
296
  labels[:separator] = separators[separator]
297
297
  end
298
298
 
299
+
300
+ # Set the line properties for the data labels.
301
+ line = line_properties( labels[:line] )
302
+
303
+ # Allow 'border' as a synonym for 'line'.
304
+ if labels[:border]
305
+ line = line_properties(labels[:border])
306
+ end
307
+
308
+ # Set the fill properties for the labels.
309
+ fill = fill_properties(labels[:fill])
310
+
311
+ # Set the pattern properties for the labels.
312
+ pattern = pattern_properties(labels[:pattern])
313
+
314
+ # Set the gradient fill properties for the labels.
315
+ gradient = gradient_properties(labels[:gradient])
316
+
317
+ # Pattern fill overrides solid fill.
318
+ if pattern
319
+ fill = nil
320
+ end
321
+
322
+ # Gradient fill overrides solid and pattern fills.
323
+ if gradient
324
+ pattern = nil
325
+ fill = nil
326
+ end
327
+
328
+ labels[:line] = line
329
+ labels[:fill] = fill
330
+ labels[:pattern] = pattern
331
+ labels[:gradient] = gradient
332
+
299
333
  if labels[:font]
300
334
  labels[:font] = convert_font_args(labels[:font])
301
335
  end
302
336
 
337
+ if labels[:custom]
338
+ # Duplicate, and modify, the custom label properties.
339
+ custom = []
340
+
341
+ labels[:custom].each do |label|
342
+ if !label
343
+ custom << nil
344
+ next
345
+ end
346
+
347
+ property = label.dup
348
+
349
+ # Convert formula.
350
+ if property[:value] && property[:value] =~ /^=[^!]+!\$/
351
+ property[:formula] = property[:value]
352
+ end
353
+
354
+ if property[:formula]
355
+ property[:formula] = property[:formula].sub(/^=/, '')
356
+
357
+ data_id = @chart.data_id(property[:formula], property[:data])
358
+ property[:data_id] = data_id
359
+ end
360
+
361
+ if property[:font]
362
+ property[:font] = convert_font_args(property[:font])
363
+ end
364
+
365
+ # Allow 'border' as a synonym for 'line'.
366
+ if property[:border]
367
+ line = line_properties(property[:border])
368
+ else
369
+ # Set the line properties for the data labels.
370
+ line = line_properties(property[:line])
371
+ end
372
+
373
+ # Set the fill properties for the labels.
374
+ fill = fill_properties(property[:fill])
375
+
376
+ # Set the pattern properties for the labels.
377
+ pattern = pattern_properties(property[:pattern])
378
+
379
+ # Set the gradient fill properties for the labels.
380
+ gradient = gradient_properties(property[:gradient])
381
+
382
+ # Pattern fill overrides solid fill.
383
+ if pattern
384
+ fill = nil
385
+ end
386
+
387
+ # Gradient fill overrides solid and pattern fills.
388
+ if gradient
389
+ pattern = nil
390
+ fill = nil
391
+ end
392
+
393
+ property[:line] = line
394
+ property[:fill] = fill
395
+ property[:pattern] = pattern
396
+ property[:gradient] = gradient
397
+
398
+ custom << property
399
+ end
400
+ labels[:custom] = custom
401
+ end
402
+
303
403
  labels
304
404
  end
305
405
  end