WriteExcel 0.2.0

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 (80) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +47 -0
  6. data/VERSION +1 -0
  7. data/examples/a_simple.rb +42 -0
  8. data/examples/autofilters.rb +266 -0
  9. data/examples/bigfile.rb +30 -0
  10. data/examples/copyformat.rb +51 -0
  11. data/examples/data_validate.rb +278 -0
  12. data/examples/date_time.rb +86 -0
  13. data/examples/demo.rb +118 -0
  14. data/examples/diag_border.rb +35 -0
  15. data/examples/formats.rb +489 -0
  16. data/examples/header.rb +136 -0
  17. data/examples/hidden.rb +28 -0
  18. data/examples/hyperlink.rb +42 -0
  19. data/examples/images.rb +52 -0
  20. data/examples/merge1.rb +39 -0
  21. data/examples/merge2.rb +44 -0
  22. data/examples/merge3.rb +65 -0
  23. data/examples/merge4.rb +82 -0
  24. data/examples/merge5.rb +79 -0
  25. data/examples/protection.rb +46 -0
  26. data/examples/regions.rb +52 -0
  27. data/examples/repeat.rb +42 -0
  28. data/examples/stats.rb +75 -0
  29. data/examples/stocks.rb +80 -0
  30. data/examples/tab_colors.rb +30 -0
  31. data/lib/WriteExcel.rb +30 -0
  32. data/lib/WriteExcel/biffwriter.rb +259 -0
  33. data/lib/WriteExcel/chart.rb +217 -0
  34. data/lib/WriteExcel/excelformula.y +138 -0
  35. data/lib/WriteExcel/excelformulaparser.rb +573 -0
  36. data/lib/WriteExcel/format.rb +1108 -0
  37. data/lib/WriteExcel/formula.rb +986 -0
  38. data/lib/WriteExcel/olewriter.rb +322 -0
  39. data/lib/WriteExcel/properties.rb +250 -0
  40. data/lib/WriteExcel/storage_lite.rb +590 -0
  41. data/lib/WriteExcel/workbook.rb +2602 -0
  42. data/lib/WriteExcel/worksheet.rb +6378 -0
  43. data/spec/WriteExcel_spec.rb +7 -0
  44. data/spec/spec.opts +1 -0
  45. data/spec/spec_helper.rb +9 -0
  46. data/test/tc_all.rb +31 -0
  47. data/test/tc_biff.rb +104 -0
  48. data/test/tc_chart.rb +22 -0
  49. data/test/tc_example_match.rb +1280 -0
  50. data/test/tc_format.rb +1264 -0
  51. data/test/tc_formula.rb +63 -0
  52. data/test/tc_ole.rb +110 -0
  53. data/test/tc_storage_lite.rb +102 -0
  54. data/test/tc_workbook.rb +115 -0
  55. data/test/tc_worksheet.rb +115 -0
  56. data/test/test_00_IEEE_double.rb +14 -0
  57. data/test/test_01_add_worksheet.rb +12 -0
  58. data/test/test_02_merge_formats.rb +58 -0
  59. data/test/test_04_dimensions.rb +397 -0
  60. data/test/test_05_rows.rb +182 -0
  61. data/test/test_06_extsst.rb +80 -0
  62. data/test/test_11_date_time.rb +484 -0
  63. data/test/test_12_date_only.rb +506 -0
  64. data/test/test_13_date_seconds.rb +486 -0
  65. data/test/test_21_escher.rb +629 -0
  66. data/test/test_22_mso_drawing_group.rb +739 -0
  67. data/test/test_23_note.rb +78 -0
  68. data/test/test_24_txo.rb +80 -0
  69. data/test/test_26_autofilter.rb +327 -0
  70. data/test/test_27_autofilter.rb +144 -0
  71. data/test/test_28_autofilter.rb +174 -0
  72. data/test/test_29_process_jpg.rb +131 -0
  73. data/test/test_30_validation_dval.rb +82 -0
  74. data/test/test_31_validation_dv_strings.rb +131 -0
  75. data/test/test_32_validation_dv_formula.rb +211 -0
  76. data/test/test_40_property_types.rb +191 -0
  77. data/test/test_41_properties.rb +238 -0
  78. data/test/test_42_set_properties.rb +430 -0
  79. data/test/ts_all.rb +34 -0
  80. metadata +154 -0
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ##############################################################################
4
+ #
5
+ # A simple formatting example using Spreadsheet::WriteExcel.
6
+ #
7
+ # This program demonstrates the diagonal border cell format.
8
+ #
9
+ # reverse('©'), May 2004, John McNamara, jmcnamara@cpan.org
10
+ #
11
+ # original written in Perl by John McNamara
12
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
13
+ #
14
+
15
+ require 'rubygems'
16
+ require 'WriteExcel'
17
+
18
+ workbook = Spreadsheet::WriteExcel.new('diag_border.xls')
19
+ worksheet = workbook.add_worksheet
20
+
21
+ format1 = workbook.add_format(:diag_type => 1)
22
+ format2 = workbook.add_format(:diag_type => 2)
23
+ format3 = workbook.add_format(:diag_type => 3)
24
+ format4 = workbook.add_format(
25
+ :diag_type => 3,
26
+ :diag_border => 7,
27
+ :diag_color => 'red'
28
+ )
29
+
30
+ worksheet.write('B3', 'Text', format1)
31
+ worksheet.write('B6', 'Text', format2)
32
+ worksheet.write('B9', 'Text', format3)
33
+ worksheet.write('B12', 'Text', format4)
34
+
35
+ workbook.close
@@ -0,0 +1,489 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ######################################################################
4
+ #
5
+ # Examples of formatting using the Spreadsheet::WriteExcel module
6
+ #
7
+ # reverse('©'), September 2002, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+
13
+ require 'rubygems'
14
+ require 'WriteExcel'
15
+
16
+
17
+ ######################################################################
18
+ #
19
+ # Intro.
20
+ #
21
+ def intro(workbook)
22
+
23
+ worksheet = workbook.add_worksheet('Introduction')
24
+
25
+ worksheet.set_column(0, 0, 60)
26
+
27
+ format = workbook.add_format()
28
+ format.set_bold()
29
+ format.set_size(14)
30
+ format.set_color('blue')
31
+ format.set_align('center')
32
+
33
+ format2 = workbook.add_format()
34
+ format2.set_bold()
35
+ format2.set_color('blue')
36
+
37
+ worksheet.write(2, 0, 'This workbook demonstrates some of', format)
38
+ worksheet.write(3, 0, 'the formatting options provided by', format)
39
+ worksheet.write(4, 0, 'the Spreadsheet::WriteExcel module.', format)
40
+
41
+ worksheet.write('A7', 'Sections:', format2)
42
+ worksheet.write('A8', "internal:Fonts!A1", 'Fonts' )
43
+ worksheet.write('A9', "internal:'Named colors'!A1", 'Named colors' )
44
+ worksheet.write('A10', "internal:'Standard colors'!A1", 'Standard colors')
45
+ worksheet.write('A11', "internal:'Numeric formats'!A1", 'Numeric formats')
46
+ worksheet.write('A12', "internal:Borders!A1", 'Borders' )
47
+ worksheet.write('A13', "internal:Patterns!A1", 'Patterns' )
48
+ worksheet.write('A14', "internal:Alignment!A1", 'Alignment' )
49
+ worksheet.write('A15', "internal:Miscellaneous!A1", 'Miscellaneous' )
50
+
51
+ end
52
+
53
+
54
+ ######################################################################
55
+ #
56
+ # Demonstrate the named colors.
57
+ #
58
+ def named_colors(workbook, heading, center)
59
+
60
+ worksheet = workbook.add_worksheet('Named colors')
61
+
62
+ worksheet.set_column(0, 3, 15)
63
+
64
+ worksheet.write(0, 0, "Index", heading)
65
+ worksheet.write(0, 1, "Index", heading)
66
+ worksheet.write(0, 2, "Name", heading)
67
+ worksheet.write(0, 3, "Color", heading)
68
+
69
+ i = 1
70
+
71
+ COLORS.each do |index, color|
72
+ format = workbook.add_format(
73
+ :bg_color => color,
74
+ :pattern => 1,
75
+ :border => 1
76
+ )
77
+
78
+ worksheet.write(i+1, 0, index, center)
79
+ worksheet.write(i+1, 1, sprintf("0x%02X", index), center)
80
+ worksheet.write(i+1, 2, color, center)
81
+ worksheet.write(i+1, 3, '', format)
82
+ i += 1
83
+ end
84
+ end
85
+
86
+
87
+ ######################################################################
88
+ #
89
+ # Demonstrate the standard Excel colors in the range 8..63.
90
+ #
91
+ def standard_colors(workbook, heading, center)
92
+
93
+ worksheet = workbook.add_worksheet('Standard colors')
94
+
95
+ worksheet.set_column(0, 3, 15)
96
+
97
+ worksheet.write(0, 0, "Index", heading)
98
+ worksheet.write(0, 1, "Index", heading)
99
+ worksheet.write(0, 2, "Color", heading)
100
+ worksheet.write(0, 3, "Name", heading)
101
+
102
+ 8.upto(63) do |i|
103
+ format = workbook.add_format(
104
+ :bg_color => i,
105
+ :pattern => 1,
106
+ :border => 1
107
+ )
108
+
109
+ worksheet.write((i -7), 0, i, center)
110
+ worksheet.write((i -7), 1, sprintf("0x%02X", i), center)
111
+ worksheet.write((i -7), 2, '', format)
112
+
113
+ # Add the color names
114
+ if COLORS[i]
115
+ worksheet.write((i -7), 3, COLORS[i], center)
116
+
117
+ end
118
+ end
119
+ end
120
+
121
+
122
+ ######################################################################
123
+ #
124
+ # Demonstrate the standard numeric formats.
125
+ #
126
+ def numeric_formats(workbook, heading, center)
127
+
128
+ worksheet = workbook.add_worksheet('Numeric formats')
129
+
130
+ worksheet.set_column(0, 4, 15)
131
+ worksheet.set_column(5, 5, 45)
132
+
133
+ worksheet.write(0, 0, "Index", heading)
134
+ worksheet.write(0, 1, "Index", heading)
135
+ worksheet.write(0, 2, "Unformatted", heading)
136
+ worksheet.write(0, 3, "Formatted", heading)
137
+ worksheet.write(0, 4, "Negative", heading)
138
+ worksheet.write(0, 5, "Format", heading)
139
+
140
+ formats = []
141
+ formats.push([ 0x00, 1234.567, 0, 'General' ])
142
+ formats.push([ 0x01, 1234.567, 0, '0' ])
143
+ formats.push([ 0x02, 1234.567, 0, '0.00' ])
144
+ formats.push([ 0x03, 1234.567, 0, '#,##0' ])
145
+ formats.push([ 0x04, 1234.567, 0, '#,##0.00' ])
146
+ formats.push([ 0x05, 1234.567, -1234.567, '($#,##0_);($#,##0)' ])
147
+ formats.push([ 0x06, 1234.567, -1234.567, '($#,##0_);[Red]($#,##0)' ])
148
+ formats.push([ 0x07, 1234.567, -1234.567, '($#,##0.00_);($#,##0.00)' ])
149
+ formats.push([ 0x08, 1234.567, -1234.567, '($#,##0.00_);[Red]($#,##0.00)' ])
150
+ formats.push([ 0x09, 0.567, 0, '0%' ])
151
+ formats.push([ 0x0a, 0.567, 0, '0.00%' ])
152
+ formats.push([ 0x0b, 1234.567, 0, '0.00E+00' ])
153
+ formats.push([ 0x0c, 0.75, 0, '# ?/?' ])
154
+ formats.push([ 0x0d, 0.3125, 0, '# ??/??' ])
155
+ formats.push([ 0x0e, 36892.521, 0, 'm/d/yy' ])
156
+ formats.push([ 0x0f, 36892.521, 0, 'd-mmm-yy' ])
157
+ formats.push([ 0x10, 36892.521, 0, 'd-mmm' ])
158
+ formats.push([ 0x11, 36892.521, 0, 'mmm-yy' ])
159
+ formats.push([ 0x12, 36892.521, 0, 'h:mm AM/PM' ])
160
+ formats.push([ 0x13, 36892.521, 0, 'h:mm:ss AM/PM' ])
161
+ formats.push([ 0x14, 36892.521, 0, 'h:mm' ])
162
+ formats.push([ 0x15, 36892.521, 0, 'h:mm:ss' ])
163
+ formats.push([ 0x16, 36892.521, 0, 'm/d/yy h:mm' ])
164
+ formats.push([ 0x25, 1234.567, -1234.567, '(#,##0_);(#,##0)' ])
165
+ formats.push([ 0x26, 1234.567, -1234.567, '(#,##0_);[Red](#,##0)' ])
166
+ formats.push([ 0x27, 1234.567, -1234.567, '(#,##0.00_);(#,##0.00)' ])
167
+ formats.push([ 0x28, 1234.567, -1234.567, '(#,##0.00_);[Red](#,##0.00)' ])
168
+ formats.push([ 0x29, 1234.567, -1234.567, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' ])
169
+ formats.push([ 0x2a, 1234.567, -1234.567, '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' ])
170
+ formats.push([ 0x2b, 1234.567, -1234.567, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' ])
171
+ formats.push([ 0x2c, 1234.567, -1234.567, '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' ])
172
+ formats.push([ 0x2d, 36892.521, 0, 'mm:ss' ])
173
+ formats.push([ 0x2e, 3.0153, 0, '[h]:mm:ss' ])
174
+ formats.push([ 0x2f, 36892.521, 0, 'mm:ss.0' ])
175
+ formats.push([ 0x30, 1234.567, 0, '##0.0E+0' ])
176
+ formats.push([ 0x31, 1234.567, 0, '@' ])
177
+
178
+ i = 0
179
+ formats.each do |format|
180
+ style = workbook.add_format()
181
+ style.set_num_format(format[0])
182
+
183
+ i += 1
184
+ worksheet.write(i, 0, format[0], center)
185
+ worksheet.write(i, 1, sprintf("0x%02X", format[0]), center)
186
+ worksheet.write(i, 2, format[1], center)
187
+ worksheet.write(i, 3, format[1], style)
188
+
189
+ if format[2] != 0
190
+ worksheet.write(i, 4, format[2], style)
191
+ end
192
+
193
+ worksheet.write_string(i, 5, format[3])
194
+ end
195
+ end
196
+
197
+
198
+ ######################################################################
199
+ #
200
+ # Demonstrate the font options.
201
+ #
202
+ def fonts(workbook, heading, center)
203
+
204
+ worksheet = workbook.add_worksheet('Fonts')
205
+
206
+ worksheet.set_column(0, 0, 30)
207
+ worksheet.set_column(1, 1, 10)
208
+
209
+ worksheet.write(0, 0, "Font name", heading)
210
+ worksheet.write(0, 1, "Font size", heading)
211
+
212
+ fonts = []
213
+ fonts.push([10, 'Arial' ])
214
+ fonts.push([12, 'Arial' ])
215
+ fonts.push([14, 'Arial' ])
216
+ fonts.push([12, 'Arial Black' ])
217
+ fonts.push([12, 'Arial Narrow' ])
218
+ fonts.push([12, 'Century Schoolbook' ])
219
+ fonts.push([12, 'Courier' ])
220
+ fonts.push([12, 'Courier New' ])
221
+ fonts.push([12, 'Garamond' ])
222
+ fonts.push([12, 'Impact' ])
223
+ fonts.push([12, 'Lucida Handwriting'] )
224
+ fonts.push([12, 'Times New Roman' ])
225
+ fonts.push([12, 'Symbol' ])
226
+ fonts.push([12, 'Wingdings' ])
227
+ fonts.push([12, 'A font that doesnt exist' ])
228
+
229
+ i = 0
230
+ fonts.each do |font|
231
+ format = workbook.add_format()
232
+
233
+ format.set_size(font[0])
234
+ format.set_font(font[1])
235
+
236
+ i += 1
237
+ worksheet.write(i, 0, font[1], format)
238
+ worksheet.write(i, 1, font[0], format)
239
+ end
240
+
241
+ end
242
+
243
+
244
+ ######################################################################
245
+ #
246
+ # Demonstrate the standard Excel border styles.
247
+ #
248
+ def borders(workbook, heading, center)
249
+
250
+ worksheet = workbook.add_worksheet('Borders')
251
+
252
+ worksheet.set_column(0, 4, 10)
253
+ worksheet.set_column(5, 5, 40)
254
+
255
+ worksheet.write(0, 0, "Index", heading)
256
+ worksheet.write(0, 1, "Index", heading)
257
+ worksheet.write(0, 3, "Style", heading)
258
+ worksheet.write(0, 5, "The style is highlighted in red for ", heading)
259
+ worksheet.write(1, 5, "emphasis, the default color is black.", heading)
260
+
261
+ 0.upto(13) do |i|
262
+ format = workbook.add_format()
263
+ format.set_border(i)
264
+ format.set_border_color('red')
265
+ format.set_align('center')
266
+
267
+ worksheet.write((2*(i+1)), 0, i, center)
268
+ worksheet.write((2*(i+1)), 1, sprintf("0x%02X", i), center)
269
+
270
+ worksheet.write((2*(i+1)), 3, "Border", format)
271
+ end
272
+
273
+ worksheet.write(30, 0, "Diag type", heading)
274
+ worksheet.write(30, 1, "Index", heading)
275
+ worksheet.write(30, 3, "Style", heading)
276
+ worksheet.write(30, 5, "Diagonal Boder styles", heading)
277
+
278
+ 1.upto(3) do |i|
279
+ format = workbook.add_format()
280
+ format.set_diag_type(i)
281
+ format.set_diag_border(1)
282
+ format.set_diag_color('red')
283
+ format.set_align('center')
284
+
285
+ worksheet.write((2*(i+15)), 0, i, center)
286
+ worksheet.write((2*(i+15)), 1, sprintf("0x%02X", i), center)
287
+
288
+ worksheet.write((2*(i+15)), 3, "Border", format)
289
+ end
290
+ end
291
+
292
+
293
+
294
+ ######################################################################
295
+ #
296
+ # Demonstrate the standard Excel cell patterns.
297
+ #
298
+ def patterns(workbook, heading, center)
299
+
300
+ worksheet = workbook.add_worksheet('Patterns')
301
+
302
+ worksheet.set_column(0, 4, 10)
303
+ worksheet.set_column(5, 5, 50)
304
+
305
+ worksheet.write(0, 0, "Index", heading)
306
+ worksheet.write(0, 1, "Index", heading)
307
+ worksheet.write(0, 3, "Pattern", heading)
308
+
309
+ worksheet.write(0, 5, "The background colour has been set to silver.", heading)
310
+ worksheet.write(1, 5, "The foreground colour has been set to green.", heading)
311
+
312
+ 0.upto(18) do |i|
313
+ format = workbook.add_format()
314
+
315
+ format.set_pattern(i)
316
+ format.set_bg_color('silver')
317
+ format.set_fg_color('green')
318
+ format.set_align('center')
319
+
320
+ worksheet.write((2*(i+1)), 0, i, center)
321
+ worksheet.write((2*(i+1)), 1, sprintf("0x%02X", i), center)
322
+
323
+ worksheet.write((2*(i+1)), 3, "Pattern", format)
324
+
325
+ if i == 1
326
+ worksheet.write((2*(i+1)), 5, "This is solid colour, the most useful pattern.", heading)
327
+ end
328
+ end
329
+ end
330
+
331
+
332
+ ######################################################################
333
+ #
334
+ # Demonstrate the standard Excel cell alignments.
335
+ #
336
+ def alignment(workbook, heading, center)
337
+
338
+ worksheet = workbook.add_worksheet('Alignment')
339
+
340
+ worksheet.set_column(0, 7, 12)
341
+ worksheet.set_row(0, 40)
342
+ worksheet.set_selection(7, 0)
343
+
344
+ format01 = workbook.add_format()
345
+ format02 = workbook.add_format()
346
+ format03 = workbook.add_format()
347
+ format04 = workbook.add_format()
348
+ format05 = workbook.add_format()
349
+ format06 = workbook.add_format()
350
+ format07 = workbook.add_format()
351
+ format08 = workbook.add_format()
352
+ format09 = workbook.add_format()
353
+ format10 = workbook.add_format()
354
+ format11 = workbook.add_format()
355
+ format12 = workbook.add_format()
356
+ format13 = workbook.add_format()
357
+ format14 = workbook.add_format()
358
+ format15 = workbook.add_format()
359
+ format16 = workbook.add_format()
360
+ format17 = workbook.add_format()
361
+
362
+ format02.set_align('top')
363
+ format03.set_align('bottom')
364
+ format04.set_align('vcenter')
365
+ format05.set_align('vjustify')
366
+ format06.set_text_wrap()
367
+
368
+ format07.set_align('left')
369
+ format08.set_align('right')
370
+ format09.set_align('center')
371
+ format10.set_align('fill')
372
+ format11.set_align('justify')
373
+ format12.set_merge()
374
+
375
+ format13.set_rotation(45)
376
+ format14.set_rotation(-45)
377
+ format15.set_rotation(270)
378
+
379
+ format16.set_shrink()
380
+ format17.set_indent(1)
381
+
382
+ worksheet.write(0, 0, 'Vertical', heading)
383
+ worksheet.write(0, 1, 'top', format02)
384
+ worksheet.write(0, 2, 'bottom', format03)
385
+ worksheet.write(0, 3, 'vcenter', format04)
386
+ worksheet.write(0, 4, 'vjustify', format05)
387
+ worksheet.write(0, 5, "text\nwrap", format06)
388
+
389
+ worksheet.write(2, 0, 'Horizontal', heading)
390
+ worksheet.write(2, 1, 'left', format07)
391
+ worksheet.write(2, 2, 'right', format08)
392
+ worksheet.write(2, 3, 'center', format09)
393
+ worksheet.write(2, 4, 'fill', format10)
394
+ worksheet.write(2, 5, 'justify', format11)
395
+
396
+ worksheet.write(3, 1, 'merge', format12)
397
+ worksheet.write(3, 2, '', format12)
398
+
399
+ worksheet.write(3, 3, 'Shrink ' * 3, format16)
400
+ worksheet.write(3, 4, 'Indent', format17)
401
+
402
+
403
+ worksheet.write(5, 0, 'Rotation', heading)
404
+ worksheet.write(5, 1, 'Rotate 45', format13)
405
+ worksheet.write(6, 1, 'Rotate -45', format14)
406
+ worksheet.write(7, 1, 'Rotate 270', format15)
407
+ end
408
+
409
+
410
+ ######################################################################
411
+ #
412
+ # Demonstrate other miscellaneous features.
413
+ #
414
+ def misc(workbook)
415
+
416
+ worksheet = workbook.add_worksheet('Miscellaneous')
417
+
418
+ worksheet.set_column(2, 2, 25)
419
+
420
+ format01 = workbook.add_format()
421
+ format02 = workbook.add_format()
422
+ format03 = workbook.add_format()
423
+ format04 = workbook.add_format()
424
+ format05 = workbook.add_format()
425
+ format06 = workbook.add_format()
426
+ format07 = workbook.add_format()
427
+
428
+ format01.set_underline(0x01)
429
+ format02.set_underline(0x02)
430
+ format03.set_underline(0x21)
431
+ format04.set_underline(0x22)
432
+ format05.set_font_strikeout()
433
+ format06.set_font_outline()
434
+ format07.set_font_shadow()
435
+
436
+ worksheet.write(1, 2, 'Underline 0x01', format01)
437
+ worksheet.write(3, 2, 'Underline 0x02', format02)
438
+ worksheet.write(5, 2, 'Underline 0x21', format03)
439
+ worksheet.write(7, 2, 'Underline 0x22', format04)
440
+ worksheet.write(9, 2, 'Strikeout', format05)
441
+ worksheet.write(11, 2, 'Outline (Macintosh only)', format06)
442
+ worksheet.write(13, 2, 'Shadow (Macintosh only)', format07)
443
+ end
444
+
445
+
446
+ ######################################################################
447
+ #
448
+ # main
449
+ #
450
+ workbook = Spreadsheet::WriteExcel.new('formats.xls')
451
+
452
+ # Some common formats
453
+ center = workbook.add_format(:align => 'center')
454
+ heading = workbook.add_format(:align => 'center', :bold => 1)
455
+
456
+ # The named colors
457
+ COLORS = {
458
+ 0x08 => 'black',
459
+ 0x0C => 'blue',
460
+ 0x10 => 'brown',
461
+ 0x0F => 'cyan',
462
+ 0x17 => 'gray',
463
+ 0x11 => 'green',
464
+ 0x0B => 'lime',
465
+ 0x0E => 'magenta',
466
+ 0x12 => 'navy',
467
+ 0x35 => 'orange',
468
+ 0x21 => 'pink',
469
+ 0x14 => 'purple',
470
+ 0x0A => 'red',
471
+ 0x16 => 'silver',
472
+ 0x09 => 'white',
473
+ 0x0D => 'yellow',
474
+ }
475
+
476
+ # Call these subroutines to demonstrate different formatting options
477
+ intro(workbook)
478
+ fonts(workbook, heading, center)
479
+ named_colors(workbook, heading, center)
480
+ standard_colors(workbook, heading, center)
481
+ numeric_formats(workbook, heading, center)
482
+ borders(workbook, heading, center)
483
+ patterns(workbook, heading, center)
484
+ alignment(workbook, heading, center)
485
+ misc(workbook)
486
+
487
+ # Note: this is required
488
+ workbook.close
489
+