1Spreadsheet::WriteExcelU:s:eErxaCmopnltersi(b3u)ted PerlSpDroecaudmsehneteatt:i:oWnriteExcel::Examples(3)
2
3
4
6 Examples - Spreadsheet::WriteExcel example programs.
7
9 This is a documentation only module showing the examples that are
10 included in the Spreadsheet::WriteExcel distribution.
11
12 This file was auto-generated via the gen_examples_pod.pl program that
13 is also included in the examples directory.
14
16 The following is a list of the 85 example programs that are included in
17 the Spreadsheet::WriteExcel distribution.
18
19 · "Example: a_simple.pl" A get started example with some basic
20 features.
21
22 · "Example: demo.pl" A demo of some of the available features.
23
24 · "Example: regions.pl" A simple example of multiple worksheets.
25
26 · "Example: stats.pl" Basic formulas and functions.
27
28 · "Example: formats.pl" All the available formatting on several
29 worksheets.
30
31 · "Example: bug_report.pl" A template for submitting bug reports.
32
33 · "Example: autofilter.pl" Examples of worksheet autofilters.
34
35 · "Example: autofit.pl" Simulate Excel's autofit for column widths.
36
37 · "Example: bigfile.pl" Write past the 7MB limit with
38 OLE::Storage_Lite.
39
40 · "Example: cgi.pl" A simple CGI program.
41
42 · "Example: chart_area.pl" A demo of area style charts.
43
44 · "Example: chart_bar.pl" A demo of bar (vertical histogram) style
45 charts.
46
47 · "Example: chart_column.pl" A demo of column (histogram) style
48 charts.
49
50 · "Example: chart_line.pl" A demo of line style charts.
51
52 · "Example: chart_pie.pl" A demo of pie style charts.
53
54 · "Example: chart_scatter.pl" A demo of scatter style charts.
55
56 · "Example: chart_stock.pl" A demo of stock style charts.
57
58 · "Example: chess.pl" An example of reusing formatting via
59 properties.
60
61 · "Example: colors.pl" A demo of the colour palette and named
62 colours.
63
64 · "Example: comments1.pl" Add comments to worksheet cells.
65
66 · "Example: comments2.pl" Add comments with advanced options.
67
68 · "Example: copyformat.pl" Example of copying a cell format.
69
70 · "Example: data_validate.pl" An example of data validation and
71 dropdown lists.
72
73 · "Example: date_time.pl" Write dates and times with
74 write_date_time().
75
76 · "Example: defined_name.pl" Example of how to create defined names.
77
78 · "Example: diag_border.pl" A simple example of diagonal cell
79 borders.
80
81 · "Example: easter_egg.pl" Expose the Excel97 flight simulator.
82
83 · "Example: filehandle.pl" Examples of working with filehandles.
84
85 · "Example: formula_result.pl" Formulas with user specified results.
86
87 · "Example: headers.pl" Examples of worksheet headers and footers.
88
89 · "Example: hide_sheet.pl" Simple example of hiding a worksheet.
90
91 · "Example: hyperlink1.pl" Shows how to create web hyperlinks.
92
93 · "Example: hyperlink2.pl" Examples of internal and external
94 hyperlinks.
95
96 · "Example: images.pl" Adding images to worksheets.
97
98 · "Example: indent.pl" An example of cell indentation.
99
100 · "Example: merge1.pl" A simple example of cell merging.
101
102 · "Example: merge2.pl" A simple example of cell merging with
103 formatting.
104
105 · "Example: merge3.pl" Add hyperlinks to merged cells.
106
107 · "Example: merge4.pl" An advanced example of merging with
108 formatting.
109
110 · "Example: merge5.pl" An advanced example of merging with
111 formatting.
112
113 · "Example: merge6.pl" An example of merging with Unicode strings.
114
115 · "Example: mod_perl1.pl" A simple mod_perl 1 program.
116
117 · "Example: mod_perl2.pl" A simple mod_perl 2 program.
118
119 · "Example: outline.pl" An example of outlines and grouping.
120
121 · "Example: outline_collapsed.pl" An example of collapsed outlines.
122
123 · "Example: panes.pl" An examples of how to create panes.
124
125 · "Example: properties.pl" Add document properties to a workbook.
126
127 · "Example: protection.pl" Example of cell locking and formula
128 hiding.
129
130 · "Example: repeat.pl" Example of writing repeated formulas.
131
132 · "Example: right_to_left.pl" Change default sheet direction to right
133 to left.
134
135 · "Example: row_wrap.pl" How to wrap data from one worksheet onto
136 another.
137
138 · "Example: sales.pl" An example of a simple sales spreadsheet.
139
140 · "Example: sendmail.pl" Send an Excel email attachment using
141 Mail::Sender.
142
143 · "Example: stats_ext.pl" Same as stats.pl with external references.
144
145 · "Example: stocks.pl" Demonstrates conditional formatting.
146
147 · "Example: tab_colors.pl" Example of how to set worksheet tab
148 colours.
149
150 · "Example: textwrap.pl" Demonstrates text wrapping options.
151
152 · "Example: win32ole.pl" A sample Win32::OLE example for comparison.
153
154 · "Example: write_arrays.pl" Example of writing 1D or 2D arrays of
155 data.
156
157 · "Example: write_handler1.pl" Example of extending the write()
158 method. Step 1.
159
160 · "Example: write_handler2.pl" Example of extending the write()
161 method. Step 2.
162
163 · "Example: write_handler3.pl" Example of extending the write()
164 method. Step 3.
165
166 · "Example: write_handler4.pl" Example of extending the write()
167 method. Step 4.
168
169 · "Example: write_to_scalar.pl" Example of writing an Excel file to a
170 Perl scalar.
171
172 · "Example: unicode_utf16.pl" Simple example of using Unicode UTF16
173 strings.
174
175 · "Example: unicode_utf16_japan.pl" Write Japanese Unicode strings
176 using UTF-16.
177
178 · "Example: unicode_cyrillic.pl" Write Russian Cyrillic strings using
179 UTF-8.
180
181 · "Example: unicode_list.pl" List the chars in a Unicode font.
182
183 · "Example: unicode_2022_jp.pl" Japanese: ISO-2022-JP to utf8 in perl
184 5.8.
185
186 · "Example: unicode_8859_11.pl" Thai: ISO-8859_11 to utf8 in perl
187 5.8.
188
189 · "Example: unicode_8859_7.pl" Greek: ISO-8859_7 to utf8 in perl
190 5.8.
191
192 · "Example: unicode_big5.pl" Chinese: BIG5 to utf8 in perl
193 5.8.
194
195 · "Example: unicode_cp1251.pl" Russian: CP1251 to utf8 in perl
196 5.8.
197
198 · "Example: unicode_cp1256.pl" Arabic: CP1256 to utf8 in perl
199 5.8.
200
201 · "Example: unicode_koi8r.pl" Russian: KOI8-R to utf8 in perl
202 5.8.
203
204 · "Example: unicode_polish_utf8.pl" Polish : UTF8 to utf8 in
205 perl 5.8.
206
207 · "Example: unicode_shift_jis.pl" Japanese: Shift JIS to utf8 in
208 perl 5.8.
209
210 · "Example: csv2xls.pl" Program to convert a CSV file to an Excel
211 file.
212
213 · "Example: tab2xls.pl" Program to convert a tab separated file to
214 xls.
215
216 · "Example: datecalc1.pl" Convert Unix/Perl time to Excel time.
217
218 · "Example: datecalc2.pl" Calculate an Excel date using Date::Calc.
219
220 · "Example: lecxe.pl" Convert Excel to WriteExcel using Win32::OLE.
221
222 · "Example: convertA1.pl" Helper functions for dealing with A1
223 notation.
224
225 · "Example: function_locale.pl" Add non-English function names to
226 Formula.pm.
227
228 · "Example: writeA1.pl" Example of how to extend the module.
229
230 Example: a_simple.pl
231 A simple example of how to use the Spreadsheet::WriteExcel module to
232 write some text and numbers to an Excel binary file.
233
234 Source code for this example:
235
236 #!/usr/bin/perl -w
237
238 ###############################################################################
239 #
240 # A simple example of how to use the Spreadsheet::WriteExcel module to write
241 # some text and numbers to an Excel binary file.
242 #
243 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
244 #
245
246 use strict;
247 use Spreadsheet::WriteExcel;
248
249 # Create a new workbook called simple.xls and add a worksheet
250 my $workbook = Spreadsheet::WriteExcel->new('a_simple.xls');
251 my $worksheet = $workbook->add_worksheet();
252
253 # The general syntax is write($row, $column, $token). Note that row and
254 # column are zero indexed
255 #
256
257 # Write some text
258 $worksheet->write(0, 0, "Hi Excel!");
259
260
261 # Write some numbers
262 $worksheet->write(2, 0, 3); # Writes 3
263 $worksheet->write(3, 0, 3.00000); # Writes 3
264 $worksheet->write(4, 0, 3.00001); # Writes 3.00001
265 $worksheet->write(5, 0, 3.14159); # TeX revision no.?
266
267
268 # Write some formulas
269 $worksheet->write(7, 0, '=A3 + A6');
270 $worksheet->write(8, 0, '=IF(A5>3,"Yes", "No")');
271
272
273 # Write a hyperlink
274 $worksheet->write(10, 0, 'http://www.perl.com/');
275
276 __END__
277
278 Download this example:
279 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/a_simple.pl
280 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
281 WriteExcel-2.36/examples/a_simple.pl>
282
283 Example: demo.pl
284 A simple demo of some of the features of Spreadsheet::WriteExcel.
285
286 This program is used to create the project screenshot for Freshmeat:
287 <http://freshmeat.net/projects/writeexcel/>
288
289 Source code for this example:
290
291 #!/usr/bin/perl -w
292
293 #######################################################################
294 #
295 # A simple demo of some of the features of Spreadsheet::WriteExcel.
296 #
297 # This program is used to create the project screenshot for Freshmeat:
298 # L<http://freshmeat.net/projects/writeexcel/>
299 #
300 # reverse('X'), October 2001, John McNamara, jmcnamara@cpan.org
301 #
302
303 use strict;
304 use Spreadsheet::WriteExcel;
305
306 my $workbook = Spreadsheet::WriteExcel->new("demo.xls");
307 my $worksheet = $workbook->add_worksheet('Demo');
308 my $worksheet2 = $workbook->add_worksheet('Another sheet');
309 my $worksheet3 = $workbook->add_worksheet('And another');
310
311 my $bold = $workbook->add_format(bold => 1);
312
313
314 #######################################################################
315 #
316 # Write a general heading
317 #
318 $worksheet->set_column('A:A', 36, $bold);
319 $worksheet->set_column('B:B', 20 );
320 $worksheet->set_row (0, 40 );
321
322 my $heading = $workbook->add_format(
323 bold => 1,
324 color => 'blue',
325 size => 16,
326 merge => 1,
327 align => 'vcenter',
328 );
329
330 my @headings = ('Features of Spreadsheet::WriteExcel', '');
331 $worksheet->write_row('A1', \@headings, $heading);
332
333
334 #######################################################################
335 #
336 # Some text examples
337 #
338 my $text_format = $workbook->add_format(
339 bold => 1,
340 italic => 1,
341 color => 'red',
342 size => 18,
343 font =>'Lucida Calligraphy'
344 );
345
346 # A phrase in Cyrillic
347 my $unicode = pack "H*", "042d0442043e002004440440043004370430002004".
348 "3d043000200440044304410441043a043e043c0021";
349
350
351 $worksheet->write('A2', "Text");
352 $worksheet->write('B2', "Hello Excel");
353 $worksheet->write('A3', "Formatted text");
354 $worksheet->write('B3', "Hello Excel", $text_format);
355 $worksheet->write('A4', "Unicode text");
356 $worksheet->write_utf16be_string('B4', $unicode);
357
358 #######################################################################
359 #
360 # Some numeric examples
361 #
362 my $num1_format = $workbook->add_format(num_format => '$#,##0.00');
363 my $num2_format = $workbook->add_format(num_format => ' d mmmm yyy');
364
365
366 $worksheet->write('A5', "Numbers");
367 $worksheet->write('B5', 1234.56);
368 $worksheet->write('A6', "Formatted numbers");
369 $worksheet->write('B6', 1234.56, $num1_format);
370 $worksheet->write('A7', "Formatted numbers");
371 $worksheet->write('B7', 37257, $num2_format);
372
373
374 #######################################################################
375 #
376 # Formulae
377 #
378 $worksheet->set_selection('B8');
379 $worksheet->write('A8', 'Formulas and functions, "=SIN(PI()/4)"');
380 $worksheet->write('B8', '=SIN(PI()/4)');
381
382
383 #######################################################################
384 #
385 # Hyperlinks
386 #
387 $worksheet->write('A9', "Hyperlinks");
388 $worksheet->write('B9', 'http://www.perl.com/' );
389
390
391 #######################################################################
392 #
393 # Images
394 #
395 $worksheet->write('A10', "Images");
396 $worksheet->insert_image('B10', 'republic.png', 16, 8);
397
398
399 #######################################################################
400 #
401 # Misc
402 #
403 $worksheet->write('A18', "Page/printer setup");
404 $worksheet->write('A19', "Multiple worksheets");
405
406 __END__
407
408 Download this example:
409 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/demo.pl
410 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
411 WriteExcel-2.36/examples/demo.pl>
412
413 Example: regions.pl
414 An example of how to use the Spreadsheet:WriteExcel module to write a
415 basic Excel workbook with multiple worksheets.
416
417 Source code for this example:
418
419 #!/usr/bin/perl -w
420
421 ###############################################################################
422 #
423 # An example of how to use the Spreadsheet:WriteExcel module to write a basic
424 # Excel workbook with multiple worksheets.
425 #
426 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
427 #
428
429 use strict;
430 use Spreadsheet::WriteExcel;
431
432 # Create a new Excel workbook
433 my $workbook = Spreadsheet::WriteExcel->new("regions.xls");
434
435 # Add some worksheets
436 my $north = $workbook->add_worksheet("North");
437 my $south = $workbook->add_worksheet("South");
438 my $east = $workbook->add_worksheet("East");
439 my $west = $workbook->add_worksheet("West");
440
441 # Add a Format
442 my $format = $workbook->add_format();
443 $format->set_bold();
444 $format->set_color('blue');
445
446 # Add a caption to each worksheet
447 foreach my $worksheet ($workbook->sheets()) {
448 $worksheet->write(0, 0, "Sales", $format);
449 }
450
451 # Write some data
452 $north->write(0, 1, 200000);
453 $south->write(0, 1, 100000);
454 $east->write (0, 1, 150000);
455 $west->write (0, 1, 100000);
456
457 # Set the active worksheet
458 $south->activate();
459
460 # Set the width of the first column
461 $south->set_column(0, 0, 20);
462
463 # Set the active cell
464 $south->set_selection(0, 1);
465
466 Download this example:
467 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/regions.pl
468 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
469 WriteExcel-2.36/examples/regions.pl>
470
471 Example: stats.pl
472 A simple example of how to use functions with the
473 Spreadsheet::WriteExcel module.
474
475 Source code for this example:
476
477 #!/usr/bin/perl -w
478
479 ###############################################################################
480 #
481 # A simple example of how to use functions with the Spreadsheet::WriteExcel
482 # module.
483 #
484 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
485 #
486
487 use strict;
488 use Spreadsheet::WriteExcel;
489
490 # Create a new workbook and add a worksheet
491 my $workbook = Spreadsheet::WriteExcel->new("stats.xls");
492 my $worksheet = $workbook->add_worksheet('Test data');
493
494 # Set the column width for columns 1
495 $worksheet->set_column(0, 0, 20);
496
497
498 # Create a format for the headings
499 my $format = $workbook->add_format();
500 $format->set_bold();
501
502
503 # Write the sample data
504 $worksheet->write(0, 0, 'Sample', $format);
505 $worksheet->write(0, 1, 1);
506 $worksheet->write(0, 2, 2);
507 $worksheet->write(0, 3, 3);
508 $worksheet->write(0, 4, 4);
509 $worksheet->write(0, 5, 5);
510 $worksheet->write(0, 6, 6);
511 $worksheet->write(0, 7, 7);
512 $worksheet->write(0, 8, 8);
513
514 $worksheet->write(1, 0, 'Length', $format);
515 $worksheet->write(1, 1, 25.4);
516 $worksheet->write(1, 2, 25.4);
517 $worksheet->write(1, 3, 24.8);
518 $worksheet->write(1, 4, 25.0);
519 $worksheet->write(1, 5, 25.3);
520 $worksheet->write(1, 6, 24.9);
521 $worksheet->write(1, 7, 25.2);
522 $worksheet->write(1, 8, 24.8);
523
524 # Write some statistical functions
525 $worksheet->write(4, 0, 'Count', $format);
526 $worksheet->write(4, 1, '=COUNT(B1:I1)');
527
528 $worksheet->write(5, 0, 'Sum', $format);
529 $worksheet->write(5, 1, '=SUM(B2:I2)');
530
531 $worksheet->write(6, 0, 'Average', $format);
532 $worksheet->write(6, 1, '=AVERAGE(B2:I2)');
533
534 $worksheet->write(7, 0, 'Min', $format);
535 $worksheet->write(7, 1, '=MIN(B2:I2)');
536
537 $worksheet->write(8, 0, 'Max', $format);
538 $worksheet->write(8, 1, '=MAX(B2:I2)');
539
540 $worksheet->write(9, 0, 'Standard Deviation', $format);
541 $worksheet->write(9, 1, '=STDEV(B2:I2)');
542
543 $worksheet->write(10, 0, 'Kurtosis', $format);
544 $worksheet->write(10, 1, '=KURT(B2:I2)');
545
546 __END__
547
548 Download this example:
549 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/stats.pl
550 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
551 WriteExcel-2.36/examples/stats.pl>
552
553 Example: formats.pl
554 Examples of formatting using the Spreadsheet::WriteExcel module.
555
556 This program demonstrates almost all possible formatting options. It is
557 worth running this program and viewing the output Excel file if you are
558 interested in the various formatting possibilities.
559
560 Source code for this example:
561
562 #!/usr/bin/perl -w
563
564 ###############################################################################
565 #
566 # Examples of formatting using the Spreadsheet::WriteExcel module.
567 #
568 # This program demonstrates almost all possible formatting options. It is worth
569 # running this program and viewing the output Excel file if you are interested
570 # in the various formatting possibilities.
571 #
572 # reverse('X'), September 2002, John McNamara, jmcnamara@cpan.org
573 #
574
575 use strict;
576 use Spreadsheet::WriteExcel;
577
578 my $workbook = Spreadsheet::WriteExcel->new('formats.xls');
579
580 # Some common formats
581 my $center = $workbook->add_format(align => 'center');
582 my $heading = $workbook->add_format(align => 'center', bold => 1);
583
584 # The named colors
585 my %colors = (
586 0x08, 'black',
587 0x0C, 'blue',
588 0x10, 'brown',
589 0x0F, 'cyan',
590 0x17, 'gray',
591 0x11, 'green',
592 0x0B, 'lime',
593 0x0E, 'magenta',
594 0x12, 'navy',
595 0x35, 'orange',
596 0x21, 'pink',
597 0x14, 'purple',
598 0x0A, 'red',
599 0x16, 'silver',
600 0x09, 'white',
601 0x0D, 'yellow',
602 );
603
604 # Call these subroutines to demonstrate different formatting options
605 intro();
606 fonts();
607 named_colors();
608 standard_colors();
609 numeric_formats();
610 borders();
611 patterns();
612 alignment();
613 misc();
614
615 # Note: this is required
616 $workbook->close();
617
618
619 ######################################################################
620 #
621 # Intro.
622 #
623 sub intro {
624
625 my $worksheet = $workbook->add_worksheet('Introduction');
626
627 $worksheet->set_column(0, 0, 60);
628
629 my $format = $workbook->add_format();
630 $format->set_bold();
631 $format->set_size(14);
632 $format->set_color('blue');
633 $format->set_align('center');
634
635 my $format2 = $workbook->add_format();
636 $format2->set_bold();
637 $format2->set_color('blue');
638
639 $worksheet->write(2, 0, 'This workbook demonstrates some of', $format);
640 $worksheet->write(3, 0, 'the formatting options provided by', $format);
641 $worksheet->write(4, 0, 'the Spreadsheet::WriteExcel module.', $format);
642
643 $worksheet->write('A7', 'Sections:', $format2);
644 $worksheet->write('A8', "internal:Fonts!A1", 'Fonts' );
645 $worksheet->write('A9', "internal:'Named colors'!A1", 'Named colors' );
646 $worksheet->write('A10', "internal:'Standard colors'!A1", 'Standard colors');
647 $worksheet->write('A11', "internal:'Numeric formats'!A1", 'Numeric formats');
648 $worksheet->write('A12', "internal:Borders!A1", 'Borders' );
649 $worksheet->write('A13', "internal:Patterns!A1", 'Patterns' );
650 $worksheet->write('A14', "internal:Alignment!A1", 'Alignment' );
651 $worksheet->write('A15', "internal:Miscellaneous!A1", 'Miscellaneous' );
652
653 }
654
655
656 ######################################################################
657 #
658 # Demonstrate the named colors.
659 #
660 sub named_colors {
661
662 my $worksheet = $workbook->add_worksheet('Named colors');
663
664 $worksheet->set_column(0, 3, 15);
665
666 $worksheet->write(0, 0, "Index", $heading);
667 $worksheet->write(0, 1, "Index", $heading);
668 $worksheet->write(0, 2, "Name", $heading);
669 $worksheet->write(0, 3, "Color", $heading);
670
671 my $i = 1;
672
673 while (my($index, $color) = each %colors) {
674 my $format = $workbook->add_format(
675 bg_color => $color,
676 pattern => 1,
677 border => 1
678 );
679
680 $worksheet->write($i+1, 0, $index, $center);
681 $worksheet->write($i+1, 1, sprintf("0x%02X", $index), $center);
682 $worksheet->write($i+1, 2, $color, $center);
683 $worksheet->write($i+1, 3, '', $format);
684 $i++;
685 }
686 }
687
688
689 ######################################################################
690 #
691 # Demonstrate the standard Excel colors in the range 8..63.
692 #
693 sub standard_colors {
694
695 my $worksheet = $workbook->add_worksheet('Standard colors');
696
697 $worksheet->set_column(0, 3, 15);
698
699 $worksheet->write(0, 0, "Index", $heading);
700 $worksheet->write(0, 1, "Index", $heading);
701 $worksheet->write(0, 2, "Color", $heading);
702 $worksheet->write(0, 3, "Name", $heading);
703
704 for my $i (8..63) {
705 my $format = $workbook->add_format(
706 bg_color => $i,
707 pattern => 1,
708 border => 1
709 );
710
711 $worksheet->write(($i -7), 0, $i, $center);
712 $worksheet->write(($i -7), 1, sprintf("0x%02X", $i), $center);
713 $worksheet->write(($i -7), 2, '', $format);
714
715 # Add the color names
716 if (exists $colors{$i}) {
717 $worksheet->write(($i -7), 3, $colors{$i}, $center);
718
719 }
720 }
721 }
722
723
724 ######################################################################
725 #
726 # Demonstrate the standard numeric formats.
727 #
728 sub numeric_formats {
729
730 my $worksheet = $workbook->add_worksheet('Numeric formats');
731
732 $worksheet->set_column(0, 4, 15);
733 $worksheet->set_column(5, 5, 45);
734
735 $worksheet->write(0, 0, "Index", $heading);
736 $worksheet->write(0, 1, "Index", $heading);
737 $worksheet->write(0, 2, "Unformatted", $heading);
738 $worksheet->write(0, 3, "Formatted", $heading);
739 $worksheet->write(0, 4, "Negative", $heading);
740 $worksheet->write(0, 5, "Format", $heading);
741
742 my @formats;
743 push @formats, [ 0x00, 1234.567, 0, 'General' ];
744 push @formats, [ 0x01, 1234.567, 0, '0' ];
745 push @formats, [ 0x02, 1234.567, 0, '0.00' ];
746 push @formats, [ 0x03, 1234.567, 0, '#,##0' ];
747 push @formats, [ 0x04, 1234.567, 0, '#,##0.00' ];
748 push @formats, [ 0x05, 1234.567, -1234.567, '($#,##0_);($#,##0)' ];
749 push @formats, [ 0x06, 1234.567, -1234.567, '($#,##0_);[Red]($#,##0)' ];
750 push @formats, [ 0x07, 1234.567, -1234.567, '($#,##0.00_);($#,##0.00)' ];
751 push @formats, [ 0x08, 1234.567, -1234.567, '($#,##0.00_);[Red]($#,##0.00)' ];
752 push @formats, [ 0x09, 0.567, 0, '0%' ];
753 push @formats, [ 0x0a, 0.567, 0, '0.00%' ];
754 push @formats, [ 0x0b, 1234.567, 0, '0.00E+00' ];
755 push @formats, [ 0x0c, 0.75, 0, '# ?/?' ];
756 push @formats, [ 0x0d, 0.3125, 0, '# ??/??' ];
757 push @formats, [ 0x0e, 36892.521, 0, 'm/d/yy' ];
758 push @formats, [ 0x0f, 36892.521, 0, 'd-mmm-yy' ];
759 push @formats, [ 0x10, 36892.521, 0, 'd-mmm' ];
760 push @formats, [ 0x11, 36892.521, 0, 'mmm-yy' ];
761 push @formats, [ 0x12, 36892.521, 0, 'h:mm AM/PM' ];
762 push @formats, [ 0x13, 36892.521, 0, 'h:mm:ss AM/PM' ];
763 push @formats, [ 0x14, 36892.521, 0, 'h:mm' ];
764 push @formats, [ 0x15, 36892.521, 0, 'h:mm:ss' ];
765 push @formats, [ 0x16, 36892.521, 0, 'm/d/yy h:mm' ];
766 push @formats, [ 0x25, 1234.567, -1234.567, '(#,##0_);(#,##0)' ];
767 push @formats, [ 0x26, 1234.567, -1234.567, '(#,##0_);[Red](#,##0)' ];
768 push @formats, [ 0x27, 1234.567, -1234.567, '(#,##0.00_);(#,##0.00)' ];
769 push @formats, [ 0x28, 1234.567, -1234.567, '(#,##0.00_);[Red](#,##0.00)' ];
770 push @formats, [ 0x29, 1234.567, -1234.567, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' ];
771 push @formats, [ 0x2a, 1234.567, -1234.567, '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' ];
772 push @formats, [ 0x2b, 1234.567, -1234.567, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' ];
773 push @formats, [ 0x2c, 1234.567, -1234.567, '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' ];
774 push @formats, [ 0x2d, 36892.521, 0, 'mm:ss' ];
775 push @formats, [ 0x2e, 3.0153, 0, '[h]:mm:ss' ];
776 push @formats, [ 0x2f, 36892.521, 0, 'mm:ss.0' ];
777 push @formats, [ 0x30, 1234.567, 0, '##0.0E+0' ];
778 push @formats, [ 0x31, 1234.567, 0, '@' ];
779
780 my $i;
781 foreach my $format (@formats){
782 my $style = $workbook->add_format();
783 $style->set_num_format($format->[0]);
784
785 $i++;
786 $worksheet->write($i, 0, $format->[0], $center);
787 $worksheet->write($i, 1, sprintf("0x%02X", $format->[0]), $center);
788 $worksheet->write($i, 2, $format->[1], $center);
789 $worksheet->write($i, 3, $format->[1], $style);
790
791 if ($format->[2]) {
792 $worksheet->write($i, 4, $format->[2], $style);
793 }
794
795 $worksheet->write_string($i, 5, $format->[3]);
796 }
797 }
798
799
800 ######################################################################
801 #
802 # Demonstrate the font options.
803 #
804 sub fonts {
805
806 my $worksheet = $workbook->add_worksheet('Fonts');
807
808 $worksheet->set_column(0, 0, 30);
809 $worksheet->set_column(1, 1, 10);
810
811 $worksheet->write(0, 0, "Font name", $heading);
812 $worksheet->write(0, 1, "Font size", $heading);
813
814 my @fonts;
815 push @fonts, [ 10, 'Arial' ];
816 push @fonts, [ 12, 'Arial' ];
817 push @fonts, [ 14, 'Arial' ];
818 push @fonts, [ 12, 'Arial Black' ];
819 push @fonts, [ 12, 'Arial Narrow' ];
820 push @fonts, [ 12, 'Century Schoolbook' ];
821 push @fonts, [ 12, 'Courier' ];
822 push @fonts, [ 12, 'Courier New' ];
823 push @fonts, [ 12, 'Garamond' ];
824 push @fonts, [ 12, 'Impact' ];
825 push @fonts, [ 12, 'Lucida Handwriting'] ;
826 push @fonts, [ 12, 'Times New Roman' ];
827 push @fonts, [ 12, 'Symbol' ];
828 push @fonts, [ 12, 'Wingdings' ];
829 push @fonts, [ 12, 'A font that doesn\'t exist' ];
830
831 my $i;
832 foreach my $font (@fonts){
833 my $format = $workbook->add_format();
834
835 $format->set_size($font->[0]);
836 $format->set_font($font->[1]);
837
838 $i++;
839 $worksheet->write($i, 0, $font->[1], $format);
840 $worksheet->write($i, 1, $font->[0], $format);
841 }
842
843 }
844
845
846 ######################################################################
847 #
848 # Demonstrate the standard Excel border styles.
849 #
850 sub borders {
851
852 my $worksheet = $workbook->add_worksheet('Borders');
853
854 $worksheet->set_column(0, 4, 10);
855 $worksheet->set_column(5, 5, 40);
856
857 $worksheet->write(0, 0, "Index", $heading);
858 $worksheet->write(0, 1, "Index", $heading);
859 $worksheet->write(0, 3, "Style", $heading);
860 $worksheet->write(0, 5, "The style is highlighted in red for ", $heading);
861 $worksheet->write(1, 5, "emphasis, the default color is black.", $heading);
862
863 for my $i (0..13){
864 my $format = $workbook->add_format();
865 $format->set_border($i);
866 $format->set_border_color('red');
867 $format->set_align('center');
868
869 $worksheet->write((2*($i+1)), 0, $i, $center);
870 $worksheet->write((2*($i+1)), 1, sprintf("0x%02X", $i), $center);
871
872 $worksheet->write((2*($i+1)), 3, "Border", $format);
873 }
874
875 $worksheet->write(30, 0, "Diag type", $heading);
876 $worksheet->write(30, 1, "Index", $heading);
877 $worksheet->write(30, 3, "Style", $heading);
878 $worksheet->write(30, 5, "Diagonal Boder styles", $heading);
879
880 for my $i (1..3){
881 my $format = $workbook->add_format();
882 $format->set_diag_type($i);
883 $format->set_diag_border(1);
884 $format->set_diag_color('red');
885 $format->set_align('center');
886
887 $worksheet->write((2*($i+15)), 0, $i, $center);
888 $worksheet->write((2*($i+15)), 1, sprintf("0x%02X", $i), $center);
889
890 $worksheet->write((2*($i+15)), 3, "Border", $format);
891 }
892 }
893
894
895
896 ######################################################################
897 #
898 # Demonstrate the standard Excel cell patterns.
899 #
900 sub patterns {
901
902 my $worksheet = $workbook->add_worksheet('Patterns');
903
904 $worksheet->set_column(0, 4, 10);
905 $worksheet->set_column(5, 5, 50);
906
907 $worksheet->write(0, 0, "Index", $heading);
908 $worksheet->write(0, 1, "Index", $heading);
909 $worksheet->write(0, 3, "Pattern", $heading);
910
911 $worksheet->write(0, 5, "The background colour has been set to silver.", $heading);
912 $worksheet->write(1, 5, "The foreground colour has been set to green.", $heading);
913
914 for my $i (0..18){
915 my $format = $workbook->add_format();
916
917 $format->set_pattern($i);
918 $format->set_bg_color('silver');
919 $format->set_fg_color('green');
920 $format->set_align('center');
921
922 $worksheet->write((2*($i+1)), 0, $i, $center);
923 $worksheet->write((2*($i+1)), 1, sprintf("0x%02X", $i), $center);
924
925 $worksheet->write((2*($i+1)), 3, "Pattern", $format);
926
927 if ($i == 1) {
928 $worksheet->write((2*($i+1)), 5, "This is solid colour, the most useful pattern.", $heading);
929 }
930 }
931 }
932
933
934 ######################################################################
935 #
936 # Demonstrate the standard Excel cell alignments.
937 #
938 sub alignment {
939
940 my $worksheet = $workbook->add_worksheet('Alignment');
941
942 $worksheet->set_column(0, 7, 12);
943 $worksheet->set_row(0, 40);
944 $worksheet->set_selection(7, 0);
945
946 my $format01 = $workbook->add_format();
947 my $format02 = $workbook->add_format();
948 my $format03 = $workbook->add_format();
949 my $format04 = $workbook->add_format();
950 my $format05 = $workbook->add_format();
951 my $format06 = $workbook->add_format();
952 my $format07 = $workbook->add_format();
953 my $format08 = $workbook->add_format();
954 my $format09 = $workbook->add_format();
955 my $format10 = $workbook->add_format();
956 my $format11 = $workbook->add_format();
957 my $format12 = $workbook->add_format();
958 my $format13 = $workbook->add_format();
959 my $format14 = $workbook->add_format();
960 my $format15 = $workbook->add_format();
961 my $format16 = $workbook->add_format();
962 my $format17 = $workbook->add_format();
963
964 $format02->set_align('top');
965 $format03->set_align('bottom');
966 $format04->set_align('vcenter');
967 $format05->set_align('vjustify');
968 $format06->set_text_wrap();
969
970 $format07->set_align('left');
971 $format08->set_align('right');
972 $format09->set_align('center');
973 $format10->set_align('fill');
974 $format11->set_align('justify');
975 $format12->set_merge();
976
977 $format13->set_rotation(45);
978 $format14->set_rotation(-45);
979 $format15->set_rotation(270);
980
981 $format16->set_shrink();
982 $format17->set_indent(1);
983
984 $worksheet->write(0, 0, 'Vertical', $heading);
985 $worksheet->write(0, 1, 'top', $format02);
986 $worksheet->write(0, 2, 'bottom', $format03);
987 $worksheet->write(0, 3, 'vcenter', $format04);
988 $worksheet->write(0, 4, 'vjustify', $format05);
989 $worksheet->write(0, 5, "text\nwrap", $format06);
990
991 $worksheet->write(2, 0, 'Horizontal', $heading);
992 $worksheet->write(2, 1, 'left', $format07);
993 $worksheet->write(2, 2, 'right', $format08);
994 $worksheet->write(2, 3, 'center', $format09);
995 $worksheet->write(2, 4, 'fill', $format10);
996 $worksheet->write(2, 5, 'justify', $format11);
997
998 $worksheet->write(3, 1, 'merge', $format12);
999 $worksheet->write(3, 2, '', $format12);
1000
1001 $worksheet->write(3, 3, 'Shrink ' x 3, $format16);
1002 $worksheet->write(3, 4, 'Indent', $format17);
1003
1004
1005 $worksheet->write(5, 0, 'Rotation', $heading);
1006 $worksheet->write(5, 1, 'Rotate 45', $format13);
1007 $worksheet->write(6, 1, 'Rotate -45', $format14);
1008 $worksheet->write(7, 1, 'Rotate 270', $format15);
1009 }
1010
1011
1012 ######################################################################
1013 #
1014 # Demonstrate other miscellaneous features.
1015 #
1016 sub misc {
1017
1018 my $worksheet = $workbook->add_worksheet('Miscellaneous');
1019
1020 $worksheet->set_column(2, 2, 25);
1021
1022 my $format01 = $workbook->add_format();
1023 my $format02 = $workbook->add_format();
1024 my $format03 = $workbook->add_format();
1025 my $format04 = $workbook->add_format();
1026 my $format05 = $workbook->add_format();
1027 my $format06 = $workbook->add_format();
1028 my $format07 = $workbook->add_format();
1029
1030 $format01->set_underline(0x01);
1031 $format02->set_underline(0x02);
1032 $format03->set_underline(0x21);
1033 $format04->set_underline(0x22);
1034 $format05->set_font_strikeout();
1035 $format06->set_font_outline();
1036 $format07->set_font_shadow();
1037
1038 $worksheet->write(1, 2, 'Underline 0x01', $format01);
1039 $worksheet->write(3, 2, 'Underline 0x02', $format02);
1040 $worksheet->write(5, 2, 'Underline 0x21', $format03);
1041 $worksheet->write(7, 2, 'Underline 0x22', $format04);
1042 $worksheet->write(9, 2, 'Strikeout', $format05);
1043 $worksheet->write(11, 2, 'Outline (Macintosh only)', $format06);
1044 $worksheet->write(13, 2, 'Shadow (Macintosh only)', $format07);
1045 }
1046
1047 __END__
1048
1049 Download this example:
1050 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/formats.pl
1051 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
1052 WriteExcel-2.36/examples/formats.pl>
1053
1054 Example: bug_report.pl
1055 A template for submitting a bug report.
1056
1057 Run this program and read the output from the command line.
1058
1059 #!/usr/bin/perl -w
1060
1061
1062 ###############################################################################
1063 #
1064 # A template for submitting a bug report.
1065 #
1066 # Run this program and read the output from the command line.
1067 #
1068 # reverse('X'), March 2004, John McNamara, jmcnamara@cpan.org
1069 #
1070
1071
1072 use strict;
1073
1074 print << 'HINTS_1';
1075
1076 REPORTING A BUG OR ASKING A QUESTION
1077
1078 Feel free to report bugs or ask questions. However, to save time
1079 consider the following steps first:
1080
1081 Read the documentation:
1082
1083 The Spreadsheet::WriteExcel documentation has been refined in
1084 response to user questions. Therefore, if you have a question it is
1085 possible that someone else has asked it before you and that it is
1086 already addressed in the documentation. Since there is a lot of
1087 documentation to get through you should at least read the table of
1088 contents and search for keywords that you are interested in.
1089
1090 Look at the example programs:
1091
1092 There are over 70 example programs shipped with the standard
1093 Spreadsheet::WriteExcel distribution. Many of these were created in
1094 response to user questions. Try to identify an example program that
1095 corresponds to your query and adapt it to your needs.
1096
1097 HINTS_1
1098 print "Press enter ..."; <STDIN>;
1099
1100 print << 'HINTS_2';
1101
1102 If you submit a bug report here are some pointers.
1103
1104 1. Put "WriteExcel:" at the beginning of the subject line. This helps
1105 to filter genuine messages from spam.
1106
1107 2. Describe the problems as clearly and as concisely as possible.
1108
1109 3. Send a sample program. It is often easier to describe a problem in
1110 code than in written prose.
1111
1112 4. The sample program should be as small as possible to demonstrate the
1113 problem. Don't copy and past large sections of your program. The
1114 program should also be self contained and working.
1115
1116 A sample bug report is generated below. If you use this format then it
1117 will help to analyse your question and respond to it more quickly.
1118
1119 Please don't send patches without contacting the author first.
1120
1121
1122 HINTS_2
1123 print "Press enter ..."; <STDIN>;
1124
1125
1126 print << 'EMAIL';
1127
1128 =======================================================================
1129
1130 To: John McNamara <jmcnamara@cpan.org>
1131 Subject: WriteExcel: Problem with something.
1132
1133 Hi John,
1134
1135 I am using Spreadsheet::WriteExcel and I have encountered a problem. I
1136 want it to do SOMETHING but the module appears to do SOMETHING_ELSE.
1137
1138 Here is some code that demonstrates the problem.
1139
1140 #!/usr/bin/perl -w
1141
1142 use strict;
1143 use Spreadsheet::WriteExcel;
1144
1145 my $workbook = Spreadsheet::WriteExcel->new("reload.xls");
1146 my $worksheet = $workbook->add_worksheet();
1147
1148 $worksheet->write(0, 0, "Hi Excel!");
1149
1150 __END__
1151
1152
1153 I tested using Excel XX (or Gnumeric or OpenOffice.org).
1154
1155 My automatically generated system details are as follows:
1156 EMAIL
1157
1158
1159 print "\n Perl version : $]";
1160 print "\n OS name : $^O";
1161 print "\n Module versions: (not all are required)\n";
1162
1163
1164 my @modules = qw(
1165 Spreadsheet::WriteExcel
1166 Spreadsheet::ParseExcel
1167 OLE::Storage_Lite
1168 Parse::RecDescent
1169 File::Temp
1170 Digest::MD4
1171 Digest::Perl::MD4
1172 Digest::MD5
1173 );
1174
1175
1176 for my $module (@modules) {
1177 my $version;
1178 eval "require $module";
1179
1180 if (not $@) {
1181 $version = $module->VERSION;
1182 $version = '(unknown)' if not defined $version;
1183 }
1184 else {
1185 $version = '(not installed)';
1186 }
1187
1188 printf "%21s%-24s\t%s\n", "", $module, $version;
1189 }
1190
1191
1192 print << "BYE";
1193 Yours etc.,
1194
1195 A. Person
1196 --
1197
1198 BYE
1199
1200 __END__
1201
1202 Download this example:
1203 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/bug_report.pl
1204 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
1205 WriteExcel-2.36/examples/bug_report.pl>
1206
1207 Example: autofilter.pl
1208 An example of how to create autofilters with Spreadsheet::WriteExcel.
1209
1210 An autofilter is a way of adding drop down lists to the headers of a 2D
1211 range of worksheet data. This is turn allow users to filter the data
1212 based on simple criteria so that some data is shown and some is hidden.
1213
1214 Source code for this example:
1215
1216 #!/usr/bin/perl -w
1217
1218 ###############################################################################
1219 #
1220 # An example of how to create autofilters with Spreadsheet::WriteExcel.
1221 #
1222 # An autofilter is a way of adding drop down lists to the headers of a 2D range
1223 # of worksheet data. This is turn allow users to filter the data based on
1224 # simple criteria so that some data is shown and some is hidden.
1225 #
1226 # reverse('X'), September 2007, John McNamara, jmcnamara@cpan.org
1227 #
1228
1229 use strict;
1230 use Spreadsheet::WriteExcel;
1231
1232 my $workbook = Spreadsheet::WriteExcel->new('autofilter.xls');
1233
1234 die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
1235
1236 my $worksheet1 = $workbook->add_worksheet();
1237 my $worksheet2 = $workbook->add_worksheet();
1238 my $worksheet3 = $workbook->add_worksheet();
1239 my $worksheet4 = $workbook->add_worksheet();
1240 my $worksheet5 = $workbook->add_worksheet();
1241 my $worksheet6 = $workbook->add_worksheet();
1242
1243 my $bold = $workbook->add_format(bold => 1);
1244
1245
1246 # Extract the data embedded at the end of this file.
1247 my @headings = split ' ', <DATA>;
1248 my @data;
1249 push @data, [split] while <DATA>;
1250
1251
1252 # Set up several sheets with the same data.
1253 for my $worksheet ($workbook->sheets()) {
1254 $worksheet->set_column('A:D', 12);
1255 $worksheet->set_row(0, 20, $bold);
1256 $worksheet->write('A1', \@headings);
1257 }
1258
1259
1260 ###############################################################################
1261 #
1262 # Example 1. Autofilter without conditions.
1263 #
1264
1265 $worksheet1->autofilter('A1:D51');
1266 $worksheet1->write('A2', [[@data]]);
1267
1268
1269 ###############################################################################
1270 #
1271 #
1272 # Example 2. Autofilter with a filter condition in the first column.
1273 #
1274
1275 # The range in this example is the same as above but in row-column notation.
1276 $worksheet2->autofilter(0, 0, 50, 3);
1277
1278 # The placeholder "Region" in the filter is ignored and can be any string
1279 # that adds clarity to the expression.
1280 #
1281 $worksheet2->filter_column(0, 'Region eq East');
1282
1283 #
1284 # Hide the rows that don't match the filter criteria.
1285 #
1286 my $row = 1;
1287
1288 for my $row_data (@data) {
1289 my $region = $row_data->[0];
1290
1291 if ($region eq 'East') {
1292 # Row is visible.
1293 }
1294 else {
1295 # Hide row.
1296 $worksheet2->set_row($row, undef, undef, 1);
1297 }
1298
1299 $worksheet2->write($row++, 0, $row_data);
1300 }
1301
1302
1303 ###############################################################################
1304 #
1305 #
1306 # Example 3. Autofilter with a dual filter condition in one of the columns.
1307 #
1308
1309 $worksheet3->autofilter('A1:D51');
1310
1311 $worksheet3->filter_column('A', 'x eq East or x eq South');
1312
1313 #
1314 # Hide the rows that don't match the filter criteria.
1315 #
1316 $row = 1;
1317
1318 for my $row_data (@data) {
1319 my $region = $row_data->[0];
1320
1321 if ($region eq 'East' or $region eq 'South') {
1322 # Row is visible.
1323 }
1324 else {
1325 # Hide row.
1326 $worksheet3->set_row($row, undef, undef, 1);
1327 }
1328
1329 $worksheet3->write($row++, 0, $row_data);
1330 }
1331
1332
1333 ###############################################################################
1334 #
1335 #
1336 # Example 4. Autofilter with filter conditions in two columns.
1337 #
1338
1339 $worksheet4->autofilter('A1:D51');
1340
1341 $worksheet4->filter_column('A', 'x eq East');
1342 $worksheet4->filter_column('C', 'x > 3000 and x < 8000' );
1343
1344 #
1345 # Hide the rows that don't match the filter criteria.
1346 #
1347 $row = 1;
1348
1349 for my $row_data (@data) {
1350 my $region = $row_data->[0];
1351 my $volume = $row_data->[2];
1352
1353 if ($region eq 'East' and
1354 $volume > 3000 and $volume < 8000
1355 )
1356 {
1357 # Row is visible.
1358 }
1359 else {
1360 # Hide row.
1361 $worksheet4->set_row($row, undef, undef, 1);
1362 }
1363
1364 $worksheet4->write($row++, 0, $row_data);
1365 }
1366
1367
1368 ###############################################################################
1369 #
1370 #
1371 # Example 5. Autofilter with filter for blanks.
1372 #
1373
1374 # Create a blank cell in our test data.
1375 $data[5]->[0] = '';
1376
1377
1378 $worksheet5->autofilter('A1:D51');
1379 $worksheet5->filter_column('A', 'x == Blanks');
1380
1381 #
1382 # Hide the rows that don't match the filter criteria.
1383 #
1384 $row = 1;
1385
1386 for my $row_data (@data) {
1387 my $region = $row_data->[0];
1388
1389 if ($region eq '')
1390 {
1391 # Row is visible.
1392 }
1393 else {
1394 # Hide row.
1395 $worksheet5->set_row($row, undef, undef, 1);
1396 }
1397
1398 $worksheet5->write($row++, 0, $row_data);
1399 }
1400
1401
1402 ###############################################################################
1403 #
1404 #
1405 # Example 6. Autofilter with filter for non-blanks.
1406 #
1407
1408
1409 $worksheet6->autofilter('A1:D51');
1410 $worksheet6->filter_column('A', 'x == NonBlanks');
1411
1412 #
1413 # Hide the rows that don't match the filter criteria.
1414 #
1415 $row = 1;
1416
1417 for my $row_data (@data) {
1418 my $region = $row_data->[0];
1419
1420 if ($region ne '')
1421 {
1422 # Row is visible.
1423 }
1424 else {
1425 # Hide row.
1426 $worksheet6->set_row($row, undef, undef, 1);
1427 }
1428
1429 $worksheet6->write($row++, 0, $row_data);
1430 }
1431
1432
1433
1434 __DATA__
1435 Region Item Volume Month
1436 East Apple 9000 July
1437 East Apple 5000 July
1438 South Orange 9000 September
1439 North Apple 2000 November
1440 West Apple 9000 November
1441 South Pear 7000 October
1442 North Pear 9000 August
1443 West Orange 1000 December
1444 West Grape 1000 November
1445 South Pear 10000 April
1446 West Grape 6000 January
1447 South Orange 3000 May
1448 North Apple 3000 December
1449 South Apple 7000 February
1450 West Grape 1000 December
1451 East Grape 8000 February
1452 South Grape 10000 June
1453 West Pear 7000 December
1454 South Apple 2000 October
1455 East Grape 7000 December
1456 North Grape 6000 April
1457 East Pear 8000 February
1458 North Apple 7000 August
1459 North Orange 7000 July
1460 North Apple 6000 June
1461 South Grape 8000 September
1462 West Apple 3000 October
1463 South Orange 10000 November
1464 West Grape 4000 July
1465 North Orange 5000 August
1466 East Orange 1000 November
1467 East Orange 4000 October
1468 North Grape 5000 August
1469 East Apple 1000 December
1470 South Apple 10000 March
1471 East Grape 7000 October
1472 West Grape 1000 September
1473 East Grape 10000 October
1474 South Orange 8000 March
1475 North Apple 4000 July
1476 South Orange 5000 July
1477 West Apple 4000 June
1478 East Apple 5000 April
1479 North Pear 3000 August
1480 East Grape 9000 November
1481 North Orange 8000 October
1482 East Apple 10000 June
1483 South Pear 1000 December
1484 North Grape 10000 July
1485 East Grape 6000 February
1486
1487 Download this example:
1488 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/autofilter.pl
1489 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
1490 WriteExcel-2.36/examples/autofilter.pl>
1491
1492 Example: autofit.pl
1493 Simulate Excel's autofit for column widths.
1494
1495 Excel provides a function called Autofit (Format->Columns->Autofit)
1496 that adjusts column widths to match the length of the longest string in
1497 a column. Excel calculates these widths at run time when it has access
1498 to information about string lengths and font information. This function
1499 is *not* a feature of the file format and thus cannot be implemented by
1500 Spreadsheet::WriteExcel.
1501
1502 However, we can make an attempt to simulate it by keeping track of the
1503 longest string written to each column and then adjusting the column
1504 widths prior to closing the file.
1505
1506 We keep track of the longest strings by adding a handler to the write()
1507 function. See add_handler() in the S::WE docs for more information.
1508
1509 The main problem with trying to simulate Autofit lies in defining a
1510 relationship between a string length and its width in a arbitrary font
1511 and size. We use two approaches below. The first is a simple direct
1512 relationship obtained by trial and error. The second is a slightly more
1513 sophisticated method using an external module. For more complicated
1514 applications you will probably have to work out your own methods.
1515
1516 Source code for this example:
1517
1518 #!/usr/bin/perl -w
1519
1520 ##############################################################################
1521 #
1522 # Simulate Excel's autofit for column widths.
1523 #
1524 # Excel provides a function called Autofit (Format->Columns->Autofit) that
1525 # adjusts column widths to match the length of the longest string in a column.
1526 # Excel calculates these widths at run time when it has access to information
1527 # about string lengths and font information. This function is *not* a feature
1528 # of the file format and thus cannot be implemented by Spreadsheet::WriteExcel.
1529 #
1530 # However, we can make an attempt to simulate it by keeping track of the
1531 # longest string written to each column and then adjusting the column widths
1532 # prior to closing the file.
1533 #
1534 # We keep track of the longest strings by adding a handler to the write()
1535 # function. See add_handler() in the S::WE docs for more information.
1536 #
1537 # The main problem with trying to simulate Autofit lies in defining a
1538 # relationship between a string length and its width in a arbitrary font and
1539 # size. We use two approaches below. The first is a simple direct relationship
1540 # obtained by trial and error. The second is a slightly more sophisticated
1541 # method using an external module. For more complicated applications you will
1542 # probably have to work out your own methods.
1543 #
1544 # reverse('X'), May 2006, John McNamara, jmcnamara@cpan.org
1545 #
1546
1547 use strict;
1548 use Spreadsheet::WriteExcel;
1549
1550 my $workbook = Spreadsheet::WriteExcel->new('autofit.xls');
1551 my $worksheet = $workbook->add_worksheet();
1552
1553
1554 ###############################################################################
1555 #
1556 # Add a handler to store the width of the longest string written to a column.
1557 # We use the stored width to simulate an autofit of the column widths.
1558 #
1559 # You should do this for every worksheet you want to autofit.
1560 #
1561 $worksheet->add_write_handler(qr[\w], \&store_string_widths);
1562
1563
1564
1565 $worksheet->write('A1', 'Hello');
1566 $worksheet->write('B1', 'Hello World');
1567 $worksheet->write('D1', 'Hello');
1568 $worksheet->write('F1', 'This is a long string as an example.');
1569
1570 # Run the autofit after you have finished writing strings to the workbook.
1571 autofit_columns($worksheet);
1572
1573
1574
1575 ###############################################################################
1576 #
1577 # Functions used for Autofit.
1578 #
1579 ###############################################################################
1580
1581 ###############################################################################
1582 #
1583 # Adjust the column widths to fit the longest string in the column.
1584 #
1585 sub autofit_columns {
1586
1587 my $worksheet = shift;
1588 my $col = 0;
1589
1590 for my $width (@{$worksheet->{__col_widths}}) {
1591
1592 $worksheet->set_column($col, $col, $width) if $width;
1593 $col++;
1594 }
1595 }
1596
1597
1598 ###############################################################################
1599 #
1600 # The following function is a callback that was added via add_write_handler()
1601 # above. It modifies the write() function so that it stores the maximum
1602 # unwrapped width of a string in a column.
1603 #
1604 sub store_string_widths {
1605
1606 my $worksheet = shift;
1607 my $col = $_[1];
1608 my $token = $_[2];
1609
1610 # Ignore some tokens that we aren't interested in.
1611 return if not defined $token; # Ignore undefs.
1612 return if $token eq ''; # Ignore blank cells.
1613 return if ref $token eq 'ARRAY'; # Ignore array refs.
1614 return if $token =~ /^=/; # Ignore formula
1615
1616 # Ignore numbers
1617 return if $token =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/;
1618
1619 # Ignore various internal and external hyperlinks. In a real scenario
1620 # you may wish to track the length of the optional strings used with
1621 # urls.
1622 return if $token =~ m{^[fh]tt?ps?://};
1623 return if $token =~ m{^mailto:};
1624 return if $token =~ m{^(?:in|ex)ternal:};
1625
1626
1627 # We store the string width as data in the Worksheet object. We use
1628 # a double underscore key name to avoid conflicts with future names.
1629 #
1630 my $old_width = $worksheet->{__col_widths}->[$col];
1631 my $string_width = string_width($token);
1632
1633 if (not defined $old_width or $string_width > $old_width) {
1634 # You may wish to set a minimum column width as follows.
1635 #return undef if $string_width < 10;
1636
1637 $worksheet->{__col_widths}->[$col] = $string_width;
1638 }
1639
1640
1641 # Return control to write();
1642 return undef;
1643 }
1644
1645
1646 ###############################################################################
1647 #
1648 # Very simple conversion between string length and string width for Arial 10.
1649 # See below for a more sophisticated method.
1650 #
1651 sub string_width {
1652
1653 return 0.9 * length $_[0];
1654 }
1655
1656 __END__
1657
1658
1659
1660 ###############################################################################
1661 #
1662 # This function uses an external module to get a more accurate width for a
1663 # string. Note that in a real program you could "use" the module instead of
1664 # "require"-ing it and you could make the Font object global to avoid repeated
1665 # initialisation.
1666 #
1667 # Note also that the $pixel_width to $cell_width is specific to Arial. For
1668 # other fonts you should calculate appropriate relationships. A future version
1669 # of S::WE will provide a way of specifying column widths in pixels instead of
1670 # cell units in order to simplify this conversion.
1671 #
1672 sub string_width {
1673
1674 require Font::TTFMetrics;
1675
1676 my $arial = Font::TTFMetrics->new('c:\windows\fonts\arial.ttf');
1677
1678 my $font_size = 10;
1679 my $dpi = 96;
1680 my $units_per_em = $arial->get_units_per_em();
1681 my $font_width = $arial->string_width($_[0]);
1682
1683 # Convert to pixels as per TTFMetrics docs.
1684 my $pixel_width = 6 + $font_width *$font_size *$dpi /(72 *$units_per_em);
1685
1686 # Add extra pixels for border around text.
1687 $pixel_width += 6;
1688
1689 # Convert to cell width (for Arial) and for cell widths > 1.
1690 my $cell_width = ($pixel_width -5) /7;
1691
1692 return $cell_width;
1693
1694 }
1695
1696 __END__
1697
1698 Download this example:
1699 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/autofit.pl
1700 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
1701 WriteExcel-2.36/examples/autofit.pl>
1702
1703 Example: bigfile.pl
1704 Example of creating a Spreadsheet::WriteExcel that is larger than the
1705 default 7MB limit.
1706
1707 It is exactly that same as any other Spreadsheet::WriteExcel program
1708 except that is requires that the OLE::Storage module is installed.
1709
1710 Source code for this example:
1711
1712 #!/usr/bin/perl -w
1713
1714 ###############################################################################
1715 #
1716 # Example of creating a Spreadsheet::WriteExcel that is larger than the
1717 # default 7MB limit.
1718 #
1719 # It is exactly that same as any other Spreadsheet::WriteExcel program except
1720 # that is requires that the OLE::Storage module is installed.
1721 #
1722 # reverse('X'), Jan 2007, John McNamara, jmcnamara@cpan.org
1723
1724
1725 use strict;
1726 use Spreadsheet::WriteExcel;
1727
1728
1729 my $workbook = Spreadsheet::WriteExcel->new('bigfile.xls');
1730 my $worksheet = $workbook->add_worksheet();
1731
1732 $worksheet->set_column(0, 50, 18);
1733
1734 for my $col (0 .. 50) {
1735 for my $row (0 .. 6000) {
1736 $worksheet->write($row, $col, "Row: $row Col: $col");
1737 }
1738 }
1739
1740 __END__
1741
1742 Download this example:
1743 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/bigfile.pl
1744 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
1745 WriteExcel-2.36/examples/bigfile.pl>
1746
1747 Example: cgi.pl
1748 Example of how to use the Spreadsheet::WriteExcel module to send an
1749 Excel file to a browser in a CGI program.
1750
1751 On Windows the hash-bang line should be something like:
1752
1753 #!C:\Perl\bin\perl.exe
1754
1755 The "Content-Disposition" line will cause a prompt to be generated to
1756 save the file. If you want to stream the file to the browser instead,
1757 comment out that line as shown below.
1758
1759 #!/usr/bin/perl -w
1760
1761 ###############################################################################
1762 #
1763 # Example of how to use the Spreadsheet::WriteExcel module to send an Excel
1764 # file to a browser in a CGI program.
1765 #
1766 # On Windows the hash-bang line should be something like:
1767 #
1768 # #!C:\Perl\bin\perl.exe
1769 #
1770 # The "Content-Disposition" line will cause a prompt to be generated to save
1771 # the file. If you want to stream the file to the browser instead, comment out
1772 # that line as shown below.
1773 #
1774 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
1775 #
1776
1777 use strict;
1778 use Spreadsheet::WriteExcel;
1779
1780 # Set the filename and send the content type
1781 my $filename ="cgitest.xls";
1782
1783 print "Content-type: application/vnd.ms-excel\n";
1784 # The Content-Disposition will generate a prompt to save the file. If you want
1785 # to stream the file to the browser, comment out the following line.
1786 print "Content-Disposition: attachment; filename=$filename\n";
1787 print "\n";
1788
1789 # Create a new workbook and add a worksheet. The special Perl filehandle - will
1790 # redirect the output to STDOUT
1791 #
1792 my $workbook = Spreadsheet::WriteExcel->new("-");
1793 my $worksheet = $workbook->add_worksheet();
1794
1795
1796 # Set the column width for column 1
1797 $worksheet->set_column(0, 0, 20);
1798
1799
1800 # Create a format
1801 my $format = $workbook->add_format();
1802 $format->set_bold();
1803 $format->set_size(15);
1804 $format->set_color('blue');
1805
1806
1807 # Write to the workbook
1808 $worksheet->write(0, 0, "Hi Excel!", $format);
1809
1810 __END__
1811
1812 Download this example:
1813 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/cgi.pl
1814 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
1815 WriteExcel-2.36/examples/cgi.pl>
1816
1817 Example: chart_area.pl
1818 A simple demo of Area charts in Spreadsheet::WriteExcel.
1819
1820 Source code for this example:
1821
1822 #!/usr/bin/perl -w
1823
1824 ###############################################################################
1825 #
1826 # A simple demo of Area charts in Spreadsheet::WriteExcel.
1827 #
1828 # reverse('X'), December 2009, John McNamara, jmcnamara@cpan.org
1829 #
1830
1831 use strict;
1832 use Spreadsheet::WriteExcel;
1833
1834 my $workbook = Spreadsheet::WriteExcel->new( 'chart_area.xls' );
1835 my $worksheet = $workbook->add_worksheet();
1836 my $bold = $workbook->add_format( bold => 1 );
1837
1838 # Add the worksheet data that the charts will refer to.
1839 my $headings = [ 'Category', 'Values 1', 'Values 2' ];
1840 my $data = [
1841 [ 2, 3, 4, 5, 6, 7 ],
1842 [ 1, 4, 5, 2, 1, 5 ],
1843 [ 3, 6, 7, 5, 4, 3 ],
1844 ];
1845
1846 $worksheet->write( 'A1', $headings, $bold );
1847 $worksheet->write( 'A2', $data );
1848
1849
1850 ###############################################################################
1851 #
1852 # Example 1. A minimal chart.
1853 #
1854 my $chart1 = $workbook->add_chart( type => 'area' );
1855
1856 # Add values only. Use the default categories.
1857 $chart1->add_series( values => '=Sheet1!$B$2:$B$7' );
1858
1859
1860 ###############################################################################
1861 #
1862 # Example 2. A minimal chart with user specified categories (X axis)
1863 # and a series name.
1864 #
1865 my $chart2 = $workbook->add_chart( type => 'area' );
1866
1867 # Configure the series.
1868 $chart2->add_series(
1869 categories => '=Sheet1!$A$2:$A$7',
1870 values => '=Sheet1!$B$2:$B$7',
1871 name => 'Test data series 1',
1872 );
1873
1874
1875 ###############################################################################
1876 #
1877 # Example 3. Same as previous chart but with added title and axes labels.
1878 #
1879 my $chart3 = $workbook->add_chart( type => 'area' );
1880
1881 # Configure the series.
1882 $chart3->add_series(
1883 categories => '=Sheet1!$A$2:$A$7',
1884 values => '=Sheet1!$B$2:$B$7',
1885 name => 'Test data series 1',
1886 );
1887
1888 # Add some labels.
1889 $chart3->set_title( name => 'Results of sample analysis' );
1890 $chart3->set_x_axis( name => 'Sample number' );
1891 $chart3->set_y_axis( name => 'Sample length (cm)' );
1892
1893
1894 ###############################################################################
1895 #
1896 # Example 4. Same as previous chart but with an added series and with a
1897 # user specified chart sheet name.
1898 #
1899 my $chart4 = $workbook->add_chart( name => 'Results Chart', type => 'area' );
1900
1901 # Configure the series.
1902 $chart4->add_series(
1903 categories => '=Sheet1!$A$2:$A$7',
1904 values => '=Sheet1!$B$2:$B$7',
1905 name => 'Test data series 1',
1906 );
1907
1908 # Add another series.
1909 $chart4->add_series(
1910 categories => '=Sheet1!$A$2:$A$7',
1911 values => '=Sheet1!$C$2:$C$7',
1912 name => 'Test data series 2',
1913 );
1914
1915 # Add some labels.
1916 $chart4->set_title( name => 'Results of sample analysis' );
1917 $chart4->set_x_axis( name => 'Sample number' );
1918 $chart4->set_y_axis( name => 'Sample length (cm)' );
1919
1920
1921 ###############################################################################
1922 #
1923 # Example 5. Same as Example 3 but as an embedded chart.
1924 #
1925 my $chart5 = $workbook->add_chart( type => 'area', embedded => 1 );
1926
1927 # Configure the series.
1928 $chart5->add_series(
1929 categories => '=Sheet1!$A$2:$A$7',
1930 values => '=Sheet1!$B$2:$B$7',
1931 name => 'Test data series 1',
1932 );
1933
1934 # Add some labels.
1935 $chart5->set_title( name => 'Results of sample analysis' );
1936 $chart5->set_x_axis( name => 'Sample number' );
1937 $chart5->set_y_axis( name => 'Sample length (cm)' );
1938
1939 # Insert the chart into the main worksheet.
1940 $worksheet->insert_chart( 'E2', $chart5 );
1941
1942 __END__
1943
1944 Download this example:
1945 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/chart_area.pl
1946 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
1947 WriteExcel-2.36/examples/chart_area.pl>
1948
1949 Example: chart_bar.pl
1950 A simple demo of Bar charts in Spreadsheet::WriteExcel.
1951
1952 Source code for this example:
1953
1954 #!/usr/bin/perl -w
1955
1956 ###############################################################################
1957 #
1958 # A simple demo of Bar charts in Spreadsheet::WriteExcel.
1959 #
1960 # reverse('X'), December 2009, John McNamara, jmcnamara@cpan.org
1961 #
1962
1963 use strict;
1964 use Spreadsheet::WriteExcel;
1965
1966 my $workbook = Spreadsheet::WriteExcel->new( 'chart_bar.xls' );
1967 my $worksheet = $workbook->add_worksheet();
1968 my $bold = $workbook->add_format( bold => 1 );
1969
1970 # Add the worksheet data that the charts will refer to.
1971 my $headings = [ 'Category', 'Values 1', 'Values 2' ];
1972 my $data = [
1973 [ 2, 3, 4, 5, 6, 7 ],
1974 [ 1, 4, 5, 2, 1, 5 ],
1975 [ 3, 6, 7, 5, 4, 3 ],
1976 ];
1977
1978 $worksheet->write( 'A1', $headings, $bold );
1979 $worksheet->write( 'A2', $data );
1980
1981
1982 ###############################################################################
1983 #
1984 # Example 1. A minimal chart.
1985 #
1986 my $chart1 = $workbook->add_chart( type => 'bar' );
1987
1988 # Add values only. Use the default categories.
1989 $chart1->add_series( values => '=Sheet1!$B$2:$B$7' );
1990
1991
1992 ###############################################################################
1993 #
1994 # Example 2. A minimal chart with user specified categories (X axis)
1995 # and a series name.
1996 #
1997 my $chart2 = $workbook->add_chart( type => 'bar' );
1998
1999 # Configure the series.
2000 $chart2->add_series(
2001 categories => '=Sheet1!$A$2:$A$7',
2002 values => '=Sheet1!$B$2:$B$7',
2003 name => 'Test data series 1',
2004 );
2005
2006
2007 ###############################################################################
2008 #
2009 # Example 3. Same as previous chart but with added title and axes labels.
2010 #
2011 my $chart3 = $workbook->add_chart( type => 'bar' );
2012
2013 # Configure the series.
2014 $chart3->add_series(
2015 categories => '=Sheet1!$A$2:$A$7',
2016 values => '=Sheet1!$B$2:$B$7',
2017 name => 'Test data series 1',
2018 );
2019
2020 # Add some labels.
2021 $chart3->set_title( name => 'Results of sample analysis' );
2022 $chart3->set_x_axis( name => 'Sample number' );
2023 $chart3->set_y_axis( name => 'Sample length (cm)' );
2024
2025
2026 ###############################################################################
2027 #
2028 # Example 4. Same as previous chart but with an added series and with a
2029 # user specified chart sheet name.
2030 #
2031 my $chart4 = $workbook->add_chart( name => 'Results Chart', type => 'bar' );
2032
2033 # Configure the series.
2034 $chart4->add_series(
2035 categories => '=Sheet1!$A$2:$A$7',
2036 values => '=Sheet1!$B$2:$B$7',
2037 name => 'Test data series 1',
2038 );
2039
2040 # Add another series.
2041 $chart4->add_series(
2042 categories => '=Sheet1!$A$2:$A$7',
2043 values => '=Sheet1!$C$2:$C$7',
2044 name => 'Test data series 2',
2045 );
2046
2047 # Add some labels.
2048 $chart4->set_title( name => 'Results of sample analysis' );
2049 $chart4->set_x_axis( name => 'Sample number' );
2050 $chart4->set_y_axis( name => 'Sample length (cm)' );
2051
2052
2053 ###############################################################################
2054 #
2055 # Example 5. Same as Example 3 but as an embedded chart.
2056 #
2057 my $chart5 = $workbook->add_chart( type => 'bar', embedded => 1 );
2058
2059 # Configure the series.
2060 $chart5->add_series(
2061 categories => '=Sheet1!$A$2:$A$7',
2062 values => '=Sheet1!$B$2:$B$7',
2063 name => 'Test data series 1',
2064 );
2065
2066 # Add some labels.
2067 $chart5->set_title( name => 'Results of sample analysis' );
2068 $chart5->set_x_axis( name => 'Sample number' );
2069 $chart5->set_y_axis( name => 'Sample length (cm)' );
2070
2071 # Insert the chart into the main worksheet.
2072 $worksheet->insert_chart( 'E2', $chart5 );
2073
2074 __END__
2075
2076 Download this example:
2077 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/chart_bar.pl
2078 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
2079 WriteExcel-2.36/examples/chart_bar.pl>
2080
2081 Example: chart_column.pl
2082 A simple demo of Column charts in Spreadsheet::WriteExcel.
2083
2084 Source code for this example:
2085
2086 #!/usr/bin/perl -w
2087
2088 ###############################################################################
2089 #
2090 # A simple demo of Column charts in Spreadsheet::WriteExcel.
2091 #
2092 # reverse('X'), December 2009, John McNamara, jmcnamara@cpan.org
2093 #
2094
2095 use strict;
2096 use Spreadsheet::WriteExcel;
2097
2098 my $workbook = Spreadsheet::WriteExcel->new( 'chart_column.xls' );
2099 my $worksheet = $workbook->add_worksheet();
2100 my $bold = $workbook->add_format( bold => 1 );
2101
2102 # Add the worksheet data that the charts will refer to.
2103 my $headings = [ 'Category', 'Values 1', 'Values 2' ];
2104 my $data = [
2105 [ 2, 3, 4, 5, 6, 7 ],
2106 [ 1, 4, 5, 2, 1, 5 ],
2107 [ 3, 6, 7, 5, 4, 3 ],
2108 ];
2109
2110 $worksheet->write( 'A1', $headings, $bold );
2111 $worksheet->write( 'A2', $data );
2112
2113
2114 ###############################################################################
2115 #
2116 # Example 1. A minimal chart.
2117 #
2118 my $chart1 = $workbook->add_chart( type => 'column' );
2119
2120 # Add values only. Use the default categories.
2121 $chart1->add_series( values => '=Sheet1!$B$2:$B$7' );
2122
2123
2124 ###############################################################################
2125 #
2126 # Example 2. A minimal chart with user specified categories (X axis)
2127 # and a series name.
2128 #
2129 my $chart2 = $workbook->add_chart( type => 'column' );
2130
2131 # Configure the series.
2132 $chart2->add_series(
2133 categories => '=Sheet1!$A$2:$A$7',
2134 values => '=Sheet1!$B$2:$B$7',
2135 name => 'Test data series 1',
2136 );
2137
2138
2139 ###############################################################################
2140 #
2141 # Example 3. Same as previous chart but with added title and axes labels.
2142 #
2143 my $chart3 = $workbook->add_chart( type => 'column' );
2144
2145 # Configure the series.
2146 $chart3->add_series(
2147 categories => '=Sheet1!$A$2:$A$7',
2148 values => '=Sheet1!$B$2:$B$7',
2149 name => 'Test data series 1',
2150 );
2151
2152 # Add some labels.
2153 $chart3->set_title( name => 'Results of sample analysis' );
2154 $chart3->set_x_axis( name => 'Sample number' );
2155 $chart3->set_y_axis( name => 'Sample length (cm)' );
2156
2157
2158 ###############################################################################
2159 #
2160 # Example 4. Same as previous chart but with an added series and with a
2161 # user specified chart sheet name.
2162 #
2163 my $chart4 = $workbook->add_chart( name => 'Results Chart', type => 'column' );
2164
2165 # Configure the series.
2166 $chart4->add_series(
2167 categories => '=Sheet1!$A$2:$A$7',
2168 values => '=Sheet1!$B$2:$B$7',
2169 name => 'Test data series 1',
2170 );
2171
2172 # Add another series.
2173 $chart4->add_series(
2174 categories => '=Sheet1!$A$2:$A$7',
2175 values => '=Sheet1!$C$2:$C$7',
2176 name => 'Test data series 2',
2177 );
2178
2179 # Add some labels.
2180 $chart4->set_title( name => 'Results of sample analysis' );
2181 $chart4->set_x_axis( name => 'Sample number' );
2182 $chart4->set_y_axis( name => 'Sample length (cm)' );
2183
2184
2185 ###############################################################################
2186 #
2187 # Example 5. Same as Example 3 but as an embedded chart.
2188 #
2189 my $chart5 = $workbook->add_chart( type => 'column', embedded => 1 );
2190
2191 # Configure the series.
2192 $chart5->add_series(
2193 categories => '=Sheet1!$A$2:$A$7',
2194 values => '=Sheet1!$B$2:$B$7',
2195 name => 'Test data series 1',
2196 );
2197
2198 # Add some labels.
2199 $chart5->set_title( name => 'Results of sample analysis' );
2200 $chart5->set_x_axis( name => 'Sample number' );
2201 $chart5->set_y_axis( name => 'Sample length (cm)' );
2202
2203 # Insert the chart into the main worksheet.
2204 $worksheet->insert_chart( 'E2', $chart5 );
2205
2206 __END__
2207
2208 Download this example:
2209 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/chart_column.pl
2210 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
2211 WriteExcel-2.36/examples/chart_column.pl>
2212
2213 Example: chart_line.pl
2214 A simple demo of Line charts in Spreadsheet::WriteExcel.
2215
2216 Source code for this example:
2217
2218 #!/usr/bin/perl -w
2219
2220 ###############################################################################
2221 #
2222 # A simple demo of Line charts in Spreadsheet::WriteExcel.
2223 #
2224 # reverse('X'), December 2009, John McNamara, jmcnamara@cpan.org
2225 #
2226
2227 use strict;
2228 use Spreadsheet::WriteExcel;
2229
2230 my $workbook = Spreadsheet::WriteExcel->new( 'chart_line.xls' );
2231 my $worksheet = $workbook->add_worksheet();
2232 my $bold = $workbook->add_format( bold => 1 );
2233
2234 # Add the worksheet data that the charts will refer to.
2235 my $headings = [ 'Category', 'Values 1', 'Values 2' ];
2236 my $data = [
2237 [ 2, 3, 4, 5, 6, 7 ],
2238 [ 1, 4, 5, 2, 1, 5 ],
2239 [ 3, 6, 7, 5, 4, 3 ],
2240 ];
2241
2242 $worksheet->write( 'A1', $headings, $bold );
2243 $worksheet->write( 'A2', $data );
2244
2245
2246 ###############################################################################
2247 #
2248 # Example 1. A minimal chart.
2249 #
2250 my $chart1 = $workbook->add_chart( type => 'line' );
2251
2252 # Add values only. Use the default categories.
2253 $chart1->add_series( values => '=Sheet1!$B$2:$B$7' );
2254
2255
2256 ###############################################################################
2257 #
2258 # Example 2. A minimal chart with user specified categories (X axis)
2259 # and a series name.
2260 #
2261 my $chart2 = $workbook->add_chart( type => 'line' );
2262
2263 # Configure the series.
2264 $chart2->add_series(
2265 categories => '=Sheet1!$A$2:$A$7',
2266 values => '=Sheet1!$B$2:$B$7',
2267 name => 'Test data series 1',
2268 );
2269
2270
2271 ###############################################################################
2272 #
2273 # Example 3. Same as previous chart but with added title and axes labels.
2274 #
2275 my $chart3 = $workbook->add_chart( type => 'line' );
2276
2277 # Configure the series.
2278 $chart3->add_series(
2279 categories => '=Sheet1!$A$2:$A$7',
2280 values => '=Sheet1!$B$2:$B$7',
2281 name => 'Test data series 1',
2282 );
2283
2284 # Add some labels.
2285 $chart3->set_title( name => 'Results of sample analysis' );
2286 $chart3->set_x_axis( name => 'Sample number' );
2287 $chart3->set_y_axis( name => 'Sample length (cm)' );
2288
2289
2290 ###############################################################################
2291 #
2292 # Example 4. Same as previous chart but with an added series and with a
2293 # user specified chart sheet name.
2294 #
2295 my $chart4 = $workbook->add_chart( name => 'Results Chart', type => 'line' );
2296
2297 # Configure the series.
2298 $chart4->add_series(
2299 categories => '=Sheet1!$A$2:$A$7',
2300 values => '=Sheet1!$B$2:$B$7',
2301 name => 'Test data series 1',
2302 );
2303
2304 # Add another series.
2305 $chart4->add_series(
2306 categories => '=Sheet1!$A$2:$A$7',
2307 values => '=Sheet1!$C$2:$C$7',
2308 name => 'Test data series 2',
2309 );
2310
2311 # Add some labels.
2312 $chart4->set_title( name => 'Results of sample analysis' );
2313 $chart4->set_x_axis( name => 'Sample number' );
2314 $chart4->set_y_axis( name => 'Sample length (cm)' );
2315
2316
2317 ###############################################################################
2318 #
2319 # Example 5. Same as Example 3 but as an embedded chart.
2320 #
2321 my $chart5 = $workbook->add_chart( type => 'line', embedded => 1 );
2322
2323 # Configure the series.
2324 $chart5->add_series(
2325 categories => '=Sheet1!$A$2:$A$7',
2326 values => '=Sheet1!$B$2:$B$7',
2327 name => 'Test data series 1',
2328 );
2329
2330 # Add some labels.
2331 $chart5->set_title( name => 'Results of sample analysis' );
2332 $chart5->set_x_axis( name => 'Sample number' );
2333 $chart5->set_y_axis( name => 'Sample length (cm)' );
2334
2335 # Insert the chart into the main worksheet.
2336 $worksheet->insert_chart( 'E2', $chart5 );
2337
2338 __END__
2339
2340 Download this example:
2341 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/chart_line.pl
2342 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
2343 WriteExcel-2.36/examples/chart_line.pl>
2344
2345 Example: chart_pie.pl
2346 A simple demo of Pie charts in Spreadsheet::WriteExcel.
2347
2348 Source code for this example:
2349
2350 #!/usr/bin/perl -w
2351
2352 ###############################################################################
2353 #
2354 # A simple demo of Pie charts in Spreadsheet::WriteExcel.
2355 #
2356 # reverse('X'), December 2009, John McNamara, jmcnamara@cpan.org
2357 #
2358
2359 use strict;
2360 use Spreadsheet::WriteExcel;
2361
2362 my $workbook = Spreadsheet::WriteExcel->new( 'chart_pie.xls' );
2363 my $worksheet = $workbook->add_worksheet();
2364 my $bold = $workbook->add_format( bold => 1 );
2365
2366 # Add the worksheet data that the charts will refer to.
2367 my $headings = [ 'Category', 'Values' ];
2368 my $data = [
2369 [ 'Apple', 'Cherry', 'Pecan' ],
2370 [ 60, 30, 10 ],
2371 ];
2372
2373 $worksheet->write( 'A1', $headings, $bold );
2374 $worksheet->write( 'A2', $data );
2375
2376
2377 ###############################################################################
2378 #
2379 # Example 1. A minimal chart.
2380 #
2381 my $chart1 = $workbook->add_chart( type => 'pie' );
2382
2383 # Add values only. Use the default categories.
2384 $chart1->add_series( values => '=Sheet1!$B$2:$B$4' );
2385
2386
2387 ###############################################################################
2388 #
2389 # Example 2. A minimal chart with user specified categories and a series name.
2390 #
2391 my $chart2 = $workbook->add_chart( type => 'pie' );
2392
2393 # Configure the series.
2394 $chart2->add_series(
2395 categories => '=Sheet1!$A$2:$A$4',
2396 values => '=Sheet1!$B$2:$B$4',
2397 name => 'Pie sales data',
2398 );
2399
2400
2401 ###############################################################################
2402 #
2403 # Example 3. Same as previous chart but with an added title.
2404 #
2405 my $chart3 = $workbook->add_chart( type => 'pie' );
2406
2407 # Configure the series.
2408 $chart3->add_series(
2409 categories => '=Sheet1!$A$2:$A$4',
2410 values => '=Sheet1!$B$2:$B$4',
2411 name => 'Pie sales data',
2412 );
2413
2414 # Add a title.
2415 $chart3->set_title( name => 'Popular Pie Types' );
2416
2417
2418 ###############################################################################
2419 #
2420 # Example 4. Same as previous chart with a user specified chart sheet name.
2421 #
2422 my $chart4 = $workbook->add_chart( name => 'Results Chart', type => 'pie' );
2423
2424 # Configure the series.
2425 $chart4->add_series(
2426 categories => '=Sheet1!$A$2:$A$4',
2427 values => '=Sheet1!$B$2:$B$4',
2428 name => 'Pie sales data',
2429 );
2430
2431 # The other chart_*.pl examples add a second series in example 4 but additional
2432 # series aren't plotted in a pie chart.
2433
2434 # Add a title.
2435 $chart4->set_title( name => 'Popular Pie Types' );
2436
2437
2438 ###############################################################################
2439 #
2440 # Example 5. Same as Example 3 but as an embedded chart.
2441 #
2442 my $chart5 = $workbook->add_chart( type => 'pie', embedded => 1 );
2443
2444 # Configure the series.
2445 $chart5->add_series(
2446 categories => '=Sheet1!$A$2:$A$4',
2447 values => '=Sheet1!$B$2:$B$4',
2448 name => 'Pie sales data',
2449 );
2450
2451 # Add a title.
2452 $chart5->set_title( name => 'Popular Pie Types' );
2453
2454 # Insert the chart into the main worksheet.
2455 $worksheet->insert_chart( 'D2', $chart5 );
2456
2457 __END__
2458
2459 Download this example:
2460 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/chart_pie.pl
2461 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
2462 WriteExcel-2.36/examples/chart_pie.pl>
2463
2464 Example: chart_scatter.pl
2465 A simple demo of Scatter charts in Spreadsheet::WriteExcel.
2466
2467 Source code for this example:
2468
2469 #!/usr/bin/perl -w
2470
2471 ###############################################################################
2472 #
2473 # A simple demo of Scatter charts in Spreadsheet::WriteExcel.
2474 #
2475 # reverse('X'), December 2009, John McNamara, jmcnamara@cpan.org
2476 #
2477
2478 use strict;
2479 use Spreadsheet::WriteExcel;
2480
2481 my $workbook = Spreadsheet::WriteExcel->new( 'chart_scatter.xls' );
2482 my $worksheet = $workbook->add_worksheet();
2483 my $bold = $workbook->add_format( bold => 1 );
2484
2485 # Add the worksheet data that the charts will refer to.
2486 my $headings = [ 'Category', 'Values 1', 'Values 2' ];
2487 my $data = [
2488 [ 2, 3, 4, 5, 6, 7 ],
2489 [ 1, 4, 5, 2, 1, 5 ],
2490 [ 3, 6, 7, 5, 4, 3 ],
2491 ];
2492
2493 $worksheet->write( 'A1', $headings, $bold );
2494 $worksheet->write( 'A2', $data );
2495
2496
2497 ###############################################################################
2498 #
2499 # Example 1. A minimal chart.
2500 #
2501 my $chart1 = $workbook->add_chart( type => 'scatter' );
2502
2503 # Add values only. Use the default categories.
2504 $chart1->add_series( values => '=Sheet1!$B$2:$B$7' );
2505
2506
2507 ###############################################################################
2508 #
2509 # Example 2. A minimal chart with user specified categories (X axis)
2510 # and a series name.
2511 #
2512 my $chart2 = $workbook->add_chart( type => 'scatter' );
2513
2514 # Configure the series.
2515 $chart2->add_series(
2516 categories => '=Sheet1!$A$2:$A$7',
2517 values => '=Sheet1!$B$2:$B$7',
2518 name => 'Test data series 1',
2519 );
2520
2521
2522 ###############################################################################
2523 #
2524 # Example 3. Same as previous chart but with added title and axes labels.
2525 #
2526 my $chart3 = $workbook->add_chart( type => 'scatter' );
2527
2528 # Configure the series.
2529 $chart3->add_series(
2530 categories => '=Sheet1!$A$2:$A$7',
2531 values => '=Sheet1!$B$2:$B$7',
2532 name => 'Test data series 1',
2533 );
2534
2535 # Add some labels.
2536 $chart3->set_title( name => 'Results of sample analysis' );
2537 $chart3->set_x_axis( name => 'Sample number' );
2538 $chart3->set_y_axis( name => 'Sample length (cm)' );
2539
2540
2541 ###############################################################################
2542 #
2543 # Example 4. Same as previous chart but with an added series and with a
2544 # user specified chart sheet name.
2545 #
2546 my $chart4 = $workbook->add_chart( name => 'Results Chart', type => 'scatter' );
2547
2548 # Configure the series.
2549 $chart4->add_series(
2550 categories => '=Sheet1!$A$2:$A$7',
2551 values => '=Sheet1!$B$2:$B$7',
2552 name => 'Test data series 1',
2553 );
2554
2555 # Add another series.
2556 $chart4->add_series(
2557 categories => '=Sheet1!$A$2:$A$7',
2558 values => '=Sheet1!$C$2:$C$7',
2559 name => 'Test data series 2',
2560 );
2561
2562 # Add some labels.
2563 $chart4->set_title( name => 'Results of sample analysis' );
2564 $chart4->set_x_axis( name => 'Sample number' );
2565 $chart4->set_y_axis( name => 'Sample length (cm)' );
2566
2567
2568 ###############################################################################
2569 #
2570 # Example 5. Same as Example 3 but as an embedded chart.
2571 #
2572 my $chart5 = $workbook->add_chart( type => 'scatter', embedded => 1 );
2573
2574 # Configure the series.
2575 $chart5->add_series(
2576 categories => '=Sheet1!$A$2:$A$7',
2577 values => '=Sheet1!$B$2:$B$7',
2578 name => 'Test data series 1',
2579 );
2580
2581 # Add some labels.
2582 $chart5->set_title( name => 'Results of sample analysis' );
2583 $chart5->set_x_axis( name => 'Sample number' );
2584 $chart5->set_y_axis( name => 'Sample length (cm)' );
2585
2586 # Insert the chart into the main worksheet.
2587 $worksheet->insert_chart( 'E2', $chart5 );
2588
2589 __END__
2590
2591 Download this example:
2592 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/chart_scatter.pl
2593 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
2594 WriteExcel-2.36/examples/chart_scatter.pl>
2595
2596 Example: chart_stock.pl
2597 A simple demo of Stock charts in Spreadsheet::WriteExcel.
2598
2599 Source code for this example:
2600
2601 #!/usr/bin/perl -w
2602
2603 ###############################################################################
2604 #
2605 # A simple demo of Stock charts in Spreadsheet::WriteExcel.
2606 #
2607 # reverse('AX'), January 2010, John McNamara, jmcnamara@cpan.org
2608 #
2609
2610
2611 use strict;
2612 use Spreadsheet::WriteExcel;
2613
2614 my $workbook = Spreadsheet::WriteExcel->new( 'chart_stock.xls' );
2615 my $worksheet = $workbook->add_worksheet();
2616
2617
2618 ###############################################################################
2619 #
2620 # Set up the data worksheet that the charts will refer to. We read the example
2621 # data from the __DATA__ section at the end of the file. This simulates
2622 # reading the data from a database or other source.
2623 #
2624 # The default Excel Stock chart is an Open-High-Low-Close chart. Therefore
2625 # we will need data for each of those series.
2626 #
2627 # The layout of the __DATA__ section is similar to the layout of the worksheet.
2628 #
2629
2630 # Add some formats.
2631 my $bold = $workbook->add_format( bold => 1 );
2632 my $date_format = $workbook->add_format( num_format => 'dd/mm/yyyy' );
2633
2634 # Increase the width of the column used for date to make it clearer.
2635 $worksheet->set_column( 'A:A', 12 );
2636
2637 # Read the data from the __DATA__ section at the end. In a real example this
2638 # would probably be a database query.
2639 my @stock_data;
2640
2641 while ( <DATA> ) {
2642 next unless /\S/; # Skip blank lines.
2643 next if /^#/; # Skip comments.
2644
2645 push @stock_data, [split];
2646 }
2647
2648 # Write the data to the worksheet.
2649 my $row = 0;
2650 my $col = 0;
2651
2652 my $headers = shift @stock_data;
2653 $worksheet->write( $row++, $col, $headers, $bold );
2654
2655 for my $stock_data ( @stock_data ) {
2656
2657 my @data = @$stock_data;
2658 my $date = shift @data;
2659
2660 $worksheet->write( $row, $col, $date, $date_format );
2661 $worksheet->write( $row, $col + 1, \@data );
2662
2663 $row++;
2664 }
2665
2666
2667 ###############################################################################
2668 #
2669 # Example 1. A default Open-High-Low-Close chart with series names, axes labels
2670 # and a title.
2671 #
2672
2673 my $chart1 = $workbook->add_chart( type => 'stock' );
2674
2675 # Add a series for each of the Open-High-Low-Close columns. The categories are
2676 # the dates in the first column.
2677
2678 $chart1->add_series(
2679 categories => '=Sheet1!$A$2:$A$10',
2680 values => '=Sheet1!$B$2:$B$10',
2681 name => 'Open',
2682 );
2683
2684 $chart1->add_series(
2685 categories => '=Sheet1!$A$2:$A$10',
2686 values => '=Sheet1!$C$2:$C$10',
2687 name => 'High',
2688 );
2689
2690 $chart1->add_series(
2691 categories => '=Sheet1!$A$2:$A$10',
2692 values => '=Sheet1!$D$2:$D$10',
2693 name => 'Low',
2694 );
2695
2696 $chart1->add_series(
2697 categories => '=Sheet1!$A$2:$A$10',
2698 values => '=Sheet1!$E$2:$E$10',
2699 name => 'Close',
2700 );
2701
2702 # Add a chart title and axes labels.
2703 $chart1->set_title( name => 'Open-High-Low-Close', );
2704 $chart1->set_x_axis( name => 'Date', );
2705 $chart1->set_y_axis( name => 'Share price', );
2706
2707 ###############################################################################
2708 #
2709 # Example 2. Same as the previous as an embedded chart.
2710 #
2711
2712 my $chart2 = $workbook->add_chart( type => 'stock', embedded => 1 );
2713
2714 # Add a series for each of the Open-High-Low-Close columns. The categories are
2715 # the dates in the first column.
2716
2717 $chart2->add_series(
2718 categories => '=Sheet1!$A$2:$A$10',
2719 values => '=Sheet1!$B$2:$B$10',
2720 name => 'Open',
2721 );
2722
2723 $chart2->add_series(
2724 categories => '=Sheet1!$A$2:$A$10',
2725 values => '=Sheet1!$C$2:$C$10',
2726 name => 'High',
2727 );
2728
2729 $chart2->add_series(
2730 categories => '=Sheet1!$A$2:$A$10',
2731 values => '=Sheet1!$D$2:$D$10',
2732 name => 'Low',
2733 );
2734
2735 $chart2->add_series(
2736 categories => '=Sheet1!$A$2:$A$10',
2737 values => '=Sheet1!$E$2:$E$10',
2738 name => 'Close',
2739 );
2740
2741 # Add a chart title and axes labels.
2742 $chart2->set_title( name => 'Open-High-Low-Close', );
2743 $chart2->set_x_axis( name => 'Date', );
2744 $chart2->set_y_axis( name => 'Share price', );
2745
2746 # Insert the chart into the main worksheet.
2747 $worksheet->insert_chart( 'G2', $chart2 );
2748
2749
2750 __DATA__
2751 # Some sample stock data used for charting.
2752 Date Open High Low Close
2753 2009-08-19 100.00 104.06 95.96 100.34
2754 2009-08-20 101.01 109.08 100.50 108.31
2755 2009-08-23 110.75 113.48 109.05 109.40
2756 2009-08-24 111.24 111.60 103.57 104.87
2757 2009-08-25 104.96 108.00 103.88 106.00
2758 2009-08-26 104.95 107.95 104.66 107.91
2759 2009-08-27 108.10 108.62 105.69 106.15
2760 2009-08-30 105.28 105.49 102.01 102.01
2761 2009-08-31 102.30 103.71 102.16 102.37
2762
2763 Download this example:
2764 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/chart_stock.pl
2765 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
2766 WriteExcel-2.36/examples/chart_stock.pl>
2767
2768 Example: chess.pl
2769 Example of formatting using the Spreadsheet::WriteExcel module via
2770 property hashes.
2771
2772 Setting format properties via hashes of values is useful when you have
2773 to deal with a large number of similar formats. Consider for example a
2774 chess board pattern with black squares, white unformatted squares and a
2775 border.
2776
2777 This relatively simple example requires 14 separate Format objects
2778 although there are only 5 different properties: black background, top
2779 border, bottom border, left border and right border.
2780
2781 Using property hashes it is possible to define these 5 sets of
2782 properties and then add them together to create the 14 Format
2783 configurations.
2784
2785 Source code for this example:
2786
2787 #!/usr/bin/perl -w
2788
2789 ########################################################################
2790 #
2791 # Example of formatting using the Spreadsheet::WriteExcel module via
2792 # property hashes.
2793 #
2794 # Setting format properties via hashes of values is useful when you have
2795 # to deal with a large number of similar formats. Consider for example a
2796 # chess board pattern with black squares, white unformatted squares and
2797 # a border.
2798 #
2799 # This relatively simple example requires 14 separate Format
2800 # objects although there are only 5 different properties: black
2801 # background, top border, bottom border, left border and right border.
2802 #
2803 # Using property hashes it is possible to define these 5 sets of
2804 # properties and then add them together to create the 14 Format
2805 # configurations.
2806 #
2807 # reverse('X'), July 2001, John McNamara, jmcnamara@cpan.org
2808 #
2809
2810 use strict;
2811 use Spreadsheet::WriteExcel;
2812
2813 my $workbook = Spreadsheet::WriteExcel->new("chess.xls");
2814 my $worksheet = $workbook->add_worksheet();
2815
2816
2817 # Some row and column formatting
2818 $worksheet->set_column('B:I', 10);
2819
2820 for my $i (1..8) {
2821 $worksheet->set_row($i, 50);
2822 }
2823
2824
2825 # Define the property hashes
2826 #
2827 my %black = (
2828 'fg_color' => 'black',
2829 'pattern' => 1,
2830 );
2831
2832 my %top = ( 'top' => 6 );
2833 my %bottom = ( 'bottom' => 6 );
2834 my %left = ( 'left' => 6 );
2835 my %right = ( 'right' => 6 );
2836
2837
2838 # Define the formats
2839 #
2840 my $format01 = $workbook->add_format(%top, %left );
2841 my $format02 = $workbook->add_format(%top, %black );
2842 my $format03 = $workbook->add_format(%top, );
2843 my $format04 = $workbook->add_format(%top, %right, %black );
2844
2845 my $format05 = $workbook->add_format(%left );
2846 my $format06 = $workbook->add_format(%black );
2847 my $format07 = $workbook->add_format( );
2848 my $format08 = $workbook->add_format(%right, %black );
2849 my $format09 = $workbook->add_format(%right );
2850 my $format10 = $workbook->add_format(%left, %black );
2851
2852 my $format11 = $workbook->add_format(%bottom, %left, %black );
2853 my $format12 = $workbook->add_format(%bottom );
2854 my $format13 = $workbook->add_format(%bottom, %black );
2855 my $format14 = $workbook->add_format(%bottom, %right );
2856
2857
2858 # Draw the pattern
2859 $worksheet->write('B2', '', $format01);
2860 $worksheet->write('C2', '', $format02);
2861 $worksheet->write('D2', '', $format03);
2862 $worksheet->write('E2', '', $format02);
2863 $worksheet->write('F2', '', $format03);
2864 $worksheet->write('G2', '', $format02);
2865 $worksheet->write('H2', '', $format03);
2866 $worksheet->write('I2', '', $format04);
2867
2868 $worksheet->write('B3', '', $format10);
2869 $worksheet->write('C3', '', $format07);
2870 $worksheet->write('D3', '', $format06);
2871 $worksheet->write('E3', '', $format07);
2872 $worksheet->write('F3', '', $format06);
2873 $worksheet->write('G3', '', $format07);
2874 $worksheet->write('H3', '', $format06);
2875 $worksheet->write('I3', '', $format09);
2876
2877 $worksheet->write('B4', '', $format05);
2878 $worksheet->write('C4', '', $format06);
2879 $worksheet->write('D4', '', $format07);
2880 $worksheet->write('E4', '', $format06);
2881 $worksheet->write('F4', '', $format07);
2882 $worksheet->write('G4', '', $format06);
2883 $worksheet->write('H4', '', $format07);
2884 $worksheet->write('I4', '', $format08);
2885
2886 $worksheet->write('B5', '', $format10);
2887 $worksheet->write('C5', '', $format07);
2888 $worksheet->write('D5', '', $format06);
2889 $worksheet->write('E5', '', $format07);
2890 $worksheet->write('F5', '', $format06);
2891 $worksheet->write('G5', '', $format07);
2892 $worksheet->write('H5', '', $format06);
2893 $worksheet->write('I5', '', $format09);
2894
2895 $worksheet->write('B6', '', $format05);
2896 $worksheet->write('C6', '', $format06);
2897 $worksheet->write('D6', '', $format07);
2898 $worksheet->write('E6', '', $format06);
2899 $worksheet->write('F6', '', $format07);
2900 $worksheet->write('G6', '', $format06);
2901 $worksheet->write('H6', '', $format07);
2902 $worksheet->write('I6', '', $format08);
2903
2904 $worksheet->write('B7', '', $format10);
2905 $worksheet->write('C7', '', $format07);
2906 $worksheet->write('D7', '', $format06);
2907 $worksheet->write('E7', '', $format07);
2908 $worksheet->write('F7', '', $format06);
2909 $worksheet->write('G7', '', $format07);
2910 $worksheet->write('H7', '', $format06);
2911 $worksheet->write('I7', '', $format09);
2912
2913 $worksheet->write('B8', '', $format05);
2914 $worksheet->write('C8', '', $format06);
2915 $worksheet->write('D8', '', $format07);
2916 $worksheet->write('E8', '', $format06);
2917 $worksheet->write('F8', '', $format07);
2918 $worksheet->write('G8', '', $format06);
2919 $worksheet->write('H8', '', $format07);
2920 $worksheet->write('I8', '', $format08);
2921
2922 $worksheet->write('B9', '', $format11);
2923 $worksheet->write('C9', '', $format12);
2924 $worksheet->write('D9', '', $format13);
2925 $worksheet->write('E9', '', $format12);
2926 $worksheet->write('F9', '', $format13);
2927 $worksheet->write('G9', '', $format12);
2928 $worksheet->write('H9', '', $format13);
2929 $worksheet->write('I9', '', $format14);
2930
2931 Download this example:
2932 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/chess.pl
2933 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
2934 WriteExcel-2.36/examples/chess.pl>
2935
2936 Example: colors.pl
2937 Demonstrates Spreadsheet::WriteExcel's named colors and the Excel color
2938 palette.
2939
2940 The set_custom_color() Worksheet method can be used to override one of
2941 the built-in palette values with a more suitable colour. See the main
2942 docs.
2943
2944 Source code for this example:
2945
2946 #!/usr/bin/perl -w
2947
2948 ################################################################################
2949 #
2950 # Demonstrates Spreadsheet::WriteExcel's named colors and the Excel color
2951 # palette.
2952 #
2953 # The set_custom_color() Worksheet method can be used to override one of the
2954 # built-in palette values with a more suitable colour. See the main docs.
2955 #
2956 # reverse('X'), March 2002, John McNamara, jmcnamara@cpan.org
2957 #
2958
2959 use strict;
2960 use Spreadsheet::WriteExcel;
2961
2962 my $workbook = Spreadsheet::WriteExcel->new("colors.xls");
2963
2964 # Some common formats
2965 my $center = $workbook->add_format(align => 'center');
2966 my $heading = $workbook->add_format(align => 'center', bold => 1);
2967
2968
2969 ######################################################################
2970 #
2971 # Demonstrate the named colors.
2972 #
2973
2974 my %colors = (
2975 0x08, 'black',
2976 0x0C, 'blue',
2977 0x10, 'brown',
2978 0x0F, 'cyan',
2979 0x17, 'gray',
2980 0x11, 'green',
2981 0x0B, 'lime',
2982 0x0E, 'magenta',
2983 0x12, 'navy',
2984 0x35, 'orange',
2985 0x21, 'pink',
2986 0x14, 'purple',
2987 0x0A, 'red',
2988 0x16, 'silver',
2989 0x09, 'white',
2990 0x0D, 'yellow',
2991 );
2992
2993 my $worksheet1 = $workbook->add_worksheet('Named colors');
2994
2995 $worksheet1->set_column(0, 3, 15);
2996
2997 $worksheet1->write(0, 0, "Index", $heading);
2998 $worksheet1->write(0, 1, "Index", $heading);
2999 $worksheet1->write(0, 2, "Name", $heading);
3000 $worksheet1->write(0, 3, "Color", $heading);
3001
3002 my $i = 1;
3003
3004 while (my($index, $color) = each %colors) {
3005 my $format = $workbook->add_format(
3006 fg_color => $color,
3007 pattern => 1,
3008 border => 1
3009 );
3010
3011 $worksheet1->write($i+1, 0, $index, $center);
3012 $worksheet1->write($i+1, 1, sprintf("0x%02X", $index), $center);
3013 $worksheet1->write($i+1, 2, $color, $center);
3014 $worksheet1->write($i+1, 3, '', $format);
3015 $i++;
3016 }
3017
3018
3019 ######################################################################
3020 #
3021 # Demonstrate the standard Excel colors in the range 8..63.
3022 #
3023
3024 my $worksheet2 = $workbook->add_worksheet('Standard colors');
3025
3026 $worksheet2->set_column(0, 3, 15);
3027
3028 $worksheet2->write(0, 0, "Index", $heading);
3029 $worksheet2->write(0, 1, "Index", $heading);
3030 $worksheet2->write(0, 2, "Color", $heading);
3031 $worksheet2->write(0, 3, "Name", $heading);
3032
3033 for my $i (8..63) {
3034 my $format = $workbook->add_format(
3035 fg_color => $i,
3036 pattern => 1,
3037 border => 1
3038 );
3039
3040 $worksheet2->write(($i -7), 0, $i, $center);
3041 $worksheet2->write(($i -7), 1, sprintf("0x%02X", $i), $center);
3042 $worksheet2->write(($i -7), 2, '', $format);
3043
3044 # Add the color names
3045 if (exists $colors{$i}) {
3046 $worksheet2->write(($i -7), 3, $colors{$i}, $center);
3047
3048 }
3049 }
3050
3051 __END__
3052
3053 Download this example:
3054 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/colors.pl
3055 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
3056 WriteExcel-2.36/examples/colors.pl>
3057
3058 Example: comments1.pl
3059 This example demonstrates writing cell comments.
3060
3061 A cell comment is indicated in Excel by a small red triangle in the
3062 upper right-hand corner of the cell.
3063
3064 For more advanced comment options see comments2.pl.
3065
3066 Source code for this example:
3067
3068 #!/usr/bin/perl -w
3069
3070 ###############################################################################
3071 #
3072 # This example demonstrates writing cell comments.
3073 #
3074 # A cell comment is indicated in Excel by a small red triangle in the upper
3075 # right-hand corner of the cell.
3076 #
3077 # For more advanced comment options see comments2.pl.
3078 #
3079 # reverse('X'), November 2005, John McNamara, jmcnamara@cpan.org
3080 #
3081
3082 use strict;
3083 use Spreadsheet::WriteExcel;
3084
3085 my $workbook = Spreadsheet::WriteExcel->new("comments1.xls");
3086 my $worksheet = $workbook->add_worksheet();
3087
3088
3089
3090 $worksheet->write ('A1', 'Hello' );
3091 $worksheet->write_comment('A1', 'This is a comment');
3092
3093 __END__
3094
3095 Download this example:
3096 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/comments1.pl
3097 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
3098 WriteExcel-2.36/examples/comments1.pl>
3099
3100 Example: comments2.pl
3101 This example demonstrates writing cell comments.
3102
3103 A cell comment is indicated in Excel by a small red triangle in the
3104 upper right-hand corner of the cell.
3105
3106 Each of the worksheets demonstrates different features of cell
3107 comments.
3108
3109 Source code for this example:
3110
3111 #!/usr/bin/perl -w
3112
3113 ###############################################################################
3114 #
3115 # This example demonstrates writing cell comments.
3116 #
3117 # A cell comment is indicated in Excel by a small red triangle in the upper
3118 # right-hand corner of the cell.
3119 #
3120 # Each of the worksheets demonstrates different features of cell comments.
3121 #
3122 # reverse('X'), November 2005, John McNamara, jmcnamara@cpan.org
3123 #
3124
3125 use strict;
3126 use Spreadsheet::WriteExcel;
3127
3128 my $workbook = Spreadsheet::WriteExcel->new("comments2.xls");
3129 my $text_wrap = $workbook->add_format(text_wrap => 1, valign => 'top');
3130 my $worksheet1 = $workbook->add_worksheet();
3131 my $worksheet2 = $workbook->add_worksheet();
3132 my $worksheet3 = $workbook->add_worksheet();
3133 my $worksheet4 = $workbook->add_worksheet();
3134 my $worksheet5 = $workbook->add_worksheet();
3135 my $worksheet6 = $workbook->add_worksheet();
3136 my $worksheet7 = $workbook->add_worksheet();
3137 my $worksheet8 = $workbook->add_worksheet();
3138
3139
3140 # Variables that we will use in each example.
3141 my $cell_text = '';
3142 my $comment = '';
3143
3144
3145
3146
3147 ###############################################################################
3148 #
3149 # Example 1. Demonstrates a simple cell comment without formatting and Unicode
3150 # comments encoded as UTF-16 and as UTF-8.
3151 #
3152
3153 # Set up some formatting.
3154 $worksheet1->set_column('C:C', 25);
3155 $worksheet1->set_row(2, 50);
3156 $worksheet1->set_row(5, 50);
3157
3158
3159 # Simple ascii string.
3160 $cell_text = 'Hold the mouse over this cell to see the comment.';
3161
3162 $comment = 'This is a comment.';
3163
3164 $worksheet1->write ('C3', $cell_text, $text_wrap);
3165 $worksheet1->write_comment('C3', $comment);
3166
3167
3168 # UTF-16 string.
3169 $cell_text = 'This is a UTF-16 comment.';
3170
3171 $comment = pack "n", 0x263a;
3172
3173 $worksheet1->write ('C6', $cell_text, $text_wrap);
3174 $worksheet1->write_comment('C6', $comment, encoding => 1);
3175
3176
3177 # UTF-8 string in perl 5.8.
3178 if ($] >= 5.008) {
3179
3180 $worksheet1->set_row(8, 50);
3181 $cell_text = 'This is a UTF-8 string.';
3182 $comment = chr 0x263a;
3183
3184 $worksheet1->write ('C9', $cell_text, $text_wrap);
3185 $worksheet1->write_comment('C9', $comment);
3186 }
3187
3188
3189
3190 ###############################################################################
3191 #
3192 # Example 2. Demonstrates visible and hidden comments.
3193 #
3194
3195 # Set up some formatting.
3196 $worksheet2->set_column('C:C', 25);
3197 $worksheet2->set_row(2, 50);
3198 $worksheet2->set_row(5, 50);
3199
3200
3201 $cell_text = 'This cell comment is visible.';
3202
3203 $comment = 'Hello.';
3204
3205 $worksheet2->write ('C3', $cell_text, $text_wrap);
3206 $worksheet2->write_comment('C3', $comment, visible => 1);
3207
3208
3209 $cell_text = "This cell comment isn't visible (the default).";
3210
3211 $comment = 'Hello.';
3212
3213 $worksheet2->write ('C6', $cell_text, $text_wrap);
3214 $worksheet2->write_comment('C6', $comment);
3215
3216
3217
3218
3219 ###############################################################################
3220 #
3221 # Example 3. Demonstrates visible and hidden comments set at the worksheet
3222 # level.
3223 #
3224
3225 # Set up some formatting.
3226 $worksheet3->set_column('C:C', 25);
3227 $worksheet3->set_row(2, 50);
3228 $worksheet3->set_row(5, 50);
3229 $worksheet3->set_row(8, 50);
3230
3231 # Make all comments on the worksheet visible.
3232 $worksheet3->show_comments();
3233
3234 $cell_text = 'This cell comment is visible, explicitly.';
3235
3236 $comment = 'Hello.';
3237
3238 $worksheet3->write ('C3', $cell_text, $text_wrap);
3239 $worksheet3->write_comment('C3', $comment, visible => 1);
3240
3241
3242 $cell_text = 'This cell comment is also visible because '.
3243 'we used show_comments().';
3244
3245 $comment = 'Hello.';
3246
3247 $worksheet3->write ('C6', $cell_text, $text_wrap);
3248 $worksheet3->write_comment('C6', $comment);
3249
3250
3251 $cell_text = 'However, we can still override it locally.';
3252
3253 $comment = 'Hello.';
3254
3255 $worksheet3->write ('C9', $cell_text, $text_wrap);
3256 $worksheet3->write_comment('C9', $comment, visible => 0);
3257
3258
3259
3260
3261 ###############################################################################
3262 #
3263 # Example 4. Demonstrates changes to the comment box dimensions.
3264 #
3265
3266 # Set up some formatting.
3267 $worksheet4->set_column('C:C', 25);
3268 $worksheet4->set_row(2, 50);
3269 $worksheet4->set_row(5, 50);
3270 $worksheet4->set_row(8, 50);
3271 $worksheet4->set_row(15, 50);
3272
3273 $worksheet4->show_comments();
3274
3275 $cell_text = 'This cell comment is default size.';
3276
3277 $comment = 'Hello.';
3278
3279 $worksheet4->write ('C3', $cell_text, $text_wrap);
3280 $worksheet4->write_comment('C3', $comment);
3281
3282
3283 $cell_text = 'This cell comment is twice as wide.';
3284
3285 $comment = 'Hello.';
3286
3287 $worksheet4->write ('C6', $cell_text, $text_wrap);
3288 $worksheet4->write_comment('C6', $comment, x_scale => 2);
3289
3290
3291 $cell_text = 'This cell comment is twice as high.';
3292
3293 $comment = 'Hello.';
3294
3295 $worksheet4->write ('C9', $cell_text, $text_wrap);
3296 $worksheet4->write_comment('C9', $comment, y_scale => 2);
3297
3298
3299 $cell_text = 'This cell comment is scaled in both directions.';
3300
3301 $comment = 'Hello.';
3302
3303 $worksheet4->write ('C16', $cell_text, $text_wrap);
3304 $worksheet4->write_comment('C16', $comment, x_scale => 1.2, y_scale => 0.8);
3305
3306
3307 $cell_text = 'This cell comment has width and height specified in pixels.';
3308
3309 $comment = 'Hello.';
3310
3311 $worksheet4->write ('C19', $cell_text, $text_wrap);
3312 $worksheet4->write_comment('C19', $comment, width => 200, height => 20);
3313
3314
3315
3316 ###############################################################################
3317 #
3318 # Example 5. Demonstrates changes to the cell comment position.
3319 #
3320
3321 $worksheet5->set_column('C:C', 25);
3322 $worksheet5->set_row(2, 50);
3323 $worksheet5->set_row(5, 50);
3324 $worksheet5->set_row(8, 50);
3325 $worksheet5->set_row(11, 50);
3326
3327 $worksheet5->show_comments();
3328
3329 $cell_text = 'This cell comment is in the default position.';
3330
3331 $comment = 'Hello.';
3332
3333 $worksheet5->write ('C3', $cell_text, $text_wrap);
3334 $worksheet5->write_comment('C3', $comment);
3335
3336
3337 $cell_text = 'This cell comment has been moved to another cell.';
3338
3339 $comment = 'Hello.';
3340
3341 $worksheet5->write ('C6', $cell_text, $text_wrap);
3342 $worksheet5->write_comment('C6', $comment, start_cell => 'E4');
3343
3344
3345 $cell_text = 'This cell comment has been moved to another cell.';
3346
3347 $comment = 'Hello.';
3348
3349 $worksheet5->write ('C9', $cell_text, $text_wrap);
3350 $worksheet5->write_comment('C9', $comment, start_row => 8, start_col => 4);
3351
3352
3353 $cell_text = 'This cell comment has been shifted within its default cell.';
3354
3355 $comment = 'Hello.';
3356
3357 $worksheet5->write ('C12', $cell_text, $text_wrap);
3358 $worksheet5->write_comment('C12', $comment, x_offset => 30, y_offset => 12);
3359
3360
3361
3362 ###############################################################################
3363 #
3364 # Example 6. Demonstrates changes to the comment background colour.
3365 #
3366
3367 $worksheet6->set_column('C:C', 25);
3368 $worksheet6->set_row(2, 50);
3369 $worksheet6->set_row(5, 50);
3370 $worksheet6->set_row(8, 50);
3371
3372 $worksheet6->show_comments();
3373
3374 $cell_text = 'This cell comment has a different colour.';
3375
3376 $comment = 'Hello.';
3377
3378 $worksheet6->write ('C3', $cell_text, $text_wrap);
3379 $worksheet6->write_comment('C3', $comment, color => 'green');
3380
3381
3382 $cell_text = 'This cell comment has the default colour.';
3383
3384 $comment = 'Hello.';
3385
3386 $worksheet6->write ('C6', $cell_text, $text_wrap);
3387 $worksheet6->write_comment('C6', $comment);
3388
3389
3390 $cell_text = 'This cell comment has a different colour.';
3391
3392 $comment = 'Hello.';
3393
3394 $worksheet6->write ('C9', $cell_text, $text_wrap);
3395 $worksheet6->write_comment('C9', $comment, color => 0x35);
3396
3397
3398
3399
3400 ###############################################################################
3401 #
3402 # Example 7. Demonstrates how to set the cell comment author.
3403 #
3404
3405 $worksheet7->set_column('C:C', 30);
3406 $worksheet7->set_row(2, 50);
3407 $worksheet7->set_row(5, 50);
3408 $worksheet7->set_row(8, 50);
3409 $worksheet7->set_row(11, 50);
3410
3411 my $author = '';
3412 my $cell = 'C3';
3413
3414 $cell_text = "Move the mouse over this cell and you will see 'Cell commented ".
3415 "by $author' (blank) in the status bar at the bottom";
3416
3417 $comment = 'Hello.';
3418
3419 $worksheet7->write ($cell, $cell_text, $text_wrap);
3420 $worksheet7->write_comment($cell, $comment);
3421
3422
3423 $author = 'Perl';
3424 $cell = 'C6';
3425 $cell_text = "Move the mouse over this cell and you will see 'Cell commented ".
3426 "by $author' in the status bar at the bottom";
3427
3428 $comment = 'Hello.';
3429
3430 $worksheet7->write ($cell, $cell_text, $text_wrap);
3431 $worksheet7->write_comment($cell, $comment, author => $author);
3432
3433
3434 $author = pack "n", 0x20AC; # UTF-16 Euro
3435 $cell = 'C9';
3436 $cell_text = "Move the mouse over this cell and you will see 'Cell commented ".
3437 "by Euro' in the status bar at the bottom";
3438
3439 $comment = 'Hello.';
3440
3441 $worksheet7->write ($cell, $cell_text, $text_wrap);
3442 $worksheet7->write_comment($cell, $comment, author => $author,
3443 author_encoding => 1 );
3444
3445 # UTF-8 string in perl 5.8.
3446 if ($] >= 5.008) {
3447 $author = chr 0x20AC;
3448 $cell = 'C12';
3449 $cell_text = "Move the mouse over this cell and you will see 'Cell commented ".
3450 "by $author' in the status bar at the bottom";
3451 $comment = 'Hello.';
3452
3453 $worksheet7->write ($cell, $cell_text, $text_wrap);
3454 $worksheet7->write_comment($cell, $comment, author => $author);
3455
3456 }
3457
3458
3459 ###############################################################################
3460 #
3461 # Example 8. Demonstrates the need to explicitly set the row height.
3462 #
3463
3464 # Set up some formatting.
3465 $worksheet8->set_column('C:C', 25);
3466 $worksheet8->set_row(2, 80);
3467
3468 $worksheet8->show_comments();
3469
3470
3471 $cell_text = 'The height of this row has been adjusted explicitly using ' .
3472 'set_row(). The size of the comment box is adjusted ' .
3473 'accordingly by WriteExcel.';
3474
3475 $comment = 'Hello.';
3476
3477 $worksheet8->write ('C3', $cell_text, $text_wrap);
3478 $worksheet8->write_comment('C3', $comment);
3479
3480
3481 $cell_text = 'The height of this row has been adjusted by Excel due to the ' .
3482 'text wrap property being set. Unfortunately this means that ' .
3483 'the height of the row is unknown to WriteExcel at run time ' .
3484 "and thus the comment box is stretched as well.\n\n" .
3485 'Use set_row() to specify the row height explicitly to avoid ' .
3486 'this problem.';
3487
3488 $comment = 'Hello.';
3489
3490 $worksheet8->write ('C6', $cell_text, $text_wrap);
3491 $worksheet8->write_comment('C6', $comment);
3492
3493 __END__
3494
3495 Download this example:
3496 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/comments2.pl
3497 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
3498 WriteExcel-2.36/examples/comments2.pl>
3499
3500 Example: copyformat.pl
3501 Example of how to use the format copying method with
3502 Spreadsheet::WriteExcel.
3503
3504 This feature isn't required very often.
3505
3506 Source code for this example:
3507
3508 #!/usr/bin/perl -w
3509
3510 ###############################################################################
3511 #
3512 # Example of how to use the format copying method with Spreadsheet::WriteExcel.
3513 #
3514 # This feature isn't required very often.
3515 #
3516 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
3517 #
3518
3519 use strict;
3520 use Spreadsheet::WriteExcel;
3521
3522 # Create workbook1
3523 my $workbook1 = Spreadsheet::WriteExcel->new("workbook1.xls");
3524 my $worksheet1 = $workbook1->add_worksheet();
3525 my $format1a = $workbook1->add_format();
3526 my $format1b = $workbook1->add_format();
3527
3528 # Create workbook2
3529 my $workbook2 = Spreadsheet::WriteExcel->new("workbook2.xls");
3530 my $worksheet2 = $workbook2->add_worksheet();
3531 my $format2a = $workbook2->add_format();
3532 my $format2b = $workbook2->add_format();
3533
3534
3535 # Create a global format object that isn't tied to a workbook
3536 my $global_format = Spreadsheet::WriteExcel::Format->new();
3537
3538 # Set the formatting
3539 $global_format->set_color('blue');
3540 $global_format->set_bold();
3541 $global_format->set_italic();
3542
3543 # Create another example format
3544 $format1b->set_color('red');
3545
3546 # Copy the global format properties to the worksheet formats
3547 $format1a->copy($global_format);
3548 $format2a->copy($global_format);
3549
3550 # Copy a format from worksheet1 to worksheet2
3551 $format2b->copy($format1b);
3552
3553 # Write some output
3554 $worksheet1->write(0, 0, "Ciao", $format1a);
3555 $worksheet1->write(1, 0, "Ciao", $format1b);
3556
3557 $worksheet2->write(0, 0, "Hello", $format2a);
3558 $worksheet2->write(1, 0, "Hello", $format2b);
3559
3560 Download this example:
3561 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/copyformat.pl
3562 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
3563 WriteExcel-2.36/examples/copyformat.pl>
3564
3565 Example: data_validate.pl
3566 Example of how to add data validation and dropdown lists to a
3567 Spreadsheet::WriteExcel file.
3568
3569 Data validation is a feature of Excel which allows you to restrict the
3570 data that a users enters in a cell and to display help and warning
3571 messages. It also allows you to restrict input to values in a drop down
3572 list.
3573
3574 Source code for this example:
3575
3576 #!/usr/bin/perl -w
3577
3578 ###############################################################################
3579 #
3580 # Example of how to add data validation and dropdown lists to a
3581 # Spreadsheet::WriteExcel file.
3582 #
3583 # Data validation is a feature of Excel which allows you to restrict the data
3584 # that a users enters in a cell and to display help and warning messages. It
3585 # also allows you to restrict input to values in a drop down list.
3586 #
3587 # reverse('X'), August 2008, John McNamara, jmcnamara@cpan.org
3588 #
3589
3590 use strict;
3591 use Spreadsheet::WriteExcel;
3592
3593 my $workbook = Spreadsheet::WriteExcel->new('data_validate.xls');
3594 my $worksheet = $workbook->add_worksheet();
3595
3596 # Add a format for the header cells.
3597 my $header_format = $workbook->add_format(
3598 border => 1,
3599 bg_color => 43,
3600 bold => 1,
3601 text_wrap => 1,
3602 valign => 'vcenter',
3603 indent => 1,
3604 );
3605
3606 # Set up layout of the worksheet.
3607 $worksheet->set_column('A:A', 64);
3608 $worksheet->set_column('B:B', 15);
3609 $worksheet->set_column('D:D', 15);
3610 $worksheet->set_row(0, 36);
3611 $worksheet->set_selection('B3');
3612
3613
3614 # Write the header cells and some data that will be used in the examples.
3615 my $row = 0;
3616 my $txt;
3617 my $heading1 = 'Some examples of data validation in Spreadsheet::WriteExcel';
3618 my $heading2 = 'Enter values in this column';
3619 my $heading3 = 'Sample Data';
3620
3621 $worksheet->write('A1', $heading1, $header_format);
3622 $worksheet->write('B1', $heading2, $header_format);
3623 $worksheet->write('D1', $heading3, $header_format);
3624
3625 $worksheet->write('D3', ['Integers', 1, 10]);
3626 $worksheet->write('D4', ['List data', 'open', 'high', 'close']);
3627 $worksheet->write('D5', ['Formula', '=AND(F5=50,G5=60)', 50, 60]);
3628
3629
3630 #
3631 # Example 1. Limiting input to an integer in a fixed range.
3632 #
3633 $txt = 'Enter an integer between 1 and 10';
3634 $row += 2;
3635
3636 $worksheet->write($row, 0, $txt);
3637 $worksheet->data_validation($row, 1,
3638 {
3639 validate => 'integer',
3640 criteria => 'between',
3641 minimum => 1,
3642 maximum => 10,
3643 });
3644
3645
3646 #
3647 # Example 2. Limiting input to an integer outside a fixed range.
3648 #
3649 $txt = 'Enter an integer that is not between 1 and 10 (using cell references)';
3650 $row += 2;
3651
3652 $worksheet->write($row, 0, $txt);
3653 $worksheet->data_validation($row, 1,
3654 {
3655 validate => 'integer',
3656 criteria => 'not between',
3657 minimum => '=E3',
3658 maximum => '=F3',
3659 });
3660
3661
3662 #
3663 # Example 3. Limiting input to an integer greater than a fixed value.
3664 #
3665 $txt = 'Enter an integer greater than 0';
3666 $row += 2;
3667
3668 $worksheet->write($row, 0, $txt);
3669 $worksheet->data_validation($row, 1,
3670 {
3671 validate => 'integer',
3672 criteria => '>',
3673 value => 0,
3674 });
3675
3676
3677 #
3678 # Example 4. Limiting input to an integer less than a fixed value.
3679 #
3680 $txt = 'Enter an integer less than 10';
3681 $row += 2;
3682
3683 $worksheet->write($row, 0, $txt);
3684 $worksheet->data_validation($row, 1,
3685 {
3686 validate => 'integer',
3687 criteria => '<',
3688 value => 10,
3689 });
3690
3691
3692 #
3693 # Example 5. Limiting input to a decimal in a fixed range.
3694 #
3695 $txt = 'Enter a decimal between 0.1 and 0.5';
3696 $row += 2;
3697
3698 $worksheet->write($row, 0, $txt);
3699 $worksheet->data_validation($row, 1,
3700 {
3701 validate => 'decimal',
3702 criteria => 'between',
3703 minimum => 0.1,
3704 maximum => 0.5,
3705 });
3706
3707
3708 #
3709 # Example 6. Limiting input to a value in a dropdown list.
3710 #
3711 $txt = 'Select a value from a drop down list';
3712 $row += 2;
3713
3714 $worksheet->write($row, 0, $txt);
3715 $worksheet->data_validation($row, 1,
3716 {
3717 validate => 'list',
3718 source => ['open', 'high', 'close'],
3719 });
3720
3721
3722 #
3723 # Example 6. Limiting input to a value in a dropdown list.
3724 #
3725 $txt = 'Select a value from a drop down list (using a cell range)';
3726 $row += 2;
3727
3728 $worksheet->write($row, 0, $txt);
3729 $worksheet->data_validation($row, 1,
3730 {
3731 validate => 'list',
3732 source => '=E4:G4',
3733 });
3734
3735
3736 #
3737 # Example 7. Limiting input to a date in a fixed range.
3738 #
3739 $txt = 'Enter a date between 1/1/2008 and 12/12/2008';
3740 $row += 2;
3741
3742 $worksheet->write($row, 0, $txt);
3743 $worksheet->data_validation($row, 1,
3744 {
3745 validate => 'date',
3746 criteria => 'between',
3747 minimum => '2008-01-01T',
3748 maximum => '2008-12-12T',
3749 });
3750
3751
3752 #
3753 # Example 8. Limiting input to a time in a fixed range.
3754 #
3755 $txt = 'Enter a time between 6:00 and 12:00';
3756 $row += 2;
3757
3758 $worksheet->write($row, 0, $txt);
3759 $worksheet->data_validation($row, 1,
3760 {
3761 validate => 'time',
3762 criteria => 'between',
3763 minimum => 'T06:00',
3764 maximum => 'T12:00',
3765 });
3766
3767
3768 #
3769 # Example 9. Limiting input to a string greater than a fixed length.
3770 #
3771 $txt = 'Enter a string longer than 3 characters';
3772 $row += 2;
3773
3774 $worksheet->write($row, 0, $txt);
3775 $worksheet->data_validation($row, 1,
3776 {
3777 validate => 'length',
3778 criteria => '>',
3779 value => 3,
3780 });
3781
3782
3783 #
3784 # Example 10. Limiting input based on a formula.
3785 #
3786 $txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"';
3787 $row += 2;
3788
3789 $worksheet->write($row, 0, $txt);
3790 $worksheet->data_validation($row, 1,
3791 {
3792 validate => 'custom',
3793 value => '=AND(F5=50,G5=60)',
3794 });
3795
3796
3797 #
3798 # Example 11. Displaying and modify data validation messages.
3799 #
3800 $txt = 'Displays a message when you select the cell';
3801 $row += 2;
3802
3803 $worksheet->write($row, 0, $txt);
3804 $worksheet->data_validation($row, 1,
3805 {
3806 validate => 'integer',
3807 criteria => 'between',
3808 minimum => 1,
3809 maximum => 100,
3810 input_title => 'Enter an integer:',
3811 input_message => 'between 1 and 100',
3812 });
3813
3814
3815 #
3816 # Example 12. Displaying and modify data validation messages.
3817 #
3818 $txt = 'Display a custom error message when integer isn\'t between 1 and 100';
3819 $row += 2;
3820
3821 $worksheet->write($row, 0, $txt);
3822 $worksheet->data_validation($row, 1,
3823 {
3824 validate => 'integer',
3825 criteria => 'between',
3826 minimum => 1,
3827 maximum => 100,
3828 input_title => 'Enter an integer:',
3829 input_message => 'between 1 and 100',
3830 error_title => 'Input value is not valid!',
3831 error_message => 'It should be an integer between 1 and 100',
3832 });
3833
3834
3835 #
3836 # Example 13. Displaying and modify data validation messages.
3837 #
3838 $txt = 'Display a custom information message when integer isn\'t between 1 and 100';
3839 $row += 2;
3840
3841 $worksheet->write($row, 0, $txt);
3842 $worksheet->data_validation($row, 1,
3843 {
3844 validate => 'integer',
3845 criteria => 'between',
3846 minimum => 1,
3847 maximum => 100,
3848 input_title => 'Enter an integer:',
3849 input_message => 'between 1 and 100',
3850 error_title => 'Input value is not valid!',
3851 error_message => 'It should be an integer between 1 and 100',
3852 error_type => 'information',
3853 });
3854
3855
3856 __END__
3857
3858 Download this example:
3859 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/data_validate.pl
3860 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
3861 WriteExcel-2.36/examples/data_validate.pl>
3862
3863 Example: date_time.pl
3864 Spreadsheet::WriteExcel example of writing dates and times using the
3865 write_date_time() Worksheet method.
3866
3867 Source code for this example:
3868
3869 #!/usr/bin/perl -w
3870
3871 ###############################################################################
3872 #
3873 # Spreadsheet::WriteExcel example of writing dates and times using the
3874 # write_date_time() Worksheet method.
3875 #
3876 # reverse('X'), August 2004, John McNamara, jmcnamara@cpan.org
3877 #
3878
3879 use strict;
3880 use Spreadsheet::WriteExcel;
3881
3882
3883 # Create a new workbook and add a worksheet
3884 my $workbook = Spreadsheet::WriteExcel->new("date_time.xls");
3885 my $worksheet = $workbook->add_worksheet();
3886 my $bold = $workbook->add_format(bold => 1);
3887 my $row = 0;
3888
3889
3890 # Expand the first column so that the date is visible.
3891 $worksheet->set_column("A:B", 30);
3892
3893
3894 # Write the column headers
3895 $worksheet->write('A1', 'Formatted date', $bold);
3896 $worksheet->write('B1', 'Format', $bold);
3897
3898
3899 # Examples date and time formats. In the output file compare how changing
3900 # the format codes change the appearance of the date.
3901 #
3902 my @date_formats = (
3903 'dd/mm/yy',
3904 'mm/dd/yy',
3905 '',
3906 'd mm yy',
3907 'dd mm yy',
3908 '',
3909 'dd m yy',
3910 'dd mm yy',
3911 'dd mmm yy',
3912 'dd mmmm yy',
3913 '',
3914 'dd mm y',
3915 'dd mm yyy',
3916 'dd mm yyyy',
3917 '',
3918 'd mmmm yyyy',
3919 '',
3920 'dd/mm/yy',
3921 'dd/mm/yy hh:mm',
3922 'dd/mm/yy hh:mm:ss',
3923 'dd/mm/yy hh:mm:ss.000',
3924 '',
3925 'hh:mm',
3926 'hh:mm:ss',
3927 'hh:mm:ss.000',
3928 );
3929
3930
3931 # Write the same date and time using each of the above formats. The empty
3932 # string formats create a blank line to make the example clearer.
3933 #
3934 for my $date_format (@date_formats) {
3935 $row++;
3936 next if $date_format eq '';
3937
3938 # Create a format for the date or time.
3939 my $format = $workbook->add_format(
3940 num_format => $date_format,
3941 align => 'left'
3942 );
3943
3944 # Write the same date using different formats.
3945 $worksheet->write_date_time($row, 0, '2004-08-01T12:30:45.123', $format);
3946 $worksheet->write ($row, 1, $date_format);
3947 }
3948
3949
3950 # The following is an example of an invalid date. It is written as a string
3951 # instead of a number. This is also Excel's default behaviour.
3952 #
3953 $row += 2;
3954 $worksheet->write_date_time($row, 0, '2004-13-01T12:30:45.123');
3955 $worksheet->write ($row, 1, 'Invalid date. Written as string.', $bold);
3956
3957 __END__
3958
3959 Download this example:
3960 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/date_time.pl
3961 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
3962 WriteExcel-2.36/examples/date_time.pl>
3963
3964 Example: defined_name.pl
3965 Example of how to create defined names in a Spreadsheet::WriteExcel
3966 file.
3967
3968 This method is used to defined a name that can be used to represent a
3969 value, a single cell or a range of cells in a workbook.
3970
3971 Source code for this example:
3972
3973 #!/usr/bin/perl -w
3974
3975 ###############################################################################
3976 #
3977 # Example of how to create defined names in a Spreadsheet::WriteExcel file.
3978 #
3979 # This method is used to defined a name that can be used to represent a value,
3980 # a single cell or a range of cells in a workbook.
3981 #
3982 # reverse('X'), September 2008, John McNamara, jmcnamara@cpan.org
3983 #
3984
3985 use strict;
3986 use Spreadsheet::WriteExcel;
3987
3988 my $workbook = Spreadsheet::WriteExcel->new('defined_name.xls');
3989 my $worksheet1 = $workbook->add_worksheet();
3990 my $worksheet2 = $workbook->add_worksheet();
3991
3992
3993 $workbook->define_name('Exchange_rate', '=0.96');
3994 $workbook->define_name('Sales', '=Sheet1!$G$1:$H$10');
3995 $workbook->define_name('Sheet2!Sales', '=Sheet2!$G$1:$G$10');
3996
3997
3998 for my $worksheet ($workbook->sheets()) {
3999 $worksheet->set_column('A:A', 45);
4000 $worksheet->write('A2', 'This worksheet contains some defined names,');
4001 $worksheet->write('A3', 'See the Insert -> Name -> Define dialog.');
4002
4003 }
4004
4005
4006 $worksheet1->write('A4', '=Exchange_rate');
4007
4008 __END__
4009
4010 Download this example:
4011 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/defined_name.pl
4012 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4013 WriteExcel-2.36/examples/defined_name.pl>
4014
4015 Example: diag_border.pl
4016 A simple formatting example that demonstrates how to add a diagonal
4017 cell border with Spreadsheet::WriteExcel
4018
4019 Source code for this example:
4020
4021 #!/usr/bin/perl -w
4022
4023 ##############################################################################
4024 #
4025 # A simple formatting example that demonstrates how to add a diagonal cell
4026 # border with Spreadsheet::WriteExcel
4027 #
4028 # reverse('X'), May 2004, John McNamara, jmcnamara@cpan.org
4029 #
4030
4031 use strict;
4032 use Spreadsheet::WriteExcel;
4033
4034
4035 my $workbook = Spreadsheet::WriteExcel->new('diag_border.xls');
4036 my $worksheet = $workbook->add_worksheet();
4037
4038
4039 my $format1 = $workbook->add_format(diag_type => '1');
4040
4041 my $format2 = $workbook->add_format(diag_type => '2');
4042
4043 my $format3 = $workbook->add_format(diag_type => '3');
4044
4045 my $format4 = $workbook->add_format(
4046 diag_type => '3',
4047 diag_border => '7',
4048 diag_color => 'red',
4049 );
4050
4051
4052 $worksheet->write('B3', 'Text', $format1);
4053 $worksheet->write('B6', 'Text', $format2);
4054 $worksheet->write('B9', 'Text', $format3);
4055 $worksheet->write('B12', 'Text', $format4);
4056
4057
4058
4059 __END__
4060
4061 Download this example:
4062 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/diag_border.pl
4063 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4064 WriteExcel-2.36/examples/diag_border.pl>
4065
4066 Example: easter_egg.pl
4067 This uses the Win32::OLE module to expose the Flight Simulator easter
4068 egg in Excel 97 SR2.
4069
4070 #!/usr/bin/perl -w
4071
4072 ###############################################################################
4073 #
4074 # This uses the Win32::OLE module to expose the Flight Simulator easter egg
4075 # in Excel 97 SR2.
4076 #
4077 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
4078 #
4079
4080 use strict;
4081 use Win32::OLE;
4082
4083 my $application = Win32::OLE->new("Excel.Application");
4084 my $workbook = $application->Workbooks->Add;
4085 my $worksheet = $workbook->Worksheets(1);
4086
4087 $application->{Visible} = 1;
4088
4089 $worksheet->Range("L97:X97")->Select;
4090 $worksheet->Range("M97")->Activate;
4091
4092 my $message = "Hold down Shift and Ctrl and click the ".
4093 "Chart Wizard icon on the toolbar.\n\n".
4094 "Use the mouse motion and buttons to control ".
4095 "movement. Try to find the monolith. ".
4096 "Close this dialog first.";
4097
4098 $application->InputBox($message);
4099
4100 Download this example:
4101 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/easter_egg.pl
4102 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4103 WriteExcel-2.36/examples/easter_egg.pl>
4104
4105 Example: filehandle.pl
4106 Example of using Spreadsheet::WriteExcel to write Excel files to
4107 different filehandles.
4108
4109 Source code for this example:
4110
4111 #!/usr/bin/perl -w
4112
4113 ###############################################################################
4114 #
4115 # Example of using Spreadsheet::WriteExcel to write Excel files to
4116 # different filehandles.
4117 #
4118 # reverse('X'), April 2003, John McNamara, jmcnamara@cpan.org
4119 #
4120
4121 use strict;
4122 use Spreadsheet::WriteExcel;
4123 use IO::Scalar;
4124
4125
4126
4127
4128 ###############################################################################
4129 #
4130 # Example 1. This demonstrates the standard way of creating an Excel file by
4131 # specifying a file name.
4132 #
4133
4134 my $workbook1 = Spreadsheet::WriteExcel->new('fh_01.xls');
4135 my $worksheet1 = $workbook1->add_worksheet();
4136
4137 $worksheet1->write(0, 0, "Hi Excel!");
4138
4139
4140
4141
4142 ###############################################################################
4143 #
4144 # Example 2. Write an Excel file to an existing filehandle.
4145 #
4146
4147 open TEST, "> fh_02.xls" or die "Couldn't open file: $!";
4148 binmode TEST; # Always do this regardless of whether the platform requires it.
4149
4150 my $workbook2 = Spreadsheet::WriteExcel->new(\*TEST);
4151 my $worksheet2 = $workbook2->add_worksheet();
4152
4153 $worksheet2->write(0, 0, "Hi Excel!");
4154
4155
4156
4157
4158 ###############################################################################
4159 #
4160 # Example 3. Write an Excel file to an existing OO style filehandle.
4161 #
4162
4163 my $fh = FileHandle->new("> fh_03.xls")
4164 or die "Couldn't open file: $!";
4165
4166 binmode($fh);
4167
4168 my $workbook3 = Spreadsheet::WriteExcel->new($fh);
4169 my $worksheet3 = $workbook3->add_worksheet();
4170
4171 $worksheet3->write(0, 0, "Hi Excel!");
4172
4173
4174
4175
4176 ###############################################################################
4177 #
4178 # Example 4. Write an Excel file to a string via IO::Scalar. Please refer to
4179 # the IO::Scalar documentation for further details.
4180 #
4181
4182 my $xls_str;
4183
4184 tie *XLS, 'IO::Scalar', \$xls_str;
4185
4186 my $workbook4 = Spreadsheet::WriteExcel->new(\*XLS);
4187 my $worksheet4 = $workbook4->add_worksheet();
4188
4189 $worksheet4->write(0, 0, "Hi Excel 4");
4190 $workbook4->close(); # This is required before we use the scalar
4191
4192
4193 # The Excel file is now in $xls_str. As a demonstration, print it to a file.
4194 open TMP, "> fh_04.xls" or die "Couldn't open file: $!";
4195 binmode TMP;
4196 print TMP $xls_str;
4197 close TMP;
4198
4199
4200
4201
4202 ###############################################################################
4203 #
4204 # Example 5. Write an Excel file to a string via IO::Scalar's newer interface.
4205 # Please refer to the IO::Scalar documentation for further details.
4206 #
4207 my $xls_str2;
4208
4209 my $fh5 = IO::Scalar->new(\$xls_str2);
4210
4211
4212 my $workbook5 = Spreadsheet::WriteExcel->new($fh5);
4213 my $worksheet5 = $workbook5->add_worksheet();
4214
4215 $worksheet5->write(0, 0, "Hi Excel 5");
4216 $workbook5->close(); # This is required before we use the scalar
4217
4218 # The Excel file is now in $xls_str. As a demonstration, print it to a file.
4219 open TMP, "> fh_05.xls" or die "Couldn't open file: $!";
4220 binmode TMP;
4221 print TMP $xls_str2;
4222 close TMP;
4223
4224 Download this example:
4225 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/filehandle.pl
4226 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4227 WriteExcel-2.36/examples/filehandle.pl>
4228
4229 Example: formula_result.pl
4230 Example of how to write Spreadsheet::WriteExcel formulas with a user
4231 specified result.
4232
4233 This is generally only required when writing a spreadsheet for an
4234 application other than Excel where the formula isn't evaluated.
4235
4236 Source code for this example:
4237
4238 #!/usr/bin/perl -w
4239
4240 #######################################################################
4241 #
4242 # Example of how to write Spreadsheet::WriteExcel formulas with a user
4243 # specified result.
4244 #
4245 # This is generally only required when writing a spreadsheet for an
4246 # application other than Excel where the formula isn't evaluated.
4247 #
4248 # reverse('X'), August 2005, John McNamara, jmcnamara@cpan.org
4249 #
4250
4251 use strict;
4252 use Spreadsheet::WriteExcel;
4253
4254 my $workbook = Spreadsheet::WriteExcel->new('formula_result.xls');
4255 my $worksheet = $workbook->add_worksheet();
4256 my $format = $workbook->add_format(color => 'blue');
4257
4258
4259 $worksheet->write('A1', '=1+2');
4260 $worksheet->write('A2', '=1+2', $format, 4);
4261 $worksheet->write('A3', '="ABC"', undef, 'DEF');
4262 $worksheet->write('A4', '=IF(A1 > 1, TRUE, FALSE)', undef, 'TRUE');
4263 $worksheet->write('A5', '=1/0', undef, '#DIV/0!');
4264
4265
4266 __END__
4267
4268 Download this example:
4269 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/formula_result.pl
4270 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4271 WriteExcel-2.36/examples/formula_result.pl>
4272
4273 Example: headers.pl
4274 This program shows several examples of how to set up headers and
4275 footers with Spreadsheet::WriteExcel.
4276
4277 The control characters used in the header/footer strings are:
4278
4279 Control Category Description
4280 ======= ======== ===========
4281 &L Justification Left
4282 &C Center
4283 &R Right
4284
4285 &P Information Page number
4286 &N Total number of pages
4287 &D Date
4288 &T Time
4289 &F File name
4290 &A Worksheet name
4291
4292 &fontsize Font Font size
4293 &"font,style" Font name and style
4294 &U Single underline
4295 &E Double underline
4296 &S Strikethrough
4297 &X Superscript
4298 &Y Subscript
4299
4300 && Miscellaneous Literal ampersand &
4301
4302 See the main Spreadsheet::WriteExcel documentation for more
4303 information.
4304
4305 Source code for this example:
4306
4307 #!/usr/bin/perl -w
4308
4309 ######################################################################
4310 #
4311 # This program shows several examples of how to set up headers and
4312 # footers with Spreadsheet::WriteExcel.
4313 #
4314 # The control characters used in the header/footer strings are:
4315 #
4316 # Control Category Description
4317 # ======= ======== ===========
4318 # &L Justification Left
4319 # &C Center
4320 # &R Right
4321 #
4322 # &P Information Page number
4323 # &N Total number of pages
4324 # &D Date
4325 # &T Time
4326 # &F File name
4327 # &A Worksheet name
4328 #
4329 # &fontsize Font Font size
4330 # &"font,style" Font name and style
4331 # &U Single underline
4332 # &E Double underline
4333 # &S Strikethrough
4334 # &X Superscript
4335 # &Y Subscript
4336 #
4337 # && Miscellaneous Literal ampersand &
4338 #
4339 # See the main Spreadsheet::WriteExcel documentation for more information.
4340 #
4341 # reverse('X'), March 2002, John McNamara, jmcnamara@cpan.org
4342 #
4343
4344
4345 use strict;
4346 use Spreadsheet::WriteExcel;
4347
4348 my $workbook = Spreadsheet::WriteExcel->new("headers.xls");
4349 my $preview = "Select Print Preview to see the header and footer";
4350
4351
4352 ######################################################################
4353 #
4354 # A simple example to start
4355 #
4356 my $worksheet1 = $workbook->add_worksheet('Simple');
4357
4358 my $header1 = '&CHere is some centred text.';
4359
4360 my $footer1 = '&LHere is some left aligned text.';
4361
4362
4363 $worksheet1->set_header($header1);
4364 $worksheet1->set_footer($footer1);
4365
4366 $worksheet1->set_column('A:A', 50);
4367 $worksheet1->write('A1', $preview);
4368
4369
4370
4371
4372 ######################################################################
4373 #
4374 # This is an example of some of the header/footer variables.
4375 #
4376 my $worksheet2 = $workbook->add_worksheet('Variables');
4377
4378 my $header2 = '&LPage &P of &N'.
4379 '&CFilename: &F' .
4380 '&RSheetname: &A';
4381
4382 my $footer2 = '&LCurrent date: &D'.
4383 '&RCurrent time: &T';
4384
4385
4386
4387 $worksheet2->set_header($header2);
4388 $worksheet2->set_footer($footer2);
4389
4390
4391 $worksheet2->set_column('A:A', 50);
4392 $worksheet2->write('A1', $preview);
4393 $worksheet2->write('A21', "Next sheet");
4394 $worksheet2->set_h_pagebreaks(20);
4395
4396
4397
4398 ######################################################################
4399 #
4400 # This example shows how to use more than one font
4401 #
4402 my $worksheet3 = $workbook->add_worksheet('Mixed fonts');
4403
4404 my $header3 = '&C' .
4405 '&"Courier New,Bold"Hello ' .
4406 '&"Arial,Italic"World';
4407
4408 my $footer3 = '&C' .
4409 '&"Symbol"e' .
4410 '&"Arial" = mc&X2';
4411
4412 $worksheet3->set_header($header3);
4413 $worksheet3->set_footer($footer3);
4414
4415 $worksheet3->set_column('A:A', 50);
4416 $worksheet3->write('A1', $preview);
4417
4418
4419
4420
4421 ######################################################################
4422 #
4423 # Example of line wrapping
4424 #
4425 my $worksheet4 = $workbook->add_worksheet('Word wrap');
4426
4427 my $header4 = "&CHeading 1\nHeading 2\nHeading 3";
4428
4429 $worksheet4->set_header($header4);
4430
4431 $worksheet4->set_column('A:A', 50);
4432 $worksheet4->write('A1', $preview);
4433
4434
4435
4436
4437 ######################################################################
4438 #
4439 # Example of inserting a literal ampersand &
4440 #
4441 my $worksheet5 = $workbook->add_worksheet('Ampersand');
4442
4443 my $header5 = "&CCuriouser && Curiouser - Attorneys at Law";
4444
4445 $worksheet5->set_header($header5);
4446
4447 $worksheet5->set_column('A:A', 50);
4448 $worksheet5->write('A1', $preview);
4449
4450 Download this example:
4451 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/headers.pl
4452 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4453 WriteExcel-2.36/examples/headers.pl>
4454
4455 Example: hide_sheet.pl
4456 Example of how to hide a worksheet with Spreadsheet::WriteExcel.
4457
4458 Source code for this example:
4459
4460 #!/usr/bin/perl -w
4461
4462 #######################################################################
4463 #
4464 # Example of how to hide a worksheet with Spreadsheet::WriteExcel.
4465 #
4466 # reverse('X'), April 2005, John McNamara, jmcnamara@cpan.org
4467 #
4468
4469 use strict;
4470 use Spreadsheet::WriteExcel;
4471
4472 my $workbook = Spreadsheet::WriteExcel->new('hidden.xls');
4473 my $worksheet1 = $workbook->add_worksheet();
4474 my $worksheet2 = $workbook->add_worksheet();
4475 my $worksheet3 = $workbook->add_worksheet();
4476
4477 # Sheet2 won't be visible until it is unhidden in Excel.
4478 $worksheet2->hide();
4479
4480 $worksheet1->write(0, 0, 'Sheet2 is hidden');
4481 $worksheet2->write(0, 0, 'How did you find me?');
4482 $worksheet3->write(0, 0, 'Sheet2 is hidden');
4483
4484
4485 __END__
4486
4487 Download this example:
4488 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/hide_sheet.pl
4489 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4490 WriteExcel-2.36/examples/hide_sheet.pl>
4491
4492 Example: hyperlink1.pl
4493 Example of how to use the WriteExcel module to write hyperlinks.
4494
4495 See also hyperlink2.pl for worksheet URL examples.
4496
4497 Source code for this example:
4498
4499 #!/usr/bin/perl -w
4500
4501 ###############################################################################
4502 #
4503 # Example of how to use the WriteExcel module to write hyperlinks.
4504 #
4505 # See also hyperlink2.pl for worksheet URL examples.
4506 #
4507 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
4508 #
4509
4510 use strict;
4511 use Spreadsheet::WriteExcel;
4512
4513 # Create a new workbook and add a worksheet
4514 my $workbook = Spreadsheet::WriteExcel->new("hyperlink.xls");
4515 my $worksheet = $workbook->add_worksheet('Hyperlinks');
4516
4517 # Format the first column
4518 $worksheet->set_column('A:A', 30);
4519 $worksheet->set_selection('B1');
4520
4521
4522 # Add a sample format
4523 my $format = $workbook->add_format();
4524 $format->set_size(12);
4525 $format->set_bold();
4526 $format->set_color('red');
4527 $format->set_underline();
4528
4529
4530 # Write some hyperlinks
4531 $worksheet->write('A1', 'http://www.perl.com/' );
4532 $worksheet->write('A3', 'http://www.perl.com/', 'Perl home' );
4533 $worksheet->write('A5', 'http://www.perl.com/', undef, $format);
4534 $worksheet->write('A7', 'mailto:jmcnamara@cpan.org', 'Mail me');
4535
4536 # Write a URL that isn't a hyperlink
4537 $worksheet->write_string('A9', 'http://www.perl.com/');
4538
4539 Download this example:
4540 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/hyperlink1.pl
4541 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4542 WriteExcel-2.36/examples/hyperlink1.pl>
4543
4544 Example: hyperlink2.pl
4545 Example of how to use the WriteExcel module to write internal and
4546 internal hyperlinks.
4547
4548 If you wish to run this program and follow the hyperlinks you should
4549 create the following directory structure:
4550
4551 C:\ -- Temp --+-- Europe
4552 |
4553 \-- Asia
4554
4555 See also hyperlink1.pl for web URL examples.
4556
4557 #!/usr/bin/perl -w
4558
4559 ###############################################################################
4560 #
4561 # Example of how to use the WriteExcel module to write internal and internal
4562 # hyperlinks.
4563 #
4564 # If you wish to run this program and follow the hyperlinks you should create
4565 # the following directory structure:
4566 #
4567 # C:\ -- Temp --+-- Europe
4568 # |
4569 # \-- Asia
4570 #
4571 #
4572 # See also hyperlink1.pl for web URL examples.
4573 #
4574 # reverse('X'), February 2002, John McNamara, jmcnamara@cpan.org
4575 #
4576
4577
4578 use strict;
4579 use Spreadsheet::WriteExcel;
4580
4581 # Create three workbooks:
4582 # C:\Temp\Europe\Ireland.xls
4583 # C:\Temp\Europe\Italy.xls
4584 # C:\Temp\Asia\China.xls
4585 #
4586 my $ireland = Spreadsheet::WriteExcel->new('C:\Temp\Europe\Ireland.xls');
4587 my $ire_links = $ireland->add_worksheet('Links');
4588 my $ire_sales = $ireland->add_worksheet('Sales');
4589 my $ire_data = $ireland->add_worksheet('Product Data');
4590
4591 my $italy = Spreadsheet::WriteExcel->new('C:\Temp\Europe\Italy.xls');
4592 my $ita_links = $italy->add_worksheet('Links');
4593 my $ita_sales = $italy->add_worksheet('Sales');
4594 my $ita_data = $italy->add_worksheet('Product Data');
4595
4596 my $china = Spreadsheet::WriteExcel->new('C:\Temp\Asia\China.xls');
4597 my $cha_links = $china->add_worksheet('Links');
4598 my $cha_sales = $china->add_worksheet('Sales');
4599 my $cha_data = $china->add_worksheet('Product Data');
4600
4601 # Add a format
4602 my $format = $ireland->add_format(color => 'green', bold => 1);
4603 $ire_links->set_column('A:B', 25);
4604
4605
4606 ###############################################################################
4607 #
4608 # Examples of internal links
4609 #
4610 $ire_links->write('A1', 'Internal links', $format);
4611
4612 # Internal link
4613 $ire_links->write('A2', 'internal:Sales!A2');
4614
4615 # Internal link to a range
4616 $ire_links->write('A3', 'internal:Sales!A3:D3');
4617
4618 # Internal link with an alternative string
4619 $ire_links->write('A4', 'internal:Sales!A4', 'Link');
4620
4621 # Internal link with a format
4622 $ire_links->write('A5', 'internal:Sales!A5', $format);
4623
4624 # Internal link with an alternative string and format
4625 $ire_links->write('A6', 'internal:Sales!A6', 'Link', $format);
4626
4627 # Internal link (spaces in worksheet name)
4628 $ire_links->write('A7', q{internal:'Product Data'!A7});
4629
4630
4631 ###############################################################################
4632 #
4633 # Examples of external links
4634 #
4635 $ire_links->write('B1', 'External links', $format);
4636
4637 # External link to a local file
4638 $ire_links->write('B2', 'external:Italy.xls');
4639
4640 # External link to a local file with worksheet
4641 $ire_links->write('B3', 'external:Italy.xls#Sales!B3');
4642
4643 # External link to a local file with worksheet and alternative string
4644 $ire_links->write('B4', 'external:Italy.xls#Sales!B4', 'Link');
4645
4646 # External link to a local file with worksheet and format
4647 $ire_links->write('B5', 'external:Italy.xls#Sales!B5', $format);
4648
4649 # External link to a remote file, absolute path
4650 $ire_links->write('B6', 'external:c:/Temp/Asia/China.xls');
4651
4652 # External link to a remote file, relative path
4653 $ire_links->write('B7', 'external:../Asia/China.xls');
4654
4655 # External link to a remote file with worksheet
4656 $ire_links->write('B8', 'external:c:/Temp/Asia/China.xls#Sales!B8');
4657
4658 # External link to a remote file with worksheet (with spaces in the name)
4659 $ire_links->write('B9', q{external:c:/Temp/Asia/China.xls#'Product Data'!B9});
4660
4661
4662 ###############################################################################
4663 #
4664 # Some utility links to return to the main sheet
4665 #
4666 $ire_sales->write('A2', 'internal:Links!A2', 'Back');
4667 $ire_sales->write('A3', 'internal:Links!A3', 'Back');
4668 $ire_sales->write('A4', 'internal:Links!A4', 'Back');
4669 $ire_sales->write('A5', 'internal:Links!A5', 'Back');
4670 $ire_sales->write('A6', 'internal:Links!A6', 'Back');
4671 $ire_data-> write('A7', 'internal:Links!A7', 'Back');
4672
4673 $ita_links->write('A1', 'external:Ireland.xls#Links!B2', 'Back');
4674 $ita_sales->write('B3', 'external:Ireland.xls#Links!B3', 'Back');
4675 $ita_sales->write('B4', 'external:Ireland.xls#Links!B4', 'Back');
4676 $ita_sales->write('B5', 'external:Ireland.xls#Links!B5', 'Back');
4677 $cha_links->write('A1', 'external:../Europe/Ireland.xls#Links!B6', 'Back');
4678 $cha_sales->write('B8', 'external:../Europe/Ireland.xls#Links!B8', 'Back');
4679 $cha_data-> write('B9', 'external:../Europe/Ireland.xls#Links!B9', 'Back');
4680
4681 Download this example:
4682 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/hyperlink2.pl
4683 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4684 WriteExcel-2.36/examples/hyperlink2.pl>
4685
4686 Example: images.pl
4687 Example of how to insert images into an Excel worksheet using the
4688 Spreadsheet::WriteExcel insert_image() method.
4689
4690 Source code for this example:
4691
4692 #!/usr/bin/perl -w
4693
4694 #######################################################################
4695 #
4696 # Example of how to insert images into an Excel worksheet using the
4697 # Spreadsheet::WriteExcel insert_image() method.
4698 #
4699 # reverse('X'), October 2001, John McNamara, jmcnamara@cpan.org
4700 #
4701
4702 use strict;
4703 use Spreadsheet::WriteExcel;
4704
4705 # Create a new workbook called simple.xls and add a worksheet
4706 my $workbook = Spreadsheet::WriteExcel->new("images.xls");
4707 my $worksheet1 = $workbook->add_worksheet('Image 1');
4708 my $worksheet2 = $workbook->add_worksheet('Image 2');
4709 my $worksheet3 = $workbook->add_worksheet('Image 3');
4710 my $worksheet4 = $workbook->add_worksheet('Image 4');
4711
4712 # Insert a basic image
4713 $worksheet1->write('A10', "Image inserted into worksheet.");
4714 $worksheet1->insert_image('A1', 'republic.png');
4715
4716
4717 # Insert an image with an offset
4718 $worksheet2->write('A10', "Image inserted with an offset.");
4719 $worksheet2->insert_image('A1', 'republic.png', 32, 10);
4720
4721 # Insert a scaled image
4722 $worksheet3->write('A10', "Image scaled: width x 2, height x 0.8.");
4723 $worksheet3->insert_image('A1', 'republic.png', 0, 0, 2, 0.8);
4724
4725 # Insert an image over varied column and row sizes
4726 # This does not require any additional work
4727
4728 # Set the cols and row sizes
4729 # NOTE: you must do this before you call insert_image()
4730 $worksheet4->set_column('A:A', 5);
4731 $worksheet4->set_column('B:B', undef, undef, 1); # Hidden
4732 $worksheet4->set_column('C:D', 10);
4733 $worksheet4->set_row(0, 30);
4734 $worksheet4->set_row(3, 5);
4735
4736 $worksheet4->write('A10', "Image inserted over scaled rows and columns.");
4737 $worksheet4->insert_image('A1', 'republic.png');
4738
4739 Download this example:
4740 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/images.pl
4741 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4742 WriteExcel-2.36/examples/images.pl>
4743
4744 Example: indent.pl
4745 A simple formatting example using Spreadsheet::WriteExcel.
4746
4747 This program demonstrates the indentation cell format.
4748
4749 Source code for this example:
4750
4751 #!/usr/bin/perl -w
4752
4753 ##############################################################################
4754 #
4755 # A simple formatting example using Spreadsheet::WriteExcel.
4756 #
4757 # This program demonstrates the indentation cell format.
4758 #
4759 # reverse('X'), May 2004, John McNamara, jmcnamara@cpan.org
4760 #
4761
4762
4763 use strict;
4764 use Spreadsheet::WriteExcel;
4765
4766 my $workbook = Spreadsheet::WriteExcel->new('indent.xls');
4767
4768 my $worksheet = $workbook->add_worksheet();
4769 my $indent1 = $workbook->add_format(indent => 1);
4770 my $indent2 = $workbook->add_format(indent => 2);
4771
4772 $worksheet->set_column('A:A', 40);
4773
4774
4775 $worksheet->write('A1', "This text is indented 1 level", $indent1);
4776 $worksheet->write('A2', "This text is indented 2 levels", $indent2);
4777
4778
4779 __END__
4780
4781 Download this example:
4782 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/indent.pl
4783 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4784 WriteExcel-2.36/examples/indent.pl>
4785
4786 Example: merge1.pl
4787 Simple example of merging cells using the Spreadsheet::WriteExcel
4788 module.
4789
4790 This example merges three cells using the "Centre Across Selection"
4791 alignment which was the Excel 5 method of achieving a merge. For a more
4792 modern approach use the merge_range() worksheet method instead. See
4793 the merge3.pl - merge6.pl programs.
4794
4795 Source code for this example:
4796
4797 #!/usr/bin/perl -w
4798
4799 ###############################################################################
4800 #
4801 # Simple example of merging cells using the Spreadsheet::WriteExcel module.
4802 #
4803 # This example merges three cells using the "Centre Across Selection"
4804 # alignment which was the Excel 5 method of achieving a merge. For a more
4805 # modern approach use the merge_range() worksheet method instead.
4806 # See the merge3.pl - merge6.pl programs.
4807 #
4808 # reverse('X'), August 2002, John McNamara, jmcnamara@cpan.org
4809 #
4810
4811 use strict;
4812 use Spreadsheet::WriteExcel;
4813
4814 # Create a new workbook and add a worksheet
4815 my $workbook = Spreadsheet::WriteExcel->new("merge1.xls");
4816 my $worksheet = $workbook->add_worksheet();
4817
4818
4819 # Increase the cell size of the merged cells to highlight the formatting.
4820 $worksheet->set_column('B:D', 20);
4821 $worksheet->set_row(2, 30);
4822
4823
4824 # Create a merge format
4825 my $format = $workbook->add_format(center_across => 1);
4826
4827
4828 # Only one cell should contain text, the others should be blank.
4829 $worksheet->write (2, 1, "Center across selection", $format);
4830 $worksheet->write_blank(2, 2, $format);
4831 $worksheet->write_blank(2, 3, $format);
4832
4833 Download this example:
4834 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/merge1.pl
4835 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4836 WriteExcel-2.36/examples/merge1.pl>
4837
4838 Example: merge2.pl
4839 Simple example of merging cells using the Spreadsheet::WriteExcel
4840 module
4841
4842 This example merges three cells using the "Centre Across Selection"
4843 alignment which was the Excel 5 method of achieving a merge. For a more
4844 modern approach use the merge_range() worksheet method instead. See
4845 the merge3.pl - merge6.pl programs.
4846
4847 Source code for this example:
4848
4849 #!/usr/bin/perl -w
4850
4851 ###############################################################################
4852 #
4853 # Simple example of merging cells using the Spreadsheet::WriteExcel module
4854 #
4855 # This example merges three cells using the "Centre Across Selection"
4856 # alignment which was the Excel 5 method of achieving a merge. For a more
4857 # modern approach use the merge_range() worksheet method instead.
4858 # See the merge3.pl - merge6.pl programs.
4859 #
4860 # reverse('X'), August 2002, John McNamara, jmcnamara@cpan.org
4861 #
4862
4863 use strict;
4864 use Spreadsheet::WriteExcel;
4865
4866 # Create a new workbook and add a worksheet
4867 my $workbook = Spreadsheet::WriteExcel->new("merge2.xls");
4868 my $worksheet = $workbook->add_worksheet();
4869
4870
4871 # Increase the cell size of the merged cells to highlight the formatting.
4872 $worksheet->set_column(1, 2, 30);
4873 $worksheet->set_row(2, 40);
4874
4875
4876 # Create a merged format
4877 my $format = $workbook->add_format(
4878 center_across => 1,
4879 bold => 1,
4880 size => 15,
4881 pattern => 1,
4882 border => 6,
4883 color => 'white',
4884 fg_color => 'green',
4885 border_color => 'yellow',
4886 align => 'vcenter',
4887 );
4888
4889
4890 # Only one cell should contain text, the others should be blank.
4891 $worksheet->write (2, 1, "Center across selection", $format);
4892 $worksheet->write_blank(2, 2, $format);
4893
4894 Download this example:
4895 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/merge2.pl
4896 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4897 WriteExcel-2.36/examples/merge2.pl>
4898
4899 Example: merge3.pl
4900 Example of how to use Spreadsheet::WriteExcel to write a hyperlink in a
4901 merged cell. There are two options write_url_range() with a standard
4902 merge format or merge_range().
4903
4904 Source code for this example:
4905
4906 #!/usr/bin/perl -w
4907
4908 ###############################################################################
4909 #
4910 # Example of how to use Spreadsheet::WriteExcel to write a hyperlink in a
4911 # merged cell. There are two options write_url_range() with a standard merge
4912 # format or merge_range().
4913 #
4914 # reverse('X'), September 2002, John McNamara, jmcnamara@cpan.org
4915 #
4916
4917 use strict;
4918 use Spreadsheet::WriteExcel;
4919
4920 # Create a new workbook and add a worksheet
4921 my $workbook = Spreadsheet::WriteExcel->new('merge3.xls');
4922 my $worksheet = $workbook->add_worksheet();
4923
4924
4925 # Increase the cell size of the merged cells to highlight the formatting.
4926 $worksheet->set_row($_, 30) for (1, 3, 6, 7);
4927 $worksheet->set_column('B:D', 20);
4928
4929
4930 ###############################################################################
4931 #
4932 # Example 1: Merge cells containing a hyperlink using write_url_range()
4933 # and the standard Excel 5+ merge property.
4934 #
4935 my $format1 = $workbook->add_format(
4936 center_across => 1,
4937 border => 1,
4938 underline => 1,
4939 color => 'blue',
4940 );
4941
4942 # Write the cells to be merged
4943 $worksheet->write_url_range('B2:D2', 'http://www.perl.com', $format1);
4944 $worksheet->write_blank('C2', $format1);
4945 $worksheet->write_blank('D2', $format1);
4946
4947
4948
4949 ###############################################################################
4950 #
4951 # Example 2: Merge cells containing a hyperlink using merge_range().
4952 #
4953 my $format2 = $workbook->add_format(
4954 border => 1,
4955 underline => 1,
4956 color => 'blue',
4957 align => 'center',
4958 valign => 'vcenter',
4959 );
4960
4961 # Merge 3 cells
4962 $worksheet->merge_range('B4:D4', 'http://www.perl.com', $format2);
4963
4964
4965 # Merge 3 cells over two rows
4966 $worksheet->merge_range('B7:D8', 'http://www.perl.com', $format2);
4967
4968 Download this example:
4969 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/merge3.pl
4970 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
4971 WriteExcel-2.36/examples/merge3.pl>
4972
4973 Example: merge4.pl
4974 Example of how to use the Spreadsheet::WriteExcel merge_range()
4975 workbook method with complex formatting.
4976
4977 Source code for this example:
4978
4979 #!/usr/bin/perl -w
4980
4981 ###############################################################################
4982 #
4983 # Example of how to use the Spreadsheet::WriteExcel merge_range() workbook
4984 # method with complex formatting.
4985 #
4986 # reverse('X'), September 2002, John McNamara, jmcnamara@cpan.org
4987 #
4988
4989 use strict;
4990 use Spreadsheet::WriteExcel;
4991
4992 # Create a new workbook and add a worksheet
4993 my $workbook = Spreadsheet::WriteExcel->new('merge4.xls');
4994 my $worksheet = $workbook->add_worksheet();
4995
4996
4997 # Increase the cell size of the merged cells to highlight the formatting.
4998 $worksheet->set_row($_, 30) for (1..11);
4999 $worksheet->set_column('B:D', 20);
5000
5001
5002 ###############################################################################
5003 #
5004 # Example 1: Text centered vertically and horizontally
5005 #
5006 my $format1 = $workbook->add_format(
5007 border => 6,
5008 bold => 1,
5009 color => 'red',
5010 valign => 'vcenter',
5011 align => 'center',
5012 );
5013
5014
5015
5016 $worksheet->merge_range('B2:D3', 'Vertical and horizontal', $format1);
5017
5018
5019 ###############################################################################
5020 #
5021 # Example 2: Text aligned to the top and left
5022 #
5023 my $format2 = $workbook->add_format(
5024 border => 6,
5025 bold => 1,
5026 color => 'red',
5027 valign => 'top',
5028 align => 'left',
5029 );
5030
5031
5032
5033 $worksheet->merge_range('B5:D6', 'Aligned to the top and left', $format2);
5034
5035
5036 ###############################################################################
5037 #
5038 # Example 3: Text aligned to the bottom and right
5039 #
5040 my $format3 = $workbook->add_format(
5041 border => 6,
5042 bold => 1,
5043 color => 'red',
5044 valign => 'bottom',
5045 align => 'right',
5046 );
5047
5048
5049
5050 $worksheet->merge_range('B8:D9', 'Aligned to the bottom and right', $format3);
5051
5052
5053 ###############################################################################
5054 #
5055 # Example 4: Text justified (i.e. wrapped) in the cell
5056 #
5057 my $format4 = $workbook->add_format(
5058 border => 6,
5059 bold => 1,
5060 color => 'red',
5061 valign => 'top',
5062 align => 'justify',
5063 );
5064
5065
5066
5067 $worksheet->merge_range('B11:D12', 'Justified: '.'so on and ' x18, $format4);
5068
5069 Download this example:
5070 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/merge4.pl
5071 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
5072 WriteExcel-2.36/examples/merge4.pl>
5073
5074 Example: merge5.pl
5075 Example of how to use the Spreadsheet::WriteExcel merge_cells()
5076 workbook method with complex formatting and rotation.
5077
5078 Source code for this example:
5079
5080 #!/usr/bin/perl -w
5081
5082 ###############################################################################
5083 #
5084 # Example of how to use the Spreadsheet::WriteExcel merge_cells() workbook
5085 # method with complex formatting and rotation.
5086 #
5087 #
5088 # reverse('X'), September 2002, John McNamara, jmcnamara@cpan.org
5089 #
5090
5091 use strict;
5092 use Spreadsheet::WriteExcel;
5093
5094 # Create a new workbook and add a worksheet
5095 my $workbook = Spreadsheet::WriteExcel->new('merge5.xls');
5096 my $worksheet = $workbook->add_worksheet();
5097
5098
5099 # Increase the cell size of the merged cells to highlight the formatting.
5100 $worksheet->set_row($_, 36) for (3..8);
5101 $worksheet->set_column($_, $_ , 15) for (1,3,5);
5102
5103
5104 ###############################################################################
5105 #
5106 # Rotation 1, letters run from top to bottom
5107 #
5108 my $format1 = $workbook->add_format(
5109 border => 6,
5110 bold => 1,
5111 color => 'red',
5112 valign => 'vcentre',
5113 align => 'centre',
5114 rotation => 270,
5115 );
5116
5117
5118 $worksheet->merge_range('B4:B9', 'Rotation 270', $format1);
5119
5120
5121 ###############################################################################
5122 #
5123 # Rotation 2, 90X anticlockwise
5124 #
5125 my $format2 = $workbook->add_format(
5126 border => 6,
5127 bold => 1,
5128 color => 'red',
5129 valign => 'vcentre',
5130 align => 'centre',
5131 rotation => 90,
5132 );
5133
5134
5135 $worksheet->merge_range('D4:D9', 'Rotation 90X', $format2);
5136
5137
5138
5139 ###############################################################################
5140 #
5141 # Rotation 3, 90X clockwise
5142 #
5143 my $format3 = $workbook->add_format(
5144 border => 6,
5145 bold => 1,
5146 color => 'red',
5147 valign => 'vcentre',
5148 align => 'centre',
5149 rotation => -90,
5150 );
5151
5152
5153 $worksheet->merge_range('F4:F9', 'Rotation -90X', $format3);
5154
5155 Download this example:
5156 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/merge5.pl
5157 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
5158 WriteExcel-2.36/examples/merge5.pl>
5159
5160 Example: merge6.pl
5161 Example of how to use the Spreadsheet::WriteExcel merge_cells()
5162 workbook method with Unicode strings.
5163
5164 Source code for this example:
5165
5166 #!/usr/bin/perl -w
5167
5168 ###############################################################################
5169 #
5170 # Example of how to use the Spreadsheet::WriteExcel merge_cells() workbook
5171 # method with Unicode strings.
5172 #
5173 #
5174 # reverse('X'), December 2005, John McNamara, jmcnamara@cpan.org
5175 #
5176
5177 use strict;
5178 use Spreadsheet::WriteExcel;
5179
5180 # Create a new workbook and add a worksheet
5181 my $workbook = Spreadsheet::WriteExcel->new('merge6.xls');
5182 my $worksheet = $workbook->add_worksheet();
5183
5184
5185 # Increase the cell size of the merged cells to highlight the formatting.
5186 $worksheet->set_row($_, 36) for 2..9;
5187 $worksheet->set_column('B:D', 25);
5188
5189
5190 # Format for the merged cells.
5191 my $format = $workbook->add_format(
5192 border => 6,
5193 bold => 1,
5194 color => 'red',
5195 size => 20,
5196 valign => 'vcentre',
5197 align => 'left',
5198 indent => 1,
5199 );
5200
5201
5202
5203
5204 ###############################################################################
5205 #
5206 # Write an Ascii string.
5207 #
5208
5209 $worksheet->merge_range('B3:D4', 'ASCII: A simple string', $format);
5210
5211
5212
5213
5214 ###############################################################################
5215 #
5216 # Write a UTF-16 Unicode string.
5217 #
5218
5219 # A phrase in Cyrillic encoded as UTF-16BE.
5220 my $utf16_str = pack "H*", '005500540046002d00310036003a0020'.
5221 '042d0442043e002004440440043004370430002004'.
5222 '3d043000200440044304410441043a043e043c0021';
5223
5224 # Note the extra parameter at the end to indicate UTF-16 encoding.
5225 $worksheet->merge_range('B6:D7', $utf16_str, $format, 1);
5226
5227
5228
5229
5230 ###############################################################################
5231 #
5232 # Write a UTF-8 Unicode string.
5233 #
5234
5235 if ($] >= 5.008) {
5236 my $smiley = chr 0x263a;
5237 $worksheet->merge_range('B9:D10', "UTF-8: A Unicode smiley $smiley",
5238 $format);
5239 }
5240 else {
5241 $worksheet->merge_range('B9:D10', "UTF-8: Requires Perl 5.8", $format);
5242 }
5243
5244
5245
5246
5247 __END__
5248
5249 Download this example:
5250 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/merge6.pl
5251 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
5252 WriteExcel-2.36/examples/merge6.pl>
5253
5254 Example: mod_perl1.pl
5255 Example of how to use the Spreadsheet::WriteExcel module to send an
5256 Excel file to a browser using mod_perl 1 and Apache
5257
5258 This module ties *XLS directly to Apache, and with the correct
5259 content-disposition/types it will prompt the user to save the file, or
5260 open it at this location.
5261
5262 This script is a modification of the Spreadsheet::WriteExcel cgi.pl
5263 example.
5264
5265 Change the name of this file to Cgi.pm. Change the package location to
5266 where ever you locate this package. In the example below it is located
5267 in the WriteExcel directory.
5268
5269 Your httpd.conf entry for this module, should you choose to use it as a
5270 stand alone app, should look similar to the following:
5271
5272 <Location /spreadsheet-test>
5273 SetHandler perl-script
5274 PerlHandler Spreadsheet::WriteExcel::Cgi
5275 PerlSendHeader On
5276 </Location>
5277
5278 The PerlHandler name above and the package name below *have* to match.
5279
5280 ###############################################################################
5281 #
5282 # Example of how to use the Spreadsheet::WriteExcel module to send an Excel
5283 # file to a browser using mod_perl 1 and Apache
5284 #
5285 # This module ties *XLS directly to Apache, and with the correct
5286 # content-disposition/types it will prompt the user to save
5287 # the file, or open it at this location.
5288 #
5289 # This script is a modification of the Spreadsheet::WriteExcel cgi.pl example.
5290 #
5291 # Change the name of this file to Cgi.pm.
5292 # Change the package location to where ever you locate this package.
5293 # In the example below it is located in the WriteExcel directory.
5294 #
5295 # Your httpd.conf entry for this module, should you choose to use it
5296 # as a stand alone app, should look similar to the following:
5297 #
5298 # <Location /spreadsheet-test>
5299 # SetHandler perl-script
5300 # PerlHandler Spreadsheet::WriteExcel::Cgi
5301 # PerlSendHeader On
5302 # </Location>
5303 #
5304 # The PerlHandler name above and the package name below *have* to match.
5305
5306 # Apr 2001, Thomas Sullivan, webmaster@860.org
5307 # Feb 2001, John McNamara, jmcnamara@cpan.org
5308
5309 package Spreadsheet::WriteExcel::Cgi;
5310
5311 ##########################################
5312 # Pragma Definitions
5313 ##########################################
5314 use strict;
5315
5316 ##########################################
5317 # Required Modules
5318 ##########################################
5319 use Apache::Constants qw(:common);
5320 use Apache::Request;
5321 use Apache::URI; # This may not be needed
5322 use Spreadsheet::WriteExcel;
5323
5324 ##########################################
5325 # Main App Body
5326 ##########################################
5327 sub handler {
5328 # New apache object
5329 # Should you decide to use it.
5330 my $r = Apache::Request->new(shift);
5331
5332 # Set the filename and send the content type
5333 # This will appear when they save the spreadsheet
5334 my $filename ="cgitest.xls";
5335
5336 ####################################################
5337 ## Send the content type headers
5338 ####################################################
5339 print "Content-disposition: attachment;filename=$filename\n";
5340 print "Content-type: application/vnd.ms-excel\n\n";
5341
5342 ####################################################
5343 # Tie a filehandle to Apache's STDOUT.
5344 # Create a new workbook and add a worksheet.
5345 ####################################################
5346 tie *XLS => 'Apache';
5347 binmode(*XLS);
5348
5349 my $workbook = Spreadsheet::WriteExcel->new(\*XLS);
5350 my $worksheet = $workbook->add_worksheet();
5351
5352
5353 # Set the column width for column 1
5354 $worksheet->set_column(0, 0, 20);
5355
5356
5357 # Create a format
5358 my $format = $workbook->add_format();
5359 $format->set_bold();
5360 $format->set_size(15);
5361 $format->set_color('blue');
5362
5363
5364 # Write to the workbook
5365 $worksheet->write(0, 0, "Hi Excel!", $format);
5366
5367 # You must close the workbook for Content-disposition
5368 $workbook->close();
5369 }
5370
5371 1;
5372
5373 Download this example:
5374 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/mod_perl1.pl
5375 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
5376 WriteExcel-2.36/examples/mod_perl1.pl>
5377
5378 Example: mod_perl2.pl
5379 Example of how to use the Spreadsheet::WriteExcel module to send an
5380 Excel file to a browser using mod_perl 2 and Apache.
5381
5382 This module ties *XLS directly to Apache, and with the correct
5383 content-disposition/types it will prompt the user to save the file, or
5384 open it at this location.
5385
5386 This script is a modification of the Spreadsheet::WriteExcel cgi.pl
5387 example.
5388
5389 Change the name of this file to MP2Test.pm. Change the package
5390 location to where ever you locate this package. In the example below
5391 it is located in the WriteExcel directory.
5392
5393 Your httpd.conf entry for this module, should you choose to use it as a
5394 stand alone app, should look similar to the following:
5395
5396 PerlModule Apache2::RequestRec
5397 PerlModule APR::Table
5398 PerlModule Apache2::RequestIO
5399
5400 <Location /spreadsheet-test>
5401 SetHandler perl-script
5402 PerlResponseHandler Spreadsheet::WriteExcel::MP2Test
5403 </Location>
5404
5405 The PerlResponseHandler must match the package name below.
5406
5407 ###############################################################################
5408 #
5409 # Example of how to use the Spreadsheet::WriteExcel module to send an Excel
5410 # file to a browser using mod_perl 2 and Apache.
5411 #
5412 # This module ties *XLS directly to Apache, and with the correct
5413 # content-disposition/types it will prompt the user to save
5414 # the file, or open it at this location.
5415 #
5416 # This script is a modification of the Spreadsheet::WriteExcel cgi.pl example.
5417 #
5418 # Change the name of this file to MP2Test.pm.
5419 # Change the package location to where ever you locate this package.
5420 # In the example below it is located in the WriteExcel directory.
5421 #
5422 # Your httpd.conf entry for this module, should you choose to use it
5423 # as a stand alone app, should look similar to the following:
5424 #
5425 # PerlModule Apache2::RequestRec
5426 # PerlModule APR::Table
5427 # PerlModule Apache2::RequestIO
5428 #
5429 # <Location /spreadsheet-test>
5430 # SetHandler perl-script
5431 # PerlResponseHandler Spreadsheet::WriteExcel::MP2Test
5432 # </Location>
5433 #
5434 # The PerlResponseHandler must match the package name below.
5435
5436 # Jun 2004, Matisse Enzer, matisse@matisse.net (mod_perl 2 version)
5437 # Apr 2001, Thomas Sullivan, webmaster@860.org
5438 # Feb 2001, John McNamara, jmcnamara@cpan.org
5439
5440 package Spreadsheet::WriteExcel::MP2Test;
5441
5442 ##########################################
5443 # Pragma Definitions
5444 ##########################################
5445 use strict;
5446
5447 ##########################################
5448 # Required Modules
5449 ##########################################
5450 use Apache2::Const -compile => qw( :common );
5451 use Spreadsheet::WriteExcel;
5452
5453 ##########################################
5454 # Main App Body
5455 ##########################################
5456 sub handler {
5457 my($r) = @_; # Apache request object is passed to handler in mod_perl 2
5458
5459 # Set the filename and send the content type
5460 # This will appear when they save the spreadsheet
5461 my $filename ="mod_perl2_test.xls";
5462
5463 ####################################################
5464 ## Send the content type headers the mod_perl 2 way
5465 ####################################################
5466 $r->headers_out->{'Content-Disposition'} = "attachment;filename=$filename";
5467 $r->content_type('application/vnd.ms-excel');
5468
5469 ####################################################
5470 # Tie a filehandle to Apache's STDOUT.
5471 # Create a new workbook and add a worksheet.
5472 ####################################################
5473 tie *XLS => $r; # The mod_perl 2 way. Tie to the Apache::RequestRec object
5474 binmode(*XLS);
5475
5476 my $workbook = Spreadsheet::WriteExcel->new(\*XLS);
5477 my $worksheet = $workbook->add_worksheet();
5478
5479
5480 # Set the column width for column 1
5481 $worksheet->set_column(0, 0, 20);
5482
5483
5484 # Create a format
5485 my $format = $workbook->add_format();
5486 $format->set_bold();
5487 $format->set_size(15);
5488 $format->set_color('blue');
5489
5490
5491 # Write to the workbook
5492 $worksheet->write(0, 0, 'Hi Excel! from ' . $r->hostname , $format);
5493
5494 # You must close the workbook for Content-disposition
5495 $workbook->close();
5496 return Apache2::Const::OK;
5497 }
5498
5499 1;
5500
5501 Download this example:
5502 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/mod_perl2.pl
5503 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
5504 WriteExcel-2.36/examples/mod_perl2.pl>
5505
5506 Example: outline.pl
5507 Example of how use Spreadsheet::WriteExcel to generate Excel outlines
5508 and grouping.
5509
5510 Excel allows you to group rows or columns so that they can be hidden or
5511 displayed with a single mouse click. This feature is referred to as
5512 outlines.
5513
5514 Outlines can reduce complex data down to a few salient sub-totals or
5515 summaries.
5516
5517 This feature is best viewed in Excel but the following is an ASCII
5518 representation of what a worksheet with three outlines might look like.
5519 Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
5520 level 1. The lines at the left hand side are called outline level bars.
5521
5522 ------------------------------------------
5523 1 2 3 | | A | B | C | D | ...
5524 ------------------------------------------
5525 _ | 1 | A | | | | ...
5526 | _ | 2 | B | | | | ...
5527 | | | 3 | (C) | | | | ...
5528 | | | 4 | (D) | | | | ...
5529 | - | 5 | E | | | | ...
5530 | _ | 6 | F | | | | ...
5531 | | | 7 | (G) | | | | ...
5532 | | | 8 | (H) | | | | ...
5533 | - | 9 | I | | | | ...
5534 - | . | ... | ... | ... | ... | ...
5535
5536 Clicking the minus sign on each of the level 2 outlines will collapse
5537 and hide the data as shown in the next figure. The minus sign changes
5538 to a plus sign to indicate that the data in the outline is hidden.
5539
5540 ------------------------------------------
5541 1 2 3 | | A | B | C | D | ...
5542 ------------------------------------------
5543 _ | 1 | A | | | | ...
5544 | | 2 | B | | | | ...
5545 | + | 5 | E | | | | ...
5546 | | 6 | F | | | | ...
5547 | + | 9 | I | | | | ...
5548 - | . | ... | ... | ... | ... | ...
5549
5550 Clicking on the minus sign on the level 1 outline will collapse the
5551 remaining rows as follows:
5552
5553 ------------------------------------------
5554 1 2 3 | | A | B | C | D | ...
5555 ------------------------------------------
5556 | 1 | A | | | | ...
5557 + | . | ... | ... | ... | ... | ...
5558
5559 See the main Spreadsheet::WriteExcel documentation for more
5560 information.
5561
5562 Source code for this example:
5563
5564 #!/usr/bin/perl -w
5565
5566 ###############################################################################
5567 #
5568 # Example of how use Spreadsheet::WriteExcel to generate Excel outlines and
5569 # grouping.
5570 #
5571 #
5572 # Excel allows you to group rows or columns so that they can be hidden or
5573 # displayed with a single mouse click. This feature is referred to as outlines.
5574 #
5575 # Outlines can reduce complex data down to a few salient sub-totals or
5576 # summaries.
5577 #
5578 # This feature is best viewed in Excel but the following is an ASCII
5579 # representation of what a worksheet with three outlines might look like.
5580 # Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
5581 # level 1. The lines at the left hand side are called outline level bars.
5582 #
5583 #
5584 # ------------------------------------------
5585 # 1 2 3 | | A | B | C | D | ...
5586 # ------------------------------------------
5587 # _ | 1 | A | | | | ...
5588 # | _ | 2 | B | | | | ...
5589 # | | | 3 | (C) | | | | ...
5590 # | | | 4 | (D) | | | | ...
5591 # | - | 5 | E | | | | ...
5592 # | _ | 6 | F | | | | ...
5593 # | | | 7 | (G) | | | | ...
5594 # | | | 8 | (H) | | | | ...
5595 # | - | 9 | I | | | | ...
5596 # - | . | ... | ... | ... | ... | ...
5597 #
5598 #
5599 # Clicking the minus sign on each of the level 2 outlines will collapse and
5600 # hide the data as shown in the next figure. The minus sign changes to a plus
5601 # sign to indicate that the data in the outline is hidden.
5602 #
5603 # ------------------------------------------
5604 # 1 2 3 | | A | B | C | D | ...
5605 # ------------------------------------------
5606 # _ | 1 | A | | | | ...
5607 # | | 2 | B | | | | ...
5608 # | + | 5 | E | | | | ...
5609 # | | 6 | F | | | | ...
5610 # | + | 9 | I | | | | ...
5611 # - | . | ... | ... | ... | ... | ...
5612 #
5613 #
5614 # Clicking on the minus sign on the level 1 outline will collapse the remaining
5615 # rows as follows:
5616 #
5617 # ------------------------------------------
5618 # 1 2 3 | | A | B | C | D | ...
5619 # ------------------------------------------
5620 # | 1 | A | | | | ...
5621 # + | . | ... | ... | ... | ... | ...
5622 #
5623 # See the main Spreadsheet::WriteExcel documentation for more information.
5624 #
5625 # reverse('X'), April 2003, John McNamara, jmcnamara@cpan.org
5626 #
5627
5628
5629
5630 use strict;
5631 use Spreadsheet::WriteExcel;
5632
5633 # Create a new workbook and add some worksheets
5634 my $workbook = Spreadsheet::WriteExcel->new('outline.xls');
5635 my $worksheet1 = $workbook->add_worksheet('Outlined Rows');
5636 my $worksheet2 = $workbook->add_worksheet('Collapsed Rows');
5637 my $worksheet3 = $workbook->add_worksheet('Outline Columns');
5638 my $worksheet4 = $workbook->add_worksheet('Outline levels');
5639
5640 # Add a general format
5641 my $bold = $workbook->add_format(bold => 1);
5642
5643
5644
5645 ###############################################################################
5646 #
5647 # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
5648 # functions so that it looks like the type of automatic outlines that are
5649 # generated when you use the Excel Data->SubTotals menu item.
5650 #
5651
5652
5653 # For outlines the important parameters are $hidden and $level. Rows with the
5654 # same $level are grouped together. The group will be collapsed if $hidden is
5655 # non-zero. $height and $XF are assigned default values if they are undef.
5656 #
5657 # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
5658 #
5659 $worksheet1->set_row(1, undef, undef, 0, 2);
5660 $worksheet1->set_row(2, undef, undef, 0, 2);
5661 $worksheet1->set_row(3, undef, undef, 0, 2);
5662 $worksheet1->set_row(4, undef, undef, 0, 2);
5663 $worksheet1->set_row(5, undef, undef, 0, 1);
5664
5665 $worksheet1->set_row(6, undef, undef, 0, 2);
5666 $worksheet1->set_row(7, undef, undef, 0, 2);
5667 $worksheet1->set_row(8, undef, undef, 0, 2);
5668 $worksheet1->set_row(9, undef, undef, 0, 2);
5669 $worksheet1->set_row(10, undef, undef, 0, 1);
5670
5671
5672 # Add a column format for clarity
5673 $worksheet1->set_column('A:A', 20);
5674
5675 # Add the data, labels and formulas
5676 $worksheet1->write('A1', 'Region', $bold);
5677 $worksheet1->write('A2', 'North');
5678 $worksheet1->write('A3', 'North');
5679 $worksheet1->write('A4', 'North');
5680 $worksheet1->write('A5', 'North');
5681 $worksheet1->write('A6', 'North Total', $bold);
5682
5683 $worksheet1->write('B1', 'Sales', $bold);
5684 $worksheet1->write('B2', 1000);
5685 $worksheet1->write('B3', 1200);
5686 $worksheet1->write('B4', 900);
5687 $worksheet1->write('B5', 1200);
5688 $worksheet1->write('B6', '=SUBTOTAL(9,B2:B5)', $bold);
5689
5690 $worksheet1->write('A7', 'South');
5691 $worksheet1->write('A8', 'South');
5692 $worksheet1->write('A9', 'South');
5693 $worksheet1->write('A10', 'South');
5694 $worksheet1->write('A11', 'South Total', $bold);
5695
5696 $worksheet1->write('B7', 400);
5697 $worksheet1->write('B8', 600);
5698 $worksheet1->write('B9', 500);
5699 $worksheet1->write('B10', 600);
5700 $worksheet1->write('B11', '=SUBTOTAL(9,B7:B10)', $bold);
5701
5702 $worksheet1->write('A12', 'Grand Total', $bold);
5703 $worksheet1->write('B12', '=SUBTOTAL(9,B2:B10)', $bold);
5704
5705
5706 ###############################################################################
5707 #
5708 # Example 2: Create a worksheet with outlined rows. This is the same as the
5709 # previous example except that the rows are collapsed.
5710 # Note: We need to indicate the row that contains the collapsed symbol '+'
5711 # with the optional parameter, $collapsed.
5712
5713 # The group will be collapsed if $hidden is non-zero.
5714 # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
5715 #
5716 $worksheet2->set_row(1, undef, undef, 1, 2);
5717 $worksheet2->set_row(2, undef, undef, 1, 2);
5718 $worksheet2->set_row(3, undef, undef, 1, 2);
5719 $worksheet2->set_row(4, undef, undef, 1, 2);
5720 $worksheet2->set_row(5, undef, undef, 1, 1);
5721
5722 $worksheet2->set_row(6, undef, undef, 1, 2);
5723 $worksheet2->set_row(7, undef, undef, 1, 2);
5724 $worksheet2->set_row(8, undef, undef, 1, 2);
5725 $worksheet2->set_row(9, undef, undef, 1, 2);
5726 $worksheet2->set_row(10, undef, undef, 1, 1);
5727 $worksheet2->set_row(11, undef, undef, 0, 0, 1);
5728
5729
5730 # Add a column format for clarity
5731 $worksheet2->set_column('A:A', 20);
5732
5733 # Add the data, labels and formulas
5734 $worksheet2->write('A1', 'Region', $bold);
5735 $worksheet2->write('A2', 'North');
5736 $worksheet2->write('A3', 'North');
5737 $worksheet2->write('A4', 'North');
5738 $worksheet2->write('A5', 'North');
5739 $worksheet2->write('A6', 'North Total', $bold);
5740
5741 $worksheet2->write('B1', 'Sales', $bold);
5742 $worksheet2->write('B2', 1000);
5743 $worksheet2->write('B3', 1200);
5744 $worksheet2->write('B4', 900);
5745 $worksheet2->write('B5', 1200);
5746 $worksheet2->write('B6', '=SUBTOTAL(9,B2:B5)', $bold);
5747
5748 $worksheet2->write('A7', 'South');
5749 $worksheet2->write('A8', 'South');
5750 $worksheet2->write('A9', 'South');
5751 $worksheet2->write('A10', 'South');
5752 $worksheet2->write('A11', 'South Total', $bold);
5753
5754 $worksheet2->write('B7', 400);
5755 $worksheet2->write('B8', 600);
5756 $worksheet2->write('B9', 500);
5757 $worksheet2->write('B10', 600);
5758 $worksheet2->write('B11', '=SUBTOTAL(9,B7:B10)', $bold);
5759
5760 $worksheet2->write('A12', 'Grand Total', $bold);
5761 $worksheet2->write('B12', '=SUBTOTAL(9,B2:B10)', $bold);
5762
5763
5764
5765 ###############################################################################
5766 #
5767 # Example 3: Create a worksheet with outlined columns.
5768 #
5769 my $data = [
5770 ['Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',' Total'],
5771 ['North', 50, 20, 15, 25, 65, 80, ,'=SUM(B2:G2)'],
5772 ['South', 10, 20, 30, 50, 50, 50, ,'=SUM(B3:G3)'],
5773 ['East', 45, 75, 50, 15, 75, 100, ,'=SUM(B4:G4)'],
5774 ['West', 15, 15, 55, 35, 20, 50, ,'=SUM(B5:G6)'],
5775 ];
5776
5777 # Add bold format to the first row
5778 $worksheet3->set_row(0, undef, $bold);
5779
5780 # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
5781 $worksheet3->set_column('A:A', 10, $bold );
5782 $worksheet3->set_column('B:G', 5, undef, 0, 1);
5783 $worksheet3->set_column('H:H', 10);
5784
5785 # Write the data and a formula
5786 $worksheet3->write_col('A1', $data);
5787 $worksheet3->write('H6', '=SUM(H2:H5)', $bold);
5788
5789
5790
5791 ###############################################################################
5792 #
5793 # Example 4: Show all possible outline levels.
5794 #
5795 my $levels = ["Level 1", "Level 2", "Level 3", "Level 4",
5796 "Level 5", "Level 6", "Level 7", "Level 6",
5797 "Level 5", "Level 4", "Level 3", "Level 2", "Level 1"];
5798
5799
5800 $worksheet4->write_col('A1', $levels);
5801
5802 $worksheet4->set_row(0, undef, undef, undef, 1);
5803 $worksheet4->set_row(1, undef, undef, undef, 2);
5804 $worksheet4->set_row(2, undef, undef, undef, 3);
5805 $worksheet4->set_row(3, undef, undef, undef, 4);
5806 $worksheet4->set_row(4, undef, undef, undef, 5);
5807 $worksheet4->set_row(5, undef, undef, undef, 6);
5808 $worksheet4->set_row(6, undef, undef, undef, 7);
5809 $worksheet4->set_row(7, undef, undef, undef, 6);
5810 $worksheet4->set_row(8, undef, undef, undef, 5);
5811 $worksheet4->set_row(9, undef, undef, undef, 4);
5812 $worksheet4->set_row(10, undef, undef, undef, 3);
5813 $worksheet4->set_row(11, undef, undef, undef, 2);
5814 $worksheet4->set_row(12, undef, undef, undef, 1);
5815
5816
5817
5818 __END__
5819
5820 Download this example:
5821 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/outline.pl
5822 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
5823 WriteExcel-2.36/examples/outline.pl>
5824
5825 Example: outline_collapsed.pl
5826 Example of how use Spreadsheet::WriteExcel to generate Excel outlines
5827 and grouping.
5828
5829 These example focus mainly on collapsed outlines. See also the
5830 outlines.pl example program for more general examples.
5831
5832 Source code for this example:
5833
5834 #!/usr/bin/perl -w
5835
5836 ###############################################################################
5837 #
5838 # Example of how use Spreadsheet::WriteExcel to generate Excel outlines and
5839 # grouping.
5840 #
5841 # These example focus mainly on collapsed outlines. See also the
5842 # outlines.pl example program for more general examples.
5843 #
5844 # reverse('X'), March 2008, John McNamara, jmcnamara@cpan.org
5845 #
5846
5847 use strict;
5848 use Spreadsheet::WriteExcel;
5849
5850 # Create a new workbook and add some worksheets
5851 my $workbook = Spreadsheet::WriteExcel->new('outline_collapsed.xls');
5852 my $worksheet1 = $workbook->add_worksheet('Outlined Rows');
5853 my $worksheet2 = $workbook->add_worksheet('Collapsed Rows 1');
5854 my $worksheet3 = $workbook->add_worksheet('Collapsed Rows 2');
5855 my $worksheet4 = $workbook->add_worksheet('Collapsed Rows 3');
5856 my $worksheet5 = $workbook->add_worksheet('Outline Columns');
5857 my $worksheet6 = $workbook->add_worksheet('Collapsed Columns');
5858
5859
5860 # Add a general format
5861 my $bold = $workbook->add_format(bold => 1);
5862
5863
5864 #
5865 # This function will generate the same data and sub-totals on each worksheet.
5866 #
5867 sub create_sub_totals {
5868
5869 my $worksheet = $_[0];
5870
5871 # Add a column format for clarity
5872 $worksheet->set_column('A:A', 20);
5873
5874 # Add the data, labels and formulas
5875 $worksheet->write('A1', 'Region', $bold);
5876 $worksheet->write('A2', 'North');
5877 $worksheet->write('A3', 'North');
5878 $worksheet->write('A4', 'North');
5879 $worksheet->write('A5', 'North');
5880 $worksheet->write('A6', 'North Total', $bold);
5881
5882 $worksheet->write('B1', 'Sales', $bold);
5883 $worksheet->write('B2', 1000);
5884 $worksheet->write('B3', 1200);
5885 $worksheet->write('B4', 900);
5886 $worksheet->write('B5', 1200);
5887 $worksheet->write('B6', '=SUBTOTAL(9,B2:B5)', $bold);
5888
5889 $worksheet->write('A7', 'South');
5890 $worksheet->write('A8', 'South');
5891 $worksheet->write('A9', 'South');
5892 $worksheet->write('A10', 'South');
5893 $worksheet->write('A11', 'South Total', $bold);
5894
5895 $worksheet->write('B7', 400);
5896 $worksheet->write('B8', 600);
5897 $worksheet->write('B9', 500);
5898 $worksheet->write('B10', 600);
5899 $worksheet->write('B11', '=SUBTOTAL(9,B7:B10)', $bold);
5900
5901 $worksheet->write('A12', 'Grand Total', $bold);
5902 $worksheet->write('B12', '=SUBTOTAL(9,B2:B10)', $bold);
5903
5904 }
5905
5906
5907 ###############################################################################
5908 #
5909 # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
5910 # functions so that it looks like the type of automatic outlines that are
5911 # generated when you use the Excel Data->SubTotals menu item.
5912 #
5913
5914 # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
5915 $worksheet1->set_row(1, undef, undef, 0, 2);
5916 $worksheet1->set_row(2, undef, undef, 0, 2);
5917 $worksheet1->set_row(3, undef, undef, 0, 2);
5918 $worksheet1->set_row(4, undef, undef, 0, 2);
5919 $worksheet1->set_row(5, undef, undef, 0, 1);
5920
5921 $worksheet1->set_row(6, undef, undef, 0, 2);
5922 $worksheet1->set_row(7, undef, undef, 0, 2);
5923 $worksheet1->set_row(8, undef, undef, 0, 2);
5924 $worksheet1->set_row(9, undef, undef, 0, 2);
5925 $worksheet1->set_row(10, undef, undef, 0, 1);
5926
5927 # Write the sub-total data that is common to the row examples.
5928 create_sub_totals($worksheet1);
5929
5930
5931 ###############################################################################
5932 #
5933 # Example 2: Create a worksheet with collapsed outlined rows.
5934 # This is the same as the example 1 except that the all rows are collapsed.
5935 # Note: We need to indicate the row that contains the collapsed symbol '+' with
5936 # the optional parameter, $collapsed.
5937
5938 $worksheet2->set_row(1, undef, undef, 1, 2);
5939 $worksheet2->set_row(2, undef, undef, 1, 2);
5940 $worksheet2->set_row(3, undef, undef, 1, 2);
5941 $worksheet2->set_row(4, undef, undef, 1, 2);
5942 $worksheet2->set_row(5, undef, undef, 1, 1);
5943
5944 $worksheet2->set_row(6, undef, undef, 1, 2);
5945 $worksheet2->set_row(7, undef, undef, 1, 2);
5946 $worksheet2->set_row(8, undef, undef, 1, 2);
5947 $worksheet2->set_row(9, undef, undef, 1, 2);
5948 $worksheet2->set_row(10, undef, undef, 1, 1);
5949
5950 $worksheet2->set_row(11, undef, undef, 0, 0, 1);
5951
5952 # Write the sub-total data that is common to the row examples.
5953 create_sub_totals($worksheet2);
5954
5955
5956 ###############################################################################
5957 #
5958 # Example 3: Create a worksheet with collapsed outlined rows.
5959 # Same as the example 1 except that the two sub-totals are collapsed.
5960
5961 $worksheet3->set_row(1, undef, undef, 1, 2);
5962 $worksheet3->set_row(2, undef, undef, 1, 2);
5963 $worksheet3->set_row(3, undef, undef, 1, 2);
5964 $worksheet3->set_row(4, undef, undef, 1, 2);
5965 $worksheet3->set_row(5, undef, undef, 0, 1, 1);
5966
5967 $worksheet3->set_row(6, undef, undef, 1, 2);
5968 $worksheet3->set_row(7, undef, undef, 1, 2);
5969 $worksheet3->set_row(8, undef, undef, 1, 2);
5970 $worksheet3->set_row(9, undef, undef, 1, 2);
5971 $worksheet3->set_row(10, undef, undef, 0, 1, 1);
5972
5973
5974 # Write the sub-total data that is common to the row examples.
5975 create_sub_totals($worksheet3);
5976
5977
5978 ###############################################################################
5979 #
5980 # Example 4: Create a worksheet with outlined rows.
5981 # Same as the example 1 except that the two sub-totals are collapsed.
5982
5983 $worksheet4->set_row(1, undef, undef, 1, 2);
5984 $worksheet4->set_row(2, undef, undef, 1, 2);
5985 $worksheet4->set_row(3, undef, undef, 1, 2);
5986 $worksheet4->set_row(4, undef, undef, 1, 2);
5987 $worksheet4->set_row(5, undef, undef, 1, 1, 1);
5988
5989 $worksheet4->set_row(6, undef, undef, 1, 2);
5990 $worksheet4->set_row(7, undef, undef, 1, 2);
5991 $worksheet4->set_row(8, undef, undef, 1, 2);
5992 $worksheet4->set_row(9, undef, undef, 1, 2);
5993 $worksheet4->set_row(10, undef, undef, 1, 1, 1);
5994
5995 $worksheet4->set_row(11, undef, undef, 0, 0, 1);
5996
5997 # Write the sub-total data that is common to the row examples.
5998 create_sub_totals($worksheet4);
5999
6000
6001
6002 ###############################################################################
6003 #
6004 # Example 5: Create a worksheet with outlined columns.
6005 #
6006 my $data = [
6007 ['Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',' Total'],
6008 ['North', 50, 20, 15, 25, 65, 80, ,'=SUM(B2:G2)'],
6009 ['South', 10, 20, 30, 50, 50, 50, ,'=SUM(B3:G3)'],
6010 ['East', 45, 75, 50, 15, 75, 100, ,'=SUM(B4:G4)'],
6011 ['West', 15, 15, 55, 35, 20, 50, ,'=SUM(B5:G6)'],
6012 ];
6013
6014 # Add bold format to the first row
6015 $worksheet5->set_row(0, undef, $bold);
6016
6017 # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
6018 $worksheet5->set_column('A:A', 10, $bold );
6019 $worksheet5->set_column('B:G', 5, undef, 0, 1);
6020 $worksheet5->set_column('H:H', 10 );
6021
6022 # Write the data and a formula
6023 $worksheet5->write_col('A1', $data);
6024 $worksheet5->write('H6', '=SUM(H2:H5)', $bold);
6025
6026
6027 ###############################################################################
6028 #
6029 # Example 6: Create a worksheet with collapsed outlined columns.
6030 # This is the same as the previous example except collapsed columns.
6031
6032 # Add bold format to the first row
6033 $worksheet6->set_row(0, undef, $bold);
6034
6035 # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
6036 $worksheet6->set_column('A:A', 10, $bold );
6037 $worksheet6->set_column('B:G', 5, undef, 1, 1 );
6038 $worksheet6->set_column('H:H', 10, undef, 0, 0, 1);
6039
6040 # Write the data and a formula
6041 $worksheet6->write_col('A1', $data);
6042 $worksheet6->write('H6', '=SUM(H2:H5)', $bold);
6043
6044
6045 __END__
6046
6047 Download this example:
6048 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/outline_collapsed.pl
6049 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6050 WriteExcel-2.36/examples/outline_collapsed.pl>
6051
6052 Example: panes.pl
6053 Example of using the WriteExcel module to create worksheet panes.
6054
6055 Source code for this example:
6056
6057 #!/usr/bin/perl -w
6058
6059 #######################################################################
6060 #
6061 # Example of using the WriteExcel module to create worksheet panes.
6062 #
6063 # reverse('X'), May 2001, John McNamara, jmcnamara@cpan.org
6064 #
6065
6066 use strict;
6067 use Spreadsheet::WriteExcel;
6068
6069 my $workbook = Spreadsheet::WriteExcel->new("panes.xls");
6070
6071 my $worksheet1 = $workbook->add_worksheet('Panes 1');
6072 my $worksheet2 = $workbook->add_worksheet('Panes 2');
6073 my $worksheet3 = $workbook->add_worksheet('Panes 3');
6074 my $worksheet4 = $workbook->add_worksheet('Panes 4');
6075
6076 # Freeze panes
6077 $worksheet1->freeze_panes(1, 0); # 1 row
6078
6079 $worksheet2->freeze_panes(0, 1); # 1 column
6080 $worksheet3->freeze_panes(1, 1); # 1 row and column
6081
6082 # Split panes.
6083 # The divisions must be specified in terms of row and column dimensions.
6084 # The default row height is 12.75 and the default column width is 8.43
6085 #
6086 $worksheet4->split_panes(12.75, 8.43, 1, 1); # 1 row and column
6087
6088
6089 #######################################################################
6090 #
6091 # Set up some formatting and text to highlight the panes
6092 #
6093
6094 my $header = $workbook->add_format();
6095 $header->set_color('white');
6096 $header->set_align('center');
6097 $header->set_align('vcenter');
6098 $header->set_pattern();
6099 $header->set_fg_color('green');
6100
6101 my $center = $workbook->add_format();
6102 $center->set_align('center');
6103
6104
6105 #######################################################################
6106 #
6107 # Sheet 1
6108 #
6109
6110 $worksheet1->set_column('A:I', 16);
6111 $worksheet1->set_row(0, 20);
6112 $worksheet1->set_selection('C3');
6113
6114 for my $i (0..8){
6115 $worksheet1->write(0, $i, 'Scroll down', $header);
6116 }
6117
6118 for my $i (1..100){
6119 for my $j (0..8){
6120 $worksheet1->write($i, $j, $i+1, $center);
6121 }
6122 }
6123
6124
6125 #######################################################################
6126 #
6127 # Sheet 2
6128 #
6129
6130 $worksheet2->set_column('A:A', 16);
6131 $worksheet2->set_selection('C3');
6132
6133 for my $i (0..49){
6134 $worksheet2->set_row($i, 15);
6135 $worksheet2->write($i, 0, 'Scroll right', $header);
6136 }
6137
6138 for my $i (0..49){
6139 for my $j (1..25){
6140 $worksheet2->write($i, $j, $j, $center);
6141 }
6142 }
6143
6144
6145 #######################################################################
6146 #
6147 # Sheet 3
6148 #
6149
6150 $worksheet3->set_column('A:Z', 16);
6151 $worksheet3->set_selection('C3');
6152
6153 for my $i (1..25){
6154 $worksheet3->write(0, $i, 'Scroll down', $header);
6155 }
6156
6157 for my $i (1..49){
6158 $worksheet3->write($i, 0, 'Scroll right', $header);
6159 }
6160
6161 for my $i (1..49){
6162 for my $j (1..25){
6163 $worksheet3->write($i, $j, $j, $center);
6164 }
6165 }
6166
6167
6168 #######################################################################
6169 #
6170 # Sheet 4
6171 #
6172
6173 $worksheet4->set_selection('C3');
6174
6175 for my $i (1..25){
6176 $worksheet4->write(0, $i, 'Scroll', $center);
6177 }
6178
6179 for my $i (1..49){
6180 $worksheet4->write($i, 0, 'Scroll', $center);
6181 }
6182
6183 for my $i (1..49){
6184 for my $j (1..25){
6185 $worksheet4->write($i, $j, $j, $center);
6186 }
6187 }
6188
6189 Download this example:
6190 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/panes.pl
6191 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6192 WriteExcel-2.36/examples/panes.pl>
6193
6194 Example: properties.pl
6195 An example of adding document properties to a Spreadsheet::WriteExcel
6196 file.
6197
6198 Source code for this example:
6199
6200 #!/usr/bin/perl -w
6201
6202 ##############################################################################
6203 #
6204 # An example of adding document properties to a Spreadsheet::WriteExcel file.
6205 #
6206 # reverse('X'), August 2008, John McNamara, jmcnamara@cpan.org
6207 #
6208
6209 use strict;
6210 use Spreadsheet::WriteExcel;
6211
6212 my $workbook = Spreadsheet::WriteExcel->new('properties.xls');
6213 my $worksheet = $workbook->add_worksheet();
6214
6215
6216 $workbook->set_properties(
6217 title => 'This is an example spreadsheet',
6218 subject => 'With document properties',
6219 author => 'John McNamara',
6220 manager => 'Dr. Heinz Doofenshmirtz ',
6221 company => 'of Wolves',
6222 category => 'Example spreadsheets',
6223 keywords => 'Sample, Example, Properties',
6224 comments => 'Created with Perl and Spreadsheet::WriteExcel',
6225 );
6226
6227
6228 $worksheet->set_column('A:A', 50);
6229 $worksheet->write('A1', 'Select File->Properties to see the file properties');
6230
6231
6232 __END__
6233
6234 Download this example:
6235 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/properties.pl
6236 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6237 WriteExcel-2.36/examples/properties.pl>
6238
6239 Example: protection.pl
6240 Example of cell locking and formula hiding in an Excel worksheet via
6241 the Spreadsheet::WriteExcel module.
6242
6243 Source code for this example:
6244
6245 #!/usr/bin/perl -w
6246
6247 ########################################################################
6248 #
6249 # Example of cell locking and formula hiding in an Excel worksheet via
6250 # the Spreadsheet::WriteExcel module.
6251 #
6252 # reverse('X'), August 2001, John McNamara, jmcnamara@cpan.org
6253 #
6254
6255 use strict;
6256 use Spreadsheet::WriteExcel;
6257
6258 my $workbook = Spreadsheet::WriteExcel->new("protection.xls");
6259 my $worksheet = $workbook->add_worksheet();
6260
6261 # Create some format objects
6262 my $locked = $workbook->add_format(locked => 1);
6263 my $unlocked = $workbook->add_format(locked => 0);
6264 my $hidden = $workbook->add_format(hidden => 1);
6265
6266 # Format the columns
6267 $worksheet->set_column('A:A', 42);
6268 $worksheet->set_selection('B3:B3');
6269
6270 # Protect the worksheet
6271 $worksheet->protect();
6272
6273 # Examples of cell locking and hiding
6274 $worksheet->write('A1', 'Cell B1 is locked. It cannot be edited.');
6275 $worksheet->write('B1', '=1+2', $locked);
6276
6277 $worksheet->write('A2', 'Cell B2 is unlocked. It can be edited.');
6278 $worksheet->write('B2', '=1+2', $unlocked);
6279
6280 $worksheet->write('A3', "Cell B3 is hidden. The formula isn't visible.");
6281 $worksheet->write('B3', '=1+2', $hidden);
6282
6283 $worksheet->write('A5', 'Use Menu->Tools->Protection->Unprotect Sheet');
6284 $worksheet->write('A6', 'to remove the worksheet protection. ');
6285
6286 Download this example:
6287 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/protection.pl
6288 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6289 WriteExcel-2.36/examples/protection.pl>
6290
6291 Example: repeat.pl
6292 Example of writing repeated formulas.
6293
6294 Source code for this example:
6295
6296 #!/usr/bin/perl -w
6297
6298 ######################################################################
6299 #
6300 # Example of writing repeated formulas.
6301 #
6302 # reverse('X'), August 2002, John McNamara, jmcnamara@cpan.org
6303 #
6304
6305 use strict;
6306 use Spreadsheet::WriteExcel;
6307
6308 my $workbook = Spreadsheet::WriteExcel->new("repeat.xls");
6309 my $worksheet = $workbook->add_worksheet();
6310
6311
6312 my $limit = 1000;
6313
6314 # Write a column of numbers
6315 for my $row (0..$limit) {
6316 $worksheet->write($row, 0, $row);
6317 }
6318
6319
6320 # Store a formula
6321 my $formula = $worksheet->store_formula('=A1*5+4');
6322
6323
6324 # Write a column of formulas based on the stored formula
6325 for my $row (0..$limit) {
6326 $worksheet->repeat_formula($row, 1, $formula, undef,
6327 qr/^A1$/, 'A'.($row+1));
6328 }
6329
6330
6331 # Direct formula writing. As a speed comparison uncomment the
6332 # following and run the program again
6333
6334 #for my $row (0..$limit) {
6335 # $worksheet->write_formula($row, 2, '=A'.($row+1).'*5+4');
6336 #}
6337
6338
6339
6340 __END__
6341
6342 Download this example:
6343 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/repeat.pl
6344 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6345 WriteExcel-2.36/examples/repeat.pl>
6346
6347 Example: right_to_left.pl
6348 Example of how to change the default worksheet direction from left-to-
6349 right to right-to-left as required by some eastern verions of Excel.
6350
6351 Source code for this example:
6352
6353 #!/usr/bin/perl -w
6354
6355 #######################################################################
6356 #
6357 # Example of how to change the default worksheet direction from
6358 # left-to-right to right-to-left as required by some eastern verions
6359 # of Excel.
6360 #
6361 # reverse('X'), January 2006, John McNamara, jmcnamara@cpan.org
6362 #
6363
6364 use strict;
6365 use Spreadsheet::WriteExcel;
6366
6367 my $workbook = Spreadsheet::WriteExcel->new("right_to_left.xls");
6368 my $worksheet1 = $workbook->add_worksheet();
6369 my $worksheet2 = $workbook->add_worksheet();
6370
6371 $worksheet2->right_to_left();
6372
6373 $worksheet1->write(0, 0, 'Hello'); # A1, B1, C1, ...
6374 $worksheet2->write(0, 0, 'Hello'); # ..., C1, B1, A1
6375
6376 Download this example:
6377 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/right_to_left.pl
6378 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6379 WriteExcel-2.36/examples/right_to_left.pl>
6380
6381 Example: row_wrap.pl
6382 Demonstrates how to wrap data from one worksheet onto another.
6383
6384 Excel has a row limit of 65536 rows. Sometimes the amount of row data
6385 to be written to a file is greater than this limit. In this case it is
6386 a useful technique to wrap the data from one worksheet onto the next so
6387 that we get something like the following:
6388
6389 Sheet1 Row 1 - 65536
6390 Sheet2 Row 65537 - 131072
6391 Sheet3 Row 131073 - ...
6392
6393 In order to achieve this we use a single worksheet reference and
6394 reinitialise it to point to a new worksheet when required.
6395
6396 Source code for this example:
6397
6398 #!/usr/bin/perl -w
6399
6400 ##############################################################################
6401 #
6402 # Demonstrates how to wrap data from one worksheet onto another.
6403 #
6404 # Excel has a row limit of 65536 rows. Sometimes the amount of row data to be
6405 # written to a file is greater than this limit. In this case it is a useful
6406 # technique to wrap the data from one worksheet onto the next so that we get
6407 # something like the following:
6408 #
6409 # Sheet1 Row 1 - 65536
6410 # Sheet2 Row 65537 - 131072
6411 # Sheet3 Row 131073 - ...
6412 #
6413 # In order to achieve this we use a single worksheet reference and
6414 # reinitialise it to point to a new worksheet when required.
6415 #
6416 # reverse('X'), May 2006, John McNamara, jmcnamara@cpan.org
6417 #
6418
6419
6420 use strict;
6421 use Spreadsheet::WriteExcel;
6422
6423 my $workbook = Spreadsheet::WriteExcel->new('row_wrap.xls');
6424 my $worksheet = $workbook->add_worksheet();
6425
6426
6427 # Worksheet formatting.
6428 $worksheet->set_column('A:A', 20);
6429
6430
6431 # For the sake of this example we will use a small row limit. In order to use
6432 # the entire row range set the $row_limit to 65536.
6433 my $row_limit = 10;
6434 my $row = 0;
6435
6436 for my $count (1 .. 2 * $row_limit +10) {
6437
6438 # When we hit the row limit we redirect the output
6439 # to a new worksheet and reset the row number.
6440 if ($row == $row_limit) {
6441 $worksheet = $workbook->add_worksheet();
6442 $row = 0;
6443
6444 # Repeat any worksheet formatting.
6445 $worksheet->set_column('A:A', 20);
6446 }
6447
6448 $worksheet->write($row, 0, "This is row $count");
6449 $row++;
6450 }
6451
6452 Download this example:
6453 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/row_wrap.pl
6454 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6455 WriteExcel-2.36/examples/row_wrap.pl>
6456
6457 Example: sales.pl
6458 Example of a sales worksheet to demonstrate several different features.
6459 Also uses functions from the Spreadsheet::WriteExcel::Utility module.
6460
6461 Source code for this example:
6462
6463 #!/usr/bin/perl -w
6464
6465 ###############################################################################
6466 #
6467 # Example of a sales worksheet to demonstrate several different features.
6468 # Also uses functions from the L<Spreadsheet::WriteExcel::Utility> module.
6469 #
6470 # reverse('X'), October 2001, John McNamara, jmcnamara@cpan.org
6471 #
6472
6473 use strict;
6474 use Spreadsheet::WriteExcel;
6475 use Spreadsheet::WriteExcel::Utility;
6476
6477 # Create a new workbook and add a worksheet
6478 my $workbook = Spreadsheet::WriteExcel->new("sales.xls");
6479 my $worksheet = $workbook->add_worksheet('May Sales');
6480
6481
6482 # Set up some formats
6483 my %heading = (
6484 bold => 1,
6485 pattern => 1,
6486 fg_color => 19,
6487 border => 1,
6488 align => 'center',
6489 );
6490
6491 my %total = (
6492 bold => 1,
6493 top => 1,
6494 num_format => '$#,##0.00'
6495 );
6496
6497 my $heading = $workbook->add_format(%heading);
6498 my $total_format = $workbook->add_format(%total);
6499 my $price_format = $workbook->add_format(num_format => '$#,##0.00');
6500 my $date_format = $workbook->add_format(num_format => 'mmm d yyy');
6501
6502
6503 # Write the main headings
6504 $worksheet->freeze_panes(1); # Freeze the first row
6505 $worksheet->write('A1', 'Item', $heading);
6506 $worksheet->write('B1', 'Quantity', $heading);
6507 $worksheet->write('C1', 'Price', $heading);
6508 $worksheet->write('D1', 'Total', $heading);
6509 $worksheet->write('E1', 'Date', $heading);
6510
6511 # Set the column widths
6512 $worksheet->set_column('A:A', 25);
6513 $worksheet->set_column('B:B', 10);
6514 $worksheet->set_column('C:E', 16);
6515
6516
6517 # Extract the sales data from the __DATA__ section at the end of the file.
6518 # In reality this information would probably come from a database
6519 my @sales;
6520
6521 foreach my $line (<DATA>) {
6522 chomp $line;
6523 next if $line eq '';
6524 # Simple-minded processing of CSV data. Refer to the Text::CSV_XS
6525 # and Text::xSV modules for a more complete CSV handling.
6526 my @items = split /,/, $line;
6527 push @sales, \@items;
6528 }
6529
6530
6531 # Write out the items from each row
6532 my $row = 1;
6533 foreach my $sale (@sales) {
6534
6535 $worksheet->write($row, 0, @$sale[0]);
6536 $worksheet->write($row, 1, @$sale[1]);
6537 $worksheet->write($row, 2, @$sale[2], $price_format);
6538
6539 # Create a formula like '=B2*C2'
6540 my $formula = '='
6541 . xl_rowcol_to_cell($row, 1)
6542 . "*"
6543 . xl_rowcol_to_cell($row, 2);
6544
6545 $worksheet->write($row, 3, $formula, $price_format);
6546
6547 # Parse the date
6548 my $date = xl_decode_date_US(@$sale[3]);
6549 $worksheet->write($row, 4, $date, $date_format);
6550 $row++;
6551 }
6552
6553 # Create a formula to sum the totals, like '=SUM(D2:D6)'
6554 my $total = '=SUM(D2:'
6555 . xl_rowcol_to_cell($row-1, 3)
6556 . ")";
6557
6558 $worksheet->write($row, 3, $total, $total_format);
6559
6560
6561
6562 __DATA__
6563 586 card,20,125.50,5/12/01
6564 Flat Screen Monitor,1,1300.00,5/12/01
6565 64 MB dimms,45,49.99,5/13/01
6566 15 GB HD,12,300.00,5/13/01
6567 Speakers (pair),5,15.50,5/14/01
6568
6569 Download this example:
6570 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/sales.pl
6571 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6572 WriteExcel-2.36/examples/sales.pl>
6573
6574 Example: sendmail.pl
6575 Example of how to use Mail::Sender to send a Spreadsheet::WriteExcel
6576 Excel file as an attachment.
6577
6578 The main thing is to ensure that you close() the Worbook before you
6579 send it.
6580
6581 See the Mail::Sender module for further details.
6582
6583 #!/usr/bin/perl -w
6584
6585 ###############################################################################
6586 #
6587 # Example of how to use Mail::Sender to send a Spreadsheet::WriteExcel Excel
6588 # file as an attachment.
6589 #
6590 # The main thing is to ensure that you close() the Worbook before you send it.
6591 #
6592 # See the L<Mail::Sender> module for further details.
6593 #
6594 # reverse('X'), August 2002, John McNamara, jmcnamara@cpan.org
6595 #
6596
6597
6598 use strict;
6599 use Spreadsheet::WriteExcel;
6600 use Mail::Sender;
6601
6602 # Create an Excel file
6603 my $workbook = Spreadsheet::WriteExcel->new("sendmail.xls");
6604 my $worksheet = $workbook->add_worksheet;
6605
6606 $worksheet->write('A1', "Hello World!");
6607
6608 $workbook->close(); # Must close before sending
6609
6610
6611
6612 # Send the file. Change all variables to suit
6613 my $sender = new Mail::Sender
6614 {
6615 smtp => '123.123.123.123',
6616 from => 'Someone'
6617 };
6618
6619 $sender->MailFile(
6620 {
6621 to => 'another@mail.com',
6622 subject => 'Excel file',
6623 msg => "Here is the data.\n",
6624 file => 'mail.xls',
6625 });
6626
6627 Download this example:
6628 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/sendmail.pl
6629 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6630 WriteExcel-2.36/examples/sendmail.pl>
6631
6632 Example: stats_ext.pl
6633 Example of formatting using the Spreadsheet::WriteExcel module
6634
6635 This is a simple example of how to use functions that reference cells
6636 in other worksheets within the same workbook.
6637
6638 Source code for this example:
6639
6640 #!/usr/bin/perl -w
6641
6642 ###############################################################################
6643 #
6644 # Example of formatting using the Spreadsheet::WriteExcel module
6645 #
6646 # This is a simple example of how to use functions that reference cells in
6647 # other worksheets within the same workbook.
6648 #
6649 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
6650 #
6651
6652 use strict;
6653 use Spreadsheet::WriteExcel;
6654
6655 # Create a new workbook and add a worksheet
6656 my $workbook = Spreadsheet::WriteExcel->new("stats_ext.xls");
6657 my $worksheet1 = $workbook->add_worksheet('Test results');
6658 my $worksheet2 = $workbook->add_worksheet('Data');
6659
6660 # Set the column width for columns 1
6661 $worksheet1->set_column('A:A', 20);
6662
6663
6664 # Create a format for the headings
6665 my $heading = $workbook->add_format();
6666 $heading->set_bold();
6667
6668 # Create a numerical format
6669 my $numformat = $workbook->add_format();
6670 $numformat->set_num_format('0.00');
6671
6672
6673
6674
6675 # Write some statistical functions
6676 $worksheet1->write('A1', 'Count', $heading);
6677 $worksheet1->write('B1', '=COUNT(Data!B2:B9)');
6678
6679 $worksheet1->write('A2', 'Sum', $heading);
6680 $worksheet1->write('B2', '=SUM(Data!B2:B9)');
6681
6682 $worksheet1->write('A3', 'Average', $heading);
6683 $worksheet1->write('B3', '=AVERAGE(Data!B2:B9)');
6684
6685 $worksheet1->write('A4', 'Min', $heading);
6686 $worksheet1->write('B4', '=MIN(Data!B2:B9)');
6687
6688 $worksheet1->write('A5', 'Max', $heading);
6689 $worksheet1->write('B5', '=MAX(Data!B2:B9)');
6690
6691 $worksheet1->write('A6', 'Standard Deviation', $heading);
6692 $worksheet1->write('B6', '=STDEV(Data!B2:B9)');
6693
6694 $worksheet1->write('A7', 'Kurtosis', $heading);
6695 $worksheet1->write('B7', '=KURT(Data!B2:B9)');
6696
6697
6698 # Write the sample data
6699 $worksheet2->write('A1', 'Sample', $heading);
6700 $worksheet2->write('A2', 1);
6701 $worksheet2->write('A3', 2);
6702 $worksheet2->write('A4', 3);
6703 $worksheet2->write('A5', 4);
6704 $worksheet2->write('A6', 5);
6705 $worksheet2->write('A7', 6);
6706 $worksheet2->write('A8', 7);
6707 $worksheet2->write('A9', 8);
6708
6709 $worksheet2->write('B1', 'Length', $heading);
6710 $worksheet2->write('B2', 25.4, $numformat);
6711 $worksheet2->write('B3', 25.4, $numformat);
6712 $worksheet2->write('B4', 24.8, $numformat);
6713 $worksheet2->write('B5', 25.0, $numformat);
6714 $worksheet2->write('B6', 25.3, $numformat);
6715 $worksheet2->write('B7', 24.9, $numformat);
6716 $worksheet2->write('B8', 25.2, $numformat);
6717 $worksheet2->write('B9', 24.8, $numformat);
6718
6719 Download this example:
6720 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/stats_ext.pl
6721 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6722 WriteExcel-2.36/examples/stats_ext.pl>
6723
6724 Example: stocks.pl
6725 Example of formatting using the Spreadsheet::WriteExcel module
6726
6727 This example shows how to use a conditional numerical format with
6728 colours to indicate if a share price has gone up or down.
6729
6730 Source code for this example:
6731
6732 #!/usr/bin/perl -w
6733
6734 ###############################################################################
6735 #
6736 # Example of formatting using the Spreadsheet::WriteExcel module
6737 #
6738 # This example shows how to use a conditional numerical format
6739 # with colours to indicate if a share price has gone up or down.
6740 #
6741 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
6742 #
6743
6744 use strict;
6745 use Spreadsheet::WriteExcel;
6746
6747 # Create a new workbook and add a worksheet
6748 my $workbook = Spreadsheet::WriteExcel->new("stocks.xls");
6749 my $worksheet = $workbook->add_worksheet();
6750
6751 # Set the column width for columns 1, 2, 3 and 4
6752 $worksheet->set_column(0, 3, 15);
6753
6754
6755 # Create a format for the column headings
6756 my $header = $workbook->add_format();
6757 $header->set_bold();
6758 $header->set_size(12);
6759 $header->set_color('blue');
6760
6761
6762 # Create a format for the stock price
6763 my $f_price = $workbook->add_format();
6764 $f_price->set_align('left');
6765 $f_price->set_num_format('$0.00');
6766
6767
6768 # Create a format for the stock volume
6769 my $f_volume = $workbook->add_format();
6770 $f_volume->set_align('left');
6771 $f_volume->set_num_format('#,##0');
6772
6773
6774 # Create a format for the price change. This is an example of a conditional
6775 # format. The number is formatted as a percentage. If it is positive it is
6776 # formatted in green, if it is negative it is formatted in red and if it is
6777 # zero it is formatted as the default font colour (in this case black).
6778 # Note: the [Green] format produces an unappealing lime green. Try
6779 # [Color 10] instead for a dark green.
6780 #
6781 my $f_change = $workbook->add_format();
6782 $f_change->set_align('left');
6783 $f_change->set_num_format('[Green]0.0%;[Red]-0.0%;0.0%');
6784
6785
6786 # Write out the data
6787 $worksheet->write(0, 0, 'Company', $header);
6788 $worksheet->write(0, 1, 'Price', $header);
6789 $worksheet->write(0, 2, 'Volume', $header);
6790 $worksheet->write(0, 3, 'Change', $header);
6791
6792 $worksheet->write(1, 0, 'Damage Inc.' );
6793 $worksheet->write(1, 1, 30.25, $f_price); # $30.25
6794 $worksheet->write(1, 2, 1234567, $f_volume); # 1,234,567
6795 $worksheet->write(1, 3, 0.085, $f_change); # 8.5% in green
6796
6797 $worksheet->write(2, 0, 'Dump Corp.' );
6798 $worksheet->write(2, 1, 1.56, $f_price); # $1.56
6799 $worksheet->write(2, 2, 7564, $f_volume); # 7,564
6800 $worksheet->write(2, 3, -0.015, $f_change); # -1.5% in red
6801
6802 $worksheet->write(3, 0, 'Rev Ltd.' );
6803 $worksheet->write(3, 1, 0.13, $f_price); # $0.13
6804 $worksheet->write(3, 2, 321, $f_volume); # 321
6805 $worksheet->write(3, 3, 0, $f_change); # 0 in the font color (black)
6806
6807 Download this example:
6808 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/stocks.pl
6809 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6810 WriteExcel-2.36/examples/stocks.pl>
6811
6812 Example: tab_colors.pl
6813 Example of how to set Excel worksheet tab colours.
6814
6815 Source code for this example:
6816
6817 #!/usr/bin/perl -w
6818
6819 #######################################################################
6820 #
6821 # Example of how to set Excel worksheet tab colours.
6822 #
6823 # reverse('X'), May 2006, John McNamara, jmcnamara@cpan.org
6824 #
6825
6826 use strict;
6827 use Spreadsheet::WriteExcel;
6828
6829
6830 my $workbook = Spreadsheet::WriteExcel->new('tab_colors.xls');
6831
6832 my $worksheet1 = $workbook->add_worksheet();
6833 my $worksheet2 = $workbook->add_worksheet();
6834 my $worksheet3 = $workbook->add_worksheet();
6835 my $worksheet4 = $workbook->add_worksheet();
6836
6837 # Worksheet1 will have the default tab colour.
6838 $worksheet2->set_tab_color('red');
6839 $worksheet3->set_tab_color('green');
6840 $worksheet4->set_tab_color(0x35); # Orange
6841
6842 Download this example:
6843 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/tab_colors.pl
6844 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6845 WriteExcel-2.36/examples/tab_colors.pl>
6846
6847 Example: textwrap.pl
6848 Example of formatting using the Spreadsheet::WriteExcel module
6849
6850 This example shows how to wrap text in a cell. There are two
6851 alternatives, vertical justification and text wrap.
6852
6853 With vertical justification the text is wrapped automatically to fit
6854 the column width. With text wrap you must specify a newline with an
6855 embedded \n.
6856
6857 Source code for this example:
6858
6859 #!/usr/bin/perl -w
6860
6861 ###############################################################################
6862 #
6863 # Example of formatting using the Spreadsheet::WriteExcel module
6864 #
6865 # This example shows how to wrap text in a cell. There are two alternatives,
6866 # vertical justification and text wrap.
6867 #
6868 # With vertical justification the text is wrapped automatically to fit the
6869 # column width. With text wrap you must specify a newline with an embedded \n.
6870 #
6871 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
6872 #
6873
6874 use strict;
6875 use Spreadsheet::WriteExcel;
6876
6877 # Create a new workbook and add a worksheet
6878 my $workbook = Spreadsheet::WriteExcel->new("textwrap.xls");
6879 my $worksheet = $workbook->add_worksheet();
6880
6881 # Set the column width for columns 1, 2 and 3
6882 $worksheet->set_column(1, 1, 24);
6883 $worksheet->set_column(2, 2, 34);
6884 $worksheet->set_column(3, 3, 34);
6885
6886 # Set the row height for rows 1, 4, and 6. The height of row 2 will adjust
6887 # automatically to fit the text.
6888 #
6889 $worksheet->set_row(0, 30);
6890 $worksheet->set_row(3, 40);
6891 $worksheet->set_row(5, 80);
6892
6893
6894 # No newlines
6895 my $str1 = "For whatever we lose (like a you or a me) ";
6896 $str1 .= "it's always ourselves we find in the sea";
6897
6898 # Embedded newlines
6899 my $str2 = "For whatever we lose\n(like a you or a me)\n";
6900 $str2 .= "it's always ourselves\nwe find in the sea";
6901
6902
6903 # Create a format for the column headings
6904 my $header = $workbook->add_format();
6905 $header->set_bold();
6906 $header->set_font("Courier New");
6907 $header->set_align('center');
6908 $header->set_align('vcenter');
6909
6910 # Create a "vertical justification" format
6911 my $format1 = $workbook->add_format();
6912 $format1->set_align('vjustify');
6913
6914 # Create a "text wrap" format
6915 my $format2 = $workbook->add_format();
6916 $format2->set_text_wrap();
6917
6918 # Write the headers
6919 $worksheet->write(0, 1, "set_align('vjustify')", $header);
6920 $worksheet->write(0, 2, "set_align('vjustify')", $header);
6921 $worksheet->write(0, 3, "set_text_wrap()", $header);
6922
6923 # Write some examples
6924 $worksheet->write(1, 1, $str1, $format1);
6925 $worksheet->write(1, 2, $str1, $format1);
6926 $worksheet->write(1, 3, $str2, $format2);
6927
6928 $worksheet->write(3, 1, $str1, $format1);
6929 $worksheet->write(3, 2, $str1, $format1);
6930 $worksheet->write(3, 3, $str2, $format2);
6931
6932 $worksheet->write(5, 1, $str1, $format1);
6933 $worksheet->write(5, 2, $str1, $format1);
6934 $worksheet->write(5, 3, $str2, $format2);
6935
6936 Download this example:
6937 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/textwrap.pl
6938 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6939 WriteExcel-2.36/examples/textwrap.pl>
6940
6941 Example: win32ole.pl
6942 This is a simple example of how to create an Excel file using the
6943 Win32::OLE module for the sake of comparison.
6944
6945 #!/usr/bin/perl -w
6946
6947 ###############################################################################
6948 #
6949 # This is a simple example of how to create an Excel file using the
6950 # Win32::OLE module for the sake of comparison.
6951 #
6952 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
6953 #
6954
6955 use strict;
6956 use Cwd;
6957 use Win32::OLE;
6958 use Win32::OLE::Const 'Microsoft Excel';
6959
6960
6961 my $application = Win32::OLE->new("Excel.Application");
6962 my $workbook = $application->Workbooks->Add;
6963 my $worksheet = $workbook->Worksheets(1);
6964
6965 $worksheet->Cells(1,1)->{Value} = "Hello World";
6966 $worksheet->Cells(2,1)->{Value} = "One";
6967 $worksheet->Cells(3,1)->{Value} = "Two";
6968 $worksheet->Cells(4,1)->{Value} = 3;
6969 $worksheet->Cells(5,1)->{Value} = 4.0000001;
6970
6971 # Add some formatting
6972 $worksheet->Cells(1,1)->Font->{Bold} = "True";
6973 $worksheet->Cells(1,1)->Font->{Size} = 16;
6974 $worksheet->Cells(1,1)->Font->{ColorIndex} = 3;
6975 $worksheet->Columns("A:A")->{ColumnWidth} = 25;
6976
6977 # Write a hyperlink
6978 my $range = $worksheet->Range("A7:A7");
6979 $worksheet->Hyperlinks->Add({ Anchor => $range, Address => "http://www.perl.com/"});
6980
6981 # Get current directory using Cwd.pm
6982 my $dir = cwd();
6983
6984 $workbook->SaveAs({
6985 FileName => $dir . '/win32ole.xls',
6986 FileFormat => xlNormal,
6987 });
6988 $workbook->Close;
6989
6990 Download this example:
6991 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/win32ole.pl
6992 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
6993 WriteExcel-2.36/examples/win32ole.pl>
6994
6995 Example: write_arrays.pl
6996 Example of how to use the Spreadsheet::WriteExcel module to write 1D
6997 and 2D arrays of data.
6998
6999 To find out more about array references refer(!!) to the perlref and
7000 perlreftut manpages. To find out more about 2D arrays or "list of
7001 lists" refer to the perllol manpage.
7002
7003 Source code for this example:
7004
7005 #!/usr/bin/perl -w
7006
7007 #######################################################################
7008 #
7009 # Example of how to use the Spreadsheet::WriteExcel module to
7010 # write 1D and 2D arrays of data.
7011 #
7012 # To find out more about array references refer(!!) to the perlref and
7013 # perlreftut manpages. To find out more about 2D arrays or "list of
7014 # lists" refer to the perllol manpage.
7015 #
7016 # reverse('X'), March 2002, John McNamara, jmcnamara@cpan.org
7017 #
7018
7019
7020 use strict;
7021 use Spreadsheet::WriteExcel;
7022
7023
7024 my $workbook = Spreadsheet::WriteExcel->new("write_arrays.xls");
7025 my $worksheet1 = $workbook->add_worksheet('Example 1');
7026 my $worksheet2 = $workbook->add_worksheet('Example 2');
7027 my $worksheet3 = $workbook->add_worksheet('Example 3');
7028 my $worksheet4 = $workbook->add_worksheet('Example 4');
7029 my $worksheet5 = $workbook->add_worksheet('Example 5');
7030 my $worksheet6 = $workbook->add_worksheet('Example 6');
7031 my $worksheet7 = $workbook->add_worksheet('Example 7');
7032 my $worksheet8 = $workbook->add_worksheet('Example 8');
7033
7034 my $format = $workbook->add_format(color => 'red', bold => 1);
7035
7036
7037 # Data arrays used in the following examples.
7038 # undef values are written as blank cells (with format if specified).
7039 #
7040 my @array = ( 'one', 'two', undef, 'four' );
7041
7042 my @array2d = (
7043 ['maggie', 'milly', 'molly', 'may' ],
7044 [13, 14, 15, 16 ],
7045 ['shell', 'star', 'crab', 'stone'],
7046 );
7047
7048
7049 # 1. Write a row of data using an array reference.
7050 $worksheet1->write('A1', \@array);
7051
7052 # 2. Same as 1. above using an anonymous array ref.
7053 $worksheet2->write('A1', [ @array ]);
7054
7055 # 3. Write a row of data using an explicit write_row() method call.
7056 # This is the same as calling write() in Ex. 1 above.
7057 #
7058 $worksheet3->write_row('A1', \@array);
7059
7060 # 4. Write a column of data using the write_col() method call.
7061 $worksheet4->write_col('A1', \@array);
7062
7063 # 5. Write a column of data using a ref to an array ref, i.e. a 2D array.
7064 $worksheet5->write('A1', [ \@array ]);
7065
7066 # 6. Write a 2D array in col-row order.
7067 $worksheet6->write('A1', \@array2d);
7068
7069 # 7. Write a 2D array in row-col order.
7070 $worksheet7->write_col('A1', \@array2d);
7071
7072 # 8. Write a row of data with formatting. The blank cell is also formatted.
7073 $worksheet8->write('A1', \@array, $format);
7074
7075 Download this example:
7076 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/write_arrays.pl
7077 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7078 WriteExcel-2.36/examples/write_arrays.pl>
7079
7080 Example: write_handler1.pl
7081 Example of how to add a user defined data handler to the Spreadsheet::
7082 WriteExcel write() method.
7083
7084 The following example shows how to add a handler for a 7 digit ID
7085 number.
7086
7087 Source code for this example:
7088
7089 #!/usr/bin/perl -w
7090
7091 ###############################################################################
7092 #
7093 # Example of how to add a user defined data handler to the Spreadsheet::
7094 # WriteExcel write() method.
7095 #
7096 # The following example shows how to add a handler for a 7 digit ID number.
7097 #
7098 #
7099 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7100 #
7101
7102 use strict;
7103 use Spreadsheet::WriteExcel;
7104
7105
7106 my $workbook = Spreadsheet::WriteExcel->new("write_handler1.xls");
7107 my $worksheet = $workbook->add_worksheet();
7108
7109
7110 ###############################################################################
7111 #
7112 # Add a handler for 7 digit id numbers. This is useful when you want a string
7113 # such as 0000001 written as a string instead of a number and thus preserve
7114 # the leading zeroes.
7115 #
7116 # Note: you can get the same effect using the keep_leading_zeros() method but
7117 # this serves as a simple example.
7118 #
7119 $worksheet->add_write_handler(qr[^\d{7}$], \&write_my_id);
7120
7121
7122 ###############################################################################
7123 #
7124 # The following function processes the data when a match is found.
7125 #
7126 sub write_my_id {
7127
7128 my $worksheet = shift;
7129
7130 return $worksheet->write_string(@_);
7131 }
7132
7133
7134 # This format maintains the cell as text even if it is edited.
7135 my $id_format = $workbook->add_format(num_format => '@');
7136
7137
7138 # Write some numbers in the user defined format
7139 $worksheet->write('A1', '0000000', $id_format);
7140 $worksheet->write('A2', '0000001', $id_format);
7141 $worksheet->write('A3', '0004000', $id_format);
7142 $worksheet->write('A4', '1234567', $id_format);
7143
7144 # Write some numbers that don't match the defined format
7145 $worksheet->write('A6', '000000', $id_format);
7146 $worksheet->write('A7', '000001', $id_format);
7147 $worksheet->write('A8', '004000', $id_format);
7148 $worksheet->write('A9', '123456', $id_format);
7149
7150
7151 __END__
7152
7153 Download this example:
7154 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/write_handler1.pl
7155 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7156 WriteExcel-2.36/examples/write_handler1.pl>
7157
7158 Example: write_handler2.pl
7159 Example of how to add a user defined data handler to the Spreadsheet::
7160 WriteExcel write() method.
7161
7162 The following example shows how to add a handler for a 7 digit ID
7163 number. It adds an additional constraint to the write_handler1.pl in
7164 that it only filters data that isn't in the third column.
7165
7166 Source code for this example:
7167
7168 #!/usr/bin/perl -w
7169
7170 ###############################################################################
7171 #
7172 # Example of how to add a user defined data handler to the Spreadsheet::
7173 # WriteExcel write() method.
7174 #
7175 # The following example shows how to add a handler for a 7 digit ID number.
7176 # It adds an additional constraint to the write_handler1.pl in that it only
7177 # filters data that isn't in the third column.
7178 #
7179 #
7180 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7181 #
7182
7183 use strict;
7184 use Spreadsheet::WriteExcel;
7185
7186
7187 my $workbook = Spreadsheet::WriteExcel->new("write_handler2.xls");
7188 my $worksheet = $workbook->add_worksheet();
7189
7190
7191 ###############################################################################
7192 #
7193 # Add a handler for 7 digit id numbers. This is useful when you want a string
7194 # such as 0000001 written as a string instead of a number and thus preserve
7195 # the leading zeroes.
7196 #
7197 # Note: you can get the same effect using the keep_leading_zeros() method but
7198 # this serves as a simple example.
7199 #
7200 $worksheet->add_write_handler(qr[^\d{7}$], \&write_my_id);
7201
7202
7203 ###############################################################################
7204 #
7205 # The following function processes the data when a match is found. The handler
7206 # is set up so that it only filters data if it is in the third column.
7207 #
7208 sub write_my_id {
7209
7210 my $worksheet = shift;
7211 my $col = $_[1];
7212
7213 # col is zero based
7214 if ($col != 2) {
7215 return $worksheet->write_string(@_);
7216 }
7217 else {
7218 # Reject the match and return control to write()
7219 return undef;
7220 }
7221
7222 }
7223
7224
7225 # This format maintains the cell as text even if it is edited.
7226 my $id_format = $workbook->add_format(num_format => '@');
7227
7228
7229 # Write some numbers in the user defined format
7230 $worksheet->write('A1', '0000000', $id_format);
7231 $worksheet->write('B1', '0000001', $id_format);
7232 $worksheet->write('C1', '0000002', $id_format);
7233 $worksheet->write('D1', '0000003', $id_format);
7234
7235
7236
7237 __END__
7238
7239 Download this example:
7240 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/write_handler2.pl
7241 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7242 WriteExcel-2.36/examples/write_handler2.pl>
7243
7244 Example: write_handler3.pl
7245 Example of how to add a user defined data handler to the Spreadsheet::
7246 WriteExcel write() method.
7247
7248 The following example shows how to add a handler for dates in a
7249 specific format.
7250
7251 See write_handler4.pl for a more rigorous example with error handling.
7252
7253 Source code for this example:
7254
7255 #!/usr/bin/perl -w
7256
7257 ###############################################################################
7258 #
7259 # Example of how to add a user defined data handler to the Spreadsheet::
7260 # WriteExcel write() method.
7261 #
7262 # The following example shows how to add a handler for dates in a specific
7263 # format.
7264 #
7265 # See write_handler4.pl for a more rigorous example with error handling.
7266 #
7267 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7268 #
7269
7270 use strict;
7271 use Spreadsheet::WriteExcel;
7272
7273
7274 my $workbook = Spreadsheet::WriteExcel->new("write_handler3.xls");
7275 my $worksheet = $workbook->add_worksheet();
7276 my $date_format = $workbook->add_format(num_format => 'dd/mm/yy');
7277
7278
7279 ###############################################################################
7280 #
7281 # Add a handler to match dates in the following format: d/m/yyyy
7282 #
7283 # The day and month can be single or double digits.
7284 #
7285 $worksheet->add_write_handler(qr[^\d{1,2}/\d{1,2}/\d{4}$], \&write_my_date);
7286
7287
7288 ###############################################################################
7289 #
7290 # The following function processes the data when a match is found.
7291 # See write_handler4.pl for a more rigorous example with error handling.
7292 #
7293 sub write_my_date {
7294
7295 my $worksheet = shift;
7296 my @args = @_;
7297
7298 my $token = $args[2];
7299 $token =~ qr[^(\d{1,2})/(\d{1,2})/(\d{4})$];
7300
7301 # Change to the date format required by write_date_time().
7302 my $date = sprintf "%4d-%02d-%02dT", $3, $2, $1;
7303
7304 $args[2] = $date;
7305
7306 return $worksheet->write_date_time(@args);
7307 }
7308
7309
7310 # Write some dates in the user defined format
7311 $worksheet->write('A1', '22/12/2004', $date_format);
7312 $worksheet->write('A2', '1/1/1995', $date_format);
7313 $worksheet->write('A3', '01/01/1995', $date_format);
7314
7315
7316
7317 __END__
7318
7319 Download this example:
7320 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/write_handler3.pl
7321 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7322 WriteExcel-2.36/examples/write_handler3.pl>
7323
7324 Example: write_handler4.pl
7325 Example of how to add a user defined data handler to the Spreadsheet::
7326 WriteExcel write() method.
7327
7328 The following example shows how to add a handler for dates in a
7329 specific format.
7330
7331 This is a more rigorous version of write_handler3.pl.
7332
7333 Source code for this example:
7334
7335 #!/usr/bin/perl -w
7336
7337 ###############################################################################
7338 #
7339 # Example of how to add a user defined data handler to the Spreadsheet::
7340 # WriteExcel write() method.
7341 #
7342 # The following example shows how to add a handler for dates in a specific
7343 # format.
7344 #
7345 # This is a more rigorous version of write_handler3.pl.
7346 #
7347 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7348 #
7349
7350 use strict;
7351 use Spreadsheet::WriteExcel;
7352
7353
7354 my $workbook = Spreadsheet::WriteExcel->new("write_handler4.xls");
7355 my $worksheet = $workbook->add_worksheet();
7356 my $date_format = $workbook->add_format(num_format => 'dd/mm/yy');
7357
7358
7359 ###############################################################################
7360 #
7361 # Add a handler to match dates in the following formats: d/m/yy, d/m/yyyy
7362 #
7363 # The day and month can be single or double digits and the year can be 2 or 4
7364 # digits.
7365 #
7366 $worksheet->add_write_handler(qr[^\d{1,2}/\d{1,2}/\d{2,4}$], \&write_my_date);
7367
7368
7369 ###############################################################################
7370 #
7371 # The following function processes the data when a match is found.
7372 #
7373 sub write_my_date {
7374
7375 my $worksheet = shift;
7376 my @args = @_;
7377
7378 my $token = $args[2];
7379
7380 if ($token =~ qr[^(\d{1,2})/(\d{1,2})/(\d{2,4})$]) {
7381
7382 my $day = $1;
7383 my $mon = $2;
7384 my $year = $3;
7385
7386 # Use a window for 2 digit dates. This will keep some ragged Perl
7387 # programmer employed in thirty years time. :-)
7388 if (length $year == 2) {
7389 if ($year < 50) {
7390 $year += 2000;
7391 }
7392 else {
7393 $year += 1900;
7394 }
7395 }
7396
7397 my $date = sprintf "%4d-%02d-%02dT", $year, $mon, $day;
7398
7399 # Convert the ISO ISO8601 style string to an Excel date
7400 $date = $worksheet->convert_date_time($date);
7401
7402 if (defined $date) {
7403 # Date was valid
7404 $args[2] = $date;
7405 return $worksheet->write_number(@args);
7406 }
7407 else {
7408 # Not a valid date therefore write as a string
7409 return $worksheet->write_string(@args);
7410 }
7411 }
7412 else {
7413 # Shouldn't happen if the same match is used in the re and sub.
7414 return undef;
7415 }
7416 }
7417
7418
7419 # Write some dates in the user defined format
7420 $worksheet->write('A1', '22/12/2004', $date_format);
7421 $worksheet->write('A2', '22/12/04', $date_format);
7422 $worksheet->write('A3', '2/12/04', $date_format);
7423 $worksheet->write('A4', '2/5/04', $date_format);
7424 $worksheet->write('A5', '2/5/95', $date_format);
7425 $worksheet->write('A6', '2/5/1995', $date_format);
7426
7427 # Some erroneous dates
7428 $worksheet->write('A8', '2/5/1895', $date_format); # Date out of Excel range
7429 $worksheet->write('A9', '29/2/2003', $date_format); # Invalid leap day
7430 $worksheet->write('A10','50/50/50', $date_format); # Matches but isn't a date
7431
7432
7433 __END__
7434
7435 Download this example:
7436 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/write_handler4.pl
7437 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7438 WriteExcel-2.36/examples/write_handler4.pl>
7439
7440 Example: write_to_scalar.pl
7441 An example of writing an Excel file to a Perl scalar using
7442 Spreadsheet:: WriteExcel and the new features of perl 5.8.
7443
7444 For an examples of how to write to a scalar in versions prior to perl
7445 5.8 see the filehandle.pl program and IO:Scalar.
7446
7447 #!/usr/bin/perl -w
7448
7449 ##############################################################################
7450 #
7451 # An example of writing an Excel file to a Perl scalar using Spreadsheet::
7452 # WriteExcel and the new features of perl 5.8.
7453 #
7454 # For an examples of how to write to a scalar in versions prior to perl 5.8
7455 # see the filehandle.pl program and IO:Scalar.
7456 #
7457 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7458 #
7459
7460 use strict;
7461 use Spreadsheet::WriteExcel;
7462
7463 require 5.008;
7464
7465
7466 # Use perl 5.8's feature of using a scalar as a filehandle.
7467 my $fh;
7468 my $str = '';
7469 open $fh, '>', \$str or die "Failed to open filehandle: $!";;
7470
7471
7472 # Or replace the previous three lines with this:
7473 # open my $fh, '>', \my $str or die "Failed to open filehandle: $!";
7474
7475
7476 # Spreadsheet::WriteExce accepts filehandle as well as file names.
7477 my $workbook = Spreadsheet::WriteExcel->new($fh);
7478 my $worksheet = $workbook->add_worksheet();
7479
7480 $worksheet->write(0, 0, "Hi Excel!");
7481
7482 $workbook->close();
7483
7484
7485 # The Excel file in now in $str. Remember to binmode() the output
7486 # filehandle before printing it.
7487 binmode STDOUT;
7488 print $str;
7489
7490
7491 __END__
7492
7493 Download this example:
7494 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/write_to_scalar.pl
7495 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7496 WriteExcel-2.36/examples/write_to_scalar.pl>
7497
7498 Example: unicode_utf16.pl
7499 A simple example of writing some Unicode text with
7500 Spreadsheet::WriteExcel.
7501
7502 This example shows UTF16 encoding. With perl 5.8 it is also possible to
7503 use utf8 without modification.
7504
7505 Source code for this example:
7506
7507 #!/usr/bin/perl -w
7508
7509 ##############################################################################
7510 #
7511 # A simple example of writing some Unicode text with Spreadsheet::WriteExcel.
7512 #
7513 # This example shows UTF16 encoding. With perl 5.8 it is also possible to use
7514 # utf8 without modification.
7515 #
7516 # reverse('X'), May 2004, John McNamara, jmcnamara@cpan.org
7517 #
7518
7519
7520 use strict;
7521 use Spreadsheet::WriteExcel;
7522
7523
7524 my $workbook = Spreadsheet::WriteExcel->new('unicode_utf16.xls');
7525 my $worksheet = $workbook->add_worksheet();
7526
7527
7528 # Write the Unicode smiley face (with increased font for legibility)
7529 my $smiley = pack "n", 0x263a;
7530 my $big_font = $workbook->add_format(size => 40);
7531
7532 $worksheet->write_utf16be_string('A3', $smiley, $big_font);
7533
7534
7535 # Write a phrase in Cyrillic
7536 my $uni_str = pack "H*", "042d0442043e002004440440043004370430002004".
7537 "3d043000200440044304410441043a043e043c0021";
7538
7539 $worksheet->write_utf16be_string('A5', $uni_str);
7540
7541
7542 $worksheet->write_utf16be_string('A7', pack "H*", "0074006500730074");
7543
7544
7545
7546
7547
7548 __END__
7549
7550 Download this example:
7551 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_utf16.pl
7552 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7553 WriteExcel-2.36/examples/unicode_utf16.pl>
7554
7555 Example: unicode_utf16_japan.pl
7556 A simple example of writing some Unicode text with
7557 Spreadsheet::WriteExcel.
7558
7559 This creates an Excel file with the word Nippon in 3 character sets.
7560
7561 This example shows UTF16 encoding. With perl 5.8 it is also possible to
7562 use utf8 without modification.
7563
7564 See also the unicode_2022_jp.pl and unicode_shift_jis.pl examples.
7565
7566 Source code for this example:
7567
7568 #!/usr/bin/perl -w
7569
7570 ##############################################################################
7571 #
7572 # A simple example of writing some Unicode text with Spreadsheet::WriteExcel.
7573 #
7574 # This creates an Excel file with the word Nippon in 3 character sets.
7575 #
7576 # This example shows UTF16 encoding. With perl 5.8 it is also possible to use
7577 # utf8 without modification.
7578 #
7579 # See also the unicode_2022_jp.pl and unicode_shift_jis.pl examples.
7580 #
7581 # reverse('X'), May 2004, John McNamara, jmcnamara@cpan.org
7582 #
7583
7584
7585 use strict;
7586 use Spreadsheet::WriteExcel;
7587
7588
7589 my $workbook = Spreadsheet::WriteExcel->new('unicode_utf16_japan.xls');
7590 my $worksheet = $workbook->add_worksheet();
7591
7592
7593 # Set a Unicode font.
7594 my $uni_font = $workbook->add_format(font => 'Arial Unicode MS');
7595
7596
7597 # Create some UTF-16BE Unicode text.
7598 my $kanji = pack 'n*', 0x65e5, 0x672c;
7599 my $katakana = pack 'n*', 0xff86, 0xff8e, 0xff9d;
7600 my $hiragana = pack 'n*', 0x306b, 0x307b, 0x3093;
7601
7602
7603
7604 $worksheet->write_utf16be_string('A1', $kanji, $uni_font);
7605 $worksheet->write_utf16be_string('A2', $katakana, $uni_font);
7606 $worksheet->write_utf16be_string('A3', $hiragana, $uni_font);
7607
7608
7609 $worksheet->write('B1', 'Kanji');
7610 $worksheet->write('B2', 'Katakana');
7611 $worksheet->write('B3', 'Hiragana');
7612
7613
7614 __END__
7615
7616 Download this example:
7617 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_utf16_japan.pl
7618 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7619 WriteExcel-2.36/examples/unicode_utf16_japan.pl>
7620
7621 Example: unicode_cyrillic.pl
7622 A simple example of writing some Russian cyrillic text using
7623 Spreadsheet::WriteExcel and perl 5.8.
7624
7625 Source code for this example:
7626
7627 #!/usr/bin/perl -w
7628
7629 ##############################################################################
7630 #
7631 # A simple example of writing some Russian cyrillic text using
7632 # Spreadsheet::WriteExcel and perl 5.8.
7633 #
7634 # reverse('X'), March 2005, John McNamara, jmcnamara@cpan.org
7635 #
7636
7637
7638
7639 # Perl 5.8 or later is required for proper utf8 handling. For older perl
7640 # versions you should use UTF16 and the write_utf16be_string() method.
7641 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
7642 #
7643 require 5.008;
7644
7645 use strict;
7646 use Spreadsheet::WriteExcel;
7647
7648
7649 # In this example we generate utf8 strings from character data but in a
7650 # real application we would expect them to come from an external source.
7651 #
7652
7653
7654 # Create a Russian worksheet name in utf8.
7655 my $sheet = pack "U*", 0x0421, 0x0442, 0x0440, 0x0430, 0x043D, 0x0438,
7656 0x0446, 0x0430;
7657
7658
7659 # Create a Russian string.
7660 my $str = pack "U*", 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441,
7661 0x0442, 0x0432, 0x0443, 0x0439, 0x0020, 0x041C,
7662 0x0438, 0x0440, 0x0021;
7663
7664
7665
7666 my $workbook = Spreadsheet::WriteExcel->new("unicode_cyrillic.xls");
7667 my $worksheet = $workbook->add_worksheet($sheet . '1');
7668
7669 $worksheet->set_column('A:A', 18);
7670 $worksheet->write('A1', $str);
7671
7672
7673 __END__
7674
7675 Download this example:
7676 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_cyrillic.pl
7677 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7678 WriteExcel-2.36/examples/unicode_cyrillic.pl>
7679
7680 Example: unicode_list.pl
7681 A simple example using Spreadsheet::WriteExcel to display all available
7682 Unicode characters in a font.
7683
7684 Source code for this example:
7685
7686 #!/usr/bin/perl -w
7687
7688 ##############################################################################
7689 #
7690 # A simple example using Spreadsheet::WriteExcel to display all available
7691 # Unicode characters in a font.
7692 #
7693 # reverse('X'), May 2004, John McNamara, jmcnamara@cpan.org
7694 #
7695
7696 use strict;
7697 use Spreadsheet::WriteExcel;
7698
7699
7700 my $workbook = Spreadsheet::WriteExcel->new('unicode_list.xls');
7701 my $worksheet = $workbook->add_worksheet();
7702
7703
7704 # Set a Unicode font.
7705 my $uni_font = $workbook->add_format(font => 'Arial Unicode MS');
7706
7707 # Ascii font for labels.
7708 my $courier = $workbook->add_format(font => 'Courier New');
7709
7710
7711 my $char = 0;
7712
7713 # Loop through all 32768 UTF-16BE characters.
7714 #
7715 for my $row (0 .. 2 ** 12 -1) {
7716 for my $col (0 .. 31) {
7717
7718 last if $char == 0xffff;
7719
7720 if ($col % 2 == 0){
7721 $worksheet->write_string($row, $col,
7722 sprintf('0x%04X', $char), $courier);
7723 }
7724 else {
7725 $worksheet->write_utf16be_string($row, $col,
7726 pack('n', $char++), $uni_font);
7727 }
7728 }
7729 }
7730
7731
7732
7733 __END__
7734
7735 Download this example:
7736 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_list.pl
7737 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7738 WriteExcel-2.36/examples/unicode_list.pl>
7739
7740 Example: unicode_2022_jp.pl
7741 A simple example of converting some Unicode text to an Excel file using
7742 Spreadsheet::WriteExcel and perl 5.8.
7743
7744 This example generates some Japanese from a file with ISO-2022-JP
7745 encoded text.
7746
7747 Source code for this example:
7748
7749 #!/usr/bin/perl -w
7750
7751 ##############################################################################
7752 #
7753 # A simple example of converting some Unicode text to an Excel file using
7754 # Spreadsheet::WriteExcel and perl 5.8.
7755 #
7756 # This example generates some Japanese from a file with ISO-2022-JP
7757 # encoded text.
7758 #
7759 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7760 #
7761
7762
7763
7764 # Perl 5.8 or later is required for proper utf8 handling. For older perl
7765 # versions you should use UTF16 and the write_utf16be_string() method.
7766 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
7767 #
7768 require 5.008;
7769
7770 use strict;
7771 use Spreadsheet::WriteExcel;
7772
7773
7774 my $workbook = Spreadsheet::WriteExcel->new("unicode_2022_jp.xls");
7775 my $worksheet = $workbook->add_worksheet();
7776 $worksheet->set_column('A:A', 50);
7777
7778
7779 my $file = 'unicode_2022_jp.txt';
7780
7781 open FH, '<:encoding(iso-2022-jp)', $file or die "Couldn't open $file: $!\n";
7782
7783 my $row = 0;
7784
7785 while (<FH>) {
7786 next if /^#/; # Ignore the comments in the sample file.
7787 chomp;
7788 $worksheet->write($row++, 0, $_);
7789 }
7790
7791
7792 __END__
7793
7794 Download this example:
7795 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_2022_jp.pl
7796 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7797 WriteExcel-2.36/examples/unicode_2022_jp.pl>
7798
7799 Example: unicode_8859_11.pl
7800 A simple example of converting some Unicode text to an Excel file using
7801 Spreadsheet::WriteExcel and perl 5.8.
7802
7803 This example generates some Thai from a file with ISO-8859-11 encoded
7804 text.
7805
7806 Source code for this example:
7807
7808 #!/usr/bin/perl -w
7809
7810 ##############################################################################
7811 #
7812 # A simple example of converting some Unicode text to an Excel file using
7813 # Spreadsheet::WriteExcel and perl 5.8.
7814 #
7815 # This example generates some Thai from a file with ISO-8859-11 encoded text.
7816 #
7817 #
7818 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7819 #
7820
7821
7822
7823 # Perl 5.8 or later is required for proper utf8 handling. For older perl
7824 # versions you should use UTF16 and the write_utf16be_string() method.
7825 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
7826 #
7827 require 5.008;
7828
7829 use strict;
7830 use Spreadsheet::WriteExcel;
7831
7832
7833 my $workbook = Spreadsheet::WriteExcel->new("unicode_8859_11.xls");
7834 my $worksheet = $workbook->add_worksheet();
7835 $worksheet->set_column('A:A', 50);
7836
7837
7838 my $file = 'unicode_8859_11.txt';
7839
7840 open FH, '<:encoding(iso-8859-11)', $file or die "Couldn't open $file: $!\n";
7841
7842 my $row = 0;
7843
7844 while (<FH>) {
7845 next if /^#/; # Ignore the comments in the sample file.
7846 chomp;
7847 $worksheet->write($row++, 0, $_);
7848 }
7849
7850
7851 __END__
7852
7853 Download this example:
7854 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_8859_11.pl
7855 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7856 WriteExcel-2.36/examples/unicode_8859_11.pl>
7857
7858 Example: unicode_8859_7.pl
7859 A simple example of converting some Unicode text to an Excel file using
7860 Spreadsheet::WriteExcel and perl 5.8.
7861
7862 This example generates some Greek from a file with ISO-8859-7 encoded
7863 text.
7864
7865 Source code for this example:
7866
7867 #!/usr/bin/perl -w
7868
7869 ##############################################################################
7870 #
7871 # A simple example of converting some Unicode text to an Excel file using
7872 # Spreadsheet::WriteExcel and perl 5.8.
7873 #
7874 # This example generates some Greek from a file with ISO-8859-7 encoded text.
7875 #
7876 #
7877 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7878 #
7879
7880
7881
7882 # Perl 5.8 or later is required for proper utf8 handling. For older perl
7883 # versions you should use UTF16 and the write_utf16be_string() method.
7884 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
7885 #
7886 require 5.008;
7887
7888 use strict;
7889 use Spreadsheet::WriteExcel;
7890
7891
7892 my $workbook = Spreadsheet::WriteExcel->new("unicode_8859_7.xls");
7893 my $worksheet = $workbook->add_worksheet();
7894 $worksheet->set_column('A:A', 50);
7895
7896
7897 my $file = 'unicode_8859_7.txt';
7898
7899 open FH, '<:encoding(iso-8859-7)', $file or die "Couldn't open $file: $!\n";
7900
7901 my $row = 0;
7902
7903 while (<FH>) {
7904 next if /^#/; # Ignore the comments in the sample file.
7905 chomp;
7906 $worksheet->write($row++, 0, $_);
7907 }
7908
7909
7910 __END__
7911
7912 Download this example:
7913 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_8859_7.pl
7914 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7915 WriteExcel-2.36/examples/unicode_8859_7.pl>
7916
7917 Example: unicode_big5.pl
7918 A simple example of converting some Unicode text to an Excel file using
7919 Spreadsheet::WriteExcel and perl 5.8.
7920
7921 This example generates some Chinese from a file with BIG5 encoded text.
7922
7923 Source code for this example:
7924
7925 #!/usr/bin/perl -w
7926
7927 ##############################################################################
7928 #
7929 # A simple example of converting some Unicode text to an Excel file using
7930 # Spreadsheet::WriteExcel and perl 5.8.
7931 #
7932 # This example generates some Chinese from a file with BIG5 encoded text.
7933 #
7934 #
7935 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7936 #
7937
7938
7939
7940 # Perl 5.8 or later is required for proper utf8 handling. For older perl
7941 # versions you should use UTF16 and the write_utf16be_string() method.
7942 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
7943 #
7944 require 5.008;
7945
7946 use strict;
7947 use Spreadsheet::WriteExcel;
7948
7949
7950 my $workbook = Spreadsheet::WriteExcel->new("unicode_big5.xls");
7951 my $worksheet = $workbook->add_worksheet();
7952 $worksheet->set_column('A:A', 80);
7953
7954
7955 my $file = 'unicode_big5.txt';
7956
7957 open FH, '<:encoding(big5)', $file or die "Couldn't open $file: $!\n";
7958
7959 my $row = 0;
7960
7961 while (<FH>) {
7962 next if /^#/; # Ignore the comments in the sample file.
7963 chomp;
7964 $worksheet->write($row++, 0, $_);
7965 }
7966
7967
7968 __END__
7969
7970 Download this example:
7971 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_big5.pl
7972 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
7973 WriteExcel-2.36/examples/unicode_big5.pl>
7974
7975 Example: unicode_cp1251.pl
7976 A simple example of converting some Unicode text to an Excel file using
7977 Spreadsheet::WriteExcel and perl 5.8.
7978
7979 This example generates some Russian from a file with CP1251 encoded
7980 text.
7981
7982 Source code for this example:
7983
7984 #!/usr/bin/perl -w
7985
7986 ##############################################################################
7987 #
7988 # A simple example of converting some Unicode text to an Excel file using
7989 # Spreadsheet::WriteExcel and perl 5.8.
7990 #
7991 # This example generates some Russian from a file with CP1251 encoded text.
7992 #
7993 #
7994 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
7995 #
7996
7997
7998
7999 # Perl 5.8 or later is required for proper utf8 handling. For older perl
8000 # versions you should use UTF16 and the write_utf16be_string() method.
8001 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
8002 #
8003 require 5.008;
8004
8005 use strict;
8006 use Spreadsheet::WriteExcel;
8007
8008
8009 my $workbook = Spreadsheet::WriteExcel->new("unicode_cp1251.xls");
8010 my $worksheet = $workbook->add_worksheet();
8011 $worksheet->set_column('A:A', 50);
8012
8013
8014 my $file = 'unicode_cp1251.txt';
8015
8016 open FH, '<:encoding(cp1251)', $file or die "Couldn't open $file: $!\n";
8017
8018 my $row = 0;
8019
8020 while (<FH>) {
8021 next if /^#/; # Ignore the comments in the sample file.
8022 chomp;
8023 $worksheet->write($row++, 0, $_);
8024 }
8025
8026
8027 __END__
8028
8029 Download this example:
8030 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_cp1251.pl
8031 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
8032 WriteExcel-2.36/examples/unicode_cp1251.pl>
8033
8034 Example: unicode_cp1256.pl
8035 A simple example of converting some Unicode text to an Excel file using
8036 Spreadsheet::WriteExcel and perl 5.8.
8037
8038 This example generates some Arabic text from a CP-1256 encoded file.
8039
8040 Source code for this example:
8041
8042 #!/usr/bin/perl -w
8043
8044 ##############################################################################
8045 #
8046 # A simple example of converting some Unicode text to an Excel file using
8047 # Spreadsheet::WriteExcel and perl 5.8.
8048 #
8049 # This example generates some Arabic text from a CP-1256 encoded file.
8050 #
8051 #
8052 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
8053 #
8054
8055
8056
8057 # Perl 5.8 or later is required for proper utf8 handling. For older perl
8058 # versions you should use UTF16 and the write_utf16be_string() method.
8059 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
8060 #
8061 require 5.008;
8062
8063 use strict;
8064 use Spreadsheet::WriteExcel;
8065
8066
8067 my $workbook = Spreadsheet::WriteExcel->new("unicode_cp1256.xls");
8068 my $worksheet = $workbook->add_worksheet();
8069 $worksheet->set_column('A:A', 50);
8070
8071
8072 my $file = 'unicode_cp1256.txt';
8073
8074 open FH, '<:encoding(cp1256)', $file or die "Couldn't open $file: $!\n";
8075
8076 my $row = 0;
8077
8078 while (<FH>) {
8079 next if /^#/; # Ignore the comments in the sample file.
8080 chomp;
8081 $worksheet->write($row++, 0, $_);
8082 }
8083
8084
8085 __END__
8086
8087 Download this example:
8088 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_cp1256.pl
8089 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
8090 WriteExcel-2.36/examples/unicode_cp1256.pl>
8091
8092 Example: unicode_koi8r.pl
8093 A simple example of converting some Unicode text to an Excel file using
8094 Spreadsheet::WriteExcel and perl 5.8.
8095
8096 This example generates some Russian from a file with KOI8-R encoded
8097 text.
8098
8099 Source code for this example:
8100
8101 #!/usr/bin/perl -w
8102
8103 ##############################################################################
8104 #
8105 # A simple example of converting some Unicode text to an Excel file using
8106 # Spreadsheet::WriteExcel and perl 5.8.
8107 #
8108 # This example generates some Russian from a file with KOI8-R encoded text.
8109 #
8110 #
8111 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
8112 #
8113
8114
8115
8116 # Perl 5.8 or later is required for proper utf8 handling. For older perl
8117 # versions you should use UTF16 and the write_utf16be_string() method.
8118 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
8119 #
8120 require 5.008;
8121
8122 use strict;
8123 use Spreadsheet::WriteExcel;
8124
8125
8126 my $workbook = Spreadsheet::WriteExcel->new("unicode_koi8r.xls");
8127 my $worksheet = $workbook->add_worksheet();
8128 $worksheet->set_column('A:A', 50);
8129
8130
8131 my $file = 'unicode_koi8r.txt';
8132
8133 open FH, '<:encoding(koi8-r)', $file or die "Couldn't open $file: $!\n";
8134
8135 my $row = 0;
8136
8137 while (<FH>) {
8138 next if /^#/; # Ignore the comments in the sample file.
8139 chomp;
8140 $worksheet->write($row++, 0, $_);
8141 }
8142
8143
8144 __END__
8145
8146 Download this example:
8147 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_koi8r.pl
8148 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
8149 WriteExcel-2.36/examples/unicode_koi8r.pl>
8150
8151 Example: unicode_polish_utf8.pl
8152 A simple example of converting some Unicode text to an Excel file using
8153 Spreadsheet::WriteExcel and perl 5.8.
8154
8155 This example generates some Polish from a file with UTF8 encoded text.
8156
8157 Source code for this example:
8158
8159 #!/usr/bin/perl -w
8160
8161 ##############################################################################
8162 #
8163 # A simple example of converting some Unicode text to an Excel file using
8164 # Spreadsheet::WriteExcel and perl 5.8.
8165 #
8166 # This example generates some Polish from a file with UTF8 encoded text.
8167 #
8168 #
8169 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
8170 #
8171
8172
8173
8174 # Perl 5.8 or later is required for proper utf8 handling. For older perl
8175 # versions you should use UTF16 and the write_utf16be_string() method.
8176 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
8177 #
8178 require 5.008;
8179
8180 use strict;
8181 use Spreadsheet::WriteExcel;
8182
8183
8184 my $workbook = Spreadsheet::WriteExcel->new("unicode_polish_utf8.xls");
8185 my $worksheet = $workbook->add_worksheet();
8186 $worksheet->set_column('A:A', 50);
8187
8188
8189 my $file = 'unicode_polish_utf8.txt';
8190
8191 open FH, '<:encoding(utf8)', $file or die "Couldn't open $file: $!\n";
8192
8193 my $row = 0;
8194
8195 while (<FH>) {
8196 next if /^#/; # Ignore the comments in the sample file.
8197 chomp;
8198 $worksheet->write($row++, 0, $_);
8199 }
8200
8201
8202 __END__
8203
8204 Download this example:
8205 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_polish_utf8.pl
8206 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
8207 WriteExcel-2.36/examples/unicode_polish_utf8.pl>
8208
8209 Example: unicode_shift_jis.pl
8210 A simple example of converting some Unicode text to an Excel file using
8211 Spreadsheet::WriteExcel and perl 5.8.
8212
8213 This example generates some Japenese text from a file with Shift-JIS
8214 encoded text.
8215
8216 Source code for this example:
8217
8218 #!/usr/bin/perl -w
8219
8220 ##############################################################################
8221 #
8222 # A simple example of converting some Unicode text to an Excel file using
8223 # Spreadsheet::WriteExcel and perl 5.8.
8224 #
8225 # This example generates some Japenese text from a file with Shift-JIS
8226 # encoded text.
8227 #
8228 # reverse('X'), September 2004, John McNamara, jmcnamara@cpan.org
8229 #
8230
8231
8232
8233 # Perl 5.8 or later is required for proper utf8 handling. For older perl
8234 # versions you should use UTF16 and the write_utf16be_string() method.
8235 # See the write_utf16be_string section of the Spreadsheet::WriteExcel docs.
8236 #
8237 require 5.008;
8238
8239 use strict;
8240 use Spreadsheet::WriteExcel;
8241
8242
8243 my $workbook = Spreadsheet::WriteExcel->new("unicode_shift_jis.xls");
8244 my $worksheet = $workbook->add_worksheet();
8245 $worksheet->set_column('A:A', 50);
8246
8247
8248 my $file = 'unicode_shift_jis.txt';
8249
8250 open FH, '<:encoding(shiftjis)', $file or die "Couldn't open $file: $!\n";
8251
8252 my $row = 0;
8253
8254 while (<FH>) {
8255 next if /^#/; # Ignore the comments in the sample file.
8256 chomp;
8257 $worksheet->write($row++, 0, $_);
8258 }
8259
8260
8261 __END__
8262
8263 Download this example:
8264 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/unicode_shift_jis.pl
8265 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
8266 WriteExcel-2.36/examples/unicode_shift_jis.pl>
8267
8268 Example: csv2xls.pl
8269 Example of how to use the WriteExcel module
8270
8271 Simple program to convert a CSV comma-separated value file to an Excel
8272 file. This is more or less an non-op since Excel can read CSV files.
8273 The program uses Text::CSV_XS to parse the CSV.
8274
8275 Usage: csv2xls.pl file.csv newfile.xls
8276
8277 NOTE: This is only a simple conversion utility for illustrative
8278 purposes. For converting a CSV or Tab separated or any other type of
8279 delimited text file to Excel I recommend the more rigorous csv2xls
8280 program that is part of H.Merijn Brand's Text::CSV_XS module distro.
8281
8282 See the examples/csv2xls link here:
8283 http://search.cpan.org/~hmbrand/Text-CSV_XS/MANIFEST
8284 <http://search.cpan.org/~hmbrand/Text-CSV_XS/MANIFEST>
8285
8286 #!/usr/bin/perl -w
8287
8288 ###############################################################################
8289 #
8290 # Example of how to use the WriteExcel module
8291 #
8292 # Simple program to convert a CSV comma-separated value file to an Excel file.
8293 # This is more or less an non-op since Excel can read CSV files.
8294 # The program uses Text::CSV_XS to parse the CSV.
8295 #
8296 # Usage: csv2xls.pl file.csv newfile.xls
8297 #
8298 #
8299 # NOTE: This is only a simple conversion utility for illustrative purposes.
8300 # For converting a CSV or Tab separated or any other type of delimited
8301 # text file to Excel I recommend the more rigorous csv2xls program that is
8302 # part of H.Merijn Brand's Text::CSV_XS module distro.
8303 #
8304 # See the examples/csv2xls link here:
8305 # L<http://search.cpan.org/~hmbrand/Text-CSV_XS/MANIFEST>
8306 #
8307 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
8308 #
8309
8310 use strict;
8311 use Spreadsheet::WriteExcel;
8312 use Text::CSV_XS;
8313
8314 # Check for valid number of arguments
8315 if (($#ARGV < 1) || ($#ARGV > 2)) {
8316 die("Usage: csv2xls csvfile.txt newfile.xls\n");
8317 };
8318
8319 # Open the Comma Separated Variable file
8320 open (CSVFILE, $ARGV[0]) or die "$ARGV[0]: $!";
8321
8322 # Create a new Excel workbook
8323 my $workbook = Spreadsheet::WriteExcel->new($ARGV[1]);
8324 my $worksheet = $workbook->add_worksheet();
8325
8326 # Create a new CSV parsing object
8327 my $csv = Text::CSV_XS->new;
8328
8329 # Row and column are zero indexed
8330 my $row = 0;
8331
8332
8333 while (<CSVFILE>) {
8334 if ($csv->parse($_)) {
8335 my @Fld = $csv->fields;
8336
8337 my $col = 0;
8338 foreach my $token (@Fld) {
8339 $worksheet->write($row, $col, $token);
8340 $col++;
8341 }
8342 $row++;
8343 }
8344 else {
8345 my $err = $csv->error_input;
8346 print "Text::CSV_XS parse() failed on argument: ", $err, "\n";
8347 }
8348 }
8349
8350 Download this example:
8351 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/csv2xls.pl
8352 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
8353 WriteExcel-2.36/examples/csv2xls.pl>
8354
8355 Example: tab2xls.pl
8356 Example of how to use the WriteExcel module
8357
8358 The following converts a tab separated file into an Excel file
8359
8360 Usage: tab2xls.pl tabfile.txt newfile.xls
8361
8362 NOTE: This is only a simple conversion utility for illustrative
8363 purposes. For converting a CSV or Tab separated or any other type of
8364 delimited text file to Excel I recommend the more rigorous csv2xls
8365 program that is part of H.Merijn Brand's Text::CSV_XS module distro.
8366
8367 See the examples/csv2xls link here:
8368 http://search.cpan.org/~hmbrand/Text-CSV_XS/MANIFEST
8369 <http://search.cpan.org/~hmbrand/Text-CSV_XS/MANIFEST>
8370
8371 #!/usr/bin/perl -w
8372
8373 ###############################################################################
8374 #
8375 # Example of how to use the WriteExcel module
8376 #
8377 # The following converts a tab separated file into an Excel file
8378 #
8379 # Usage: tab2xls.pl tabfile.txt newfile.xls
8380 #
8381 #
8382 # NOTE: This is only a simple conversion utility for illustrative purposes.
8383 # For converting a CSV or Tab separated or any other type of delimited
8384 # text file to Excel I recommend the more rigorous csv2xls program that is
8385 # part of H.Merijn Brand's Text::CSV_XS module distro.
8386 #
8387 # See the examples/csv2xls link here:
8388 # L<http://search.cpan.org/~hmbrand/Text-CSV_XS/MANIFEST>
8389 #
8390 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
8391 #
8392
8393
8394 use strict;
8395 use Spreadsheet::WriteExcel;
8396
8397
8398 # Check for valid number of arguments
8399 if (($#ARGV < 1) || ($#ARGV > 2)) {
8400 die("Usage: tab2xls tabfile.txt newfile.xls\n");
8401 };
8402
8403
8404 # Open the tab delimited file
8405 open (TABFILE, $ARGV[0]) or die "$ARGV[0]: $!";
8406
8407
8408 # Create a new Excel workbook
8409 my $workbook = Spreadsheet::WriteExcel->new($ARGV[1]);
8410 my $worksheet = $workbook->add_worksheet();
8411
8412 # Row and column are zero indexed
8413 my $row = 0;
8414
8415 while (<TABFILE>) {
8416 chomp;
8417 # Split on single tab
8418 my @Fld = split('\t', $_);
8419
8420 my $col = 0;
8421 foreach my $token (@Fld) {
8422 $worksheet->write($row, $col, $token);
8423 $col++;
8424 }
8425 $row++;
8426 }
8427
8428 Download this example:
8429 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/tab2xls.pl
8430 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
8431 WriteExcel-2.36/examples/tab2xls.pl>
8432
8433 Example: datecalc1.pl
8434 NOTE: An easier way of writing dates and times is to use the newer
8435 write_date_time() Worksheet method. See the date_time.pl example.
8436
8437 Demonstration of writing date/time cells to Excel spreadsheets, using
8438 UNIX/Perl time as source of date/time.
8439
8440 UNIX/Perl time is the time since the Epoch (00:00:00 GMT, 1 Jan 1970)
8441 measured in seconds.
8442
8443 An Excel file can use exactly one of two different date/time systems.
8444 In these systems, a floating point number represents the number of days
8445 (and fractional parts of the day) since a start point. The floating
8446 point number is referred to as a 'serial'.
8447
8448 The two systems ('1900' and '1904') use different starting points:
8449
8450 '1900'; '1.00' is 1 Jan 1900 BUT 1900 is erroneously regarded as
8451 a leap year - see:
8452 http://support.microsoft.com/support/kb/articles/Q181/3/70.asp
8453 for the excuse^H^H^H^H^H^Hreason.
8454 '1904'; '1.00' is 2 Jan 1904.
8455
8456 The '1904' system is the default for Apple Macs. Windows versions of
8457 Excel have the option to use the '1904' system.
8458
8459 Note that Visual Basic's "DateSerial" function does NOT erroneously
8460 regard 1900 as a leap year, and thus its serials do not agree with the
8461 1900 serials of Excel for dates before 1 Mar 1900.
8462
8463 Note that StarOffice (at least at version 5.2) does NOT erroneously
8464 regard 1900 as a leap year, and thus its serials do not agree with the
8465 1900 serials of Excel for dates before 1 Mar 1900.
8466
8467 #!/usr/bin/perl -w
8468
8469
8470 ######################################################################
8471 #
8472 # NOTE: An easier way of writing dates and times is to use the newer
8473 # write_date_time() Worksheet method. See the date_time.pl example.
8474 #
8475 ######################################################################
8476 #
8477 # Demonstration of writing date/time cells to Excel spreadsheets,
8478 # using UNIX/Perl time as source of date/time.
8479 #
8480 ######################################################################
8481 #
8482 # UNIX/Perl time is the time since the Epoch (00:00:00 GMT, 1 Jan 1970)
8483 # measured in seconds.
8484 #
8485 # An Excel file can use exactly one of two different date/time systems.
8486 # In these systems, a floating point number represents the number of days
8487 # (and fractional parts of the day) since a start point. The floating point
8488 # number is referred to as a 'serial'.
8489 #
8490 # The two systems ('1900' and '1904') use different starting points:
8491 #
8492 # '1900'; '1.00' is 1 Jan 1900 BUT 1900 is erroneously regarded as
8493 # a leap year - see:
8494 # http://support.microsoft.com/support/kb/articles/Q181/3/70.asp
8495 # for the excuse^H^H^H^H^H^Hreason.
8496 # '1904'; '1.00' is 2 Jan 1904.
8497 #
8498 # The '1904' system is the default for Apple Macs. Windows versions of
8499 # Excel have the option to use the '1904' system.
8500 #
8501 # Note that Visual Basic's "DateSerial" function does NOT erroneously
8502 # regard 1900 as a leap year, and thus its serials do not agree with
8503 # the 1900 serials of Excel for dates before 1 Mar 1900.
8504 #
8505 # Note that StarOffice (at least at version 5.2) does NOT erroneously
8506 # regard 1900 as a leap year, and thus its serials do not agree with
8507 # the 1900 serials of Excel for dates before 1 Mar 1900.
8508 #
8509
8510 # Copyright 2000, Andrew Benham, adsb@bigfoot.com
8511 #
8512
8513 ######################################################################
8514 #
8515 # Calculation description
8516 # =======================
8517 #
8518 # 1900 system
8519 # -----------
8520 # Unix time is '0' at 00:00:00 GMT 1 Jan 1970, i.e. 70 years after 1 Jan 1900.
8521 # Of those 70 years, 17 (1904,08,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68)
8522 # were leap years with an extra day.
8523 # Thus there were 17 + 70*365 days = 25567 days between 1 Jan 1900 and
8524 # 1 Jan 1970.
8525 # In the 1900 system, '1' is 1 Jan 1900, but as 1900 was not a leap year
8526 # 1 Jan 1900 should really be '2', so 1 Jan 1970 is '25569'.
8527 #
8528 # 1904 system
8529 # -----------
8530 # Unix time is '0' at 00:00:00 GMT 1 Jan 1970, i.e. 66 years after 1 Jan 1904.
8531 # Of those 66 years, 17 (1904,08,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68)
8532 # were leap years with an extra day.
8533 # Thus there were 17 + 66*365 days = 24107 days between 1 Jan 1904 and
8534 # 1 Jan 1970.
8535 # In the 1904 system, 2 Jan 1904 being '1', 1 Jan 1970 is '24107'.
8536 #
8537 ######################################################################
8538 #
8539 # Copyright (c) 2000, Andrew Benham.
8540 # This program is free software. It may be used, redistributed and/or
8541 # modified under the same terms as Perl itself.
8542 #
8543 # Andrew Benham, adsb@bigfoot.com
8544 # London, United Kingdom
8545 # 11 Nov 2000
8546 #
8547 ######################################################################
8548
8549
8550 use strict;
8551 use Spreadsheet::WriteExcel;
8552
8553 use Time::Local;
8554
8555 use vars qw/$DATE_SYSTEM/;
8556
8557 # Use 1900 date system on all platforms other than Apple Mac (for which
8558 # use 1904 date system).
8559 $DATE_SYSTEM = ($^O eq 'MacOS') ? 1 : 0;
8560
8561 my $workbook = Spreadsheet::WriteExcel->new("dates.xls");
8562 my $worksheet = $workbook->add_worksheet();
8563
8564 my $format_date = $workbook->add_format();
8565 $format_date->set_num_format('d mmmm yyy');
8566
8567 $worksheet->set_column(0,1,21);
8568
8569 $worksheet->write_string (0,0,"The epoch (GMT)");
8570 $worksheet->write_number (0,1,&calc_serial(0,1),0x16);
8571
8572 $worksheet->write_string (1,0,"The epoch (localtime)");
8573 $worksheet->write_number (1,1,&calc_serial(0,0),0x16);
8574
8575 $worksheet->write_string (2,0,"Today");
8576 $worksheet->write_number (2,1,&calc_serial(),$format_date);
8577
8578 my $christmas2000 = timelocal(0,0,0,25,11,100);
8579 $worksheet->write_string (3,0,"Christmas 2000");
8580 $worksheet->write_number (3,1,&calc_serial($christmas2000),$format_date);
8581
8582 $workbook->close();
8583
8584 #-----------------------------------------------------------
8585 # calc_serial()
8586 #
8587 # Called with (up to) 2 parameters.
8588 # 1. Unix timestamp. If omitted, uses current time.
8589 # 2. GMT flag. Set to '1' to return serial in GMT.
8590 # If omitted, returns serial in appropriate timezone.
8591 #
8592 # Returns date/time serial according to $DATE_SYSTEM selected
8593 #-----------------------------------------------------------
8594 sub calc_serial {
8595 my $time = (defined $_[0]) ? $_[0] : time();
8596 my $gmtflag = (defined $_[1]) ? $_[1] : 0;
8597
8598 # Divide timestamp by number of seconds in a day.
8599 # This gives a date serial with '0' on 1 Jan 1970.
8600 my $serial = $time / 86400;
8601
8602 # Adjust the date serial by the offset appropriate to the
8603 # currently selected system (1900/1904).
8604 if ($DATE_SYSTEM == 0) { # use 1900 system
8605 $serial += 25569;
8606 } else { # use 1904 system
8607 $serial += 24107;
8608 }
8609
8610 unless ($gmtflag) {
8611 # Now have a 'raw' serial with the right offset. But this
8612 # gives a serial in GMT, which is false unless the timezone
8613 # is GMT. We need to adjust the serial by the appropriate
8614 # timezone offset.
8615 # Calculate the appropriate timezone offset by seeing what
8616 # the differences between localtime and gmtime for the given
8617 # time are.
8618
8619 my @gmtime = gmtime($time);
8620 my @ltime = localtime($time);
8621
8622 # For the first 7 elements of the two arrays, adjust the
8623 # date serial where the elements differ.
8624 for (0 .. 6) {
8625 my $diff = $ltime[$_] - $gmtime[$_];
8626 if ($diff) {
8627 $serial += _adjustment($diff,$_);
8628 }
8629 }
8630 }
8631
8632 # Perpetuate the error that 1900 was a leap year by decrementing
8633 # the serial if we're using the 1900 system and the date is prior to
8634 # 1 Mar 1900. This has the effect of making serial value '60'
8635 # 29 Feb 1900.
8636
8637 # This fix only has any effect if UNIX/Perl time on the platform
8638 # can represent 1900. Many can't.
8639
8640 unless ($DATE_SYSTEM) {
8641 $serial-- if ($serial < 61); # '61' is 1 Mar 1900
8642 }
8643 return $serial;
8644 }
8645
8646 sub _adjustment {
8647 # Based on the difference in the localtime/gmtime array elements
8648 # number, return the adjustment required to the serial.
8649
8650 # We only look at some elements of the localtime/gmtime arrays:
8651 # seconds unlikely to be different as all known timezones
8652 # have an offset of integral multiples of 15 minutes,
8653 # but it's easy to do.
8654 # minutes will be different for timezone offsets which are
8655 # not an exact number of hours.
8656 # hours very likely to be different.
8657 # weekday will differ when localtime/gmtime difference
8658 # straddles midnight.
8659 #
8660 # Assume that difference between localtime and gmtime is less than
8661 # 5 days, then don't have to do maths for day of month, month number,
8662 # year number, etc...
8663
8664 my ($delta,$element) = @_;
8665 my $adjust = 0;
8666
8667 if ($element == 0) { # Seconds
8668 $adjust = $delta/86400; # 60 * 60 * 24
8669 } elsif ($element == 1) { # Minutes
8670 $adjust = $delta/1440; # 60 * 24
8671 } elsif ($element == 2) { # Hours
8672 $adjust = $delta/24; # 24
8673 } elsif ($element == 6) { # Day of week number
8674 # Catch difference straddling Sat/Sun in either direction
8675 $delta += 7 if ($delta < -4);
8676 $delta -= 7 if ($delta > 4);
8677
8678 $adjust = $delta;
8679 }
8680 return $adjust;
8681 }
8682
8683 Download this example:
8684 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/datecalc1.pl
8685 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
8686 WriteExcel-2.36/examples/datecalc1.pl>
8687
8688 Example: datecalc2.pl
8689 Example of how to using the Date::Calc module to calculate Excel dates.
8690
8691 NOTE: An easier way of writing dates and times is to use the newer
8692 write_date_time() Worksheet method. See the date_time.pl example.
8693
8694 #!/usr/bin/perl -w
8695
8696 ###############################################################################
8697 #
8698 # Example of how to using the Date::Calc module to calculate Excel dates.
8699 #
8700 # NOTE: An easier way of writing dates and times is to use the newer
8701 # write_date_time() Worksheet method. See the date_time.pl example.
8702 #
8703 # reverse('X'), June 2001, John McNamara, jmcnamara@cpan.org
8704 #
8705
8706 use strict;
8707 use Spreadsheet::WriteExcel;
8708 use Date::Calc qw(Delta_DHMS); # You may need to install this module.
8709
8710
8711 # Create a new workbook and add a worksheet
8712 my $workbook = Spreadsheet::WriteExcel->new("excel_date2.xls");
8713 my $worksheet = $workbook->add_worksheet();
8714
8715 # Expand the first column so that the date is visible.
8716 $worksheet->set_column("A:A", 25);
8717
8718
8719 # Add a format for the date
8720 my $format = $workbook->add_format();
8721 $format->set_num_format('d mmmm yyy HH:MM:SS');
8722
8723
8724 my $date;
8725
8726 # Write some dates and times
8727 $date = excel_date(1900, 1, 1);
8728 $worksheet->write("A1", $date, $format);
8729
8730 $date = excel_date(2000, 1, 1);
8731 $worksheet->write("A2", $date, $format);
8732
8733 $date = excel_date(2000, 4, 17, 14, 33, 15);
8734 $worksheet->write("A3", $date, $format);
8735
8736
8737 ###############################################################################
8738 #
8739 # excel_date($years, $months, $days, $hours, $minutes, $seconds)
8740 #
8741 # Create an Excel date in the 1900 format. All of the arguments are optional
8742 # but you should at least add $years.
8743 #
8744 # Corrects for Excel's missing leap day in 1900. See excel_time1.pl for an
8745 # explanation.
8746 #
8747 sub excel_date {
8748
8749 my $years = $_[0] || 1900;
8750 my $months = $_[1] || 1;
8751 my $days = $_[2] || 1;
8752 my $hours = $_[3] || 0;
8753 my $minutes = $_[4] || 0;
8754 my $seconds = $_[5] || 0;
8755
8756 my @date = ($years, $months, $days, $hours, $minutes, $seconds);
8757 my @epoch = (1899, 12, 31, 0, 0, 0);
8758
8759 ($days, $hours, $minutes, $seconds) = Delta_DHMS(@epoch, @date);
8760
8761 my $date = $days + ($hours*3600 +$minutes*60 +$seconds)/(24*60*60);
8762
8763 # Add a day for Excel's missing leap day in 1900
8764 $date++ if ($date > 59);
8765
8766 return $date;
8767 }
8768
8769 ###############################################################################
8770 #
8771 # excel_date($years, $months, $days, $hours, $minutes, $seconds)
8772 #
8773 # Create an Excel date in the 1904 format. All of the arguments are optional
8774 # but you should at least add $years.
8775 #
8776 # You will also need to call $workbook->set_1904() for this format to be valid.
8777 #
8778 sub excel_date_1904 {
8779
8780 my $years = $_[0] || 1900;
8781 my $months = $_[1] || 1;
8782 my $days = $_[2] || 1;
8783 my $hours = $_[3] || 0;
8784 my $minutes = $_[4] || 0;
8785 my $seconds = $_[5] || 0;
8786
8787 my @date = ($years, $months, $days, $hours, $minutes, $seconds);
8788 my @epoch = (1904, 1, 1, 0, 0, 0);
8789
8790 ($days, $hours, $minutes, $seconds) = Delta_DHMS(@epoch, @date);
8791
8792 my $date = $days + ($hours*3600 +$minutes*60 +$seconds)/(24*60*60);
8793
8794 return $date;
8795 }
8796
8797 Download this example:
8798 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/datecalc2.pl
8799 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
8800 WriteExcel-2.36/examples/datecalc2.pl>
8801
8802 Example: lecxe.pl
8803 Utility program to convert an Excel file into a Spreadsheet::WriteExcel
8804 program using Win32::OLE
8805
8806 #!/usr/bin/perl -w
8807
8808 #
8809 # Utility program to convert an Excel file into a Spreadsheet::WriteExcel
8810 # program using Win32::OLE
8811 #
8812
8813 #
8814 # lecxe program
8815 # by t0mas@netlords.net
8816 #
8817 # Version 0.01a Initial release (alpha)
8818
8819
8820 # Modules
8821 use strict;
8822 use Win32::OLE;
8823 use Win32::OLE::Const;
8824 use Getopt::Std;
8825
8826
8827 # Vars
8828 use vars qw(%opts);
8829
8830
8831 # Get options
8832 getopts('i:o:v',\%opts);
8833
8834
8835 # Not enough options
8836 exit &usage unless ($opts{i} && $opts{o});
8837
8838
8839 # Create Excel object
8840 my $Excel = new Win32::OLE("Excel.Application","Quit") or
8841 die "Can't start excel: $!";
8842
8843
8844 # Get constants
8845 my $ExcelConst=Win32::OLE::Const->Load("Microsoft Excel");
8846
8847
8848 # Show Excel
8849 $Excel->{Visible} = 1 if ($opts{v});
8850
8851
8852 # Open infile
8853 my $Workbook = $Excel->Workbooks->Open({Filename=>$opts{i}});
8854
8855
8856 # Open outfile
8857 open (OUTFILE,">$opts{o}") or die "Can't open outfile $opts{o}: $!";
8858
8859
8860 # Print header for outfile
8861 print OUTFILE <<'EOH';
8862 #!/usr/bin/perl -w
8863
8864
8865 use strict;
8866 use Spreadsheet::WriteExcel;
8867
8868
8869 use vars qw($workbook %worksheets %formats);
8870
8871
8872 $workbook = Spreadsheet::WriteExcel->new("_change_me_.xls");
8873
8874
8875 EOH
8876
8877
8878 # Loop all sheets
8879 foreach my $sheetnum (1..$Excel->Workbooks(1)->Worksheets->Count) {
8880
8881
8882 # Format sheet
8883 my $name=$Excel->Workbooks(1)->Worksheets($sheetnum)->Name;
8884 print "Sheet $name\n" if ($opts{v});
8885 print OUTFILE "# Sheet $name\n";
8886 print OUTFILE "\$worksheets{'$name'} = \$workbook->add_worksheet('$name');\n";
8887
8888
8889 # Get usedrange of cells in worksheet
8890 my $usedrange=$Excel->Workbooks(1)->Worksheets($sheetnum)->UsedRange;
8891
8892
8893 # Loop all columns in used range
8894 foreach my $j (1..$usedrange->Columns->Count){
8895
8896
8897 # Format column
8898 print "Col $j\n" if ($opts{v});
8899 my ($colwidth);
8900 $colwidth=$usedrange->Columns($j)->ColumnWidth;
8901 print OUTFILE "# Column $j\n";
8902 print OUTFILE "\$worksheets{'$name'}->set_column(".($j-1).",".($j-1).
8903 ", $colwidth);\n";
8904
8905
8906 # Loop all rows in used range
8907 foreach my $i (1..$usedrange->Rows->Count){
8908
8909
8910 # Format row
8911 print "Row $i\n" if ($opts{v});
8912 print OUTFILE "# Row $i\n";
8913 do {
8914 my ($rowheight);
8915 $rowheight=$usedrange->Rows($i)->RowHeight;
8916 print OUTFILE "\$worksheets{'$name'}->set_row(".($i-1).
8917 ", $rowheight);\n";
8918 } if ($j==1);
8919
8920
8921 # Start creating cell format
8922 my $fname="\$formats{'".$name.'R'.$i.'C'.$j."'}";
8923 my $format="$fname=\$workbook->add_format();\n";
8924 my $print_format=0;
8925
8926 # Check for borders
8927 my @bfnames=qw(left right top bottom);
8928 foreach my $k (1..$usedrange->Cells($i,$j)->Borders->Count) {
8929 my $lstyle=$usedrange->Cells($i,$j)->Borders($k)->LineStyle;
8930 if ($lstyle > 0) {
8931 $format.=$fname."->set_".$bfnames[$k-1]."($lstyle);\n";
8932 $print_format=1;
8933 }
8934 }
8935
8936
8937 # Check for font
8938 my ($fontattr,$prop,$func,%fontsets,$fontColor);
8939 %fontsets=(Name=>'set_font',
8940 Size=>'set_size');
8941 while (($prop,$func) = each %fontsets) {
8942 $fontattr=$usedrange->Cells($i,$j)->Font->$prop;
8943 if ($fontattr ne "") {
8944 $format.=$fname."->$func('$fontattr');\n";
8945 $print_format=1;
8946 }
8947
8948
8949 }
8950 %fontsets=(Bold=>'set_bold(1)',
8951 Italic=>'set_italic(1)',
8952 Underline=>'set_underline(1)',
8953 Strikethrough=>'set_strikeout(1)',
8954 Superscript=>'set_script(1)',
8955 Subscript=>'set_script(2)',
8956 OutlineFont=>'set_outline(1)',
8957 Shadow=>'set_shadow(1)');
8958 while (($prop,$func) = each %fontsets) {
8959 $fontattr=$usedrange->Cells($i,$j)->Font->$prop;
8960 if ($fontattr==1) {
8961 $format.=$fname."->$func;\n" ;
8962
8963 $print_format=1;
8964 }
8965 }
8966 $fontColor=$usedrange->Cells($i,$j)->Font->ColorIndex();
8967 if ($fontColor>0&&$fontColor!=$ExcelConst->{xlColorIndexAutomatic}) {
8968 $format.=$fname."->set_color(".($fontColor+7).");\n" ;
8969 $print_format=1;
8970 }
8971
8972
8973
8974 # Check text alignment, merging and wrapping
8975 my ($halign,$valign,$merge,$wrap);
8976 $halign=$usedrange->Cells($i,$j)->HorizontalAlignment;
8977 my %hAligns=($ExcelConst->{xlHAlignCenter}=>"'center'",
8978 $ExcelConst->{xlHAlignJustify}=>"'justify'",
8979 $ExcelConst->{xlHAlignLeft}=>"'left'",
8980 $ExcelConst->{xlHAlignRight}=>"'right'",
8981 $ExcelConst->{xlHAlignFill}=>"'fill'",
8982 $ExcelConst->{xlHAlignCenterAcrossSelection}=>"'merge'");
8983 if ($halign!=$ExcelConst->{xlHAlignGeneral}) {
8984 $format.=$fname."->set_align($hAligns{$halign});\n";
8985 $print_format=1;
8986 }
8987 $valign=$usedrange->Cells($i,$j)->VerticalAlignment;
8988 my %vAligns=($ExcelConst->{xlVAlignBottom}=>"'bottom'",
8989 $ExcelConst->{xlVAlignCenter}=>"'vcenter'",
8990 $ExcelConst->{xlVAlignJustify}=>"'vjustify'",
8991 $ExcelConst->{xlVAlignTop}=>"'top'");
8992 if ($valign) {
8993 $format.=$fname."->set_align($vAligns{$valign});\n";
8994 $print_format=1;
8995 }
8996 $merge=$usedrange->Cells($i,$j)->MergeCells;
8997 if ($merge==1) {
8998 $format.=$fname."->set_merge();\n";
8999
9000 $print_format=1;
9001 }
9002 $wrap=$usedrange->Cells($i,$j)->WrapText;
9003 if ($wrap==1) {
9004 $format.=$fname."->set_text_wrap(1);\n";
9005
9006 $print_format=1;
9007 }
9008
9009
9010 # Check patterns
9011 my ($pattern,%pats);
9012 %pats=(-4142=>0,-4125=>2,-4126=>3,-4124=>4,-4128=>5,-4166=>6,
9013 -4121=>7,-4162=>8);
9014 $pattern=$usedrange->Cells($i,$j)->Interior->Pattern;
9015 if ($pattern&&$pattern!=$ExcelConst->{xlPatternAutomatic}) {
9016 $pattern=$pats{$pattern} if ($pattern<0 && defined $pats{$pattern});
9017 $format.=$fname."->set_pattern($pattern);\n";
9018
9019 # Colors fg/bg
9020 my ($cIndex);
9021 $cIndex=$usedrange->Cells($i,$j)->Interior->PatternColorIndex;
9022 if ($cIndex>0&&$cIndex!=$ExcelConst->{xlColorIndexAutomatic}) {
9023 $format.=$fname."->set_bg_color(".($cIndex+7).");\n";
9024 }
9025 $cIndex=$usedrange->Cells($i,$j)->Interior->ColorIndex;
9026 if ($cIndex>0&&$cIndex!=$ExcelConst->{xlColorIndexAutomatic}) {
9027 $format.=$fname."->set_fg_color(".($cIndex+7).");\n";
9028 }
9029 $print_format=1;
9030 }
9031
9032
9033 # Check for number format
9034 my ($num_format);
9035 $num_format=$usedrange->Cells($i,$j)->NumberFormat;
9036 if ($num_format ne "") {
9037 $format.=$fname."->set_num_format('$num_format');\n";
9038 $print_format=1;
9039 }
9040
9041
9042 # Check for contents (text or formula)
9043 my ($contents);
9044 $contents=$usedrange->Cells($i,$j)->Formula;
9045 $contents=$usedrange->Cells($i,$j)->Text if ($contents eq "");
9046
9047
9048 # Print cell
9049 if ($contents ne "" or $print_format) {
9050 print OUTFILE "# Cell($i,$j)\n";
9051 print OUTFILE $format if ($print_format);
9052 print OUTFILE "\$worksheets{'$name'}->write(".($i-1).",".($j-1).
9053 ",'$contents'";
9054 print OUTFILE ",$fname" if ($print_format);
9055 print OUTFILE ");\n";
9056 }
9057 }
9058 }
9059 }
9060
9061
9062 # Famous last words...
9063 print OUTFILE "\$workbook->close();\n";
9064
9065
9066 # Close outfile
9067 close (OUTFILE) or die "Can't close outfile $opts{o}: $!";
9068
9069
9070 ####################################################################
9071 sub usage {
9072 printf STDERR "usage: $0 [options]\n".
9073 "\tOptions:\n".
9074 "\t\t-v \tverbose mode\n" .
9075 "\t\t-i <name>\tname of input file\n" .
9076 "\t\t-o <name>\tname of output file\n";
9077 }
9078
9079
9080 ####################################################################
9081 sub END {
9082 # Quit excel
9083 do {
9084 $Excel->{DisplayAlerts} = 0;
9085 $Excel->Quit;
9086 } if (defined $Excel);
9087 }
9088
9089
9090 __END__
9091
9092
9093 =head1 NAME
9094
9095
9096 lecxe - A Excel file to Spreadsheet::WriteExcel code converter
9097
9098
9099 =head1 DESCRIPTION
9100
9101
9102 This program takes an MS Excel workbook file as input and from
9103 that file, produces an output file with Perl code that uses the
9104 Spreadsheet::WriteExcel module to reproduce the original
9105 file.
9106
9107
9108 =head1 STUFF
9109
9110
9111 Additional hands-on editing of the output file might be neccecary
9112 as:
9113
9114
9115 * This program always names the file produced by output script
9116 _change_me_.xls
9117
9118
9119 * Users of international Excel versions will have som work to do
9120 on list separators and numeric punctation characters.
9121
9122
9123 =head1 SEE ALSO
9124
9125
9126 L<Win32::OLE>, L<Win32::OLE::Variant>, L<Spreadsheet::WriteExcel>
9127
9128
9129 =head1 BUGS
9130
9131
9132 * Picks wrong color on cells sometimes.
9133
9134
9135 * Probably a few other...
9136
9137
9138 =head1 DISCLAIMER
9139
9140
9141 I do not guarantee B<ANYTHING> with this program. If you use it you
9142 are doing so B<AT YOUR OWN RISK>! I may or may not support this
9143 depending on my time schedule...
9144
9145
9146 =head1 AUTHOR
9147
9148
9149 t0mas@netlords.net
9150
9151
9152 =head1 COPYRIGHT
9153
9154
9155 Copyright 2001, t0mas@netlords.net
9156
9157
9158 This package is free software; you can redistribute it and/or
9159 modify it under the same terms as Perl itself.
9160
9161 Download this example:
9162 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/lecxe.pl
9163 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
9164 WriteExcel-2.36/examples/lecxe.pl>
9165
9166 Example: convertA1.pl
9167 This program contains helper functions to deal with the Excel A1 cell
9168 reference notation.
9169
9170 These functions have been superseded by
9171 Spreadsheet::WriteExcel::Utility.
9172
9173 #!/usr/bin/perl -w
9174
9175 ###############################################################################
9176 #
9177 # This program contains helper functions to deal with the Excel A1 cell
9178 # reference notation.
9179 #
9180 # These functions have been superseded by L<Spreadsheet::WriteExcel::Utility>.
9181 #
9182 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
9183 #
9184
9185 use strict;
9186
9187 print "\n";
9188 print "Cell B7 is equivalent to (";
9189 print join " ", cell_to_rowcol('B7');
9190 print ") in row column notation.\n";
9191
9192 print "Cell \$B7 is equivalent to (";
9193 print join " ", cell_to_rowcol('$B7');
9194 print ") in row column notation.\n";
9195
9196 print "Cell B\$7 is equivalent to (";
9197 print join " ", cell_to_rowcol('B$7');
9198 print ") in row column notation.\n";
9199
9200 print "Cell \$B\$7 is equivalent to (";
9201 print join " ", cell_to_rowcol('$B$7');
9202 print ") in row column notation.\n\n";
9203
9204 print "Row and column (1999, 29) are equivalent to ";
9205 print rowcol_to_cell(1999, 29), ".\n";
9206
9207 print "Row and column (1999, 29, 0, 1) are equivalent to ";
9208 print rowcol_to_cell(1999, 29, 0, 1), ".\n\n";
9209
9210 print "The base cell is: Z7\n";
9211 print "Increment the row: ", inc_cell_row('Z7'), "\n";
9212 print "Decrement the row: ", dec_cell_row('Z7'), "\n";
9213 print "Increment the column: ", inc_cell_col('Z7'), "\n";
9214 print "Decrement the column: ", dec_cell_col('Z7'), "\n\n";
9215
9216
9217 ###############################################################################
9218 #
9219 # rowcol_to_cell($row, $col, $row_absolute, $col_absolute)
9220 #
9221 # Convert a zero based row and column reference to a A1 reference. For example
9222 # (0, 2) to C1. $row_absolute, $col_absolute are optional. They are boolean
9223 # values used to indicate if the row or column value is absolute, i.e. if it is
9224 # prefixed by a $ sign: eg. (0, 2, 0, 1) converts to $C1.
9225 #
9226 # Returns: a cell reference string.
9227 #
9228 sub rowcol_to_cell {
9229
9230 my $row = $_[0];
9231 my $col = $_[1];
9232 my $row_abs = $_[2] || 0;
9233 my $col_abs = $_[3] || 0;
9234
9235
9236 if ($row_abs) {
9237 $row_abs = '$'
9238 }
9239 else {
9240 $row_abs = ''
9241 }
9242
9243 if ($col_abs) {
9244 $col_abs = '$'
9245 }
9246 else {
9247 $col_abs = ''
9248 }
9249
9250
9251 my $int = int ($col / 26);
9252 my $frac = $col % 26 +1;
9253
9254 my $chr1 ='';
9255 my $chr2 ='';
9256
9257
9258 if ($frac != 0) {
9259 $chr2 = chr (ord('A') + $frac -1);;
9260 }
9261
9262 if ($int > 0) {
9263 $chr1 = chr (ord('A') + $int -1);
9264 }
9265
9266 $row++; # Zero index to 1-index
9267
9268 return $col_abs . $chr1 . $chr2 . $row_abs. $row;
9269 }
9270
9271
9272 ###############################################################################
9273 #
9274 # cell_to_rowcol($cell_ref)
9275 #
9276 # Convert an Excel cell reference in A1 notation to a zero based row and column
9277 # reference; converts C1 to (0, 2, 0, 0).
9278 #
9279 # Returns: row, column, row_is_absolute, column_is_absolute
9280 #
9281 #
9282 sub cell_to_rowcol {
9283
9284 my $cell = shift;
9285
9286 $cell =~ /(\$?)([A-I]?[A-Z])(\$?)(\d+)/;
9287
9288 my $col_abs = $1 eq "" ? 0 : 1;
9289 my $col = $2;
9290 my $row_abs = $3 eq "" ? 0 : 1;
9291 my $row = $4;
9292
9293 # Convert base26 column string to number
9294 # All your Base are belong to us.
9295 my @chars = split //, $col;
9296 my $expn = 0;
9297 $col = 0;
9298
9299 while (@chars) {
9300 my $char = pop(@chars); # LS char first
9301 $col += (ord($char) -ord('A') +1) * (26**$expn);
9302 $expn++;
9303 }
9304
9305 # Convert 1-index to zero-index
9306 $row--;
9307 $col--;
9308
9309 return $row, $col, $row_abs, $col_abs;
9310 }
9311
9312
9313 ###############################################################################
9314 #
9315 # inc_cell_row($cell_ref)
9316 #
9317 # Increments the row number of an Excel cell reference in A1 notation.
9318 # For example C3 to C4
9319 #
9320 # Returns: a cell reference string.
9321 #
9322 sub inc_cell_row {
9323
9324 my $cell = shift;
9325 my ($row, $col, $row_abs, $col_abs) = cell_to_rowcol($cell);
9326
9327 $row++;
9328
9329 return rowcol_to_cell($row, $col, $row_abs, $col_abs);
9330 }
9331
9332
9333 ###############################################################################
9334 #
9335 # dec_cell_row($cell_ref)
9336 #
9337 # Decrements the row number of an Excel cell reference in A1 notation.
9338 # For example C4 to C3
9339 #
9340 # Returns: a cell reference string.
9341 #
9342 sub dec_cell_row {
9343
9344 my $cell = shift;
9345 my ($row, $col, $row_abs, $col_abs) = cell_to_rowcol($cell);
9346
9347 $row--;
9348
9349 return rowcol_to_cell($row, $col, $row_abs, $col_abs);
9350 }
9351
9352
9353 ###############################################################################
9354 #
9355 # inc_cell_col($cell_ref)
9356 #
9357 # Increments the column number of an Excel cell reference in A1 notation.
9358 # For example C3 to D3
9359 #
9360 # Returns: a cell reference string.
9361 #
9362 sub inc_cell_col {
9363
9364 my $cell = shift;
9365 my ($row, $col, $row_abs, $col_abs) = cell_to_rowcol($cell);
9366
9367 $col++;
9368
9369 return rowcol_to_cell($row, $col, $row_abs, $col_abs);
9370 }
9371
9372
9373 ###############################################################################
9374 #
9375 # dec_cell_col($cell_ref)
9376 #
9377 # Decrements the column number of an Excel cell reference in A1 notation.
9378 # For example D3 to C3
9379 #
9380 # Returns: a cell reference string.
9381 #
9382 sub dec_cell_col {
9383
9384 my $cell = shift;
9385 my ($row, $col, $row_abs, $col_abs) = cell_to_rowcol($cell);
9386
9387 $col--;
9388
9389 return rowcol_to_cell($row, $col, $row_abs, $col_abs);
9390 }
9391
9392 Download this example:
9393 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/convertA1.pl
9394 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
9395 WriteExcel-2.36/examples/convertA1.pl>
9396
9397 Example: function_locale.pl
9398 Generate function names for different locales.
9399
9400 This program can be used to generate the hash of known functions for
9401 use in the Formula.pm module. By default the function names are in
9402 English but you can also choose to support the following languages:
9403 German, French, Spanish, Portuguese, Dutch, Finnish, Italian and
9404 Swedish.
9405
9406 This would allow you to do something like the following:
9407
9408 $worksheet->write(0, 0, '=SUM(C1:C3)' );
9409 $worksheet->write(1, 0, '=SUMME(C1:C3)');
9410 $worksheet->write(2, 0, '=SOMME(C1:C3)');
9411 $worksheet->write(3, 0, '=SUMA(C1:C3)' );
9412 $worksheet->write(4, 0, '=SOMA(C1:C3)' );
9413 $worksheet->write(5, 0, '=SOM(C1:C3)' );
9414 $worksheet->write(6, 0, '=SUMMA(C1:C3)');
9415 $worksheet->write(7, 0, '=SOMMA(C1:C3)');
9416
9417 Unfortunately, if you wish to support more than one language there are
9418 some conflicts between function names:
9419
9420 Function Language 1 Language 2
9421 ======== ========== ==========
9422 NB French Dutch
9423 NA English/French Finnish
9424 TRIM French English
9425 DIA Spanish/Portuguese German
9426
9427 Therefore, if you try to generate a hash of function names to support
9428 both French and English then the function TRIM will be assigned the
9429 meaning of the first language that defines it, which in this case is
9430 French. You can get around this by renaming the function for one of the
9431 languages and documenting the change, for example: TRIM.EN or TRIM.FR.
9432
9433 Please note that this only partially solves the problem of
9434 localisation. There are also number formats to consider (1.5 == 1,5)
9435 and the fact that the list separator "," and the array separator ";"
9436 are interchanged in different locales.
9437
9438 The longest function name is LOI.NORMALE.STANDARD.INVERSE (29 chars)
9439 followed by NORM.JAKAUMA.NORMIT.KAeAeNT (25 chars). The shortest
9440 function name in all languages is T.
9441
9442 #!/usr/bin/perl -w
9443
9444 ###############################################################################
9445 #
9446 # Generate function names for different locales.
9447 #
9448 # This program can be used to generate the hash of known functions for use in
9449 # the Formula.pm module. By default the function names are in English but you
9450 # can also choose to support the following languages: German, French, Spanish,
9451 # Portuguese, Dutch, Finnish, Italian and Swedish.
9452 #
9453 # This would allow you to do something like the following:
9454 #
9455 # $worksheet->write(0, 0, '=SUM(C1:C3)' );
9456 # $worksheet->write(1, 0, '=SUMME(C1:C3)');
9457 # $worksheet->write(2, 0, '=SOMME(C1:C3)');
9458 # $worksheet->write(3, 0, '=SUMA(C1:C3)' );
9459 # $worksheet->write(4, 0, '=SOMA(C1:C3)' );
9460 # $worksheet->write(5, 0, '=SOM(C1:C3)' );
9461 # $worksheet->write(6, 0, '=SUMMA(C1:C3)');
9462 # $worksheet->write(7, 0, '=SOMMA(C1:C3)');
9463 #
9464 # Unfortunately, if you wish to support more than one language there are some
9465 # conflicts between function names:
9466 #
9467 # Function Language 1 Language 2
9468 # ======== ========== ==========
9469 # NB French Dutch
9470 # NA English/French Finnish
9471 # TRIM French English
9472 # DIA Spanish/Portuguese German
9473 #
9474 # Therefore, if you try to generate a hash of function names to support both
9475 # French and English then the function TRIM will be assigned the meaning of the
9476 # first language that defines it, which in this case is French. You can get
9477 # around this by renaming the function for one of the languages and documenting
9478 # the change, for example: TRIM.EN or TRIM.FR.
9479 #
9480 # Please note that this only partially solves the problem of localisation.
9481 # There are also number formats to consider (1.5 == 1,5) and the fact that the
9482 # list separator "," and the array separator ";" are interchanged in different
9483 # locales.
9484 #
9485 # The longest function name is LOI.NORMALE.STANDARD.INVERSE (29 chars) followed
9486 # by NORM.JAKAUMA.NORMIT.KAeAeNT (25 chars).
9487 # The shortest function name in all languages is T.
9488 #
9489 #
9490 # reverse('X'); John McNamara, March 2001, jmcnamara@cpan.org
9491 #
9492
9493
9494
9495 use strict;
9496
9497
9498 #
9499 # Modify the following variables to add the language to the function name hash
9500 #
9501 my $english = 1;
9502 my $german = 0;
9503 my $french = 0;
9504 my $spanish = 0;
9505 my $portuguese = 0;
9506 my $dutch = 0;
9507 my $finnish = 0;
9508 my $italian = 0;
9509 my $swedish = 0;
9510
9511 my %funcs;
9512
9513 # Ignore the headings
9514 <DATA>;
9515
9516 # Print the beginning of the hash definition
9517 print " %functions = (\n";
9518 print " #" . " " x 37 ;
9519 print "ptg args class vol\n";
9520
9521 while (<DATA>){
9522 my @F = split " ";
9523 my $value = $F[0];
9524 my $args = $F[1];
9525 my $ref = $F[2];
9526 my $vol = $F[3];
9527
9528 print_function($F[4], $value, $args, $ref, $vol) if $english;
9529 print_function($F[5], $value, $args, $ref, $vol) if $german;
9530 print_function($F[6], $value, $args, $ref, $vol) if $french;
9531 print_function($F[7], $value, $args, $ref, $vol) if $spanish;
9532 print_function($F[8], $value, $args, $ref, $vol) if $portuguese;
9533 print_function($F[9], $value, $args, $ref, $vol) if $dutch;
9534 print_function($F[10], $value, $args, $ref, $vol) if $finnish;
9535 print_function($F[11], $value, $args, $ref, $vol) if $italian;
9536 print_function($F[12], $value, $args, $ref, $vol) if $swedish;
9537 }
9538 # Print the end of the hash definition
9539 print " );\n";
9540
9541
9542 ###############################################################################
9543 #
9544 # Function to print the function names. It prints a warning if there is a
9545 # clash.
9546 #
9547 sub print_function {
9548
9549 my $func = shift;
9550 my $value = shift;
9551 my $args = shift;
9552 my $ref = shift;
9553 my $vol = shift;
9554
9555 $func = "'$func'";
9556
9557 if (not exists $funcs{$func}) {
9558 printf(" %-31s => [%4d, %4d, %4d, %4d ],\n",
9559 $func, $value, $args, $ref, $vol);
9560 $funcs{$func} = $value;
9561 }
9562 else {
9563 if ($funcs{$func} != $value) {
9564 print " # Warning ";
9565 print $func, " is already defined in another language\n";
9566 printf(" #%-31s => [%4d, %4d, %4d, %4d ],\n",
9567 $func, $value, $args, $ref, $vol);
9568 }
9569 }
9570 }
9571
9572
9573 # Note: The following data contains the function names in the various
9574 # languages. These lines are LONG.
9575
9576 __DATA__
9577 Value Args Refclass Volatile English German French Spanish Portuguese Dutch Finnish Italian Swedish
9578 0 -1 0 0 COUNT ANZAHL NB CONTAR CONT.NUM AANTAL LASKE CONTA.NUMERI ANTAL
9579 1 -1 1 0 IF WENN SI SI SE ALS JOS SE OM
9580 2 1 1 0 ISNA ISTNV ESTNA ESNOD E.NA~O.DISP ISNB ONPUUTTUU VAL.NON.DISP AeRSAKNAD
9581 3 1 1 0 ISERROR ISTFEHLER ESTERREUR ESERROR EERROS ISFOUT ONVIRHE VAL.ERRORE AeRFEL
9582 4 -1 0 0 SUM SUMME SOMME SUMA SOMA SOM SUMMA SOMMA SUMMA
9583 5 -1 0 0 AVERAGE MITTELWERT MOYENNE PROMEDIO MEDIA GEMIDDELDE KESKIARVO MEDIA MEDEL
9584 6 -1 0 0 MIN MIN MIN MIN MINIMO MIN MIN MIN MIN
9585 7 -1 0 0 MAX MAX MAX MAX MAXIMO MAX MAKS MAX MAX
9586 8 -1 0 0 ROW ZEILE LIGNE FILA LIN RIJ RIVI RIF.RIGA RAD
9587 9 -1 0 0 COLUMN SPALTE COLONNE COLUMNA COL KOLOM SARAKE RIF.COLONNA KOLUMN
9588 10 0 0 0 NA NV NA NOD NA~O.DISP NB PUUTTUU NON.DISP SAKNAS
9589 11 -1 1 0 NPV NBW VAN VNA VPL NHW NNA VAN NETNUVAeRDE
9590 12 -1 0 0 STDEV STABW ECARTYPE DESVEST DESVPAD STDEV KESKIHAJONTA DEV.ST STDAV
9591 13 -1 1 0 DOLLAR DM FRANC MONEDA MOEDA GULDEN VALUUTTA VALUTA VALUTA
9592 14 -1 1 0 FIXED FEST CTXT DECIMAL DEF.NUM.DEC VAST KIINTEAe FISSO FASTTAL
9593 15 1 1 0 SIN SIN SIN SENO SEN SIN SIN SEN SIN
9594 16 1 1 0 COS COS COS COS COS COS COS COS COS
9595 17 1 1 0 TAN TAN TAN TAN TAN TAN TAN TAN TAN
9596 18 1 1 0 ATAN ARCTAN ATAN ATAN ATAN BOOGTAN ATAN ARCTAN ARCTAN
9597 19 0 1 0 PI PI PI PI PI PI PII PI.GRECO PI
9598 20 1 1 0 SQRT WURZEL RACINE RAIZ RAIZ WORTEL NELIOeJUURI RADQ ROT
9599 21 1 1 0 EXP EXP EXP EXP EXP EXP EKSPONENTTI EXP EXP
9600 22 1 1 0 LN LN LN LN LN LN LUONNLOG LN LN
9601 23 1 1 0 LOG10 LOG10 LOG10 LOG10 LOG10 LOG10 LOG10 LOG10 LOG10
9602 24 1 1 0 ABS ABS ABS ABS ABS ABS ITSEISARVO ASS ABS
9603 25 1 1 0 INT GANZZAHL ENT ENTERO INT INTEGER KOKONAISLUKU INT HELTAL
9604 26 1 1 0 SIGN VORZEICHEN SIGNE SIGNO SINAL POS.NEG ETUMERKKI SEGNO TECKEN
9605 27 2 1 0 ROUND RUNDEN ARRONDI REDONDEAR ARRED AFRONDEN PYOeRISTAe ARROTONDA AVRUNDA
9606 28 -1 0 0 LOOKUP VERWEIS RECHERCHE BUSCAR PROC ZOEKEN HAKU CERCA LETAUPP
9607 29 -1 0 1 INDEX INDEX INDEX INDICE INDICE INDEX INDEKSI INDICE INDEX
9608 30 2 1 0 REPT WIEDERHOLEN REPT REPETIR REPETIR HERHALING TOISTA RIPETI REP
9609 31 3 1 0 MID TEIL STXT EXTRAE EXT.TEXTO DEEL POIMI.TEKSTI STRINGA.ESTRAI EXTEXT
9610 32 1 1 0 LEN LAeNGE NBCAR LARGO NUM.CARACT LENGTE PITUUS LUNGHEZZA LAeNGD
9611 33 1 1 0 VALUE WERT CNUM VALOR VALOR WAARDE ARVO VALORE TEXTNUM
9612 34 0 1 0 TRUE WAHR VRAI VERDADERO VERDADEIRO WAAR TOSI VERO SANT
9613 35 0 1 0 FALSE FALSCH FAUX FALSO FALSO ONWAAR EPAeTOSI FALSO FALSKT
9614 36 -1 0 0 AND UND ET Y E EN JA E OCH
9615 37 -1 0 0 OR ODER OU O OU OF TAI O ELLER
9616 38 1 1 0 NOT NICHT NON NO NA~O NIET EI NON ICKE
9617 39 2 1 0 MOD REST MOD RESIDUO MOD REST JAKOJ RESTO REST
9618 40 3 0 0 DCOUNT DBANZAHL BDNB BDCONTAR BDCONTAR DBAANTAL TLASKE DB.CONTA.NUMERI DANTAL
9619 41 3 0 0 DSUM DBSUMME BDSOMME BDSUMA BDSOMA DBSOM TSUMMA DB.SOMMA DSUMMA
9620 42 3 0 0 DAVERAGE DBMITTELWERT BDMOYENNE BDPROMEDIO BDMEDIA DBGEMIDDELDE TKESKIARVO DB.MEDIA DMEDEL
9621 43 3 0 0 DMIN DBMIN BDMIN BDMIN BDMIN DBMIN TMIN DB.MIN DMIN
9622 44 3 0 0 DMAX DBMAX BDMAX BDMAX BDMAX DBMAX TMAKS DB.MAX DMAX
9623 45 3 0 0 DSTDEV DBSTDABW BDECARTYPE BDDESVEST BDEST DBSTDEV TKESKIHAJONTA DB.DEV.ST DSTDAV
9624 46 -1 0 0 VAR VARIANZ VAR VAR VAR VAR VAR VAR VARIANS
9625 47 3 0 0 DVAR DBVARIANZ BDVAR BDVAR BDVAREST DBVAR TVARIANSSI DB.VAR DVARIANS
9626 48 2 1 0 TEXT TEXT TEXTE TEXTO TEXTO TEKST TEKSTI TESTO TEXT
9627 49 -1 0 0 LINEST RGP DROITEREG ESTIMACION.LINEAL PROJ.LIN LIJNSCH LINREGR REGR.LIN REGR
9628 50 -1 0 0 TREND TREND TENDANCE TENDENCIA TENDENCIA TREND SUUNTAUS TENDENZA TREND
9629 51 -1 0 0 LOGEST RKP LOGREG ESTIMACION.LOGARITMICA PROJ.LOG LOGSCH LOGREGR REGR.LOG EXPREGR
9630 52 -1 0 0 GROWTH VARIATION CROISSANCE CRECIMIENTO CRESCIMENTO GROEI KASVU CRESCITA EXPTREND
9631 56 -1 1 0 PV BW VA VA VP HW NA VA NUVAeRDE
9632 57 -1 1 0 FV ZW VC VF VF TW TULEVA.ARVO VAL.FUT SLUTVAeRDE
9633 58 -1 1 0 NPER ZZR NPM NPER NPER NPER NJAKSO NUM.RATE PERIODER
9634 59 -1 1 0 PMT RMZ VPM PAGO PGTO BET MAKSU RATA BETALNING
9635 60 -1 1 0 RATE ZINS TAUX TASA TAXA RENTE KORKO TASSO RAeNTA
9636 61 3 0 0 MIRR QIKV TRIM TIRM MTIR GIR MSISAeINEN TIR.VAR MODIR
9637 62 -1 0 0 IRR IKV TRI TIR TIR IR SISAeINEN.KORKO TIR.COST IR
9638 63 0 1 1 RAND ZUFALLSZAHL ALEA ALEATORIO ALEATORIO ASELECT SATUNNAISLUKU CASUALE SLUMP
9639 64 -1 0 0 MATCH VERGLEICH EQUIV COINCIDIR CORRESP VERGELIJKEN VASTINE CONFRONTA PASSA
9640 65 3 1 0 DATE DATUM DATE FECHA DATA DATUM PAeIVAeYS DATA DATUM
9641 66 3 1 0 TIME ZEIT TEMPS NSHORA TEMPO TIJD AIKA ORARIO KLOCKSLAG
9642 67 1 1 0 DAY TAG JOUR DIA DIA DAG PAeIVAe GIORNO DAG
9643 68 1 1 0 MONTH MONAT MOIS MES MES MAAND KUUKAUSI MESE MAaNAD
9644 69 1 1 0 YEAR JAHR ANNEE AN~O ANO JAAR VUOSI ANNO AaR
9645 70 -1 1 0 WEEKDAY WOCHENTAG JOURSEM DIASEM DIA.DA.SEMANA WEEKDAG VIIKONPAeIVAe GIORNO.SETTIMANA VECKODAG
9646 71 1 1 0 HOUR STUNDE HEURE HORA HORA UUR TUNNIT ORA TIMME
9647 72 1 1 0 MINUTE MINUTE MINUTE MINUTO MINUTO MINUUT MINUUTIT MINUTO MINUT
9648 73 1 1 0 SECOND SEKUNDE SECONDE SEGUNDO SEGUNDO SECONDE SEKUNNIT SECONDO SEKUND
9649 74 0 1 1 NOW JETZT MAINTENANT AHORA AGORA NU NYT ADESSO NU
9650 75 1 0 1 AREAS BEREICHE ZONES AREAS AREAS BEREIKEN ALUEET AREE OMRAaDEN
9651 76 1 0 1 ROWS ZEILEN LIGNES FILAS LINS RIJEN RIVIT RIGHE RADER
9652 77 1 0 1 COLUMNS SPALTEN COLONNES COLUMNAS COLS KOLOMMEN SARAKKEET COLONNE KOLUMNER
9653 78 -1 0 1 OFFSET BEREICH.VERSCHIEBEN DECALER DESREF DESLOC VERSCHUIVING SIIRTYMAe SCARTO FOeRSKJUTNING
9654 82 -1 1 0 SEARCH SUCHEN CHERCHE HALLAR LOCALIZAR VIND.SPEC KAeY.LAePI RICERCA SOeK
9655 83 1 1 0 TRANSPOSE MTRANS TRANSPOSE TRANSPONER TRANSPOR TRANSPONEREN TRANSPONOI MATR.TRASPOSTA TRANSPONERA
9656 86 1 1 0 TYPE TYP TYPE TIPO TIPO TYPE TYYPPI TIPO VAeRDETYP
9657 97 2 1 0 ATAN2 ARCTAN2 ATAN2 ATAN2 ATAN2 BOOGTAN2 ATAN2 ARCTAN.2 ARCTAN2
9658 98 1 1 0 ASIN ARCSIN ASIN ASENO ASEN BOOGSIN ASIN ARCSEN ARCSIN
9659 99 1 1 0 ACOS ARCCOS ACOS ACOS ACOS BOOGCOS ACOS ARCCOS ARCCOS
9660 100 -1 1 0 CHOOSE WAHL CHOISIR ELEGIR ESCOLHER KIEZEN VALITSE.INDEKSI SCEGLI VAeLJ
9661 101 -1 0 0 HLOOKUP WVERWEIS RECHERCHEH BUSCARH PROCH HORIZ.ZOEKEN VHAKU CERCA.ORIZZ LETAKOLUMN
9662 102 -1 0 0 VLOOKUP SVERWEIS RECHERCHEV BUSCARV PROCV VERT.ZOEKEN PHAKU CERCA.VERT LETARAD
9663 105 1 0 0 ISREF ISTBEZUG ESTREF ESREF EREF ISVERWIJZING ONVIITT VAL.RIF AeRREF
9664 109 -1 1 0 LOG LOG LOG LOG LOG LOG LOG LOG LOG
9665 111 1 1 0 CHAR ZEICHEN CAR CARACTER CARACT TEKEN MERKKI CODICE.CARATT TECKENKOD
9666 112 1 1 0 LOWER KLEIN MINUSCULE MINUSC MINUSCULA KLEINE.LETTERS PIENET MINUSC GEMENER
9667 113 1 1 0 UPPER GROSS MAJUSCULE MAYUSC MAIUSCULA HOOFDLETTERS ISOT MAIUSC VERSALER
9668 114 1 1 0 PROPER GROSS2 NOMPROPRE NOMPROPIO PRI.MAIUSCULA BEGINLETTERS ERISNIMI MAIUSC.INIZ INITIAL
9669 115 -1 1 0 LEFT LINKS GAUCHE IZQUIERDA ESQUERDA LINKS VASEN SINISTRA VAeNSTER
9670 116 -1 1 0 RIGHT RECHTS DROITE DERECHA DIREITA RECHTS OIKEA DESTRA HOeGER
9671 117 2 1 0 EXACT IDENTISCH EXACT IGUAL EXATO GELIJK VERTAA IDENTICO EXAKT
9672 118 1 1 0 TRIM GLAeTTEN SUPPRESPACE ESPACIOS ARRUMAR SPATIES.WISSEN POISTA.VAeLIT ANNULLA.SPAZI RENSA
9673 119 4 1 0 REPLACE ERSETZEN REMPLACER REEMPLAZAR MUDAR VERVANGEN KORVAA RIMPIAZZA ERSAeTT
9674 120 -1 1 0 SUBSTITUTE WECHSELN SUBSTITUE SUSTITUIR SUBSTITUIR SUBSTITUEREN VAIHDA SOSTITUISCI BYT.UT
9675 121 1 1 0 CODE CODE CODE CODIGO CODIGO CODE KOODI CODICE KOD
9676 124 -1 1 0 FIND FINDEN TROUVE ENCONTRAR PROCURAR VIND.ALLES ETSI TROVA HITTA
9677 125 -1 0 1 CELL ZELLE CELLULE CELDA CEL CEL SOLU CELLA CELL
9678 126 1 1 0 ISERR ISTFEHL ESTERR ESERR EERRO ISFOUT2 ONVIRH VAL.ERR AeRF
9679 127 1 1 0 ISTEXT ISTTEXT ESTTEXTE ESTEXTO ETEXTO ISTEKST ONTEKSTI VAL.TESTO AeRTEXT
9680 128 1 1 0 ISNUMBER ISTZAHL ESTNUM ESNUMERO ENUM ISGETAL ONLUKU VAL.NUMERO AeRTAL
9681 129 1 1 0 ISBLANK ISTLEER ESTVIDE ESBLANCO ECEL.VAZIA ISLEEG ONTYHJAe VAL.VUOTO AeRTOM
9682 130 1 0 0 T T T T T T T T T
9683 131 1 0 0 N N N N N N N NUM N
9684 140 1 1 0 DATEVALUE DATWERT DATEVAL FECHANUMERO DATA.VALOR DATUMWAARDE PAeIVAeYSARVO DATA.VALORE DATUMVAeRDE
9685 141 1 1 0 TIMEVALUE ZEITWERT TEMPSVAL HORANUMERO VALOR.TEMPO TIJDWAARDE AIKA_ARVO ORARIO.VALORE TIDVAeRDE
9686 142 3 1 0 SLN LIA AMORLIN SLN DPD LIN.AFSCHR STP AMMORT.COST LINAVSKR
9687 143 4 1 0 SYD DIA SYD SYD SDA SYD VUOSIPOISTO AMMORT.ANNUO AaRSAVSKR
9688 144 -1 1 0 DDB GDA DDB DDB BDD DDB DDB AMMORT DEGAVSKR
9689 148 -1 1 1 INDIRECT INDIREKT INDIRECT INDIRECTO INDIRETO INDIRECT EPAeSUORA INDIRETTO INDIREKT
9690 150 -1 1 0 CALL AUFRUFEN FONCTION.APPELANTE LLAMAR CHAMAR ROEPEN KUTSU RICHIAMA ANROPA
9691 162 1 1 0 CLEAN SAeUBERN EPURAGE LIMPIAR TIRAR WISSEN.CONTROL SIIVOA LIBERA STAeDA
9692 163 1 2 0 MDETERM MDET DETERMAT MDETERM MATRIZ.DETERM DETERMINANTMAT MDETERM MATR.DETERM MDETERM
9693 164 1 2 0 MINVERSE MINV INVERSEMAT MINVERSA MATRIZ.INVERSO INVERSEMAT MKAeAeNTEINEN MATR.INVERSA MINVERT
9694 165 2 2 0 MMULT MMULT PRODUITMAT MMULT MATRIZ.MULT PRODUKTMAT MKERRO MATR.PRODOTTO MMULT
9695 167 -1 1 0 IPMT ZINSZ INTPER PAGOINT IPGTO IBET IPMT INTERESSI RBETALNING
9696 168 -1 1 0 PPMT KAPZ PRINCPER PAGOPRIN PPGTO PBET PPMT P.RATA AMORT
9697 169 -1 0 0 COUNTA ANZAHL2 NBVAL CONTARA CONT.VALORES AANTALARG LASKE.A CONTA.VALORI ANTALV
9698 183 -1 0 0 PRODUCT PRODUKT PRODUIT PRODUCTO MULT PRODUKT TULO PRODOTTO PRODUKT
9699 184 1 1 0 FACT FAKULTAeT FACT FACT FATORIAL FACULTEIT KERTOMA FATTORIALE FAKULTET
9700 189 3 0 0 DPRODUCT DBPRODUKT BDPRODUIT BDPRODUCTO BDMULTIPL DBPRODUKT TTULO DB.PRODOTTO DPRODUKT
9701 190 1 1 0 ISNONTEXT ISTKTEXT ESTNONTEXTE ESNOTEXTO E.NA~O.TEXTO ISGEENTEKST ONEI_TEKSTI VAL.NON.TESTO AeREJTEXT
9702 193 -1 0 0 STDEVP STABWN ECARTYPEP DESVESTP DESVPADP STDEVP KESKIHAJONTAP DEV.ST.POP STDAVP
9703 194 -1 0 0 VARP VARIANZEN VAR.P VARP VARP VARP VARP VAR.POP VARIANSP
9704 195 3 0 0 DSTDEVP DBSTDABWN BDECARTYPEP BDDESVESTP BDDESVPA DBSTDEVP TKESKIHAJONTAP DB.DEV.ST.POP DSTDAVP
9705 196 3 0 0 DVARP DBVARIANZEN BDVARP BDVARP BDVARP DBVARP TVARIANSSIP DB.VAR.POP DVARIANSP
9706 197 -1 1 0 TRUNC KUeRZEN TRONQUE TRUNCAR TRUNCAR GEHEEL KATKAISE TRONCA AVKORTA
9707 198 1 1 0 ISLOGICAL ISTLOG ESTLOGIQUE ESLOGICO ELOGICO ISLOGISCH ONTOTUUS VAL.LOGICO AeRLOGISK
9708 199 3 0 0 DCOUNTA DBANZAHL2 BDNBVAL BDCONTARA BDCONTARA DBAANTALC TLASKEA DB.CONTA.VALORI DANTALV
9709 212 2 1 0 ROUNDUP AUFRUNDEN ARRONDI.SUP REDONDEAR.MAS ARREDONDAR.PARA.CIMA AFRONDEN.NAAR.BOVEN PYOeRISTAe.DES.YLOeS ARROTONDA.PER.ECC AVRUNDA.UPPAaT
9710 213 2 1 0 ROUNDDOWN ABRUNDEN ARRONDI.INF REDONDEAR.MENOS ARREDONDAR.PARA.BAIXO AFRONDEN.NAAR.BENEDEN PYOeRISTAe.DES.ALAS ARROTONDA.PER.DIF AVRUNDA.NEDAaT
9711 216 -1 0 0 RANK RANG RANG JERARQUIA ORDEM RANG ARVON.MUKAAN RANGO RANG
9712 219 -1 1 0 ADDRESS ADRESSE ADRESSE DIRECCION ENDERECO ADRES OSOITE INDIRIZZO ADRESS
9713 220 -1 1 0 DAYS360 TAGE360 JOURS360 DIAS360 DIAS360 DAGEN360 PAeIVAeT360 GIORNO360 DAGAR360
9714 221 0 1 1 TODAY HEUTE AUJOURDHUI HOY HOJE VANDAAG TAeMAe.PAeIVAe OGGI IDAG
9715 222 -1 1 0 VDB VDB VDB DVS BDV VDB VDB AMMORT.VAR VDEGRAVSKR
9716 227 -1 0 0 MEDIAN MEDIAN MEDIANE MEDIANA MED MEDIAAN MEDIAANI MEDIANA MEDIAN
9717 228 -1 2 0 SUMPRODUCT SUMMENPRODUKT SOMMEPROD SUMAPRODUCTO SOMARPRODUTO SOMPRODUKT TULOJEN.SUMMA MATR.SOMMA.PRODOTTO PRODUKTSUMMA
9718 229 1 1 0 SINH SINHYP SINH SENOH SENH SINH SINH SENH SINH
9719 230 1 1 0 COSH COSHYP COSH COSH COSH COSH COSH COSH COSH
9720 231 1 1 0 TANH TANHYP TANH TANH TANH TANH TANH TANH TANH
9721 232 1 1 0 ASINH ARCSINHYP ASINH ASENOH ASENH BOOGSINH ASINH ARCSENH ARCSINH
9722 233 1 1 0 ACOSH ARCCOSHYP ACOSH ACOSH ACOSH BOOGCOSH ACOSH ARCCOSH ARCCOSH
9723 234 1 1 0 ATANH ARCTANHYP ATANH ATANH ATANH BOOGTANH ATANH ARCTANH ARCTANH
9724 235 3 0 0 DGET DBAUSZUG BDLIRE BDEXTRAER BDEXTRAIR DBLEZEN TNOUDA DB.VALORI DHAeMTA
9725 244 1 1 1 INFO INFO INFO INFO INFORMACA~O INFO KUVAUS AMBIENTE.INFO INFO
9726 247 -1 1 0 DB GDA2 DB DB BD DB DB AMMORT.FISSO DB
9727 252 2 0 0 FREQUENCY HAeUFIGKEIT FREQUENCE FRECUENCIA FREQUeENCIA INTERVAL TAAJUUS FREQUENZA FREKVENS
9728 261 1 1 0 ERROR.TYPE FEHLER.TYP TYPE.ERREUR TIPO.DE.ERROR TIPO.ERRO TYPE.FOUT VIRHEEN.LAJI ERRORE.TIPO FEL.TYP
9729 267 -1 1 0 REGISTER.ID REGISTER.KENNUMMER REGISTRE.NUMERO ID.REGISTRO IDENT.REGISTRO REGISTRATIE.ID REKISTERI.TUNNUS IDENTIFICATORE.REGISTRO REGISTRERA.ID
9730 269 -1 0 0 AVEDEV MITTELABW ECART.MOYEN DESVPROM DESV.MEDIO GEM.DEVIATIE KESKIPOIKKEAMA MEDIA.DEV MEDELAVV
9731 270 -1 1 0 BETADIST BETAVERT LOI.BETA DISTR.BETA DISTBETA BETA.VERD BEETAJAKAUMA DISTRIB.BETA BETAFOeRD
9732 271 1 1 0 GAMMALN GAMMALN LNGAMMA GAMMA.LN LNGAMA GAMMA.LN GAMMALN LN.GAMMA GAMMALN
9733 272 -1 1 0 BETAINV BETAINV BETA.INVERSE DISTR.BETA.INV BETA.ACUM.INV BETA.INV BEETAJAKAUMA.KAeAeNT INV.BETA BETAINV
9734 273 4 1 0 BINOMDIST BINOMVERT LOI.BINOMIALE DISTR.BINOM DISTRBINOM BINOMIALE.VERD BINOMIJAKAUMA DISTRIB.BINOM BINOMFOeRD
9735 274 2 1 0 CHIDIST CHIVERT LOI.KHIDEUX DISTR.CHI DIST.QUI CHI.KWADRAAT CHIJAKAUMA DISTRIB.CHI CHI2FOeRD
9736 275 2 1 0 CHIINV CHIINV KHIDEUX.INVERSE PRUEBA.CHI.INV INV.QUI CHI.KWADRAAT.INV CHIJAKAUMA.KAeAeNT INV.CHI CHI2INV
9737 276 2 1 0 COMBIN KOMBINATIONEN COMBIN COMBINAT COMBIN COMBINATIES KOMBINAATIO COMBINAZIONE KOMBIN
9738 277 3 1 0 CONFIDENCE KONFIDENZ INTERVALLE.CONFIANCE INTERVALO.CONFIANZA INT.CONFIANCA BETROUWBAARHEID LUOTTAMUSVAeLI CONFIDENZA KONFIDENS
9739 278 3 1 0 CRITBINOM KRITBINOM CRITERE.LOI.BINOMIALE BINOM.CRIT CRIT.BINOM CRIT.BINOM BINOMIJAKAUMA.KRIT CRIT.BINOM KRITBINOM
9740 279 1 1 0 EVEN GERADE PAIR REDONDEA.PAR PAR EVEN PARILLINEN PARI JAeMN
9741 280 3 1 0 EXPONDIST EXPONVERT LOI.EXPONENTIELLE DISTR.EXP DISTEXPON EXPON.VERD EKSPONENTIAALIJAKAUMA DISTRIB.EXP EXPONFOeRD
9742 281 3 1 0 FDIST FVERT LOI.F DISTR.F DISTF F.VERDELING FJAKAUMA DISTRIB.F FFOeRD
9743 282 3 1 0 FINV FINV INVERSE.LOI.F DISTR.F.INV INVF F.INVERSE FJAKAUMA.KAeAeNT INV.F FINV
9744 283 1 1 0 FISHER FISHER FISHER FISHER FISHER FISHER FISHER FISHER FISHER
9745 284 1 1 0 FISHERINV FISHERINV FISHER.INVERSE PRUEBA.FISHER.INV FISHERINV FISHER.INV FISHER.KAeAeNT INV.FISHER FISHERINV
9746 285 2 1 0 FLOOR UNTERGRENZE PLANCHER MULTIPLO.INFERIOR ARREDMULTB AFRONDEN.BENEDEN PYOeRISTAe.KERR.ALAS ARROTONDA.DIFETTO RUNDA.NER
9747 286 4 1 0 GAMMADIST GAMMAVERT LOI.GAMMA DISTR.GAMMA DISTGAMA GAMMA.VERD GAMMAJAKAUMA DISTRIB.GAMMA GAMMAFOeRD
9748 287 3 1 0 GAMMAINV GAMMAINV LOI.GAMMA.INVERSE DISTR.GAMMA.INV INVGAMA GAMMA.INV GAMMAJAKAUMA.KAeAeNT INV.GAMMA GAMMAINV
9749 288 2 1 0 CEILING OBERGRENZE PLAFOND MULTIPLO.SUPERIOR TETO AFRONDEN.BOVEN PYOeRISTAe.KERR.YLOeS ARROTONDA.ECCESSO RUNDA.UPP
9750 289 4 1 0 HYPGEOMDIST HYPGEOMVERT LOI.HYPERGEOMETRIQUE DISTR.HIPERGEOM DIST.HIPERGEOM HYPERGEO.VERD HYPERGEOM.JAKAUMA DISTRIB.IPERGEOM HYPGEOMFOeRD
9751 290 3 1 0 LOGNORMDIST LOGNORMVERT LOI.LOGNORMALE DISTR.LOG.NORM DIST.LOGNORMAL LOG.NORM.VERD LOGNORM.JAKAUMA DISTRIB.LOGNORM LOGNORMFOeRD
9752 291 3 1 0 LOGINV LOGINV LOI.LOGNORMALE.INVERSE DISTR.LOG.INV INVLOG LOG.NORM.INV LOGNORM.JAKAUMA.KAeAeNT INV.LOGNORM LOGINV
9753 292 3 1 0 NEGBINOMDIST NEGBINOMVERT LOI.BINOMIALE.NEG NEGBINOMDIST DIST.BIN.NEG NEG.BINOM.VERD BINOMIJAKAUMA.NEG DISTRIB.BINOM.NEG NEGBINOMFOeRD
9754 293 4 1 0 NORMDIST NORMVERT LOI.NORMALE DISTR.NORM DIST.NORM NORM.VERD NORM.JAKAUMA DISTRIB.NORM NORMFOeRD
9755 294 1 1 0 NORMSDIST STANDNORMVERT LOI.NORMALE.STANDARD DISTR.NORM.ESTAND DIST.NORMP STAND.NORM.VERD NORM.JAKAUMA.NORMIT DISTRIB.NORM.ST NORMSFOeRD
9756 295 3 1 0 NORMINV NORMINV LOI.NORMALE.INVERSE DISTR.NORM.INV INV.NORM NORM.INV NORM.JAKAUMA.KAeAeNT INV.NORM NORMINV
9757 296 1 1 0 NORMSINV STANDNORMINV LOI.NORMALE.STANDARD.INVERSE DISTR.NORM.ESTAND.INV INV.NORMP STAND.NORM.INV NORM.JAKAUMA.NORMIT.KAeAeNT INV.NORM.ST NORMSINV
9758 297 3 1 0 STANDARDIZE STANDARDISIERUNG CENTREE.REDUITE NORMALIZACION PADRONIZAR NORMALISEREN NORMITA NORMALIZZA STANDARDISERA
9759 298 1 1 0 ODD UNGERADE IMPAIR REDONDEA.IMPAR IMPAR ONEVEN PARITON DISPARI UDDA
9760 299 2 1 0 PERMUT VARIATIONEN PERMUTATION PERMUTACIONES PERMUT PERMUTATIES PERMUTAATIO PERMUTAZIONE PERMUT
9761 300 3 1 0 POISSON POISSON LOI.POISSON POISSON POISSON POISSON POISSON POISSON POISSON
9762 301 3 1 0 TDIST TVERT LOI.STUDENT DISTR.T DISTT T.VERD TJAKAUMA DISTRIB.T TFOeRD
9763 302 4 1 0 WEIBULL WEIBULL LOI.WEIBULL DIST.WEIBULL WEIBULL WEIBULL WEIBULL WEIBULL WEIBULL
9764 303 2 2 0 SUMXMY2 SUMMEXMY2 SOMME.XMY2 SUMAXMENOSY2 SOMAXMY2 SOM.XMINY.2 EROTUSTEN.NELIOeSUMMA SOMMA.Q.DIFF SUMMAXMY2
9765 304 2 2 0 SUMX2MY2 SUMMEX2MY2 SOMME.X2MY2 SUMAX2MENOSY2 SOMAX2DY2 SOM.X2MINY2 NELIOeSUMMIEN.EROTUS SOMMA.DIFF.Q SUMMAX2MY2
9766 305 2 2 0 SUMX2PY2 SUMMEX2PY2 SOMME.X2PY2 SUMAX2MASY2 SOMAX2SY2 SOM.X2PLUSY2 NELIOeSUMMIEN.SUMMA SOMMA.SOMMA.Q SUMMAX2PY2
9767 306 2 2 0 CHITEST CHITEST TEST.KHIDEUX PRUEBA.CHI TESTE.QUI CHI.TOETS CHITESTI TEST.CHI CHI2TEST
9768 307 2 2 0 CORREL KORREL COEFFICIENT.CORRELATION COEF.DE.CORREL CORREL CORRELATIE KORRELAATIO CORRELAZIONE KORREL
9769 308 2 2 0 COVAR KOVAR COVARIANCE COVAR COVAR COVARIANTIE KOVARIANSSI COVARIANZA KOVAR
9770 309 3 2 0 FORECAST SCHAeTZER PREVISION PRONOSTICO PREVISA~O VOORSPELLEN ENNUSTE PREVISIONE PREDIKTION
9771 310 2 2 0 FTEST FTEST TEST.F PRUEBA.F TESTEF F.TOETS FTESTI TEST.F FTEST
9772 311 2 2 0 INTERCEPT ACHSENABSCHNITT ORDONNEE.ORIGINE INTERSECCION INTERCEPCA~O SNIJPUNT LEIKKAUSPISTE INTERCETTA SKAeRNINGSPUNKT
9773 312 2 2 0 PEARSON PEARSON PEARSON PEARSON PEARSON PEARSON PEARSON PEARSON PEARSON
9774 313 2 2 0 RSQ BESTIMMTHEITSMASS COEFFICIENT.DETERMINATION COEFICIENTE.R2 RQUAD R.KWADRAAT PEARSON.NELIOe RQ RKV
9775 314 2 2 0 STEYX STFEHLERYX ERREUR.TYPE.XY ERROR.TIPICO.XY EPADYX STAND.FOUT.YX KESKIVIRHE ERR.STD.YX STDFELYX
9776 315 2 2 0 SLOPE STEIGUNG PENTE PENDIENTE INCLINACA~O RICHTING KULMAKERROIN PENDENZA LUTNING
9777 316 4 2 0 TTEST TTEST TEST.STUDENT PRUEBA.T TESTET T.TOETS TTESTI TEST.T TTEST
9778 317 -1 2 0 PROB WAHRSCHBEREICH PROBABILITE PROBABILIDAD PROB KANS TODENNAeKOeISYYS PROBABILITA SANNOLIKHET
9779 318 -1 0 0 DEVSQ SUMQUADABW SOMME.CARRES.ECARTS DESVIA2 DESVQ DEV.KWAD OIKAISTU.NELIOeSUMMA DEV.Q KVADAVV
9780 319 -1 0 0 GEOMEAN GEOMITTEL MOYENNE.GEOMETRIQUE MEDIA.GEOM MEDIA.GEOMETRICA MEETK.GEM KESKIARVO.GEOM MEDIA.GEOMETRICA GEOMEDEL
9781 320 -1 0 0 HARMEAN HARMITTEL MOYENNE.HARMONIQUE MEDIA.ARMO MEDIA.HARMONICA HARM.GEM KESKIARVO.HARM MEDIA.ARMONICA HARMMEDEL
9782 321 -1 0 0 SUMSQ QUADRATESUMME SOMME.CARRES SUMA.CUADRADOS SOMAQUAD KWADRATENSOM NELIOeSUMMA SOMMA.Q KVADRATSUMMA
9783 322 -1 0 0 KURT KURT KURTOSIS CURTOSIS CURT KURTOSIS KURT CURTOSI TOPPIGHET
9784 323 -1 0 0 SKEW SCHIEFE COEFFICIENT.ASYMETRIE COEFICIENTE.ASIMETRIA DISTORCA~O SCHEEFHEID JAKAUMAN.VINOUS ASIMMETRIA SNEDHET
9785 324 -1 0 0 ZTEST GTEST TEST.Z PRUEBA.Z TESTEZ Z.TOETS ZTESTI TEST.Z ZTEST
9786 325 2 0 0 LARGE KGROeSSTE GRANDE.VALEUR K.ESIMO.MAYOR MAIOR GROOTSTE SUURI GRANDE STOeRSTA
9787 326 2 0 0 SMALL KKLEINSTE PETITE.VALEUR K.ESIMO.MENOR MENOR KLEINSTE PIENI PICCOLO MINSTA
9788 327 2 0 0 QUARTILE QUARTILE QUARTILE CUARTIL QUARTIL KWARTIEL NELJAeNNES QUARTILE KVARTIL
9789 328 2 0 0 PERCENTILE QUANTIL CENTILE PERCENTIL PERCENTIL PERCENTIEL PROSENTTIPISTE PERCENTILE PERCENTIL
9790 329 -1 0 0 PERCENTRANK QUANTILSRANG RANG.POURCENTAGE RANGO.PERCENTIL ORDEM.PORCENTUAL PERCENT.RANG PROSENTTIJAeRJESTYS PERCENT.RANGO PROCENTRANG
9791 330 -1 2 0 MODE MODALWERT MODE MODA MODO MODUS MOODI MODA TYPVAeRDE
9792 331 2 0 0 TRIMMEAN GESTUTZTMITTEL MOYENNE.REDUITE MEDIA.ACOTADA MEDIA.INTERNA GETRIMD.GEM KESKIARVO.TASATTU MEDIA.TRONCATA TRIMMEDEL
9793 332 2 1 0 TINV TINV LOI.STUDENT.INVERSE DISTR.T.INV INVT T.INV TJAKAUMA.KAeAeNT INV.T TINV
9794 336 -1 1 0 CONCATENATE VERKETTEN CONCATENER CONCATENAR CONCATENAR TEKST.SAMENVOEGEN KETJUTA CONCATENA SAMMANFOGA
9795 337 2 1 0 POWER POTENZ PUISSANCE POTENCIA POTENCIA MACHT POTENSSI POTENZA UPPHOeJT.TILL
9796 342 1 1 0 RADIANS RADIANT RADIANS RADIANES RADIANOS RADIALEN RADIAANIT RADIANTI RADIANER
9797 343 1 1 0 DEGREES GRAD DEGRES GRADOS GRAUS GRADEN ASTEET GRADI GRADER
9798 344 -1 0 0 SUBTOTAL TEILERGEBNIS SOUS.TOTAL SUBTOTALES SUBTOTAL SUBTOTAAL VAeLISUMMA SUBTOTALE DELSUMMA
9799 345 -1 0 0 SUMIF SUMMEWENN SOMME.SI SUMAR.SI SOMASE SOM.ALS SUMMA.JOS SOMMA.SE SUMMA.OM
9800 346 2 0 0 COUNTIF ZAeHLENWENN NB.SI CONTAR.SI CONT.SE AANTAL.ALS LASKE.JOS CONTA.SE ANTAL.OM
9801 347 1 0 0 COUNTBLANK ANZAHLLEEREZELLEN NB.VIDE CONTAR.BLANCO CONTAR.VAZIO AANTAL.LEGE.CELLEN LASKE.TYHJAeT CONTA.VUOTE ANTAL.TOMMA
9802 354 -1 1 0 ROMAN ROeMISCH ROMAIN NUMERO.ROMANO ROMANO ROMEINS ROMAN ROMANO ROMERSK
9803
9804 Download this example:
9805 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/function_locale.pl
9806 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
9807 WriteExcel-2.36/examples/function_locale.pl>
9808
9809 Example: writeA1.pl
9810 This is an example of how to extend the Spreadsheet::WriteExcel module.
9811
9812 Code is appended to the Spreadsheet::WriteExcel::Worksheet module by
9813 reusing the package name. The new code provides a write() method that
9814 allows you to use Excels A1 style cell references. This is not
9815 particularly useful but it serves as an example of how the module can
9816 be extended without modifying the code directly.
9817
9818 #!/usr/bin/perl -w
9819
9820 ###############################################################################
9821 #
9822 # This is an example of how to extend the Spreadsheet::WriteExcel module.
9823 #
9824 # Code is appended to the Spreadsheet::WriteExcel::Worksheet module by reusing
9825 # the package name. The new code provides a write() method that allows you to
9826 # use Excels A1 style cell references. This is not particularly useful but it
9827 # serves as an example of how the module can be extended without modifying the
9828 # code directly.
9829 #
9830 # reverse('X'), March 2001, John McNamara, jmcnamara@cpan.org
9831 #
9832
9833 use strict;
9834 use Spreadsheet::WriteExcel;
9835
9836 # Create a new workbook called simple.xls and add a worksheet
9837 my $workbook = Spreadsheet::WriteExcel->new("writeA1.xls");
9838 my $worksheet = $workbook->add_worksheet();
9839
9840 # Write numbers or text
9841 $worksheet->write (0, 0, "Hello");
9842 $worksheet->writeA1("A3", "A3" );
9843 $worksheet->writeA1("A5", 1.2345 );
9844
9845
9846 ###############################################################################
9847 #
9848 # The following will be appended to the Spreadsheet::WriteExcel::Worksheet
9849 # package.
9850 #
9851
9852 package Spreadsheet::WriteExcel::Worksheet;
9853
9854 ###############################################################################
9855 #
9856 # writeA1($cell, $token, $format)
9857 #
9858 # Convert $cell from Excel A1 notation to $row, $col notation and
9859 # call write() on $token.
9860 #
9861 # Returns: return value of called subroutine or -4 for invalid cell
9862 # reference.
9863 #
9864 sub writeA1 {
9865 my $self = shift;
9866 my $cell = shift;
9867 my $col;
9868 my $row;
9869
9870 if ($cell =~ /([A-z]+)(\d+)/) {
9871 ($row, $col) = _convertA1($2, $1);
9872 $self->write($row, $col, @_);
9873 } else {
9874 return -4;
9875 }
9876 }
9877
9878 ###############################################################################
9879 #
9880 # _convertA1($row, $col)
9881 #
9882 # Convert Excel A1 notation to $row, $col notation. Convert base26 column
9883 # string to a number.
9884 #
9885 sub _convertA1 {
9886 my $row = $_[0];
9887 my $col = $_[1]; # String in AA notation
9888
9889 my @chars = split //, $col;
9890 my $expn = 0;
9891 $col = 0;
9892
9893 while (@chars) {
9894 my $char = uc(pop(@chars)); # LS char first
9895 $col += (ord($char) -ord('A') +1) * (26**$expn);
9896 $expn++;
9897 }
9898
9899 # Convert 1 index to 0 index
9900 $row--;
9901 $col--;
9902
9903 return($row, $col);
9904 }
9905
9906 Download this example:
9907 http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.36/examples/writeA1.pl
9908 <http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-
9909 WriteExcel-2.36/examples/writeA1.pl>
9910
9912 John McNamara jmcnamara@cpan.org
9913
9914 Contributed examples contain the original author's name.
9915
9917 Copyright MM-MMX, John McNamara.
9918
9919 All Rights Reserved. This module is free software. It may be used,
9920 redistributed and/or modified under the same terms as Perl itself.
9921
9922
9923
9924perl v5.12.0 2010-01-2S1preadsheet::WriteExcel::Examples(3)