writeexcel 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +26 -31
- data/examples/a_simple.rb +42 -42
- data/examples/{autofilters.rb → autofilter.rb} +264 -266
- data/examples/bigfile.rb +29 -0
- data/examples/chart_area.rb +120 -0
- data/examples/chart_bar.rb +119 -0
- data/examples/chart_column.rb +119 -0
- data/examples/chart_line.rb +119 -0
- data/examples/chart_pie.rb +107 -0
- data/examples/chart_scatter.rb +120 -0
- data/examples/chart_stock.rb +147 -0
- data/examples/copyformat.rb +51 -51
- data/examples/data_validate.rb +278 -278
- data/examples/date_time.rb +86 -86
- data/examples/defined_name.rb +31 -0
- data/examples/demo.rb +120 -118
- data/examples/diag_border.rb +35 -35
- data/examples/formats.rb +489 -489
- data/examples/header.rb +136 -136
- data/examples/hidden.rb +28 -28
- data/examples/hyperlink.rb +42 -42
- data/examples/images.rb +52 -52
- data/examples/merge1.rb +39 -39
- data/examples/merge2.rb +44 -44
- data/examples/merge3.rb +65 -65
- data/examples/merge4.rb +82 -82
- data/examples/merge5.rb +79 -79
- data/examples/properties.rb +33 -0
- data/examples/properties_jp.rb +32 -0
- data/examples/protection.rb +46 -46
- data/examples/regions.rb +52 -52
- data/examples/repeat.rb +42 -42
- data/examples/stats.rb +75 -75
- data/examples/stocks.rb +80 -80
- data/examples/tab_colors.rb +30 -30
- data/examples/write_arrays.rb +82 -0
- data/lib/writeexcel.rb +1134 -18
- data/lib/writeexcel/biffwriter.rb +273 -260
- data/lib/writeexcel/chart.rb +2306 -217
- data/lib/writeexcel/charts/area.rb +152 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +61 -0
- data/lib/writeexcel/charts/line.rb +152 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +211 -0
- data/lib/writeexcel/excelformulaparser.rb +208 -195
- data/lib/writeexcel/format.rb +1697 -1108
- data/lib/writeexcel/formula.rb +1050 -986
- data/lib/writeexcel/olewriter.rb +322 -322
- data/lib/writeexcel/properties.rb +251 -250
- data/lib/writeexcel/storage_lite.rb +968 -0
- data/lib/writeexcel/workbook.rb +3294 -2630
- data/lib/writeexcel/worksheet.rb +9012 -6377
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/tc_all.rb +32 -31
- data/test/tc_biff.rb +104 -104
- data/test/tc_chart.rb +22 -22
- data/test/tc_example_match.rb +1944 -1280
- data/test/tc_format.rb +1254 -1267
- data/test/tc_formula.rb +63 -63
- data/test/tc_ole.rb +110 -110
- data/test/tc_storage_lite.rb +149 -0
- data/test/tc_workbook.rb +140 -115
- data/test/tc_worksheet.rb +115 -115
- data/test/test_00_IEEE_double.rb +14 -14
- data/test/test_01_add_worksheet.rb +12 -12
- data/test/test_02_merge_formats.rb +58 -58
- data/test/test_04_dimensions.rb +397 -397
- data/test/test_05_rows.rb +182 -182
- data/test/test_06_extsst.rb +80 -80
- data/test/test_11_date_time.rb +484 -484
- data/test/test_12_date_only.rb +506 -506
- data/test/test_13_date_seconds.rb +486 -486
- data/test/test_21_escher.rb +642 -629
- data/test/test_22_mso_drawing_group.rb +750 -739
- data/test/test_23_note.rb +78 -78
- data/test/test_24_txo.rb +80 -80
- data/test/test_25_position_object.rb +82 -0
- data/test/test_26_autofilter.rb +327 -327
- data/test/test_27_autofilter.rb +144 -144
- data/test/test_28_autofilter.rb +174 -174
- data/test/test_29_process_jpg.rb +681 -131
- data/test/test_30_validation_dval.rb +82 -82
- data/test/test_31_validation_dv_strings.rb +131 -131
- data/test/test_32_validation_dv_formula.rb +211 -211
- data/test/test_40_property_types.rb +191 -191
- data/test/test_41_properties.rb +238 -238
- data/test/test_42_set_properties.rb +442 -419
- data/test/test_50_name_stored.rb +305 -0
- data/test/test_51_name_print_area.rb +363 -0
- data/test/test_52_name_print_titles.rb +460 -0
- data/test/test_53_autofilter.rb +209 -0
- data/test/test_60_chart_generic.rb +576 -0
- data/test/test_61_chart_subclasses.rb +97 -0
- data/test/test_62_chart_formats.rb +270 -0
- data/test/test_63_chart_area_formats.rb +647 -0
- data/test/test_chartex.rb +35 -0
- data/test/ts_all.rb +46 -34
- data/writeexcel.gemspec +18 -0
- data/writeexcel.rdoc +583 -0
- metadata +162 -108
data/examples/data_validate.rb
CHANGED
@@ -1,278 +1,278 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
###############################################################################
|
4
|
-
#
|
5
|
-
# Example of how to add data validation and dropdown lists to a
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# reverse('©'), August 2008, John McNamara, jmcnamara@cpan.org
|
9
|
-
#
|
10
|
-
# original written in Perl by John McNamara
|
11
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
12
|
-
#
|
13
|
-
|
14
|
-
require 'rubygems'
|
15
|
-
require 'writeexcel'
|
16
|
-
|
17
|
-
workbook =
|
18
|
-
worksheet = workbook.add_worksheet
|
19
|
-
|
20
|
-
# Add a format for the header cells.
|
21
|
-
header_format = workbook.add_format(
|
22
|
-
:border => 1,
|
23
|
-
:bg_color => 43,
|
24
|
-
:bold => 1,
|
25
|
-
:text_wrap => 1,
|
26
|
-
:valign => 'vcenter',
|
27
|
-
:indent => 1
|
28
|
-
)
|
29
|
-
|
30
|
-
# Set up layout of the worksheet.
|
31
|
-
worksheet.set_column('A:A', 64)
|
32
|
-
worksheet.set_column('B:B', 15)
|
33
|
-
worksheet.set_column('D:D', 15)
|
34
|
-
worksheet.set_row(0, 36)
|
35
|
-
worksheet.set_selection('B3')
|
36
|
-
|
37
|
-
|
38
|
-
# Write the header cells and some data that will be used in the examples.
|
39
|
-
row = 0
|
40
|
-
heading1 = 'Some examples of data validation in
|
41
|
-
heading2 = 'Enter values in this column'
|
42
|
-
heading3 = 'Sample Data'
|
43
|
-
|
44
|
-
worksheet.write('A1', heading1, header_format)
|
45
|
-
worksheet.write('B1', heading2, header_format)
|
46
|
-
worksheet.write('D1', heading3, header_format)
|
47
|
-
|
48
|
-
worksheet.write('D3', ['Integers', 1, 10])
|
49
|
-
worksheet.write('D4', ['List data', 'open', 'high', 'close'])
|
50
|
-
worksheet.write('D5', ['Formula', '=AND(F5=50,G5=60)', 50, 60])
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
# Example 1. Limiting input to an integer in a fixed range.
|
55
|
-
#
|
56
|
-
txt = 'Enter an integer between 1 and 10'
|
57
|
-
row += 2
|
58
|
-
|
59
|
-
worksheet.write(row, 0, txt)
|
60
|
-
worksheet.data_validation(row, 1,
|
61
|
-
{
|
62
|
-
:validate => 'integer',
|
63
|
-
:criteria => 'between',
|
64
|
-
:minimum => 1,
|
65
|
-
:maximum => 10
|
66
|
-
})
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
# Example 2. Limiting input to an integer outside a fixed range.
|
71
|
-
#
|
72
|
-
txt = 'Enter an integer that is not between 1 and 10 (using cell references)'
|
73
|
-
row += 2
|
74
|
-
|
75
|
-
worksheet.write(row, 0, txt)
|
76
|
-
worksheet.data_validation(row, 1,
|
77
|
-
{
|
78
|
-
:validate => 'integer',
|
79
|
-
:criteria => 'not between',
|
80
|
-
:minimum => '=E3',
|
81
|
-
:maximum => '=F3'
|
82
|
-
})
|
83
|
-
|
84
|
-
|
85
|
-
#
|
86
|
-
# Example 3. Limiting input to an integer greater than a fixed value.
|
87
|
-
#
|
88
|
-
txt = 'Enter an integer greater than 0'
|
89
|
-
row += 2
|
90
|
-
|
91
|
-
worksheet.write(row, 0, txt)
|
92
|
-
worksheet.data_validation(row, 1,
|
93
|
-
{
|
94
|
-
:validate => 'integer',
|
95
|
-
:criteria => '>',
|
96
|
-
:value => 0
|
97
|
-
})
|
98
|
-
|
99
|
-
|
100
|
-
#
|
101
|
-
# Example 4. Limiting input to an integer less than a fixed value.
|
102
|
-
#
|
103
|
-
txt = 'Enter an integer less than 10'
|
104
|
-
row += 2
|
105
|
-
|
106
|
-
worksheet.write(row, 0, txt)
|
107
|
-
worksheet.data_validation(row, 1,
|
108
|
-
{
|
109
|
-
:validate => 'integer',
|
110
|
-
:criteria => '<',
|
111
|
-
:value => 10
|
112
|
-
})
|
113
|
-
|
114
|
-
|
115
|
-
#
|
116
|
-
# Example 5. Limiting input to a decimal in a fixed range.
|
117
|
-
#
|
118
|
-
txt = 'Enter a decimal between 0.1 and 0.5'
|
119
|
-
row += 2
|
120
|
-
|
121
|
-
worksheet.write(row, 0, txt)
|
122
|
-
worksheet.data_validation(row, 1,
|
123
|
-
{
|
124
|
-
:validate => 'decimal',
|
125
|
-
:criteria => 'between',
|
126
|
-
:minimum => 0.1,
|
127
|
-
:maximum => 0.5
|
128
|
-
})
|
129
|
-
|
130
|
-
|
131
|
-
#
|
132
|
-
# Example 6. Limiting input to a value in a dropdown list.
|
133
|
-
#
|
134
|
-
txt = 'Select a value from a drop down list'
|
135
|
-
row += 2
|
136
|
-
bp=1
|
137
|
-
worksheet.write(row, 0, txt)
|
138
|
-
worksheet.data_validation(row, 1,
|
139
|
-
{
|
140
|
-
:validate => 'list',
|
141
|
-
:source => ['open', 'high', 'close']
|
142
|
-
})
|
143
|
-
|
144
|
-
|
145
|
-
#
|
146
|
-
# Example 6. Limiting input to a value in a dropdown list.
|
147
|
-
#
|
148
|
-
txt = 'Select a value from a drop down list (using a cell range)'
|
149
|
-
row += 2
|
150
|
-
|
151
|
-
worksheet.write(row, 0, txt)
|
152
|
-
worksheet.data_validation(row, 1,
|
153
|
-
{
|
154
|
-
:validate => 'list',
|
155
|
-
:source => '=E4:G4'
|
156
|
-
})
|
157
|
-
|
158
|
-
|
159
|
-
#
|
160
|
-
# Example 7. Limiting input to a date in a fixed range.
|
161
|
-
#
|
162
|
-
txt = 'Enter a date between 1/1/2008 and 12/12/2008'
|
163
|
-
row += 2
|
164
|
-
|
165
|
-
worksheet.write(row, 0, txt)
|
166
|
-
worksheet.data_validation(row, 1,
|
167
|
-
{
|
168
|
-
:validate => 'date',
|
169
|
-
:criteria => 'between',
|
170
|
-
:minimum => '2008-01-01T',
|
171
|
-
:maximum => '2008-12-12T'
|
172
|
-
})
|
173
|
-
|
174
|
-
|
175
|
-
#
|
176
|
-
# Example 8. Limiting input to a time in a fixed range.
|
177
|
-
#
|
178
|
-
txt = 'Enter a time between 6:00 and 12:00'
|
179
|
-
row += 2
|
180
|
-
|
181
|
-
worksheet.write(row, 0, txt)
|
182
|
-
worksheet.data_validation(row, 1,
|
183
|
-
{
|
184
|
-
:validate => 'time',
|
185
|
-
:criteria => 'between',
|
186
|
-
:minimum => 'T06:00',
|
187
|
-
:maximum => 'T12:00'
|
188
|
-
})
|
189
|
-
|
190
|
-
|
191
|
-
#
|
192
|
-
# Example 9. Limiting input to a string greater than a fixed length.
|
193
|
-
#
|
194
|
-
txt = 'Enter a string longer than 3 characters'
|
195
|
-
row += 2
|
196
|
-
|
197
|
-
worksheet.write(row, 0, txt)
|
198
|
-
worksheet.data_validation(row, 1,
|
199
|
-
{
|
200
|
-
:validate => 'length',
|
201
|
-
:criteria => '>',
|
202
|
-
:value => 3
|
203
|
-
})
|
204
|
-
|
205
|
-
|
206
|
-
#
|
207
|
-
# Example 10. Limiting input based on a formula.
|
208
|
-
#
|
209
|
-
txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"'
|
210
|
-
row += 2
|
211
|
-
|
212
|
-
worksheet.write(row, 0, txt)
|
213
|
-
worksheet.data_validation(row, 1,
|
214
|
-
{
|
215
|
-
:validate => 'custom',
|
216
|
-
:value => '=AND(F5=50,G5=60)'
|
217
|
-
})
|
218
|
-
|
219
|
-
|
220
|
-
#
|
221
|
-
# Example 11. Displaying and modify data validation messages.
|
222
|
-
#
|
223
|
-
txt = 'Displays a message when you select the cell'
|
224
|
-
row += 2
|
225
|
-
|
226
|
-
worksheet.write(row, 0, txt)
|
227
|
-
worksheet.data_validation(row, 1,
|
228
|
-
{
|
229
|
-
:validate => 'integer',
|
230
|
-
:criteria => 'between',
|
231
|
-
:minimum => 1,
|
232
|
-
:maximum => 100,
|
233
|
-
:input_title => 'Enter an integer:',
|
234
|
-
:input_message => 'between 1 and 100'
|
235
|
-
})
|
236
|
-
|
237
|
-
|
238
|
-
#
|
239
|
-
# Example 12. Displaying and modify data validation messages.
|
240
|
-
#
|
241
|
-
txt = 'Display a custom error message when integer isn\'t between 1 and 100'
|
242
|
-
row += 2
|
243
|
-
|
244
|
-
worksheet.write(row, 0, txt)
|
245
|
-
worksheet.data_validation(row, 1,
|
246
|
-
{
|
247
|
-
:validate => 'integer',
|
248
|
-
:criteria => 'between',
|
249
|
-
:minimum => 1,
|
250
|
-
:maximum => 100,
|
251
|
-
:input_title => 'Enter an integer:',
|
252
|
-
:input_message => 'between 1 and 100',
|
253
|
-
:error_title => 'Input value is not valid!',
|
254
|
-
:error_message => 'It should be an integer between 1 and 100'
|
255
|
-
})
|
256
|
-
|
257
|
-
|
258
|
-
#
|
259
|
-
# Example 13. Displaying and modify data validation messages.
|
260
|
-
#
|
261
|
-
txt = 'Display a custom information message when integer isn\'t between 1 and 100'
|
262
|
-
row += 2
|
263
|
-
|
264
|
-
worksheet.write(row, 0, txt)
|
265
|
-
worksheet.data_validation(row, 1,
|
266
|
-
{
|
267
|
-
:validate => 'integer',
|
268
|
-
:criteria => 'between',
|
269
|
-
:minimum => 1,
|
270
|
-
:maximum => 100,
|
271
|
-
:input_title => 'Enter an integer:',
|
272
|
-
:input_message => 'between 1 and 100',
|
273
|
-
:error_title => 'Input value is not valid!',
|
274
|
-
:error_message => 'It should be an integer between 1 and 100',
|
275
|
-
:error_type => 'information'
|
276
|
-
})
|
277
|
-
|
278
|
-
workbook.close
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# Example of how to add data validation and dropdown lists to a
|
6
|
+
# WriteExcel file.
|
7
|
+
#
|
8
|
+
# reverse('©'), August 2008, John McNamara, jmcnamara@cpan.org
|
9
|
+
#
|
10
|
+
# original written in Perl by John McNamara
|
11
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'writeexcel'
|
16
|
+
|
17
|
+
workbook = WriteExcel.new('data_validate.xls')
|
18
|
+
worksheet = workbook.add_worksheet
|
19
|
+
|
20
|
+
# Add a format for the header cells.
|
21
|
+
header_format = workbook.add_format(
|
22
|
+
:border => 1,
|
23
|
+
:bg_color => 43,
|
24
|
+
:bold => 1,
|
25
|
+
:text_wrap => 1,
|
26
|
+
:valign => 'vcenter',
|
27
|
+
:indent => 1
|
28
|
+
)
|
29
|
+
|
30
|
+
# Set up layout of the worksheet.
|
31
|
+
worksheet.set_column('A:A', 64)
|
32
|
+
worksheet.set_column('B:B', 15)
|
33
|
+
worksheet.set_column('D:D', 15)
|
34
|
+
worksheet.set_row(0, 36)
|
35
|
+
worksheet.set_selection('B3')
|
36
|
+
|
37
|
+
|
38
|
+
# Write the header cells and some data that will be used in the examples.
|
39
|
+
row = 0
|
40
|
+
heading1 = 'Some examples of data validation in WriteExcel'
|
41
|
+
heading2 = 'Enter values in this column'
|
42
|
+
heading3 = 'Sample Data'
|
43
|
+
|
44
|
+
worksheet.write('A1', heading1, header_format)
|
45
|
+
worksheet.write('B1', heading2, header_format)
|
46
|
+
worksheet.write('D1', heading3, header_format)
|
47
|
+
|
48
|
+
worksheet.write('D3', ['Integers', 1, 10])
|
49
|
+
worksheet.write('D4', ['List data', 'open', 'high', 'close'])
|
50
|
+
worksheet.write('D5', ['Formula', '=AND(F5=50,G5=60)', 50, 60])
|
51
|
+
|
52
|
+
|
53
|
+
#
|
54
|
+
# Example 1. Limiting input to an integer in a fixed range.
|
55
|
+
#
|
56
|
+
txt = 'Enter an integer between 1 and 10'
|
57
|
+
row += 2
|
58
|
+
|
59
|
+
worksheet.write(row, 0, txt)
|
60
|
+
worksheet.data_validation(row, 1,
|
61
|
+
{
|
62
|
+
:validate => 'integer',
|
63
|
+
:criteria => 'between',
|
64
|
+
:minimum => 1,
|
65
|
+
:maximum => 10
|
66
|
+
})
|
67
|
+
|
68
|
+
|
69
|
+
#
|
70
|
+
# Example 2. Limiting input to an integer outside a fixed range.
|
71
|
+
#
|
72
|
+
txt = 'Enter an integer that is not between 1 and 10 (using cell references)'
|
73
|
+
row += 2
|
74
|
+
|
75
|
+
worksheet.write(row, 0, txt)
|
76
|
+
worksheet.data_validation(row, 1,
|
77
|
+
{
|
78
|
+
:validate => 'integer',
|
79
|
+
:criteria => 'not between',
|
80
|
+
:minimum => '=E3',
|
81
|
+
:maximum => '=F3'
|
82
|
+
})
|
83
|
+
|
84
|
+
|
85
|
+
#
|
86
|
+
# Example 3. Limiting input to an integer greater than a fixed value.
|
87
|
+
#
|
88
|
+
txt = 'Enter an integer greater than 0'
|
89
|
+
row += 2
|
90
|
+
|
91
|
+
worksheet.write(row, 0, txt)
|
92
|
+
worksheet.data_validation(row, 1,
|
93
|
+
{
|
94
|
+
:validate => 'integer',
|
95
|
+
:criteria => '>',
|
96
|
+
:value => 0
|
97
|
+
})
|
98
|
+
|
99
|
+
|
100
|
+
#
|
101
|
+
# Example 4. Limiting input to an integer less than a fixed value.
|
102
|
+
#
|
103
|
+
txt = 'Enter an integer less than 10'
|
104
|
+
row += 2
|
105
|
+
|
106
|
+
worksheet.write(row, 0, txt)
|
107
|
+
worksheet.data_validation(row, 1,
|
108
|
+
{
|
109
|
+
:validate => 'integer',
|
110
|
+
:criteria => '<',
|
111
|
+
:value => 10
|
112
|
+
})
|
113
|
+
|
114
|
+
|
115
|
+
#
|
116
|
+
# Example 5. Limiting input to a decimal in a fixed range.
|
117
|
+
#
|
118
|
+
txt = 'Enter a decimal between 0.1 and 0.5'
|
119
|
+
row += 2
|
120
|
+
|
121
|
+
worksheet.write(row, 0, txt)
|
122
|
+
worksheet.data_validation(row, 1,
|
123
|
+
{
|
124
|
+
:validate => 'decimal',
|
125
|
+
:criteria => 'between',
|
126
|
+
:minimum => 0.1,
|
127
|
+
:maximum => 0.5
|
128
|
+
})
|
129
|
+
|
130
|
+
|
131
|
+
#
|
132
|
+
# Example 6. Limiting input to a value in a dropdown list.
|
133
|
+
#
|
134
|
+
txt = 'Select a value from a drop down list'
|
135
|
+
row += 2
|
136
|
+
bp=1
|
137
|
+
worksheet.write(row, 0, txt)
|
138
|
+
worksheet.data_validation(row, 1,
|
139
|
+
{
|
140
|
+
:validate => 'list',
|
141
|
+
:source => ['open', 'high', 'close']
|
142
|
+
})
|
143
|
+
|
144
|
+
|
145
|
+
#
|
146
|
+
# Example 6. Limiting input to a value in a dropdown list.
|
147
|
+
#
|
148
|
+
txt = 'Select a value from a drop down list (using a cell range)'
|
149
|
+
row += 2
|
150
|
+
|
151
|
+
worksheet.write(row, 0, txt)
|
152
|
+
worksheet.data_validation(row, 1,
|
153
|
+
{
|
154
|
+
:validate => 'list',
|
155
|
+
:source => '=E4:G4'
|
156
|
+
})
|
157
|
+
|
158
|
+
|
159
|
+
#
|
160
|
+
# Example 7. Limiting input to a date in a fixed range.
|
161
|
+
#
|
162
|
+
txt = 'Enter a date between 1/1/2008 and 12/12/2008'
|
163
|
+
row += 2
|
164
|
+
|
165
|
+
worksheet.write(row, 0, txt)
|
166
|
+
worksheet.data_validation(row, 1,
|
167
|
+
{
|
168
|
+
:validate => 'date',
|
169
|
+
:criteria => 'between',
|
170
|
+
:minimum => '2008-01-01T',
|
171
|
+
:maximum => '2008-12-12T'
|
172
|
+
})
|
173
|
+
|
174
|
+
|
175
|
+
#
|
176
|
+
# Example 8. Limiting input to a time in a fixed range.
|
177
|
+
#
|
178
|
+
txt = 'Enter a time between 6:00 and 12:00'
|
179
|
+
row += 2
|
180
|
+
|
181
|
+
worksheet.write(row, 0, txt)
|
182
|
+
worksheet.data_validation(row, 1,
|
183
|
+
{
|
184
|
+
:validate => 'time',
|
185
|
+
:criteria => 'between',
|
186
|
+
:minimum => 'T06:00',
|
187
|
+
:maximum => 'T12:00'
|
188
|
+
})
|
189
|
+
|
190
|
+
|
191
|
+
#
|
192
|
+
# Example 9. Limiting input to a string greater than a fixed length.
|
193
|
+
#
|
194
|
+
txt = 'Enter a string longer than 3 characters'
|
195
|
+
row += 2
|
196
|
+
|
197
|
+
worksheet.write(row, 0, txt)
|
198
|
+
worksheet.data_validation(row, 1,
|
199
|
+
{
|
200
|
+
:validate => 'length',
|
201
|
+
:criteria => '>',
|
202
|
+
:value => 3
|
203
|
+
})
|
204
|
+
|
205
|
+
|
206
|
+
#
|
207
|
+
# Example 10. Limiting input based on a formula.
|
208
|
+
#
|
209
|
+
txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"'
|
210
|
+
row += 2
|
211
|
+
|
212
|
+
worksheet.write(row, 0, txt)
|
213
|
+
worksheet.data_validation(row, 1,
|
214
|
+
{
|
215
|
+
:validate => 'custom',
|
216
|
+
:value => '=AND(F5=50,G5=60)'
|
217
|
+
})
|
218
|
+
|
219
|
+
|
220
|
+
#
|
221
|
+
# Example 11. Displaying and modify data validation messages.
|
222
|
+
#
|
223
|
+
txt = 'Displays a message when you select the cell'
|
224
|
+
row += 2
|
225
|
+
|
226
|
+
worksheet.write(row, 0, txt)
|
227
|
+
worksheet.data_validation(row, 1,
|
228
|
+
{
|
229
|
+
:validate => 'integer',
|
230
|
+
:criteria => 'between',
|
231
|
+
:minimum => 1,
|
232
|
+
:maximum => 100,
|
233
|
+
:input_title => 'Enter an integer:',
|
234
|
+
:input_message => 'between 1 and 100'
|
235
|
+
})
|
236
|
+
|
237
|
+
|
238
|
+
#
|
239
|
+
# Example 12. Displaying and modify data validation messages.
|
240
|
+
#
|
241
|
+
txt = 'Display a custom error message when integer isn\'t between 1 and 100'
|
242
|
+
row += 2
|
243
|
+
|
244
|
+
worksheet.write(row, 0, txt)
|
245
|
+
worksheet.data_validation(row, 1,
|
246
|
+
{
|
247
|
+
:validate => 'integer',
|
248
|
+
:criteria => 'between',
|
249
|
+
:minimum => 1,
|
250
|
+
:maximum => 100,
|
251
|
+
:input_title => 'Enter an integer:',
|
252
|
+
:input_message => 'between 1 and 100',
|
253
|
+
:error_title => 'Input value is not valid!',
|
254
|
+
:error_message => 'It should be an integer between 1 and 100'
|
255
|
+
})
|
256
|
+
|
257
|
+
|
258
|
+
#
|
259
|
+
# Example 13. Displaying and modify data validation messages.
|
260
|
+
#
|
261
|
+
txt = 'Display a custom information message when integer isn\'t between 1 and 100'
|
262
|
+
row += 2
|
263
|
+
|
264
|
+
worksheet.write(row, 0, txt)
|
265
|
+
worksheet.data_validation(row, 1,
|
266
|
+
{
|
267
|
+
:validate => 'integer',
|
268
|
+
:criteria => 'between',
|
269
|
+
:minimum => 1,
|
270
|
+
:maximum => 100,
|
271
|
+
:input_title => 'Enter an integer:',
|
272
|
+
:input_message => 'between 1 and 100',
|
273
|
+
:error_title => 'Input value is not valid!',
|
274
|
+
:error_message => 'It should be an integer between 1 and 100',
|
275
|
+
:error_type => 'information'
|
276
|
+
})
|
277
|
+
|
278
|
+
workbook.close
|