writeexcel 0.1.0 → 0.3.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.
- 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/lib/writeexcel/format.rb
CHANGED
@@ -1,1108 +1,1697 @@
|
|
1
|
-
##############################################################################
|
2
|
-
#
|
3
|
-
# Format - A class for defining Excel formatting.
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# Used in conjunction with
|
7
|
-
#
|
8
|
-
# Copyright 2000-
|
9
|
-
#
|
10
|
-
# original written in Perl by John McNamara
|
11
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
12
|
-
#
|
13
|
-
require 'nkf'
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
27
|
-
'
|
28
|
-
'
|
29
|
-
'
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'
|
33
|
-
'
|
34
|
-
'
|
35
|
-
'
|
36
|
-
'
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@
|
66
|
-
|
67
|
-
@
|
68
|
-
@
|
69
|
-
@
|
70
|
-
@
|
71
|
-
|
72
|
-
@
|
73
|
-
@
|
74
|
-
|
75
|
-
@
|
76
|
-
@
|
77
|
-
|
78
|
-
@
|
79
|
-
@
|
80
|
-
@
|
81
|
-
@
|
82
|
-
|
83
|
-
|
84
|
-
@
|
85
|
-
|
86
|
-
|
87
|
-
@
|
88
|
-
|
89
|
-
@
|
90
|
-
@
|
91
|
-
@
|
92
|
-
@
|
93
|
-
|
94
|
-
|
95
|
-
@
|
96
|
-
@
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
@
|
101
|
-
@
|
102
|
-
@
|
103
|
-
|
104
|
-
|
105
|
-
@
|
106
|
-
@
|
107
|
-
|
108
|
-
@
|
109
|
-
|
110
|
-
|
111
|
-
@
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
@
|
148
|
-
@
|
149
|
-
@
|
150
|
-
@
|
151
|
-
@
|
152
|
-
@
|
153
|
-
@
|
154
|
-
|
155
|
-
@
|
156
|
-
@
|
157
|
-
|
158
|
-
@
|
159
|
-
@
|
160
|
-
|
161
|
-
@
|
162
|
-
|
163
|
-
@
|
164
|
-
@
|
165
|
-
|
166
|
-
|
167
|
-
@
|
168
|
-
|
169
|
-
|
170
|
-
@
|
171
|
-
|
172
|
-
@
|
173
|
-
@
|
174
|
-
|
175
|
-
@
|
176
|
-
|
177
|
-
|
178
|
-
@
|
179
|
-
|
180
|
-
@
|
181
|
-
|
182
|
-
@
|
183
|
-
@
|
184
|
-
|
185
|
-
|
186
|
-
@
|
187
|
-
@
|
188
|
-
@
|
189
|
-
|
190
|
-
@
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
|
215
|
-
#
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
#
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
@
|
236
|
-
@
|
237
|
-
|
238
|
-
@
|
239
|
-
@
|
240
|
-
|
241
|
-
@
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
@
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
@
|
272
|
-
@
|
273
|
-
@
|
274
|
-
@left_color =
|
275
|
-
@
|
276
|
-
|
277
|
-
|
278
|
-
#
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
indent
|
321
|
-
indent |=
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
# my $
|
366
|
-
# my $
|
367
|
-
|
368
|
-
# my $
|
369
|
-
# my $
|
370
|
-
# my $
|
371
|
-
# my $
|
372
|
-
# my $
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
#
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
#
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
#
|
450
|
-
#
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
#
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
end
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
#
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
def
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
#
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
def
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
#
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
#
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
#
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
end
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
#
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
#
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
#
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
#
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
#
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
#
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
#
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
#
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
end
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
#
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
#
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
#
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
#
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
#
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
#
|
738
|
-
#
|
739
|
-
#
|
740
|
-
#
|
741
|
-
#
|
742
|
-
#
|
743
|
-
#
|
744
|
-
#
|
745
|
-
#
|
746
|
-
#
|
747
|
-
#
|
748
|
-
#
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
#
|
756
|
-
#
|
757
|
-
#
|
758
|
-
#
|
759
|
-
#
|
760
|
-
#
|
761
|
-
#
|
762
|
-
#
|
763
|
-
#
|
764
|
-
#
|
765
|
-
#
|
766
|
-
#
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
end
|
778
|
-
|
779
|
-
|
780
|
-
#
|
781
|
-
#
|
782
|
-
#
|
783
|
-
# Default
|
784
|
-
#
|
785
|
-
#
|
786
|
-
#
|
787
|
-
#
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
#
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
#
|
800
|
-
#
|
801
|
-
#
|
802
|
-
#
|
803
|
-
#
|
804
|
-
#
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
#
|
822
|
-
|
823
|
-
#
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
#
|
833
|
-
#
|
834
|
-
#
|
835
|
-
#
|
836
|
-
#
|
837
|
-
#
|
838
|
-
#
|
839
|
-
#
|
840
|
-
#
|
841
|
-
#
|
842
|
-
#
|
843
|
-
#
|
844
|
-
#
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
#
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
#
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
#
|
885
|
-
#
|
886
|
-
#
|
887
|
-
#
|
888
|
-
#
|
889
|
-
#
|
890
|
-
def
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
#
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
#
|
906
|
-
#
|
907
|
-
#
|
908
|
-
#
|
909
|
-
#
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
#
|
923
|
-
#
|
924
|
-
#
|
925
|
-
#
|
926
|
-
#
|
927
|
-
#
|
928
|
-
#
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
#
|
946
|
-
#
|
947
|
-
#
|
948
|
-
#
|
949
|
-
#
|
950
|
-
#
|
951
|
-
#
|
952
|
-
#
|
953
|
-
#
|
954
|
-
#
|
955
|
-
#
|
956
|
-
#
|
957
|
-
#
|
958
|
-
#
|
959
|
-
#
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
#
|
984
|
-
#
|
985
|
-
#
|
986
|
-
#
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
end
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
#
|
997
|
-
#
|
998
|
-
#
|
999
|
-
#
|
1000
|
-
#
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
#
|
1044
|
-
#
|
1045
|
-
#
|
1046
|
-
#
|
1047
|
-
#
|
1048
|
-
#
|
1049
|
-
#
|
1050
|
-
#
|
1051
|
-
#
|
1052
|
-
#
|
1053
|
-
#
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1
|
+
##############################################################################
|
2
|
+
#
|
3
|
+
# Format - A class for defining Excel formatting.
|
4
|
+
#
|
5
|
+
#
|
6
|
+
# Used in conjunction with WriteExcel
|
7
|
+
#
|
8
|
+
# Copyright 2000-2010, 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
|
+
require 'nkf'
|
14
|
+
|
15
|
+
#
|
16
|
+
# Format - A class for defining Excel formatting.
|
17
|
+
#
|
18
|
+
# See CELL FORMATTING, FORMAT METHODS, COLOURS IN EXCEL in WriteExcel's rdoc.
|
19
|
+
#
|
20
|
+
class Format
|
21
|
+
|
22
|
+
COLORS = {
|
23
|
+
'aqua' => 0x0F,
|
24
|
+
'cyan' => 0x0F,
|
25
|
+
'black' => 0x08,
|
26
|
+
'blue' => 0x0C,
|
27
|
+
'brown' => 0x10,
|
28
|
+
'magenta' => 0x0E,
|
29
|
+
'fuchsia' => 0x0E,
|
30
|
+
'gray' => 0x17,
|
31
|
+
'grey' => 0x17,
|
32
|
+
'green' => 0x11,
|
33
|
+
'lime' => 0x0B,
|
34
|
+
'navy' => 0x12,
|
35
|
+
'orange' => 0x35,
|
36
|
+
'pink' => 0x21,
|
37
|
+
'purple' => 0x14,
|
38
|
+
'red' => 0x0A,
|
39
|
+
'silver' => 0x16,
|
40
|
+
'white' => 0x09,
|
41
|
+
'yellow' => 0x0D,
|
42
|
+
} # :nodoc:
|
43
|
+
NonAscii = /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]^` ~\0\n]/ # :nodoc:
|
44
|
+
|
45
|
+
###############################################################################
|
46
|
+
#
|
47
|
+
# initialize(xf_index=0, properties = {})
|
48
|
+
# xf_index :
|
49
|
+
# properties : Hash of property => value
|
50
|
+
#
|
51
|
+
# Constructor
|
52
|
+
#
|
53
|
+
def initialize(xf_index = 0, properties = {}) # :nodoc:
|
54
|
+
@xf_index = xf_index
|
55
|
+
|
56
|
+
@type = 0
|
57
|
+
@font_index = 0
|
58
|
+
@font = 'Arial'
|
59
|
+
@size = 10
|
60
|
+
@bold = 0x0190
|
61
|
+
@italic = 0
|
62
|
+
@color = 0x7FFF
|
63
|
+
@underline = 0
|
64
|
+
@font_strikeout = 0
|
65
|
+
@font_outline = 0
|
66
|
+
@font_shadow = 0
|
67
|
+
@font_script = 0
|
68
|
+
@font_family = 0
|
69
|
+
@font_charset = 0
|
70
|
+
@font_encoding = 0
|
71
|
+
|
72
|
+
@num_format = 0
|
73
|
+
@num_format_enc = 0
|
74
|
+
|
75
|
+
@hidden = 0
|
76
|
+
@locked = 1
|
77
|
+
|
78
|
+
@text_h_align = 0
|
79
|
+
@text_wrap = 0
|
80
|
+
@text_v_align = 2
|
81
|
+
@text_justlast = 0
|
82
|
+
@rotation = 0
|
83
|
+
|
84
|
+
@fg_color = 0x40
|
85
|
+
@bg_color = 0x41
|
86
|
+
|
87
|
+
@pattern = 0
|
88
|
+
|
89
|
+
@bottom = 0
|
90
|
+
@top = 0
|
91
|
+
@left = 0
|
92
|
+
@right = 0
|
93
|
+
|
94
|
+
@bottom_color = 0x40
|
95
|
+
@top_color = 0x40
|
96
|
+
@left_color = 0x40
|
97
|
+
@right_color = 0x40
|
98
|
+
|
99
|
+
@indent = 0
|
100
|
+
@shrink = 0
|
101
|
+
@merge_range = 0
|
102
|
+
@reading_order = 0
|
103
|
+
|
104
|
+
@diag_type = 0
|
105
|
+
@diag_color = 0x40
|
106
|
+
@diag_border = 0
|
107
|
+
|
108
|
+
@font_only = 0
|
109
|
+
|
110
|
+
# Temp code to prevent merged formats in non-merged cells.
|
111
|
+
@used_merge = 0
|
112
|
+
|
113
|
+
set_format_properties(properties) unless properties.empty?
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
#
|
118
|
+
# :call-seq:
|
119
|
+
# copy(format)
|
120
|
+
#
|
121
|
+
# Copy the attributes of another Format object.
|
122
|
+
#
|
123
|
+
# This method is used to copy all of the properties from one Format object
|
124
|
+
# to another:
|
125
|
+
#
|
126
|
+
# lorry1 = workbook.add_format
|
127
|
+
# lorry1.set_bold
|
128
|
+
# lorry1.set_italic
|
129
|
+
# lorry1.set_color('red') # lorry1 is bold, italic and red
|
130
|
+
#
|
131
|
+
# lorry2 = workbook.add_format
|
132
|
+
# lorry2.copy(lorry1)
|
133
|
+
# lorry2.set_color('yellow') # lorry2 is bold, italic and yellow
|
134
|
+
#
|
135
|
+
# The copy() method is only useful if you are using the method interface
|
136
|
+
# to Format properties. It generally isn't required if you are setting
|
137
|
+
# Format properties directly using hashes.
|
138
|
+
#
|
139
|
+
# Note: this is not a copy constructor, both objects must exist prior to
|
140
|
+
# copying.
|
141
|
+
#
|
142
|
+
def copy(other)
|
143
|
+
return unless other.kind_of?(Format)
|
144
|
+
|
145
|
+
# copy properties except xf, merge_range, used_merge
|
146
|
+
# Copy properties
|
147
|
+
@type = other.type
|
148
|
+
@font_index = other.font_index
|
149
|
+
@font = other.font
|
150
|
+
@size = other.size
|
151
|
+
@bold = other.bold
|
152
|
+
@italic = other.italic
|
153
|
+
@color = other.color
|
154
|
+
@underline = other.underline
|
155
|
+
@font_strikeout = other.font_strikeout
|
156
|
+
@font_outline = other.font_outline
|
157
|
+
@font_shadow = other.font_shadow
|
158
|
+
@font_script = other.font_script
|
159
|
+
@font_family = other.font_family
|
160
|
+
@font_charset = other.font_charset
|
161
|
+
@font_encoding = other.font_encoding
|
162
|
+
|
163
|
+
@num_format = other.num_format
|
164
|
+
@num_format_enc = other.num_format_enc
|
165
|
+
|
166
|
+
@hidden = other.hidden
|
167
|
+
@locked = other.locked
|
168
|
+
|
169
|
+
@text_h_align = other.text_h_align
|
170
|
+
@text_wrap = other.text_wrap
|
171
|
+
@text_v_align = other.text_v_align
|
172
|
+
@text_justlast = other.text_justlast
|
173
|
+
@rotation = other.rotation
|
174
|
+
|
175
|
+
@fg_color = other.fg_color
|
176
|
+
@bg_color = other.bg_color
|
177
|
+
|
178
|
+
@pattern = other.pattern
|
179
|
+
|
180
|
+
@bottom = other.bottom
|
181
|
+
@top = other.top
|
182
|
+
@left = other.left
|
183
|
+
@right = other.right
|
184
|
+
|
185
|
+
@bottom_color = other.bottom_color
|
186
|
+
@top_color = other.top_color
|
187
|
+
@left_color = other.left_color
|
188
|
+
@right_color = other.right_color
|
189
|
+
|
190
|
+
@indent = other.indent
|
191
|
+
@shrink = other.shrink
|
192
|
+
@reading_order = other.reading_order
|
193
|
+
|
194
|
+
@diag_type = other.diag_type
|
195
|
+
@diag_color = other.diag_color
|
196
|
+
@diag_border = other.diag_border
|
197
|
+
|
198
|
+
@font_only = other.font_only
|
199
|
+
end
|
200
|
+
|
201
|
+
###############################################################################
|
202
|
+
#
|
203
|
+
# get_xf($style)
|
204
|
+
#
|
205
|
+
# Generate an Excel BIFF XF record.
|
206
|
+
#
|
207
|
+
def get_xf # :nodoc:
|
208
|
+
|
209
|
+
# Local Variable
|
210
|
+
# record; # Record identifier
|
211
|
+
# length; # Number of bytes to follow
|
212
|
+
#
|
213
|
+
# ifnt; # Index to FONT record
|
214
|
+
# ifmt; # Index to FORMAT record
|
215
|
+
# style; # Style and other options
|
216
|
+
# align; # Alignment
|
217
|
+
# indent; #
|
218
|
+
# icv; # fg and bg pattern colors
|
219
|
+
# border1; # Border line options
|
220
|
+
# border2; # Border line options
|
221
|
+
# border3; # Border line options
|
222
|
+
|
223
|
+
# Set the type of the XF record and some of the attributes.
|
224
|
+
if @type == 0xFFF5 then
|
225
|
+
style = 0xFFF5
|
226
|
+
else
|
227
|
+
style = @locked
|
228
|
+
style |= @hidden << 1
|
229
|
+
end
|
230
|
+
|
231
|
+
# Flags to indicate if attributes have been set.
|
232
|
+
atr_num = (@num_format != 0) ? 1 : 0
|
233
|
+
atr_fnt = (@font_index != 0) ? 1 : 0
|
234
|
+
atr_alc = (@text_h_align != 0 ||
|
235
|
+
@text_v_align != 2 ||
|
236
|
+
@shrink != 0 ||
|
237
|
+
@merge_range != 0 ||
|
238
|
+
@text_wrap != 0 ||
|
239
|
+
@indent != 0) ? 1 : 0
|
240
|
+
atr_bdr = (@bottom != 0 ||
|
241
|
+
@top != 0 ||
|
242
|
+
@left != 0 ||
|
243
|
+
@right != 0 ||
|
244
|
+
@diag_type != 0) ? 1 : 0
|
245
|
+
atr_pat = (@fg_color != 0x40 ||
|
246
|
+
@bg_color != 0x41 ||
|
247
|
+
@pattern != 0x00) ? 1 : 0
|
248
|
+
atr_prot = (@hidden != 0 ||
|
249
|
+
@locked != 1) ? 1 : 0
|
250
|
+
|
251
|
+
# Set attribute changed flags for the style formats.
|
252
|
+
if @xf_index != 0 and @type == 0xFFF5
|
253
|
+
if @xf_index >= 16
|
254
|
+
atr_num = 0
|
255
|
+
atr_fnt = 1
|
256
|
+
else
|
257
|
+
atr_num = 1
|
258
|
+
atr_fnt = 0
|
259
|
+
end
|
260
|
+
atr_alc = 1
|
261
|
+
atr_bdr = 1
|
262
|
+
atr_pat = 1
|
263
|
+
atr_prot = 1
|
264
|
+
end
|
265
|
+
|
266
|
+
# Set a default diagonal border style if none was specified.
|
267
|
+
@diag_border = 1 if (@diag_border ==0 and @diag_type != 0)
|
268
|
+
|
269
|
+
# Reset the default colours for the non-font properties
|
270
|
+
@fg_color = 0x40 if @fg_color == 0x7FFF
|
271
|
+
@bg_color = 0x41 if @bg_color == 0x7FFF
|
272
|
+
@bottom_color = 0x40 if @bottom_color == 0x7FFF
|
273
|
+
@top_color = 0x40 if @top_color == 0x7FFF
|
274
|
+
@left_color = 0x40 if @left_color == 0x7FFF
|
275
|
+
@right_color = 0x40 if @right_color == 0x7FFF
|
276
|
+
@diag_color = 0x40 if @diag_color == 0x7FFF
|
277
|
+
|
278
|
+
# Zero the default border colour if the border has not been set.
|
279
|
+
@bottom_color = 0 if @bottom == 0
|
280
|
+
@top_color = 0 if @top == 0
|
281
|
+
@right_color = 0 if @right == 0
|
282
|
+
@left_color = 0 if @left == 0
|
283
|
+
@diag_color = 0 if @diag_type == 0
|
284
|
+
|
285
|
+
# The following 2 logical statements take care of special cases in relation
|
286
|
+
# to cell colours and patterns:
|
287
|
+
# 1. For a solid fill (_pattern == 1) Excel reverses the role of foreground
|
288
|
+
# and background colours.
|
289
|
+
# 2. If the user specifies a foreground or background colour without a
|
290
|
+
# pattern they probably wanted a solid fill, so we fill in the defaults.
|
291
|
+
#
|
292
|
+
if (@pattern <= 0x01 && @bg_color != 0x41 && @fg_color == 0x40)
|
293
|
+
@fg_color = @bg_color
|
294
|
+
@bg_color = 0x40
|
295
|
+
@pattern = 1
|
296
|
+
end
|
297
|
+
|
298
|
+
if (@pattern <= 0x01 && @bg_color == 0x41 && @fg_color != 0x40)
|
299
|
+
@bg_color = 0x40
|
300
|
+
@pattern = 1
|
301
|
+
end
|
302
|
+
|
303
|
+
# Set default alignment if indent is set.
|
304
|
+
@text_h_align = 1 if @indent != 0 and @text_h_align == 0
|
305
|
+
|
306
|
+
|
307
|
+
record = 0x00E0
|
308
|
+
length = 0x0014
|
309
|
+
|
310
|
+
ifnt = @font_index
|
311
|
+
ifmt = @num_format
|
312
|
+
|
313
|
+
|
314
|
+
align = @text_h_align
|
315
|
+
align |= @text_wrap << 3
|
316
|
+
align |= @text_v_align << 4
|
317
|
+
align |= @text_justlast << 7
|
318
|
+
align |= @rotation << 8
|
319
|
+
|
320
|
+
indent = @indent
|
321
|
+
indent |= @shrink << 4
|
322
|
+
indent |= @merge_range << 5
|
323
|
+
indent |= @reading_order << 6
|
324
|
+
indent |= atr_num << 10
|
325
|
+
indent |= atr_fnt << 11
|
326
|
+
indent |= atr_alc << 12
|
327
|
+
indent |= atr_bdr << 13
|
328
|
+
indent |= atr_pat << 14
|
329
|
+
indent |= atr_prot << 15
|
330
|
+
|
331
|
+
|
332
|
+
border1 = @left
|
333
|
+
border1 |= @right << 4
|
334
|
+
border1 |= @top << 8
|
335
|
+
border1 |= @bottom << 12
|
336
|
+
|
337
|
+
border2 = @left_color
|
338
|
+
border2 |= @right_color << 7
|
339
|
+
border2 |= @diag_type << 14
|
340
|
+
|
341
|
+
border3 = @top_color
|
342
|
+
border3 |= @bottom_color << 7
|
343
|
+
border3 |= @diag_color << 14
|
344
|
+
border3 |= @diag_border << 21
|
345
|
+
border3 |= @pattern << 26
|
346
|
+
|
347
|
+
icv = @fg_color
|
348
|
+
icv |= @bg_color << 7
|
349
|
+
|
350
|
+
header = [record, length].pack("vv")
|
351
|
+
data = [ifnt, ifmt, style, align, indent,
|
352
|
+
border1, border2, border3, icv].pack("vvvvvvvVv")
|
353
|
+
|
354
|
+
return header + data
|
355
|
+
end
|
356
|
+
|
357
|
+
###############################################################################
|
358
|
+
#
|
359
|
+
# get_font()
|
360
|
+
#
|
361
|
+
# Generate an Excel BIFF FONT record.
|
362
|
+
#
|
363
|
+
def get_font # :nodoc:
|
364
|
+
|
365
|
+
# my $record; # Record identifier
|
366
|
+
# my $length; # Record length
|
367
|
+
|
368
|
+
# my $dyHeight; # Height of font (1/20 of a point)
|
369
|
+
# my $grbit; # Font attributes
|
370
|
+
# my $icv; # Index to color palette
|
371
|
+
# my $bls; # Bold style
|
372
|
+
# my $sss; # Superscript/subscript
|
373
|
+
# my $uls; # Underline
|
374
|
+
# my $bFamily; # Font family
|
375
|
+
# my $bCharSet; # Character set
|
376
|
+
# my $reserved; # Reserved
|
377
|
+
# my $cch; # Length of font name
|
378
|
+
# my $rgch; # Font name
|
379
|
+
# my $encoding; # Font name character encoding
|
380
|
+
|
381
|
+
|
382
|
+
dyHeight = @size * 20
|
383
|
+
icv = @color
|
384
|
+
bls = @bold
|
385
|
+
sss = @font_script
|
386
|
+
uls = @underline
|
387
|
+
bFamily = @font_family
|
388
|
+
bCharSet = @font_charset
|
389
|
+
rgch = @font
|
390
|
+
encoding = @font_encoding
|
391
|
+
|
392
|
+
# Handle utf8 strings
|
393
|
+
if rgch =~ NonAscii
|
394
|
+
rgch = NKF.nkf('-w16B0 -m0 -W', rgch)
|
395
|
+
encoding = 1
|
396
|
+
end
|
397
|
+
|
398
|
+
cch = rgch.length
|
399
|
+
#
|
400
|
+
# Handle Unicode font names.
|
401
|
+
if (encoding == 1)
|
402
|
+
raise "Uneven number of bytes in Unicode font name" if cch % 2 != 0
|
403
|
+
cch /= 2 if encoding !=0
|
404
|
+
rgch = rgch.unpack('n*').pack('v*')
|
405
|
+
end
|
406
|
+
|
407
|
+
record = 0x31
|
408
|
+
length = 0x10 + rgch.length
|
409
|
+
reserved = 0x00
|
410
|
+
|
411
|
+
grbit = 0x00
|
412
|
+
grbit |= 0x02 if @italic != 0
|
413
|
+
grbit |= 0x08 if @font_strikeout != 0
|
414
|
+
grbit |= 0x10 if @font_outline != 0
|
415
|
+
grbit |= 0x20 if @font_shadow != 0
|
416
|
+
|
417
|
+
|
418
|
+
header = [record, length].pack("vv")
|
419
|
+
data = [dyHeight, grbit, icv, bls,
|
420
|
+
sss, uls, bFamily,
|
421
|
+
bCharSet, reserved, cch, encoding].pack('vvvvvCCCCCC')
|
422
|
+
|
423
|
+
return header + data + rgch
|
424
|
+
end
|
425
|
+
|
426
|
+
###############################################################################
|
427
|
+
#
|
428
|
+
# get_font_key()
|
429
|
+
#
|
430
|
+
# Returns a unique hash key for a font. Used by Workbook->_store_all_fonts()
|
431
|
+
#
|
432
|
+
def get_font_key # :nodoc:
|
433
|
+
# The following elements are arranged to increase the probability of
|
434
|
+
# generating a unique key. Elements that hold a large range of numbers
|
435
|
+
# e.g. _color are placed between two binary elements such as _italic
|
436
|
+
|
437
|
+
key = "#{@font}#{@size}#{@font_script}#{@underline}#{@font_strikeout}#{@bold}#{@font_outline}"
|
438
|
+
key += "#{@font_family}#{@font_charset}#{@font_shadow}#{@color}#{@italic}#{@font_encoding}"
|
439
|
+
result = key.gsub(' ', '_') # Convert the key to a single word
|
440
|
+
|
441
|
+
return result
|
442
|
+
end
|
443
|
+
|
444
|
+
###############################################################################
|
445
|
+
#
|
446
|
+
# xf_index()
|
447
|
+
#
|
448
|
+
# Returns the used by Worksheet->_XF()
|
449
|
+
#
|
450
|
+
def xf_index # :nodoc:
|
451
|
+
return @xf_index
|
452
|
+
end
|
453
|
+
|
454
|
+
def used_merge # :nodoc:
|
455
|
+
@used_merge
|
456
|
+
end
|
457
|
+
|
458
|
+
def used_merge=(val) # :nodoc:
|
459
|
+
@used_merge = val
|
460
|
+
end
|
461
|
+
|
462
|
+
def type # :nodoc:
|
463
|
+
@type
|
464
|
+
end
|
465
|
+
|
466
|
+
def font_index # :nodoc:
|
467
|
+
@font_index
|
468
|
+
end
|
469
|
+
|
470
|
+
def font_index=(val) # :nodoc:
|
471
|
+
@font_index = val
|
472
|
+
end
|
473
|
+
|
474
|
+
def font # :nodoc:
|
475
|
+
@font
|
476
|
+
end
|
477
|
+
|
478
|
+
def size # :nodoc:
|
479
|
+
@size
|
480
|
+
end
|
481
|
+
|
482
|
+
def bold # :nodoc:
|
483
|
+
@bold
|
484
|
+
end
|
485
|
+
|
486
|
+
def italic # :nodoc:
|
487
|
+
@italic
|
488
|
+
end
|
489
|
+
|
490
|
+
def color # :nodoc:
|
491
|
+
@color
|
492
|
+
end
|
493
|
+
|
494
|
+
def underline # :nodoc:
|
495
|
+
@underline
|
496
|
+
end
|
497
|
+
|
498
|
+
def font_strikeout # :nodoc:
|
499
|
+
@font_strikeout
|
500
|
+
end
|
501
|
+
|
502
|
+
def font_outline # :nodoc:
|
503
|
+
@font_outline
|
504
|
+
end
|
505
|
+
|
506
|
+
def font_shadow # :nodoc:
|
507
|
+
@font_shadow
|
508
|
+
end
|
509
|
+
|
510
|
+
def font_script # :nodoc:
|
511
|
+
@font_script
|
512
|
+
end
|
513
|
+
|
514
|
+
def font_family # :nodoc:
|
515
|
+
@font_family
|
516
|
+
end
|
517
|
+
|
518
|
+
def font_charset # :nodoc:
|
519
|
+
@font_charset
|
520
|
+
end
|
521
|
+
|
522
|
+
def font_encoding # :nodoc:
|
523
|
+
@font_encoding
|
524
|
+
end
|
525
|
+
|
526
|
+
def num_format # :nodoc:
|
527
|
+
@num_format
|
528
|
+
end
|
529
|
+
|
530
|
+
def num_format=(val) # :nodoc:
|
531
|
+
@num_format = val
|
532
|
+
end
|
533
|
+
|
534
|
+
def num_format_enc # :nodoc:
|
535
|
+
@num_format_enc
|
536
|
+
end
|
537
|
+
|
538
|
+
def hidden # :nodoc:
|
539
|
+
@hidden
|
540
|
+
end
|
541
|
+
|
542
|
+
def locked # :nodoc:
|
543
|
+
@locked
|
544
|
+
end
|
545
|
+
|
546
|
+
def text_h_align # :nodoc:
|
547
|
+
@text_h_align
|
548
|
+
end
|
549
|
+
|
550
|
+
def text_wrap # :nodoc:
|
551
|
+
@text_wrap
|
552
|
+
end
|
553
|
+
|
554
|
+
def text_v_align # :nodoc:
|
555
|
+
@text_v_align
|
556
|
+
end
|
557
|
+
|
558
|
+
def text_justlast # :nodoc:
|
559
|
+
@text_justlast
|
560
|
+
end
|
561
|
+
|
562
|
+
def rotation # :nodoc:
|
563
|
+
@rotation
|
564
|
+
end
|
565
|
+
|
566
|
+
def fg_color # :nodoc:
|
567
|
+
@fg_color
|
568
|
+
end
|
569
|
+
|
570
|
+
def bg_color # :nodoc:
|
571
|
+
@bg_color
|
572
|
+
end
|
573
|
+
|
574
|
+
def pattern # :nodoc:
|
575
|
+
@pattern
|
576
|
+
end
|
577
|
+
|
578
|
+
def bottom # :nodoc:
|
579
|
+
@bottom
|
580
|
+
end
|
581
|
+
|
582
|
+
def top # :nodoc:
|
583
|
+
@top
|
584
|
+
end
|
585
|
+
|
586
|
+
def left # :nodoc:
|
587
|
+
@left
|
588
|
+
end
|
589
|
+
|
590
|
+
def right # :nodoc:
|
591
|
+
@right
|
592
|
+
end
|
593
|
+
|
594
|
+
def bottom_color # :nodoc:
|
595
|
+
@bottom_color
|
596
|
+
end
|
597
|
+
|
598
|
+
def top_color # :nodoc:
|
599
|
+
@top_color
|
600
|
+
end
|
601
|
+
|
602
|
+
def left_color # :nodoc:
|
603
|
+
@left_color
|
604
|
+
end
|
605
|
+
|
606
|
+
def right_color # :nodoc:
|
607
|
+
@right_color
|
608
|
+
end
|
609
|
+
|
610
|
+
def indent # :nodoc:
|
611
|
+
@indent
|
612
|
+
end
|
613
|
+
|
614
|
+
def shrink # :nodoc:
|
615
|
+
@shrink
|
616
|
+
end
|
617
|
+
|
618
|
+
def reading_order # :nodoc:
|
619
|
+
@reading_order
|
620
|
+
end
|
621
|
+
|
622
|
+
def diag_type # :nodoc:
|
623
|
+
@diag_type
|
624
|
+
end
|
625
|
+
|
626
|
+
def diag_color # :nodoc:
|
627
|
+
@diag_color
|
628
|
+
end
|
629
|
+
|
630
|
+
def diag_border # :nodoc:
|
631
|
+
@diag_border
|
632
|
+
end
|
633
|
+
|
634
|
+
def font_only # :nodoc:
|
635
|
+
@font_only
|
636
|
+
end
|
637
|
+
|
638
|
+
###############################################################################
|
639
|
+
#
|
640
|
+
# get_color(colour)
|
641
|
+
#
|
642
|
+
# Used in conjunction with the set_xxx_color methods to convert a color
|
643
|
+
# string into a number. Color range is 0..63 but we will restrict it
|
644
|
+
# to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
|
645
|
+
#
|
646
|
+
def get_color(colour = nil) # :nodoc:
|
647
|
+
# Return the default color, 0x7FFF, if undef,
|
648
|
+
return 0x7FFF if colour.nil?
|
649
|
+
|
650
|
+
if colour.kind_of?(Numeric)
|
651
|
+
if colour < 0
|
652
|
+
return 0x7FFF
|
653
|
+
|
654
|
+
# or an index < 8 mapped into the correct range,
|
655
|
+
elsif colour < 8
|
656
|
+
return (colour + 8).to_i
|
657
|
+
|
658
|
+
# or the default color if arg is outside range,
|
659
|
+
elsif colour > 63
|
660
|
+
return 0x7FFF
|
661
|
+
|
662
|
+
# or an integer in the valid range
|
663
|
+
else
|
664
|
+
return colour.to_i
|
665
|
+
end
|
666
|
+
elsif colour.kind_of?(String)
|
667
|
+
# or the color string converted to an integer,
|
668
|
+
if COLORS.has_key?(colour)
|
669
|
+
return COLORS[colour]
|
670
|
+
|
671
|
+
# or the default color if string is unrecognised,
|
672
|
+
else
|
673
|
+
return 0x7FFF
|
674
|
+
end
|
675
|
+
else
|
676
|
+
return 0x7FFF
|
677
|
+
end
|
678
|
+
end
|
679
|
+
|
680
|
+
###############################################################################
|
681
|
+
#
|
682
|
+
# class method Format._get_color(colour)
|
683
|
+
#
|
684
|
+
# used from Worksheet.rb
|
685
|
+
#
|
686
|
+
# this is cut & copy of get_color().
|
687
|
+
#
|
688
|
+
def self._get_color(colour) # :nodoc:
|
689
|
+
# Return the default color, 0x7FFF, if undef,
|
690
|
+
return 0x7FFF if colour.nil?
|
691
|
+
|
692
|
+
if colour.kind_of?(Numeric)
|
693
|
+
if colour < 0
|
694
|
+
return 0x7FFF
|
695
|
+
|
696
|
+
# or an index < 8 mapped into the correct range,
|
697
|
+
elsif colour < 8
|
698
|
+
return (colour + 8).to_i
|
699
|
+
|
700
|
+
# or the default color if arg is outside range,
|
701
|
+
elsif 63 < colour
|
702
|
+
return 0x7FFF
|
703
|
+
|
704
|
+
# or an integer in the valid range
|
705
|
+
else
|
706
|
+
return colour.to_i
|
707
|
+
end
|
708
|
+
elsif colour.kind_of?(String)
|
709
|
+
# or the color string converted to an integer,
|
710
|
+
if COLORS.has_key?(colour)
|
711
|
+
return COLORS[colour]
|
712
|
+
|
713
|
+
# or the default color if string is unrecognised,
|
714
|
+
else
|
715
|
+
return 0x7FFF
|
716
|
+
end
|
717
|
+
else
|
718
|
+
return 0x7FFF
|
719
|
+
end
|
720
|
+
end
|
721
|
+
|
722
|
+
###############################################################################
|
723
|
+
#
|
724
|
+
# set_type()
|
725
|
+
#
|
726
|
+
# Set the XF object type as 0 = cell XF or 0xFFF5 = style XF.
|
727
|
+
#
|
728
|
+
def set_type(type = nil) # :nodoc:
|
729
|
+
|
730
|
+
if !type.nil? and type == 0
|
731
|
+
@type = 0x0000
|
732
|
+
else
|
733
|
+
@type = 0xFFF5
|
734
|
+
end
|
735
|
+
end
|
736
|
+
|
737
|
+
#
|
738
|
+
# Default state: Font size is 10
|
739
|
+
# Default action: Set font size to 1
|
740
|
+
# Valid args: Integer values from 1 to as big as your screen.
|
741
|
+
#
|
742
|
+
# Set the font size. Excel adjusts the height of a row to accommodate the
|
743
|
+
# largest font size in the row. You can also explicitly specify the height
|
744
|
+
# of a row using the set_row() worksheet method.
|
745
|
+
#
|
746
|
+
# format = workbook.add_format
|
747
|
+
# format.set_size(30)
|
748
|
+
#
|
749
|
+
def set_size(size = 1)
|
750
|
+
if size.kind_of?(Numeric) && size >= 1
|
751
|
+
@size = size.to_i
|
752
|
+
end
|
753
|
+
end
|
754
|
+
|
755
|
+
#
|
756
|
+
# Set the font colour.
|
757
|
+
#
|
758
|
+
# Default state: Excels default color, usually black
|
759
|
+
# Default action: Set the default color
|
760
|
+
# Valid args: Integers from 8..63 or the following strings:
|
761
|
+
# 'black', 'blue', 'brown', 'cyan', 'gray'
|
762
|
+
# 'green', 'lime', 'magenta', 'navy', 'orange'
|
763
|
+
# 'pink', 'purple', 'red', 'silver', 'white', 'yellow'
|
764
|
+
#
|
765
|
+
# The set_color() method is used as follows:
|
766
|
+
#
|
767
|
+
# format = workbook.add_format()
|
768
|
+
# format.set_color('red')
|
769
|
+
# worksheet.write(0, 0, 'wheelbarrow', format)
|
770
|
+
#
|
771
|
+
# Note: The set_color() method is used to set the colour of the font in a cell.
|
772
|
+
# To set the colour of a cell use the set_bg_color()
|
773
|
+
# and set_pattern() methods.
|
774
|
+
#
|
775
|
+
def set_color(color = 0x7FFF)
|
776
|
+
@color = get_color(color)
|
777
|
+
end
|
778
|
+
|
779
|
+
#
|
780
|
+
# Set the italic property of the font:
|
781
|
+
#
|
782
|
+
# Default state: Italic is off
|
783
|
+
# Default action: Turn italic on
|
784
|
+
# Valid args: 0, 1
|
785
|
+
#
|
786
|
+
# format.set_italic # Turn italic on
|
787
|
+
#
|
788
|
+
def set_italic(arg = 1)
|
789
|
+
begin
|
790
|
+
if arg == 1 then @italic = 1 # italic on
|
791
|
+
elsif arg == 0 then @italic = 0 # italic off
|
792
|
+
else
|
793
|
+
raise ArgumentError,
|
794
|
+
"\n\n set_italic(#{arg.inspect})\n arg must be 0, 1, or none. ( 0:OFF , 1 and none:ON )\n"
|
795
|
+
end
|
796
|
+
end
|
797
|
+
end
|
798
|
+
|
799
|
+
#
|
800
|
+
# Set the bold property of the font:
|
801
|
+
#
|
802
|
+
# Default state: bold is off
|
803
|
+
# Default action: Turn bold on
|
804
|
+
# Valid args: 0, 1 [1]
|
805
|
+
#
|
806
|
+
# format.set_bold() # Turn bold on
|
807
|
+
#
|
808
|
+
# [1] Actually, values in the range 100..1000 are also valid. 400 is normal,
|
809
|
+
# 700 is bold and 1000 is very bold indeed. It is probably best to set the
|
810
|
+
# value to 1 and use normal bold.
|
811
|
+
#
|
812
|
+
def set_bold(weight = nil)
|
813
|
+
if weight.nil?
|
814
|
+
weight = 0x2BC
|
815
|
+
elsif !weight.kind_of?(Numeric)
|
816
|
+
weight = 0x190
|
817
|
+
elsif weight == 1 # Bold text
|
818
|
+
weight = 0x2BC
|
819
|
+
elsif weight == 0 # Normal text
|
820
|
+
weight = 0x190
|
821
|
+
elsif weight < 0x064 # Lower bound
|
822
|
+
weight = 0x190
|
823
|
+
elsif weight > 0x3E8 # Upper bound
|
824
|
+
weight = 0x190
|
825
|
+
else
|
826
|
+
weight = weight.to_i
|
827
|
+
end
|
828
|
+
|
829
|
+
@bold = weight
|
830
|
+
end
|
831
|
+
|
832
|
+
#
|
833
|
+
# Set the underline property of the font.
|
834
|
+
#
|
835
|
+
# Default state: Underline is off
|
836
|
+
# Default action: Turn on single underline
|
837
|
+
# Valid args: 0 = No underline
|
838
|
+
# 1 = Single underline
|
839
|
+
# 2 = Double underline
|
840
|
+
# 33 = Single accounting underline
|
841
|
+
# 34 = Double accounting underline
|
842
|
+
#
|
843
|
+
# format.set_underline(); # Single underline
|
844
|
+
#
|
845
|
+
def set_underline(arg = 1)
|
846
|
+
begin
|
847
|
+
case arg
|
848
|
+
when 0 then @underline = 0 # off
|
849
|
+
when 1 then @underline = 1 # Single
|
850
|
+
when 2 then @underline = 2 # Double
|
851
|
+
when 33 then @underline = 33 # Single accounting
|
852
|
+
when 34 then @underline = 34 # Double accounting
|
853
|
+
else
|
854
|
+
raise ArgumentError,
|
855
|
+
"\n\n set_underline(#{arg.inspect})\n arg must be 0, 1, or none, 2, 33, 34.\n"
|
856
|
+
" ( 0:OFF, 1 and none:Single, 2:Double, 33:Single accounting, 34:Double accounting )\n"
|
857
|
+
end
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
#
|
862
|
+
# Set the strikeout property of the font.
|
863
|
+
#
|
864
|
+
# Default state: Strikeout is off
|
865
|
+
# Default action: Turn strikeout on
|
866
|
+
# Valid args: 0, 1
|
867
|
+
#
|
868
|
+
def set_font_strikeout(arg = 1)
|
869
|
+
begin
|
870
|
+
if arg == 0 then @font_strikeout = 0
|
871
|
+
elsif arg == 1 then @font_strikeout = 1
|
872
|
+
else
|
873
|
+
raise ArgumentError,
|
874
|
+
"\n\n set_font_strikeout(#{arg.inspect})\n arg must be 0, 1, or none.\n"
|
875
|
+
" ( 0:OFF, 1 and none:Strikeout )\n"
|
876
|
+
end
|
877
|
+
end
|
878
|
+
end
|
879
|
+
|
880
|
+
#
|
881
|
+
# Set the superscript/subscript property of the font.
|
882
|
+
# This format is currently not very useful.
|
883
|
+
#
|
884
|
+
# Default state: Super/Subscript is off
|
885
|
+
# Default action: Turn Superscript on
|
886
|
+
# Valid args: 0 = Normal
|
887
|
+
# 1 = Superscript
|
888
|
+
# 2 = Subscript
|
889
|
+
#
|
890
|
+
def set_font_script(arg = 1)
|
891
|
+
begin
|
892
|
+
if arg == 0 then @font_script = 0
|
893
|
+
elsif arg == 1 then @font_script = 1
|
894
|
+
elsif arg == 2 then @font_script = 2
|
895
|
+
else
|
896
|
+
raise ArgumentError,
|
897
|
+
"\n\n set_font_script(#{arg.inspect})\n arg must be 0, 1, or none. or 2\n"
|
898
|
+
" ( 0:OFF, 1 and none:Superscript, 2:Subscript )\n"
|
899
|
+
end
|
900
|
+
end
|
901
|
+
end
|
902
|
+
|
903
|
+
#
|
904
|
+
# Macintosh only.
|
905
|
+
#
|
906
|
+
# Default state: Outline is off
|
907
|
+
# Default action: Turn outline on
|
908
|
+
# Valid args: 0, 1
|
909
|
+
#
|
910
|
+
def set_font_outline(arg = 1)
|
911
|
+
begin
|
912
|
+
if arg == 0 then @font_outline = 0
|
913
|
+
elsif arg == 1 then @font_outline = 1
|
914
|
+
else
|
915
|
+
raise ArgumentError,
|
916
|
+
"\n\n set_font_outline(#{arg.inspect})\n arg must be 0, 1, or none.\n"
|
917
|
+
" ( 0:OFF, 1 and none:outline on )\n"
|
918
|
+
end
|
919
|
+
end
|
920
|
+
end
|
921
|
+
|
922
|
+
#
|
923
|
+
# Macintosh only.
|
924
|
+
#
|
925
|
+
# Default state: Shadow is off
|
926
|
+
# Default action: Turn shadow on
|
927
|
+
# Valid args: 0, 1
|
928
|
+
#
|
929
|
+
def set_font_shadow(arg = 1)
|
930
|
+
begin
|
931
|
+
if arg == 0 then @font_shadow = 0
|
932
|
+
elsif arg == 1 then @font_shadow = 1
|
933
|
+
else
|
934
|
+
raise ArgumentError,
|
935
|
+
"\n\n set_font_shadow(#{arg.inspect})\n arg must be 0, 1, or none.\n"
|
936
|
+
" ( 0:OFF, 1 and none:shadow on )\n"
|
937
|
+
end
|
938
|
+
end
|
939
|
+
end
|
940
|
+
|
941
|
+
#
|
942
|
+
# prevent modification of a cells contents.
|
943
|
+
#
|
944
|
+
# Default state: Cell locking is on
|
945
|
+
# Default action: Turn locking on
|
946
|
+
# Valid args: 0, 1
|
947
|
+
#
|
948
|
+
# This property can be used to prevent modification of a cells contents.
|
949
|
+
# Following Excel's convention, cell locking is turned on by default.
|
950
|
+
# However, it only has an effect if the worksheet has been protected,
|
951
|
+
# see the worksheet protect() method.
|
952
|
+
#
|
953
|
+
# locked = workbook.add_format()
|
954
|
+
# locked.set_locked(1) # A non-op
|
955
|
+
#
|
956
|
+
# unlocked = workbook.add_format()
|
957
|
+
# locked.set_locked(0)
|
958
|
+
#
|
959
|
+
# # Enable worksheet protection
|
960
|
+
# worksheet.protect()
|
961
|
+
#
|
962
|
+
# # This cell cannot be edited.
|
963
|
+
# worksheet.write('A1', '=1+2', locked)
|
964
|
+
#
|
965
|
+
# # This cell can be edited.
|
966
|
+
# worksheet.write('A2', '=1+2', unlocked)
|
967
|
+
#
|
968
|
+
# Note: This offers weak protection even with a password, see the note
|
969
|
+
# in relation to the protect() method.
|
970
|
+
#
|
971
|
+
def set_locked(arg = 1)
|
972
|
+
begin
|
973
|
+
if arg == 0 then @locked = 0
|
974
|
+
elsif arg == 1 then @locked = 1
|
975
|
+
else
|
976
|
+
raise ArgumentError,
|
977
|
+
"\n\n set_locked(#{arg.inspect})\n arg must be 0, 1, or none.\n"
|
978
|
+
" ( 0:OFF, 1 and none:Lock On )\n"
|
979
|
+
end
|
980
|
+
end
|
981
|
+
end
|
982
|
+
|
983
|
+
#
|
984
|
+
# hide a formula while still displaying its result.
|
985
|
+
#
|
986
|
+
# Default state: Formula hiding is off
|
987
|
+
# Default action: Turn hiding on
|
988
|
+
# Valid args: 0, 1
|
989
|
+
#
|
990
|
+
# This property is used to hide a formula while still displaying
|
991
|
+
# its result. This is generally used to hide complex calculations
|
992
|
+
# from end users who are only interested in the result. It only has
|
993
|
+
# an effect if the worksheet has been protected,
|
994
|
+
# see the worksheet protect() method.
|
995
|
+
#
|
996
|
+
# hidden = workbook.add_format
|
997
|
+
# hidden.set_hidden
|
998
|
+
#
|
999
|
+
# # Enable worksheet protection
|
1000
|
+
# worksheet.protect
|
1001
|
+
#
|
1002
|
+
# # The formula in this cell isn't visible
|
1003
|
+
# worksheet.write('A1', '=1+2', hidden)
|
1004
|
+
#
|
1005
|
+
# Note: This offers weak protection even with a password,
|
1006
|
+
# see the note in relation to the protect() method .
|
1007
|
+
#
|
1008
|
+
def set_hidden(arg = 1)
|
1009
|
+
begin
|
1010
|
+
if arg == 0 then @hidden = 0
|
1011
|
+
elsif arg == 1 then @hidden = 1
|
1012
|
+
else
|
1013
|
+
raise ArgumentError,
|
1014
|
+
"\n\n set_hidden(#{arg.inspect})\n arg must be 0, 1, or none.\n"
|
1015
|
+
" ( 0:OFF, 1 and none:hiding On )\n"
|
1016
|
+
end
|
1017
|
+
end
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
#
|
1021
|
+
# Set cell alignment.
|
1022
|
+
#
|
1023
|
+
# Default state: Alignment is off
|
1024
|
+
# Default action: Left alignment
|
1025
|
+
# Valid args: 'left' Horizontal
|
1026
|
+
# 'center'
|
1027
|
+
# 'right'
|
1028
|
+
# 'fill'
|
1029
|
+
# 'justify'
|
1030
|
+
# 'center_across'
|
1031
|
+
#
|
1032
|
+
# 'top' Vertical
|
1033
|
+
# 'vcenter'
|
1034
|
+
# 'bottom'
|
1035
|
+
# 'vjustify'
|
1036
|
+
#
|
1037
|
+
# This method is used to set the horizontal and vertical text alignment
|
1038
|
+
# within a cell. Vertical and horizontal alignments can be combined.
|
1039
|
+
# The method is used as follows:
|
1040
|
+
#
|
1041
|
+
# format = workbook.add_format
|
1042
|
+
# format->set_align('center')
|
1043
|
+
# format->set_align('vcenter')
|
1044
|
+
# worksheet->set_row(0, 30)
|
1045
|
+
# worksheet->write(0, 0, 'X', format)
|
1046
|
+
#
|
1047
|
+
# Text can be aligned across two or more adjacent cells using
|
1048
|
+
# the center_across property. However, for genuine merged cells
|
1049
|
+
# it is better to use the merge_range() worksheet method.
|
1050
|
+
#
|
1051
|
+
# The vjustify (vertical justify) option can be used to provide
|
1052
|
+
# automatic text wrapping in a cell. The height of the cell will be
|
1053
|
+
# adjusted to accommodate the wrapped text. To specify where the text
|
1054
|
+
# wraps use the set_text_wrap() method.
|
1055
|
+
#
|
1056
|
+
# For further examples see the 'Alignment' worksheet created by formats.rb.
|
1057
|
+
#
|
1058
|
+
def set_align(align = 'left')
|
1059
|
+
|
1060
|
+
return unless align.kind_of?(String)
|
1061
|
+
|
1062
|
+
location = align.downcase
|
1063
|
+
|
1064
|
+
case location
|
1065
|
+
when 'left' then set_text_h_align(1)
|
1066
|
+
when 'centre', 'center' then set_text_h_align(2)
|
1067
|
+
when 'right' then set_text_h_align(3)
|
1068
|
+
when 'fill' then set_text_h_align(4)
|
1069
|
+
when 'justify' then set_text_h_align(5)
|
1070
|
+
when 'center_across', 'centre_across' then set_text_h_align(6)
|
1071
|
+
when 'merge' then set_text_h_align(6) # S:WE name
|
1072
|
+
when 'distributed' then set_text_h_align(7)
|
1073
|
+
when 'equal_space' then set_text_h_align(7) # ParseExcel
|
1074
|
+
|
1075
|
+
when 'top' then set_text_v_align(0)
|
1076
|
+
when 'vcentre' then set_text_v_align(1)
|
1077
|
+
when 'vcenter' then set_text_v_align(1)
|
1078
|
+
when 'bottom' then set_text_v_align(2)
|
1079
|
+
when 'vjustify' then set_text_v_align(3)
|
1080
|
+
when 'vdistributed' then set_text_v_align(4)
|
1081
|
+
when 'vequal_space' then set_text_v_align(4) # ParseExcel
|
1082
|
+
end
|
1083
|
+
end
|
1084
|
+
|
1085
|
+
###############################################################################
|
1086
|
+
#
|
1087
|
+
# set_valign()
|
1088
|
+
#
|
1089
|
+
# Set vertical cell alignment. This is required by the set_format_properties()
|
1090
|
+
# method to differentiate between the vertical and horizontal properties.
|
1091
|
+
#
|
1092
|
+
def set_valign(alignment) # :nodoc:
|
1093
|
+
set_align(alignment);
|
1094
|
+
end
|
1095
|
+
|
1096
|
+
#
|
1097
|
+
# Implements the Excel5 style "merge".
|
1098
|
+
#
|
1099
|
+
# Default state: Center across selection is off
|
1100
|
+
# Default action: Turn center across on
|
1101
|
+
# Valid args: 1
|
1102
|
+
#
|
1103
|
+
# Text can be aligned across two or more adjacent cells using the
|
1104
|
+
# set_center_across() method. This is an alias for the
|
1105
|
+
# set_align('center_across') method call.
|
1106
|
+
#
|
1107
|
+
# Only one cell should contain the text, the other cells should be blank:
|
1108
|
+
#
|
1109
|
+
# format = workbook.add_format
|
1110
|
+
# format.set_center_across
|
1111
|
+
#
|
1112
|
+
# worksheet.write(1, 1, 'Center across selection', format)
|
1113
|
+
# worksheet.write_blank(1, 2, format)
|
1114
|
+
#
|
1115
|
+
# See also the merge1.pl to merge6.rb programs in the examples directory and
|
1116
|
+
# the merge_range() method.
|
1117
|
+
#
|
1118
|
+
def set_center_across(arg = 1)
|
1119
|
+
set_text_h_align(6)
|
1120
|
+
end
|
1121
|
+
|
1122
|
+
###############################################################################
|
1123
|
+
#
|
1124
|
+
# set_merge()
|
1125
|
+
#
|
1126
|
+
# This was the way to implement a merge in Excel5. However it should have been
|
1127
|
+
# called "center_across" and not "merge".
|
1128
|
+
# This is now deprecated. Use set_center_across() or better merge_range().
|
1129
|
+
#
|
1130
|
+
#
|
1131
|
+
def set_merge(val=true) # :nodoc:
|
1132
|
+
set_text_h_align(6)
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
#
|
1136
|
+
# Default state: Text wrap is off
|
1137
|
+
# Default action: Turn text wrap on
|
1138
|
+
# Valid args: 0, 1
|
1139
|
+
#
|
1140
|
+
# Here is an example using the text wrap property, the escape
|
1141
|
+
# character \n is used to indicate the end of line:
|
1142
|
+
#
|
1143
|
+
# format = workbook.add_format()
|
1144
|
+
# format.set_text_wrap()
|
1145
|
+
# worksheet.write(0, 0, "It's\na bum\nwrap", format)
|
1146
|
+
#
|
1147
|
+
def set_text_wrap(arg = 1)
|
1148
|
+
begin
|
1149
|
+
if arg == 0 then @text_wrap = 0
|
1150
|
+
elsif arg == 1 then @text_wrap = 1
|
1151
|
+
else
|
1152
|
+
raise ArgumentError,
|
1153
|
+
"\n\n set_text_wrap(#{arg.inspect})\n arg must be 0, 1, or none.\n"
|
1154
|
+
" ( 0:OFF, 1 and none:text wrap On )\n"
|
1155
|
+
end
|
1156
|
+
end
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
#
|
1160
|
+
# Set cells borders to the same style
|
1161
|
+
#
|
1162
|
+
# Also applies to: set_bottom()
|
1163
|
+
# set_top()
|
1164
|
+
# set_left()
|
1165
|
+
# set_right()
|
1166
|
+
#
|
1167
|
+
# Default state: Border is off
|
1168
|
+
# Default action: Set border type 1
|
1169
|
+
# Valid args: 0-13, See below.
|
1170
|
+
#
|
1171
|
+
# A cell border is comprised of a border on the bottom, top, left and right.
|
1172
|
+
# These can be set to the same value using set_border() or individually
|
1173
|
+
# using the relevant method calls shown above.
|
1174
|
+
#
|
1175
|
+
# The following shows the border styles sorted by WriteExcel index number:
|
1176
|
+
#
|
1177
|
+
# Index Name Weight Style
|
1178
|
+
# ===== ============= ====== ===========
|
1179
|
+
# 0 None 0
|
1180
|
+
# 1 Continuous 1 -----------
|
1181
|
+
# 2 Continuous 2 -----------
|
1182
|
+
# 3 Dash 1 - - - - - -
|
1183
|
+
# 4 Dot 1 . . . . . .
|
1184
|
+
# 5 Continuous 3 -----------
|
1185
|
+
# 6 Double 3 ===========
|
1186
|
+
# 7 Continuous 0 -----------
|
1187
|
+
# 8 Dash 2 - - - - - -
|
1188
|
+
# 9 Dash Dot 1 - . - . - .
|
1189
|
+
# 10 Dash Dot 2 - . - . - .
|
1190
|
+
# 11 Dash Dot Dot 1 - . . - . .
|
1191
|
+
# 12 Dash Dot Dot 2 - . . - . .
|
1192
|
+
# 13 SlantDash Dot 2 / - . / - .
|
1193
|
+
#
|
1194
|
+
# The following shows the borders sorted by style:
|
1195
|
+
#
|
1196
|
+
# Name Weight Style Index
|
1197
|
+
# ============= ====== =========== =====
|
1198
|
+
# Continuous 0 ----------- 7
|
1199
|
+
# Continuous 1 ----------- 1
|
1200
|
+
# Continuous 2 ----------- 2
|
1201
|
+
# Continuous 3 ----------- 5
|
1202
|
+
# Dash 1 - - - - - - 3
|
1203
|
+
# Dash 2 - - - - - - 8
|
1204
|
+
# Dash Dot 1 - . - . - . 9
|
1205
|
+
# Dash Dot 2 - . - . - . 10
|
1206
|
+
# Dash Dot Dot 1 - . . - . . 11
|
1207
|
+
# Dash Dot Dot 2 - . . - . . 12
|
1208
|
+
# Dot 1 . . . . . . 4
|
1209
|
+
# Double 3 =========== 6
|
1210
|
+
# None 0 0
|
1211
|
+
# SlantDash Dot 2 / - . / - . 13
|
1212
|
+
#
|
1213
|
+
# The following shows the borders in the order shown in the Excel Dialog.
|
1214
|
+
#
|
1215
|
+
# Index Style Index Style
|
1216
|
+
# ===== ===== ===== =====
|
1217
|
+
# 0 None 12 - . . - . .
|
1218
|
+
# 7 ----------- 13 / - . / - .
|
1219
|
+
# 4 . . . . . . 10 - . - . - .
|
1220
|
+
# 11 - . . - . . 8 - - - - - -
|
1221
|
+
# 9 - . - . - . 2 -----------
|
1222
|
+
# 3 - - - - - - 5 -----------
|
1223
|
+
# 1 ----------- 6 ===========
|
1224
|
+
#
|
1225
|
+
# Examples of the available border styles are shown in the 'Borders' worksheet
|
1226
|
+
# created by formats.rb.
|
1227
|
+
#
|
1228
|
+
def set_border(style)
|
1229
|
+
set_bottom(style)
|
1230
|
+
set_top(style)
|
1231
|
+
set_left(style)
|
1232
|
+
set_right(style)
|
1233
|
+
end
|
1234
|
+
|
1235
|
+
#
|
1236
|
+
# set bottom border of the cell.
|
1237
|
+
# see set_border() about style.
|
1238
|
+
#
|
1239
|
+
def set_bottom(style)
|
1240
|
+
@bottom = style
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
#
|
1244
|
+
# set top border of the cell.
|
1245
|
+
# see set_border() about style.
|
1246
|
+
#
|
1247
|
+
def set_top(style)
|
1248
|
+
@top = style
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
#
|
1252
|
+
# set left border of the cell.
|
1253
|
+
# see set_border() about style.
|
1254
|
+
#
|
1255
|
+
def set_left(style)
|
1256
|
+
@left = style
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
#
|
1260
|
+
# set right border of the cell.
|
1261
|
+
# see set_border() about style.
|
1262
|
+
#
|
1263
|
+
def set_right(style)
|
1264
|
+
@right = style
|
1265
|
+
end
|
1266
|
+
|
1267
|
+
#
|
1268
|
+
# Set cells border to the same color
|
1269
|
+
#
|
1270
|
+
# Also applies to: set_bottom_color()
|
1271
|
+
# set_top_color()
|
1272
|
+
# set_left_color()
|
1273
|
+
# set_right_color()
|
1274
|
+
#
|
1275
|
+
# Default state: Color is off
|
1276
|
+
# Default action: Undefined
|
1277
|
+
# Valid args: See set_color()
|
1278
|
+
#
|
1279
|
+
# Set the colour of the cell borders. A cell border is comprised of a border
|
1280
|
+
# on the bottom, top, left and right. These can be set to the same colour
|
1281
|
+
# using set_border_color() or individually using the relevant method calls
|
1282
|
+
# shown above. Examples of the border styles and colours are shown in the
|
1283
|
+
# 'Borders' worksheet created by formats.rb.
|
1284
|
+
#
|
1285
|
+
def set_border_color(color)
|
1286
|
+
set_bottom_color(color);
|
1287
|
+
set_top_color(color);
|
1288
|
+
set_left_color(color);
|
1289
|
+
set_right_color(color);
|
1290
|
+
end
|
1291
|
+
|
1292
|
+
#
|
1293
|
+
# set bottom border color of the cell.
|
1294
|
+
# see set_border_color() about color.
|
1295
|
+
#
|
1296
|
+
def set_bottom_color(color)
|
1297
|
+
@bottom_color = get_color(color)
|
1298
|
+
end
|
1299
|
+
|
1300
|
+
#
|
1301
|
+
# set top border color of the cell.
|
1302
|
+
# see set_border_color() about color.
|
1303
|
+
#
|
1304
|
+
def set_top_color(color)
|
1305
|
+
@top_color = get_color(color)
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
#
|
1309
|
+
# set left border color of the cell.
|
1310
|
+
# see set_border_color() about color.
|
1311
|
+
#
|
1312
|
+
def set_left_color(color)
|
1313
|
+
@left_color = get_color(color)
|
1314
|
+
end
|
1315
|
+
|
1316
|
+
#
|
1317
|
+
# set right border color of the cell.
|
1318
|
+
# see set_border_color() about color.
|
1319
|
+
#
|
1320
|
+
def set_right_color(color)
|
1321
|
+
@right_color = get_color(color)
|
1322
|
+
end
|
1323
|
+
|
1324
|
+
#
|
1325
|
+
# Set the rotation angle of the text. An alignment property.
|
1326
|
+
#
|
1327
|
+
# Default state: Text rotation is off
|
1328
|
+
# Default action: None
|
1329
|
+
# Valid args: Integers in the range -90 to 90 and 270
|
1330
|
+
#
|
1331
|
+
# Set the rotation of the text in a cell. The rotation can be any angle in
|
1332
|
+
# the range -90 to 90 degrees.
|
1333
|
+
#
|
1334
|
+
# format = workbook.add_format
|
1335
|
+
# format.set_rotation(30)
|
1336
|
+
# worksheet.write(0, 0, 'This text is rotated', format)
|
1337
|
+
#
|
1338
|
+
# The angle 270 is also supported. This indicates text where the letters run
|
1339
|
+
# from top to bottom.
|
1340
|
+
#
|
1341
|
+
def set_rotation(rotation)
|
1342
|
+
# Argument should be a number
|
1343
|
+
return unless rotation.kind_of?(Numeric)
|
1344
|
+
|
1345
|
+
# The arg type can be a double but the Excel dialog only allows integers.
|
1346
|
+
rotation = rotation.to_i
|
1347
|
+
|
1348
|
+
# if (rotation == 270)
|
1349
|
+
# rotation = 255
|
1350
|
+
# elsif (rotation >= -90 or rotation <= 90)
|
1351
|
+
# rotation = -rotation +90 if rotation < 0;
|
1352
|
+
# else
|
1353
|
+
# # carp "Rotation $rotation outside range: -90 <= angle <= 90";
|
1354
|
+
# rotation = 0;
|
1355
|
+
# end
|
1356
|
+
#
|
1357
|
+
if rotation == 270
|
1358
|
+
rotation = 255
|
1359
|
+
elsif rotation >= -90 && rotation <= 90
|
1360
|
+
rotation = -rotation + 90 if rotation < 0
|
1361
|
+
else
|
1362
|
+
rotation = 0
|
1363
|
+
end
|
1364
|
+
|
1365
|
+
@rotation = rotation;
|
1366
|
+
end
|
1367
|
+
|
1368
|
+
|
1369
|
+
#
|
1370
|
+
# :call-seq:
|
1371
|
+
# set_format_properties( :bold => 1 [, :color => 'red'..] )
|
1372
|
+
# set_format_properties( font [, shade, ..])
|
1373
|
+
# set_format_properties( :bold => 1, font, ...)
|
1374
|
+
# *) font = { :color => 'red', :bold => 1 }
|
1375
|
+
# shade = { :bg_color => 'green', :pattern => 1 }
|
1376
|
+
#
|
1377
|
+
# Convert hashes of properties to method calls.
|
1378
|
+
#
|
1379
|
+
# The properties of an existing Format object can be also be set by means
|
1380
|
+
# of set_format_properties():
|
1381
|
+
#
|
1382
|
+
# format = workbook.add_format
|
1383
|
+
# format.set_format_properties(:bold => 1, :color => 'red');
|
1384
|
+
#
|
1385
|
+
# However, this method is here mainly for legacy reasons. It is preferable
|
1386
|
+
# to set the properties in the format constructor:
|
1387
|
+
#
|
1388
|
+
# format = workbook.add_format(:bold => 1, :color => 'red');
|
1389
|
+
#
|
1390
|
+
def set_format_properties(*properties) # :nodoc:
|
1391
|
+
return if properties.empty?
|
1392
|
+
properties.each do |property|
|
1393
|
+
property.each do |key, value|
|
1394
|
+
# Strip leading "-" from Tk style properties e.g. -color => 'red'.
|
1395
|
+
key.sub!(/^-/, '') if key.kind_of?(String)
|
1396
|
+
|
1397
|
+
# Create a sub to set the property.
|
1398
|
+
if value.kind_of?(String)
|
1399
|
+
s = "set_#{key}('#{value}')"
|
1400
|
+
else
|
1401
|
+
s = "set_#{key}(#{value})"
|
1402
|
+
end
|
1403
|
+
eval s
|
1404
|
+
end
|
1405
|
+
end
|
1406
|
+
end
|
1407
|
+
|
1408
|
+
#
|
1409
|
+
# Default state: Font is Arial
|
1410
|
+
# Default action: None
|
1411
|
+
# Valid args: Any valid font name
|
1412
|
+
#
|
1413
|
+
# Specify the font used:
|
1414
|
+
#
|
1415
|
+
# format.set_font('Times New Roman');
|
1416
|
+
#
|
1417
|
+
# Excel can only display fonts that are installed on the system that it is
|
1418
|
+
# running on. Therefore it is best to use the fonts that come as standard
|
1419
|
+
# such as 'Arial', 'Times New Roman' and 'Courier New'. See also the Fonts
|
1420
|
+
# worksheet created by formats.rb
|
1421
|
+
#
|
1422
|
+
def set_font(fontname)
|
1423
|
+
@font = fontname
|
1424
|
+
end
|
1425
|
+
|
1426
|
+
#
|
1427
|
+
# This method is used to define the numerical format of a number in Excel.
|
1428
|
+
#
|
1429
|
+
# Default state: General format
|
1430
|
+
# Default action: Format index 1
|
1431
|
+
# Valid args: See the following table
|
1432
|
+
#
|
1433
|
+
# It controls whether a number is displayed as an integer, a floating point
|
1434
|
+
# number, a date, a currency value or some other user defined format.
|
1435
|
+
#
|
1436
|
+
# The numerical format of a cell can be specified by using a format string
|
1437
|
+
# or an index to one of Excel's built-in formats:
|
1438
|
+
#
|
1439
|
+
# format1 = workbook.add_format
|
1440
|
+
# format2 = workbook.add_format
|
1441
|
+
# format1.set_num_format('d mmm yyyy') # Format string
|
1442
|
+
# format2.set_num_format(0x0f) # Format index
|
1443
|
+
#
|
1444
|
+
# worksheet.write(0, 0, 36892.521, format1) # 1 Jan 2001
|
1445
|
+
# worksheet.write(0, 0, 36892.521, format2) # 1-Jan-01
|
1446
|
+
#
|
1447
|
+
# Using format strings you can define very sophisticated formatting of
|
1448
|
+
# numbers.
|
1449
|
+
#
|
1450
|
+
# format01.set_num_format('0.000')
|
1451
|
+
# worksheet.write(0, 0, 3.1415926, format01) # 3.142
|
1452
|
+
#
|
1453
|
+
# format02.set_num_format('#,##0')
|
1454
|
+
# worksheet.write(1, 0, 1234.56, format02) # 1,235
|
1455
|
+
#
|
1456
|
+
# format03.set_num_format('#,##0.00')
|
1457
|
+
# worksheet.write(2, 0, 1234.56, format03) # 1,234.56
|
1458
|
+
#
|
1459
|
+
# format04.set_num_format('0.00')
|
1460
|
+
# worksheet.write(3, 0, 49.99, format04) # 49.99
|
1461
|
+
#
|
1462
|
+
# # Note you can use other currency symbols such as the pound or yen as well.
|
1463
|
+
# # Other currencies may require the use of Unicode.
|
1464
|
+
#
|
1465
|
+
# format07.set_num_format('mm/dd/yy')
|
1466
|
+
# worksheet.write(6, 0, 36892.521, format07) # 01/01/01
|
1467
|
+
#
|
1468
|
+
# format08.set_num_format('mmm d yyyy')
|
1469
|
+
# worksheet.write(7, 0, 36892.521, format08) # Jan 1 2001
|
1470
|
+
#
|
1471
|
+
# format09.set_num_format('d mmmm yyyy')
|
1472
|
+
# worksheet.write(8, 0, 36892.521, format09) # 1 January 2001
|
1473
|
+
#
|
1474
|
+
# format10.set_num_format('dd/mm/yyyy hh:mm AM/PM')
|
1475
|
+
# worksheet.write(9, 0, 36892.521, format10) # 01/01/2001 12:30 AM
|
1476
|
+
#
|
1477
|
+
# format11.set_num_format('0 "dollar and" .00 "cents"')
|
1478
|
+
# worksheet.write(10, 0, 1.87, format11) # 1 dollar and .87 cents
|
1479
|
+
#
|
1480
|
+
# # Conditional formatting
|
1481
|
+
# format12.set_num_format('[Green]General;[Red]-General;General')
|
1482
|
+
# worksheet.write(11, 0, 123, format12) # > 0 Green
|
1483
|
+
# worksheet.write(12, 0, -45, format12) # < 0 Red
|
1484
|
+
# worksheet.write(13, 0, 0, format12) # = 0 Default colour
|
1485
|
+
#
|
1486
|
+
# # Zip code
|
1487
|
+
# format13.set_num_format('00000')
|
1488
|
+
# worksheet.write(14, 0, '01209', format13)
|
1489
|
+
#
|
1490
|
+
# The number system used for dates is described in "DATES AND TIME IN EXCEL".
|
1491
|
+
#
|
1492
|
+
# The colour format should have one of the following values:
|
1493
|
+
#
|
1494
|
+
# [Black] [Blue] [Cyan] [Green] [Magenta] [Red] [White] [Yellow]
|
1495
|
+
#
|
1496
|
+
# Alternatively you can specify the colour based on a colour index as follows:
|
1497
|
+
# [Color n], where n is a standard Excel colour index - 7. See the
|
1498
|
+
# 'Standard colors' worksheet created by formats.rb.
|
1499
|
+
#
|
1500
|
+
# For more information refer to the documentation on formatting in the doc
|
1501
|
+
# directory of the WriteExcel distro, the Excel on-line help or
|
1502
|
+
# http://office.microsoft.com/en-gb/assistance/HP051995001033.aspx
|
1503
|
+
#
|
1504
|
+
# You should ensure that the format string is valid in Excel prior to using
|
1505
|
+
# it in WriteExcel.
|
1506
|
+
#
|
1507
|
+
# Excel's built-in formats are shown in the following table:
|
1508
|
+
#
|
1509
|
+
# Index Index Format String
|
1510
|
+
# 0 0x00 General
|
1511
|
+
# 1 0x01 0
|
1512
|
+
# 2 0x02 0.00
|
1513
|
+
# 3 0x03 #,##0
|
1514
|
+
# 4 0x04 #,##0.00
|
1515
|
+
# 5 0x05 ($#,##0_);($#,##0)
|
1516
|
+
# 6 0x06 ($#,##0_);[Red]($#,##0)
|
1517
|
+
# 7 0x07 ($#,##0.00_);($#,##0.00)
|
1518
|
+
# 8 0x08 ($#,##0.00_);[Red]($#,##0.00)
|
1519
|
+
# 9 0x09 0%
|
1520
|
+
# 10 0x0a 0.00%
|
1521
|
+
# 11 0x0b 0.00E+00
|
1522
|
+
# 12 0x0c # ?/?
|
1523
|
+
# 13 0x0d # ??/??
|
1524
|
+
# 14 0x0e m/d/yy
|
1525
|
+
# 15 0x0f d-mmm-yy
|
1526
|
+
# 16 0x10 d-mmm
|
1527
|
+
# 17 0x11 mmm-yy
|
1528
|
+
# 18 0x12 h:mm AM/PM
|
1529
|
+
# 19 0x13 h:mm:ss AM/PM
|
1530
|
+
# 20 0x14 h:mm
|
1531
|
+
# 21 0x15 h:mm:ss
|
1532
|
+
# 22 0x16 m/d/yy h:mm
|
1533
|
+
# .. .... ...........
|
1534
|
+
# 37 0x25 (#,##0_);(#,##0)
|
1535
|
+
# 38 0x26 (#,##0_);[Red](#,##0)
|
1536
|
+
# 39 0x27 (#,##0.00_);(#,##0.00)
|
1537
|
+
# 40 0x28 (#,##0.00_);[Red](#,##0.00)
|
1538
|
+
# 41 0x29 _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)
|
1539
|
+
# 42 0x2a _($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)
|
1540
|
+
# 43 0x2b _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)
|
1541
|
+
# 44 0x2c _($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)
|
1542
|
+
# 45 0x2d mm:ss
|
1543
|
+
# 46 0x2e [h]:mm:ss
|
1544
|
+
# 47 0x2f mm:ss.0
|
1545
|
+
# 48 0x30 ##0.0E+0
|
1546
|
+
# 49 0x31 @
|
1547
|
+
#
|
1548
|
+
# For examples of these formatting codes see the 'Numerical formats' worksheet
|
1549
|
+
# created by formats.rb.
|
1550
|
+
#--
|
1551
|
+
# See also the number_formats1.html and the number_formats2.html documents in
|
1552
|
+
# the doc directory of the distro.
|
1553
|
+
#++
|
1554
|
+
#
|
1555
|
+
# Note 1. Numeric formats 23 to 36 are not documented by Microsoft and may
|
1556
|
+
# differ in international versions.
|
1557
|
+
#
|
1558
|
+
# Note 2. In Excel 5 the dollar sign appears as a dollar sign. In Excel
|
1559
|
+
# 97-2000 it appears as the defined local currency symbol.
|
1560
|
+
#
|
1561
|
+
# Note 3. The red negative numeric formats display slightly differently in
|
1562
|
+
# Excel 5 and Excel 97-2000.
|
1563
|
+
#
|
1564
|
+
def set_num_format(num_format)
|
1565
|
+
@num_format = num_format
|
1566
|
+
end
|
1567
|
+
|
1568
|
+
#
|
1569
|
+
# This method can be used to indent text. The argument, which should be an
|
1570
|
+
# integer, is taken as the level of indentation:
|
1571
|
+
#
|
1572
|
+
# Default state: Text indentation is off
|
1573
|
+
# Default action: Indent text 1 level
|
1574
|
+
# Valid args: Positive integers
|
1575
|
+
#
|
1576
|
+
# format = workbook.add_format
|
1577
|
+
# format.set_indent(2)
|
1578
|
+
# worksheet.write(0, 0, 'This text is indented', format)
|
1579
|
+
#
|
1580
|
+
# Indentation is a horizontal alignment property. It will override any
|
1581
|
+
# other horizontal properties but it can be used in conjunction with
|
1582
|
+
# vertical properties.
|
1583
|
+
#
|
1584
|
+
def set_indent(indent = 1)
|
1585
|
+
@indent = indent
|
1586
|
+
end
|
1587
|
+
|
1588
|
+
#
|
1589
|
+
# This method can be used to shrink text so that it fits in a cell.
|
1590
|
+
#
|
1591
|
+
# Default state: Text shrinking is off
|
1592
|
+
# Default action: Turn "shrink to fit" on
|
1593
|
+
# Valid args: 1
|
1594
|
+
#
|
1595
|
+
# format = workbook.add_format
|
1596
|
+
# format.set_shrink
|
1597
|
+
# worksheet.write(0, 0, 'Honey, I shrunk the text!', format)
|
1598
|
+
#
|
1599
|
+
def set_shrink(arg = 1)
|
1600
|
+
@shrink = 1
|
1601
|
+
end
|
1602
|
+
|
1603
|
+
#
|
1604
|
+
# Default state: Justify last is off
|
1605
|
+
# Default action: Turn justify last on
|
1606
|
+
# Valid args: 0, 1
|
1607
|
+
#
|
1608
|
+
# Only applies to Far Eastern versions of Excel.
|
1609
|
+
#
|
1610
|
+
def set_text_justlast(arg = 1)
|
1611
|
+
@text_justlast = 1
|
1612
|
+
end
|
1613
|
+
|
1614
|
+
#
|
1615
|
+
# Default state: Pattern is off
|
1616
|
+
# Default action: Solid fill is on
|
1617
|
+
# Valid args: 0 .. 18
|
1618
|
+
#
|
1619
|
+
# Set the background pattern of a cell.
|
1620
|
+
#
|
1621
|
+
# Examples of the available patterns are shown in the 'Patterns' worksheet
|
1622
|
+
# created by formats.rb. However, it is unlikely that you will ever need
|
1623
|
+
# anything other than Pattern 1 which is a solid fill of the background color.
|
1624
|
+
#
|
1625
|
+
def set_pattern(pattern = 1)
|
1626
|
+
@pattern = pattern
|
1627
|
+
end
|
1628
|
+
|
1629
|
+
#
|
1630
|
+
# The set_bg_color() method can be used to set the background colour of a
|
1631
|
+
# pattern. Patterns are defined via the set_pattern() method. If a pattern
|
1632
|
+
# hasn't been defined then a solid fill pattern is used as the default.
|
1633
|
+
#
|
1634
|
+
# Default state: Color is off
|
1635
|
+
# Default action: Solid fill.
|
1636
|
+
# Valid args: See set_color()
|
1637
|
+
#
|
1638
|
+
# Here is an example of how to set up a solid fill in a cell:
|
1639
|
+
#
|
1640
|
+
# format = workbook.add_format
|
1641
|
+
#
|
1642
|
+
# format.set_pattern() # This is optional when using a solid fill
|
1643
|
+
#
|
1644
|
+
# format.set_bg_color('green')
|
1645
|
+
# worksheet.write('A1', 'Ray', format)
|
1646
|
+
#
|
1647
|
+
# For further examples see the 'Patterns' worksheet created by formats.rb.
|
1648
|
+
#
|
1649
|
+
def set_bg_color(color = 0x41)
|
1650
|
+
@bg_color = get_color(color)
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
#
|
1654
|
+
# The set_fg_color() method can be used to set the foreground colour
|
1655
|
+
# of a pattern.
|
1656
|
+
#
|
1657
|
+
# Default state: Color is off
|
1658
|
+
# Default action: Solid fill.
|
1659
|
+
# Valid args: See set_color()
|
1660
|
+
#
|
1661
|
+
# For further examples see the 'Patterns' worksheet created by formats.rb.
|
1662
|
+
#
|
1663
|
+
def set_fg_color(color = 0x40)
|
1664
|
+
@fg_color = get_color(color)
|
1665
|
+
end
|
1666
|
+
|
1667
|
+
# Dynamically create set methods that aren't already defined.
|
1668
|
+
def method_missing(name, *args) # :nodoc:
|
1669
|
+
# -- original perl comment --
|
1670
|
+
# There are two types of set methods: set_property() and
|
1671
|
+
# set_property_color(). When a method is AUTOLOADED we store a new anonymous
|
1672
|
+
# sub in the appropriate slot in the symbol table. The speeds up subsequent
|
1673
|
+
# calls to the same method.
|
1674
|
+
|
1675
|
+
method = "#{name}"
|
1676
|
+
|
1677
|
+
# Check for a valid method names, i.e. "set_xxx_yyy".
|
1678
|
+
method =~ /set_(\w+)/ or raise "Unknown method: #{method}\n"
|
1679
|
+
|
1680
|
+
# Match the attribute, i.e. "@xxx_yyy".
|
1681
|
+
attribute = "@#{$1}"
|
1682
|
+
|
1683
|
+
# Check that the attribute exists
|
1684
|
+
# ........
|
1685
|
+
if method =~ /set\w+color$/ # for "set_property_color" methods
|
1686
|
+
value = get_color(args[0])
|
1687
|
+
else # for "set_xxx" methods
|
1688
|
+
value = args[0].nil? ? 1 : args[0]
|
1689
|
+
end
|
1690
|
+
if value.kind_of?(String)
|
1691
|
+
s = "#{attribute} = \"#{value.to_s}\""
|
1692
|
+
else
|
1693
|
+
s = "#{attribute} = #{value.to_s}"
|
1694
|
+
end
|
1695
|
+
eval s
|
1696
|
+
end
|
1697
|
+
end
|