1Excel::Writer::XLSX::ExUasmeprleCso(n3t)ributed Perl DocEuxmceenlt:a:tWirointer::XLSX::Examples(3)
2
3
4

NAME

6       Examples - Excel::Writer::XLSX example programs.
7

DESCRIPTION

9       This is a documentation only module showing the examples that are
10       included in the Excel::Writer::XLSX 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

Example programs

16       The following is a list of the 87 example programs that are included in
17       the Excel::Writer::XLSX distribution.
18
19       ·   "Example: a_simple.pl" A simple demo of some of the features.
20
21       ·   "Example: bug_report.pl" A template for submitting bug reports.
22
23       ·   "Example: demo.pl" A demo of some of the available features.
24
25       ·   "Example: formats.pl" All the available formatting on several
26           worksheets.
27
28       ·   "Example: regions.pl" A simple example of multiple worksheets.
29
30       ·   "Example: stats.pl" Basic formulas and functions.
31
32       ·   "Example: autofilter.pl" Examples of worksheet autofilters.
33
34       ·   "Example: array_formula.pl" Examples of how to write array
35           formulas.
36
37       ·   "Example: cgi.pl" A simple CGI program.
38
39       ·   "Example: chart_area.pl" A demo of area style charts.
40
41       ·   "Example: chart_bar.pl" A demo of bar (vertical histogram) style
42           charts.
43
44       ·   "Example: chart_column.pl" A demo of column (histogram) style
45           charts.
46
47       ·   "Example: chart_line.pl" A demo of line style charts.
48
49       ·   "Example: chart_pie.pl" A demo of pie style charts.
50
51       ·   "Example: chart_doughnut.pl" A demo of dougnut style charts.
52
53       ·   "Example: chart_radar.pl" A demo of radar style charts.
54
55       ·   "Example: chart_scatter.pl" A demo of scatter style charts.
56
57       ·   "Example: chart_secondary_axis.pl" A demo of a line chart with a
58           secondary axis.
59
60       ·   "Example: chart_combined.pl" A demo of a combined column and line
61           chart.
62
63       ·   "Example: chart_pareto.pl" A demo of a combined Pareto chart.
64
65       ·   "Example: chart_stock.pl" A demo of stock style charts.
66
67       ·   "Example: chart_data_table.pl" A demo of a chart with a data table
68           on the axis.
69
70       ·   "Example: chart_data_tools.pl" A demo of charts with data
71           highlighting options.
72
73       ·   "Example: chart_clustered.pl" A demo of a chart with a clustered
74           axis.
75
76       ·   "Example: chart_styles.pl" A demo of the available chart styles.
77
78       ·   "Example: colors.pl" A demo of the colour palette and named
79           colours.
80
81       ·   "Example: comments1.pl" Add comments to worksheet cells.
82
83       ·   "Example: comments2.pl" Add comments with advanced options.
84
85       ·   "Example: conditional_format.pl" Add conditional formats to a range
86           of cells.
87
88       ·   "Example: data_validate.pl" An example of data validation and
89           dropdown lists.
90
91       ·   "Example: date_time.pl" Write dates and times with
92           write_date_time().
93
94       ·   "Example: defined_name.pl" Example of how to create defined names.
95
96       ·   "Example: diag_border.pl" A simple example of diagonal cell
97           borders.
98
99       ·   "Example: filehandle.pl" Examples of working with filehandles.
100
101       ·   "Example: headers.pl" Examples of worksheet headers and footers.
102
103       ·   "Example: hide_row_col.pl" Example of hiding rows and columns.
104
105       ·   "Example: hide_sheet.pl" Simple example of hiding a worksheet.
106
107       ·   "Example: hyperlink1.pl" Shows how to create web hyperlinks.
108
109       ·   "Example: hyperlink2.pl" Examples of internal and external
110           hyperlinks.
111
112       ·   "Example: indent.pl" An example of cell indentation.
113
114       ·   "Example: macros.pl" An example of adding macros from an existing
115           file.
116
117       ·   "Example: merge1.pl" A simple example of cell merging.
118
119       ·   "Example: merge2.pl" A simple example of cell merging with
120           formatting.
121
122       ·   "Example: merge3.pl" Add hyperlinks to merged cells.
123
124       ·   "Example: merge4.pl" An advanced example of merging with
125           formatting.
126
127       ·   "Example: merge5.pl" An advanced example of merging with
128           formatting.
129
130       ·   "Example: merge6.pl" An example of merging with Unicode strings.
131
132       ·   "Example: mod_perl1.pl" A simple mod_perl 1 program.
133
134       ·   "Example: mod_perl2.pl" A simple mod_perl 2 program.
135
136       ·   "Example: outline.pl" An example of outlines and grouping.
137
138       ·   "Example: outline_collapsed.pl" An example of collapsed outlines.
139
140       ·   "Example: panes.pl" An example of how to create panes.
141
142       ·   "Example: properties.pl" Add document properties to a workbook.
143
144       ·   "Example: protection.pl" Example of cell locking and formula
145           hiding.
146
147       ·   "Example: rich_strings.pl" Example of strings with multiple
148           formats.
149
150       ·   "Example: right_to_left.pl" Change default sheet direction to right
151           to left.
152
153       ·   "Example: sales.pl" An example of a simple sales spreadsheet.
154
155       ·   "Example: shape1.pl" Insert shapes in worksheet.
156
157       ·   "Example: shape2.pl" Insert shapes in worksheet. With properties.
158
159       ·   "Example: shape3.pl" Insert shapes in worksheet. Scaled.
160
161       ·   "Example: shape4.pl" Insert shapes in worksheet. With modification.
162
163       ·   "Example: shape5.pl" Insert shapes in worksheet. With connections.
164
165       ·   "Example: shape6.pl" Insert shapes in worksheet. With connections.
166
167       ·   "Example: shape7.pl" Insert shapes in worksheet. One to many
168           connections.
169
170       ·   "Example: shape8.pl" Insert shapes in worksheet. One to many
171           connections.
172
173       ·   "Example: shape_all.pl" Demo of all the available shape and
174           connector types.
175
176       ·   "Example: sparklines1.pl" Simple sparklines demo.
177
178       ·   "Example: sparklines2.pl" Sparklines demo showing formatting
179           options.
180
181       ·   "Example: stats_ext.pl" Same as stats.pl with external references.
182
183       ·   "Example: stocks.pl" Demonstrates conditional formatting.
184
185       ·   "Example: tab_colors.pl" Example of how to set worksheet tab
186           colours.
187
188       ·   "Example: tables.pl" Add Excel tables to a worksheet.
189
190       ·   "Example: write_handler1.pl" Example of extending the write()
191           method. Step 1.
192
193       ·   "Example: write_handler2.pl" Example of extending the write()
194           method. Step 2.
195
196       ·   "Example: write_handler3.pl" Example of extending the write()
197           method. Step 3.
198
199       ·   "Example: write_handler4.pl" Example of extending the write()
200           method. Step 4.
201
202       ·   "Example: write_to_scalar.pl" Example of writing an Excel file to a
203           Perl scalar.
204
205       ·   "Example: unicode_2022_jp.pl" Japanese: ISO-2022-JP.
206
207       ·   "Example: unicode_8859_11.pl" Thai:     ISO-8859_11.
208
209       ·   "Example: unicode_8859_7.pl" Greek:    ISO-8859_7.
210
211       ·   "Example: unicode_big5.pl" Chinese:  BIG5.
212
213       ·   "Example: unicode_cp1251.pl" Russian:  CP1251.
214
215       ·   "Example: unicode_cp1256.pl" Arabic:   CP1256.
216
217       ·   "Example: unicode_cyrillic.pl" Russian:  Cyrillic.
218
219       ·   "Example: unicode_koi8r.pl" Russian:  KOI8-R.
220
221       ·   "Example: unicode_polish_utf8.pl" Polish :  UTF8.
222
223       ·   "Example: unicode_shift_jis.pl" Japanese: Shift JIS.
224
225   Example: a_simple.pl
226       A simple example of how to use the Excel::Writer::XLSX module to write
227       text and numbers to an Excel xlsx file.
228
229       Source code for this example:
230
231           #!/usr/bin/perl -w
232
233           #######################################################################
234           #
235           # A simple example of how to use the Excel::Writer::XLSX module to
236           # write text and numbers to an Excel xlsx file.
237           #
238           # reverse ('(c)'), March 2001, John McNamara, jmcnamara@cpan.org
239           #
240
241           use strict;
242           use Excel::Writer::XLSX;
243
244           # Create a new workbook called simple.xls and add a worksheet
245           my $workbook  = Excel::Writer::XLSX->new( 'a_simple.xlsx' );
246           my $worksheet = $workbook->add_worksheet();
247
248           # The general syntax is write($row, $column, $token). Note that row and
249           # column are zero indexed
250           #
251
252           # Write some text
253           $worksheet->write( 0, 0, "Hi Excel!" );
254
255
256           # Write some numbers
257           $worksheet->write( 2, 0, 3 );          # Writes 3
258           $worksheet->write( 3, 0, 3.00000 );    # Writes 3
259           $worksheet->write( 4, 0, 3.00001 );    # Writes 3.00001
260           $worksheet->write( 5, 0, 3.14159 );    # TeX revision no.?
261
262
263           # Write some formulas
264           $worksheet->write( 7, 0, '=A3 + A6' );
265           $worksheet->write( 8, 0, '=IF(A5>3,"Yes", "No")' );
266
267
268           # Write a hyperlink
269           $worksheet->write( 10, 0, 'http://www.perl.com/' );
270
271           $workbook->close();
272
273           __END__
274
275       Download this example:
276       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/a_simple.pl>
277
278   Example: bug_report.pl
279       A template for submitting a bug report.
280
281       Run this program and read the output from the command line.
282
283           #!/usr/bin/perl -w
284
285           ###############################################################################
286           #
287           # A template for submitting a bug report.
288           #
289           # Run this program and read the output from the command line.
290           #
291           # reverse ('(c)'), March 2004, John McNamara, jmcnamara@cpan.org
292           #
293
294
295           use strict;
296
297           print << 'HINTS_1';
298
299           REPORTING A BUG OR ASKING A QUESTION
300
301               Feel free to report bugs or ask questions. However, to save time
302               consider the following steps first:
303
304               Read the documentation:
305
306                   The Excel::Writer::XLSX documentation has been refined in
307                   response to user questions. Therefore, if you have a question it is
308                   possible that someone else has asked it before you and that it is
309                   already addressed in the documentation. Since there is a lot of
310                   documentation to get through you should at least read the table of
311                   contents and search for keywords that you are interested in.
312
313               Look at the example programs:
314
315                   There are over 80 example programs shipped with the standard
316                   Excel::Writer::XLSX distribution. Many of these were created
317                   in response to user questions. Try to identify an example program
318                   that corresponds to your query and adapt it to your needs.
319
320           HINTS_1
321           print "Press enter ..."; <STDIN>;
322
323           print << 'HINTS_2';
324
325               If you submit a bug report here are some pointers.
326
327               1.  Put "Excel::Writer::XLSX:" at the beginning of the subject line.
328                   This helps to filter genuine messages from spam.
329
330               2.  Describe the problems as clearly and as concisely as possible.
331
332               3.  Send a sample program. It is often easier to describe a problem in
333                   code than in written prose.
334
335               4.  The sample program should be as small as possible to demonstrate the
336                   problem. Don't copy and past large sections of your program. The
337                   program should also be self contained and working.
338
339               A sample bug report is generated below. If you use this format then it
340               will help to analyse your question and respond to it more quickly.
341
342               Please don't send patches without contacting the author first.
343
344
345           HINTS_2
346           print "Press enter ..."; <STDIN>;
347
348
349           print << 'EMAIL';
350
351           =======================================================================
352
353           To:      John McNamara <jmcnamara@cpan.org>
354           Subject: Excel::Writer::XLSX: Problem with something.
355
356           Hi John,
357
358           I am using Excel::Writer::XLSX and I have encountered a problem. I
359           want it to do SOMETHING but the module appears to do SOMETHING_ELSE.
360
361           Here is some code that demonstrates the problem.
362
363               #!/usr/bin/perl -w
364
365               use strict;
366               use Excel::Writer::XLSX;
367
368               my $workbook  = Excel::Writer::XLSX->new("reload.xls");
369               my $worksheet = $workbook->add_worksheet();
370
371               $worksheet->write(0, 0, "Hi Excel!");
372
373               $workbook->close();
374
375               __END__
376
377           My automatically generated system details are as follows:
378           EMAIL
379
380
381           print "\n    Perl version   : $]";
382           print "\n    OS name        : $^O";
383           print "\n    Module versions: (not all are required)\n";
384
385
386           my @modules = qw(
387                             Excel::Writer::XLSX
388                             Spreadsheet::WriteExcel
389                             Archive::Zip
390                             XML::Writer
391                             IO::File
392                             File::Temp
393                           );
394
395
396           for my $module (@modules) {
397               my $version;
398               eval "require $module";
399
400               if (not $@) {
401                   $version = $module->VERSION;
402                   $version = '(unknown)' if not defined $version;
403               }
404               else {
405                   $version = '(not installed)';
406               }
407
408               printf "%21s%-24s\t%s\n", "", $module, $version;
409           }
410
411
412           print << "BYE";
413           Yours etc.,
414
415           A. Person
416           --
417
418           BYE
419
420           __END__
421
422       Download this example:
423       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/bug_report.pl>
424
425   Example: demo.pl
426       A simple demo of some of the features of Excel::Writer::XLSX.
427
428       This program is used to create the project screenshot for Freshmeat:
429       <http://freshmeat.net/projects/writeexcel/>
430
431       Source code for this example:
432
433           #!/usr/bin/perl -w
434
435           #######################################################################
436           #
437           # A simple demo of some of the features of Excel::Writer::XLSX.
438           #
439           # This program is used to create the project screenshot for Freshmeat:
440           # L<http://freshmeat.net/projects/writeexcel/>
441           #
442           # reverse ('(c)'), October 2001, John McNamara, jmcnamara@cpan.org
443           #
444
445           use strict;
446           use Excel::Writer::XLSX;
447
448           my $workbook   = Excel::Writer::XLSX->new( 'demo.xlsx' );
449           my $worksheet  = $workbook->add_worksheet( 'Demo' );
450           my $worksheet2 = $workbook->add_worksheet( 'Another sheet' );
451           my $worksheet3 = $workbook->add_worksheet( 'And another' );
452
453           my $bold = $workbook->add_format( bold => 1 );
454
455
456           #######################################################################
457           #
458           # Write a general heading
459           #
460           $worksheet->set_column( 'A:A', 36, $bold );
461           $worksheet->set_column( 'B:B', 20 );
462           $worksheet->set_row( 0, 40 );
463
464           my $heading = $workbook->add_format(
465               bold  => 1,
466               color => 'blue',
467               size  => 16,
468               merge => 1,
469               align => 'vcenter',
470           );
471
472           my @headings = ( 'Features of Excel::Writer::XLSX', '' );
473           $worksheet->write_row( 'A1', \@headings, $heading );
474
475
476           #######################################################################
477           #
478           # Some text examples
479           #
480           my $text_format = $workbook->add_format(
481               bold   => 1,
482               italic => 1,
483               color  => 'red',
484               size   => 18,
485               font   => 'Lucida Calligraphy'
486           );
487
488
489           $worksheet->write( 'A2', "Text" );
490           $worksheet->write( 'B2', "Hello Excel" );
491           $worksheet->write( 'A3', "Formatted text" );
492           $worksheet->write( 'B3', "Hello Excel", $text_format );
493           $worksheet->write( 'A4', "Unicode text" );
494           $worksheet->write( 'B4', "\x{0410} \x{0411} \x{0412} \x{0413} \x{0414}" );
495
496           #######################################################################
497           #
498           # Some numeric examples
499           #
500           my $num1_format = $workbook->add_format( num_format => '$#,##0.00' );
501           my $num2_format = $workbook->add_format( num_format => ' d mmmm yyy' );
502
503
504           $worksheet->write( 'A5', "Numbers" );
505           $worksheet->write( 'B5', 1234.56 );
506           $worksheet->write( 'A6', "Formatted numbers" );
507           $worksheet->write( 'B6', 1234.56, $num1_format );
508           $worksheet->write( 'A7', "Formatted numbers" );
509           $worksheet->write( 'B7', 37257, $num2_format );
510
511
512           #######################################################################
513           #
514           # Formulae
515           #
516           $worksheet->set_selection( 'B8' );
517           $worksheet->write( 'A8', 'Formulas and functions, "=SIN(PI()/4)"' );
518           $worksheet->write( 'B8', '=SIN(PI()/4)' );
519
520
521           #######################################################################
522           #
523           # Hyperlinks
524           #
525           $worksheet->write( 'A9', "Hyperlinks" );
526           $worksheet->write( 'B9', 'http://www.perl.com/' );
527
528
529           #######################################################################
530           #
531           # Images
532           #
533           $worksheet->write( 'A10', "Images" );
534           $worksheet->insert_image( 'B10', 'republic.png', 16, 8 );
535
536
537           #######################################################################
538           #
539           # Misc
540           #
541           $worksheet->write( 'A18', "Page/printer setup" );
542           $worksheet->write( 'A19', "Multiple worksheets" );
543
544           $workbook->close();
545
546           __END__
547
548       Download this example:
549       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/demo.pl>
550
551   Example: formats.pl
552       Examples of formatting using the Excel::Writer::XLSX module.
553
554       This program demonstrates almost all possible formatting options. It is
555       worth running this program and viewing the output Excel file if you are
556       interested in the various formatting possibilities.
557
558       Source code for this example:
559
560           #!/usr/bin/perl -w
561
562           ###############################################################################
563           #
564           # Examples of formatting using the Excel::Writer::XLSX module.
565           #
566           # This program demonstrates almost all possible formatting options. It is worth
567           # running this program and viewing the output Excel file if you are interested
568           # in the various formatting possibilities.
569           #
570           # reverse ('(c)'), September 2002, John McNamara, jmcnamara@cpan.org
571           #
572
573           use strict;
574           use Excel::Writer::XLSX;
575
576           my $workbook = Excel::Writer::XLSX->new( 'formats.xlsx' );
577
578           # Some common formats
579           my $center = $workbook->add_format( align => 'center' );
580           my $heading = $workbook->add_format( align => 'center', bold => 1 );
581
582           # The named colors
583           my %colors = (
584               0x08, 'black',
585               0x0C, 'blue',
586               0x10, 'brown',
587               0x0F, 'cyan',
588               0x17, 'gray',
589               0x11, 'green',
590               0x0B, 'lime',
591               0x0E, 'magenta',
592               0x12, 'navy',
593               0x35, 'orange',
594               0x21, 'pink',
595               0x14, 'purple',
596               0x0A, 'red',
597               0x16, 'silver',
598               0x09, 'white',
599               0x0D, 'yellow',
600
601           );
602
603           # Call these subroutines to demonstrate different formatting options
604           intro();
605           fonts();
606           named_colors();
607           standard_colors();
608           numeric_formats();
609           borders();
610           patterns();
611           alignment();
612           misc();
613
614           # Note: this is required
615           $workbook->close();
616
617
618           ######################################################################
619           #
620           # Intro.
621           #
622           sub intro {
623
624               my $worksheet = $workbook->add_worksheet( 'Introduction' );
625
626               $worksheet->set_column( 0, 0, 60 );
627
628               my $format = $workbook->add_format();
629               $format->set_bold();
630               $format->set_size( 14 );
631               $format->set_color( 'blue' );
632               $format->set_align( 'center' );
633
634               my $format2 = $workbook->add_format();
635               $format2->set_bold();
636               $format2->set_color( 'blue' );
637
638               my $format3 = $workbook->add_format(
639                   color     => 'blue',
640                   underline => 1,
641               );
642
643               $worksheet->write( 2, 0, 'This workbook demonstrates some of', $format );
644               $worksheet->write( 3, 0, 'the formatting options provided by', $format );
645               $worksheet->write( 4, 0, 'the Excel::Writer::XLSX module.',    $format );
646               $worksheet->write( 'A7', 'Sections:', $format2 );
647
648               $worksheet->write( 'A8', "internal:Fonts!A1", 'Fonts', $format3 );
649
650               $worksheet->write( 'A9', "internal:'Named colors'!A1",
651                   'Named colors', $format3 );
652
653               $worksheet->write(
654                   'A10',
655                   "internal:'Standard colors'!A1",
656                   'Standard colors', $format3
657               );
658
659               $worksheet->write(
660                   'A11',
661                   "internal:'Numeric formats'!A1",
662                   'Numeric formats', $format3
663               );
664
665               $worksheet->write( 'A12', "internal:Borders!A1", 'Borders', $format3 );
666               $worksheet->write( 'A13', "internal:Patterns!A1", 'Patterns', $format3 );
667               $worksheet->write( 'A14', "internal:Alignment!A1", 'Alignment', $format3 );
668               $worksheet->write( 'A15', "internal:Miscellaneous!A1", 'Miscellaneous',
669                   $format3 );
670
671           }
672
673
674           ######################################################################
675           #
676           # Demonstrate the named colors.
677           #
678           sub named_colors {
679
680               my $worksheet = $workbook->add_worksheet( 'Named colors' );
681
682               $worksheet->set_column( 0, 3, 15 );
683
684               $worksheet->write( 0, 0, "Index", $heading );
685               $worksheet->write( 0, 1, "Index", $heading );
686               $worksheet->write( 0, 2, "Name",  $heading );
687               $worksheet->write( 0, 3, "Color", $heading );
688
689               my $i = 1;
690
691               while ( my ( $index, $color ) = each %colors ) {
692                   my $format = $workbook->add_format(
693                       bg_color => $color,
694                       pattern  => 1,
695                       border   => 1
696                   );
697
698                   $worksheet->write( $i + 1, 0, $index, $center );
699                   $worksheet->write( $i + 1, 1, sprintf( "0x%02X", $index ), $center );
700                   $worksheet->write( $i + 1, 2, $color, $center );
701                   $worksheet->write( $i + 1, 3, '',     $format );
702                   $i++;
703               }
704           }
705
706
707           ######################################################################
708           #
709           # Demonstrate the standard Excel colors in the range 8..63.
710           #
711           sub standard_colors {
712
713               my $worksheet = $workbook->add_worksheet( 'Standard colors' );
714
715               $worksheet->set_column( 0, 3, 15 );
716
717               $worksheet->write( 0, 0, "Index", $heading );
718               $worksheet->write( 0, 1, "Index", $heading );
719               $worksheet->write( 0, 2, "Color", $heading );
720               $worksheet->write( 0, 3, "Name",  $heading );
721
722               for my $i ( 8 .. 63 ) {
723                   my $format = $workbook->add_format(
724                       bg_color => $i,
725                       pattern  => 1,
726                       border   => 1
727                   );
728
729                   $worksheet->write( ( $i - 7 ), 0, $i, $center );
730                   $worksheet->write( ( $i - 7 ), 1, sprintf( "0x%02X", $i ), $center );
731                   $worksheet->write( ( $i - 7 ), 2, '', $format );
732
733                   # Add the  color names
734                   if ( exists $colors{$i} ) {
735                       $worksheet->write( ( $i - 7 ), 3, $colors{$i}, $center );
736
737                   }
738               }
739           }
740
741
742           ######################################################################
743           #
744           # Demonstrate the standard numeric formats.
745           #
746           sub numeric_formats {
747
748               my $worksheet = $workbook->add_worksheet( 'Numeric formats' );
749
750               $worksheet->set_column( 0, 4, 15 );
751               $worksheet->set_column( 5, 5, 45 );
752
753               $worksheet->write( 0, 0, "Index",       $heading );
754               $worksheet->write( 0, 1, "Index",       $heading );
755               $worksheet->write( 0, 2, "Unformatted", $heading );
756               $worksheet->write( 0, 3, "Formatted",   $heading );
757               $worksheet->write( 0, 4, "Negative",    $heading );
758               $worksheet->write( 0, 5, "Format",      $heading );
759
760               #<<<
761               my @formats;
762               push @formats, [ 0x00, 1234.567,   0,         'General' ];
763               push @formats, [ 0x01, 1234.567,   0,         '0' ];
764               push @formats, [ 0x02, 1234.567,   0,         '0.00' ];
765               push @formats, [ 0x03, 1234.567,   0,         '#,##0' ];
766               push @formats, [ 0x04, 1234.567,   0,         '#,##0.00' ];
767               push @formats, [ 0x05, 1234.567,   -1234.567, '($#,##0_);($#,##0)' ];
768               push @formats, [ 0x06, 1234.567,   -1234.567, '($#,##0_);[Red]($#,##0)' ];
769               push @formats, [ 0x07, 1234.567,   -1234.567, '($#,##0.00_);($#,##0.00)' ];
770               push @formats, [ 0x08, 1234.567,   -1234.567, '($#,##0.00_);[Red]($#,##0.00)' ];
771               push @formats, [ 0x09, 0.567,      0,         '0%' ];
772               push @formats, [ 0x0a, 0.567,      0,         '0.00%' ];
773               push @formats, [ 0x0b, 1234.567,   0,         '0.00E+00' ];
774               push @formats, [ 0x0c, 0.75,       0,         '# ?/?' ];
775               push @formats, [ 0x0d, 0.3125,     0,         '# ??/??' ];
776               push @formats, [ 0x0e, 36892.521,  0,         'm/d/yy' ];
777               push @formats, [ 0x0f, 36892.521,  0,         'd-mmm-yy' ];
778               push @formats, [ 0x10, 36892.521,  0,         'd-mmm' ];
779               push @formats, [ 0x11, 36892.521,  0,         'mmm-yy' ];
780               push @formats, [ 0x12, 36892.521,  0,         'h:mm AM/PM' ];
781               push @formats, [ 0x13, 36892.521,  0,         'h:mm:ss AM/PM' ];
782               push @formats, [ 0x14, 36892.521,  0,         'h:mm' ];
783               push @formats, [ 0x15, 36892.521,  0,         'h:mm:ss' ];
784               push @formats, [ 0x16, 36892.521,  0,         'm/d/yy h:mm' ];
785               push @formats, [ 0x25, 1234.567,   -1234.567, '(#,##0_);(#,##0)' ];
786               push @formats, [ 0x26, 1234.567,   -1234.567, '(#,##0_);[Red](#,##0)' ];
787               push @formats, [ 0x27, 1234.567,   -1234.567, '(#,##0.00_);(#,##0.00)' ];
788               push @formats, [ 0x28, 1234.567,   -1234.567, '(#,##0.00_);[Red](#,##0.00)' ];
789               push @formats, [ 0x29, 1234.567,   -1234.567, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' ];
790               push @formats, [ 0x2a, 1234.567,   -1234.567, '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' ];
791               push @formats, [ 0x2b, 1234.567,   -1234.567, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' ];
792               push @formats, [ 0x2c, 1234.567,   -1234.567, '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' ];
793               push @formats, [ 0x2d, 36892.521,  0,         'mm:ss' ];
794               push @formats, [ 0x2e, 3.0153,     0,         '[h]:mm:ss' ];
795               push @formats, [ 0x2f, 36892.521,  0,         'mm:ss.0' ];
796               push @formats, [ 0x30, 1234.567,   0,         '##0.0E+0' ];
797               push @formats, [ 0x31, 1234.567,   0,         '@' ];
798               #>>>
799
800               my $i;
801               foreach my $format ( @formats ) {
802                   my $style = $workbook->add_format();
803                   $style->set_num_format( $format->[0] );
804
805                   $i++;
806                   $worksheet->write( $i, 0, $format->[0], $center );
807                   $worksheet->write( $i, 1, sprintf( "0x%02X", $format->[0] ), $center );
808                   $worksheet->write( $i, 2, $format->[1], $center );
809                   $worksheet->write( $i, 3, $format->[1], $style );
810
811                   if ( $format->[2] ) {
812                       $worksheet->write( $i, 4, $format->[2], $style );
813                   }
814
815                   $worksheet->write_string( $i, 5, $format->[3] );
816               }
817           }
818
819
820           ######################################################################
821           #
822           # Demonstrate the font options.
823           #
824           sub fonts {
825
826               my $worksheet = $workbook->add_worksheet( 'Fonts' );
827
828               $worksheet->set_column( 0, 0, 30 );
829               $worksheet->set_column( 1, 1, 10 );
830
831               $worksheet->write( 0, 0, "Font name", $heading );
832               $worksheet->write( 0, 1, "Font size", $heading );
833
834               my @fonts;
835               push @fonts, [ 10, 'Arial' ];
836               push @fonts, [ 12, 'Arial' ];
837               push @fonts, [ 14, 'Arial' ];
838               push @fonts, [ 12, 'Arial Black' ];
839               push @fonts, [ 12, 'Arial Narrow' ];
840               push @fonts, [ 12, 'Century Schoolbook' ];
841               push @fonts, [ 12, 'Courier' ];
842               push @fonts, [ 12, 'Courier New' ];
843               push @fonts, [ 12, 'Garamond' ];
844               push @fonts, [ 12, 'Impact' ];
845               push @fonts, [ 12, 'Lucida Handwriting' ];
846               push @fonts, [ 12, 'Times New Roman' ];
847               push @fonts, [ 12, 'Symbol' ];
848               push @fonts, [ 12, 'Wingdings' ];
849               push @fonts, [ 12, 'A font that doesn\'t exist' ];
850
851               my $i;
852               foreach my $font ( @fonts ) {
853                   my $format = $workbook->add_format();
854
855                   $format->set_size( $font->[0] );
856                   $format->set_font( $font->[1] );
857
858                   $i++;
859                   $worksheet->write( $i, 0, $font->[1], $format );
860                   $worksheet->write( $i, 1, $font->[0], $format );
861               }
862
863           }
864
865
866           ######################################################################
867           #
868           # Demonstrate the standard Excel border styles.
869           #
870           sub borders {
871
872               my $worksheet = $workbook->add_worksheet( 'Borders' );
873
874               $worksheet->set_column( 0, 4, 10 );
875               $worksheet->set_column( 5, 5, 40 );
876
877               $worksheet->write( 0, 0, "Index",                                $heading );
878               $worksheet->write( 0, 1, "Index",                                $heading );
879               $worksheet->write( 0, 3, "Style",                                $heading );
880               $worksheet->write( 0, 5, "The style is highlighted in red for ", $heading );
881               $worksheet->write( 1, 5, "emphasis, the default color is black.",
882                   $heading );
883
884               for my $i ( 0 .. 13 ) {
885                   my $format = $workbook->add_format();
886                   $format->set_border( $i );
887                   $format->set_border_color( 'red' );
888                   $format->set_align( 'center' );
889
890                   $worksheet->write( ( 2 * ( $i + 1 ) ), 0, $i, $center );
891                   $worksheet->write( ( 2 * ( $i + 1 ) ),
892                       1, sprintf( "0x%02X", $i ), $center );
893
894                   $worksheet->write( ( 2 * ( $i + 1 ) ), 3, "Border", $format );
895               }
896
897               $worksheet->write( 30, 0, "Diag type",             $heading );
898               $worksheet->write( 30, 1, "Index",                 $heading );
899               $worksheet->write( 30, 3, "Style",                 $heading );
900               $worksheet->write( 30, 5, "Diagonal Boder styles", $heading );
901
902               for my $i ( 1 .. 3 ) {
903                   my $format = $workbook->add_format();
904                   $format->set_diag_type( $i );
905                   $format->set_diag_border( 1 );
906                   $format->set_diag_color( 'red' );
907                   $format->set_align( 'center' );
908
909                   $worksheet->write( ( 2 * ( $i + 15 ) ), 0, $i, $center );
910                   $worksheet->write( ( 2 * ( $i + 15 ) ),
911                       1, sprintf( "0x%02X", $i ), $center );
912
913                   $worksheet->write( ( 2 * ( $i + 15 ) ), 3, "Border", $format );
914               }
915           }
916
917
918           ######################################################################
919           #
920           # Demonstrate the standard Excel cell patterns.
921           #
922           sub patterns {
923
924               my $worksheet = $workbook->add_worksheet( 'Patterns' );
925
926               $worksheet->set_column( 0, 4, 10 );
927               $worksheet->set_column( 5, 5, 50 );
928
929               $worksheet->write( 0, 0, "Index",   $heading );
930               $worksheet->write( 0, 1, "Index",   $heading );
931               $worksheet->write( 0, 3, "Pattern", $heading );
932
933               $worksheet->write( 0, 5, "The background colour has been set to silver.",
934                   $heading );
935               $worksheet->write( 1, 5, "The foreground colour has been set to green.",
936                   $heading );
937
938               for my $i ( 0 .. 18 ) {
939                   my $format = $workbook->add_format();
940
941                   $format->set_pattern( $i );
942                   $format->set_bg_color( 'silver' );
943                   $format->set_fg_color( 'green' );
944                   $format->set_align( 'center' );
945
946                   $worksheet->write( ( 2 * ( $i + 1 ) ), 0, $i, $center );
947                   $worksheet->write( ( 2 * ( $i + 1 ) ),
948                       1, sprintf( "0x%02X", $i ), $center );
949
950                   $worksheet->write( ( 2 * ( $i + 1 ) ), 3, "Pattern", $format );
951
952                   if ( $i == 1 ) {
953                       $worksheet->write( ( 2 * ( $i + 1 ) ),
954                           5, "This is solid colour, the most useful pattern.", $heading );
955                   }
956               }
957           }
958
959
960           ######################################################################
961           #
962           # Demonstrate the standard Excel cell alignments.
963           #
964           sub alignment {
965
966               my $worksheet = $workbook->add_worksheet( 'Alignment' );
967
968               $worksheet->set_column( 0, 7, 12 );
969               $worksheet->set_row( 0, 40 );
970               $worksheet->set_selection( 7, 0 );
971
972               my $format01 = $workbook->add_format();
973               my $format02 = $workbook->add_format();
974               my $format03 = $workbook->add_format();
975               my $format04 = $workbook->add_format();
976               my $format05 = $workbook->add_format();
977               my $format06 = $workbook->add_format();
978               my $format07 = $workbook->add_format();
979               my $format08 = $workbook->add_format();
980               my $format09 = $workbook->add_format();
981               my $format10 = $workbook->add_format();
982               my $format11 = $workbook->add_format();
983               my $format12 = $workbook->add_format();
984               my $format13 = $workbook->add_format();
985               my $format14 = $workbook->add_format();
986               my $format15 = $workbook->add_format();
987               my $format16 = $workbook->add_format();
988               my $format17 = $workbook->add_format();
989
990               $format02->set_align( 'top' );
991               $format03->set_align( 'bottom' );
992               $format04->set_align( 'vcenter' );
993               $format05->set_align( 'vjustify' );
994               $format06->set_text_wrap();
995
996               $format07->set_align( 'left' );
997               $format08->set_align( 'right' );
998               $format09->set_align( 'center' );
999               $format10->set_align( 'fill' );
1000               $format11->set_align( 'justify' );
1001               $format12->set_merge();
1002
1003               $format13->set_rotation( 45 );
1004               $format14->set_rotation( -45 );
1005               $format15->set_rotation( 270 );
1006
1007               $format16->set_shrink();
1008               $format17->set_indent( 1 );
1009
1010               $worksheet->write( 0, 0, 'Vertical',   $heading );
1011               $worksheet->write( 0, 1, 'top',        $format02 );
1012               $worksheet->write( 0, 2, 'bottom',     $format03 );
1013               $worksheet->write( 0, 3, 'vcenter',    $format04 );
1014               $worksheet->write( 0, 4, 'vjustify',   $format05 );
1015               $worksheet->write( 0, 5, "text\nwrap", $format06 );
1016
1017               $worksheet->write( 2, 0, 'Horizontal', $heading );
1018               $worksheet->write( 2, 1, 'left',       $format07 );
1019               $worksheet->write( 2, 2, 'right',      $format08 );
1020               $worksheet->write( 2, 3, 'center',     $format09 );
1021               $worksheet->write( 2, 4, 'fill',       $format10 );
1022               $worksheet->write( 2, 5, 'justify',    $format11 );
1023
1024               $worksheet->write( 3, 1, 'merge', $format12 );
1025               $worksheet->write( 3, 2, '',      $format12 );
1026
1027               $worksheet->write( 3, 3, 'Shrink ' x 3, $format16 );
1028               $worksheet->write( 3, 4, 'Indent',      $format17 );
1029
1030
1031               $worksheet->write( 5, 0, 'Rotation',   $heading );
1032               $worksheet->write( 5, 1, 'Rotate 45',  $format13 );
1033               $worksheet->write( 6, 1, 'Rotate -45', $format14 );
1034               $worksheet->write( 7, 1, 'Rotate 270', $format15 );
1035           }
1036
1037
1038           ######################################################################
1039           #
1040           # Demonstrate other miscellaneous features.
1041           #
1042           sub misc {
1043
1044               my $worksheet = $workbook->add_worksheet( 'Miscellaneous' );
1045
1046               $worksheet->set_column( 2, 2, 25 );
1047
1048               my $format01 = $workbook->add_format();
1049               my $format02 = $workbook->add_format();
1050               my $format03 = $workbook->add_format();
1051               my $format04 = $workbook->add_format();
1052               my $format05 = $workbook->add_format();
1053               my $format06 = $workbook->add_format();
1054               my $format07 = $workbook->add_format();
1055
1056               $format01->set_underline( 0x01 );
1057               $format02->set_underline( 0x02 );
1058               $format03->set_underline( 0x21 );
1059               $format04->set_underline( 0x22 );
1060               $format05->set_font_strikeout();
1061               $format06->set_font_outline();
1062               $format07->set_font_shadow();
1063
1064               $worksheet->write( 1,  2, 'Underline  0x01',          $format01 );
1065               $worksheet->write( 3,  2, 'Underline  0x02',          $format02 );
1066               $worksheet->write( 5,  2, 'Underline  0x21',          $format03 );
1067               $worksheet->write( 7,  2, 'Underline  0x22',          $format04 );
1068               $worksheet->write( 9,  2, 'Strikeout',                $format05 );
1069               $worksheet->write( 11, 2, 'Outline (Macintosh only)', $format06 );
1070               $worksheet->write( 13, 2, 'Shadow (Macintosh only)',  $format07 );
1071           }
1072
1073
1074           $workbook->close();
1075
1076           __END__
1077
1078       Download this example:
1079       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/formats.pl>
1080
1081   Example: regions.pl
1082       An example of how to use the Excel::Writer::XLSX module to write a
1083       basic Excel workbook with multiple worksheets.
1084
1085       Source code for this example:
1086
1087           #!/usr/bin/perl -w
1088
1089           ###############################################################################
1090           #
1091           # An example of how to use the Excel::Writer::XLSX module to write a basic
1092           # Excel workbook with multiple worksheets.
1093           #
1094           # reverse ('(c)'), March 2001, John McNamara, jmcnamara@cpan.org
1095           #
1096
1097           use strict;
1098           use Excel::Writer::XLSX;
1099
1100           # Create a new Excel workbook
1101           my $workbook = Excel::Writer::XLSX->new( 'regions.xlsx' );
1102
1103           # Add some worksheets
1104           my $north = $workbook->add_worksheet( "North" );
1105           my $south = $workbook->add_worksheet( "South" );
1106           my $east  = $workbook->add_worksheet( "East" );
1107           my $west  = $workbook->add_worksheet( "West" );
1108
1109           # Add a Format
1110           my $format = $workbook->add_format();
1111           $format->set_bold();
1112           $format->set_color( 'blue' );
1113
1114           # Add a caption to each worksheet
1115           foreach my $worksheet ( $workbook->sheets() ) {
1116               $worksheet->write( 0, 0, "Sales", $format );
1117           }
1118
1119           # Write some data
1120           $north->write( 0, 1, 200000 );
1121           $south->write( 0, 1, 100000 );
1122           $east->write( 0, 1, 150000 );
1123           $west->write( 0, 1, 100000 );
1124
1125           # Set the active worksheet
1126           $south->activate();
1127
1128           # Set the width of the first column
1129           $south->set_column( 0, 0, 20 );
1130
1131           # Set the active cell
1132           $south->set_selection( 0, 1 );
1133
1134           $workbook->close();
1135
1136           __END__
1137
1138       Download this example:
1139       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/regions.pl>
1140
1141   Example: stats.pl
1142       A simple example of how to use functions with the Excel::Writer::XLSX
1143       module.
1144
1145       Source code for this example:
1146
1147           #!/usr/bin/perl -w
1148
1149           ###############################################################################
1150           #
1151           # A simple example of how to use functions with the Excel::Writer::XLSX
1152           # module.
1153           #
1154           # reverse ('(c)'), March 2001, John McNamara, jmcnamara@cpan.org
1155           #
1156
1157           use strict;
1158           use Excel::Writer::XLSX;
1159
1160           # Create a new workbook and add a worksheet
1161           my $workbook  = Excel::Writer::XLSX->new( 'stats.xlsx' );
1162           my $worksheet = $workbook->add_worksheet( 'Test data' );
1163
1164           # Set the column width for columns 1
1165           $worksheet->set_column( 0, 0, 20 );
1166
1167
1168           # Create a format for the headings
1169           my $format = $workbook->add_format();
1170           $format->set_bold();
1171
1172
1173           # Write the sample data
1174           $worksheet->write( 0, 0, 'Sample', $format );
1175           $worksheet->write( 0, 1, 1 );
1176           $worksheet->write( 0, 2, 2 );
1177           $worksheet->write( 0, 3, 3 );
1178           $worksheet->write( 0, 4, 4 );
1179           $worksheet->write( 0, 5, 5 );
1180           $worksheet->write( 0, 6, 6 );
1181           $worksheet->write( 0, 7, 7 );
1182           $worksheet->write( 0, 8, 8 );
1183
1184           $worksheet->write( 1, 0, 'Length', $format );
1185           $worksheet->write( 1, 1, 25.4 );
1186           $worksheet->write( 1, 2, 25.4 );
1187           $worksheet->write( 1, 3, 24.8 );
1188           $worksheet->write( 1, 4, 25.0 );
1189           $worksheet->write( 1, 5, 25.3 );
1190           $worksheet->write( 1, 6, 24.9 );
1191           $worksheet->write( 1, 7, 25.2 );
1192           $worksheet->write( 1, 8, 24.8 );
1193
1194           # Write some statistical functions
1195           $worksheet->write( 4, 0, 'Count', $format );
1196           $worksheet->write( 4, 1, '=COUNT(B1:I1)' );
1197
1198           $worksheet->write( 5, 0, 'Sum', $format );
1199           $worksheet->write( 5, 1, '=SUM(B2:I2)' );
1200
1201           $worksheet->write( 6, 0, 'Average', $format );
1202           $worksheet->write( 6, 1, '=AVERAGE(B2:I2)' );
1203
1204           $worksheet->write( 7, 0, 'Min', $format );
1205           $worksheet->write( 7, 1, '=MIN(B2:I2)' );
1206
1207           $worksheet->write( 8, 0, 'Max', $format );
1208           $worksheet->write( 8, 1, '=MAX(B2:I2)' );
1209
1210           $worksheet->write( 9, 0, 'Standard Deviation', $format );
1211           $worksheet->write( 9, 1, '=STDEV(B2:I2)' );
1212
1213           $worksheet->write( 10, 0, 'Kurtosis', $format );
1214           $worksheet->write( 10, 1, '=KURT(B2:I2)' );
1215
1216           $workbook->close();
1217
1218           __END__
1219
1220       Download this example:
1221       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/stats.pl>
1222
1223   Example: autofilter.pl
1224       An example of how to create autofilters with Excel::Writer::XLSX.
1225
1226       An autofilter is a way of adding drop down lists to the headers of a 2D
1227       range of worksheet data. This allows users to filter the data based on
1228       simple criteria so that some data is shown and some is hidden.
1229
1230       Source code for this example:
1231
1232           #!/usr/bin/perl
1233
1234           ###############################################################################
1235           #
1236           # An example of how to create autofilters with Excel::Writer::XLSX.
1237           #
1238           # An autofilter is a way of adding drop down lists to the headers of a 2D range
1239           # of worksheet data. This allows users to filter the data based on
1240           # simple criteria so that some data is shown and some is hidden.
1241           #
1242           # reverse ('(c)'), September 2007, John McNamara, jmcnamara@cpan.org
1243           #
1244
1245           use strict;
1246           use warnings;
1247           use Excel::Writer::XLSX;
1248
1249           my $workbook = Excel::Writer::XLSX->new( 'autofilter.xlsx' );
1250
1251           my $worksheet1 = $workbook->add_worksheet();
1252           my $worksheet2 = $workbook->add_worksheet();
1253           my $worksheet3 = $workbook->add_worksheet();
1254           my $worksheet4 = $workbook->add_worksheet();
1255           my $worksheet5 = $workbook->add_worksheet();
1256           my $worksheet6 = $workbook->add_worksheet();
1257
1258           my $bold = $workbook->add_format( bold => 1 );
1259
1260
1261           # Extract the data embedded at the end of this file.
1262           my @headings = split ' ', <DATA>;
1263           my @data;
1264           push @data, [split] while <DATA>;
1265
1266
1267           # Set up several sheets with the same data.
1268           for my $worksheet ( $workbook->sheets() ) {
1269               $worksheet->set_column( 'A:D', 12 );
1270               $worksheet->set_row( 0, 20, $bold );
1271               $worksheet->write( 'A1', \@headings );
1272           }
1273
1274
1275           ###############################################################################
1276           #
1277           # Example 1. Autofilter without conditions.
1278           #
1279
1280           $worksheet1->autofilter( 'A1:D51' );
1281           $worksheet1->write( 'A2', [ [@data] ] );
1282
1283
1284           ###############################################################################
1285           #
1286           #
1287           # Example 2. Autofilter with a filter condition in the first column.
1288           #
1289
1290           # The range in this example is the same as above but in row-column notation.
1291           $worksheet2->autofilter( 0, 0, 50, 3 );
1292
1293           # The placeholder "Region" in the filter is ignored and can be any string
1294           # that adds clarity to the expression.
1295           #
1296           $worksheet2->filter_column( 0, 'Region eq East' );
1297
1298           #
1299           # Hide the rows that don't match the filter criteria.
1300           #
1301           my $row = 1;
1302
1303           for my $row_data ( @data ) {
1304               my $region = $row_data->[0];
1305
1306               if ( $region eq 'East' ) {
1307
1308                   # Row is visible.
1309               }
1310               else {
1311
1312                   # Hide row.
1313                   $worksheet2->set_row( $row, undef, undef, 1 );
1314               }
1315
1316               $worksheet2->write( $row++, 0, $row_data );
1317           }
1318
1319
1320           ###############################################################################
1321           #
1322           #
1323           # Example 3. Autofilter with a dual filter condition in one of the columns.
1324           #
1325
1326           $worksheet3->autofilter( 'A1:D51' );
1327
1328           $worksheet3->filter_column( 'A', 'x eq East or x eq South' );
1329
1330           #
1331           # Hide the rows that don't match the filter criteria.
1332           #
1333           $row = 1;
1334
1335           for my $row_data ( @data ) {
1336               my $region = $row_data->[0];
1337
1338               if ( $region eq 'East' or $region eq 'South' ) {
1339
1340                   # Row is visible.
1341               }
1342               else {
1343
1344                   # Hide row.
1345                   $worksheet3->set_row( $row, undef, undef, 1 );
1346               }
1347
1348               $worksheet3->write( $row++, 0, $row_data );
1349           }
1350
1351
1352           ###############################################################################
1353           #
1354           #
1355           # Example 4. Autofilter with filter conditions in two columns.
1356           #
1357
1358           $worksheet4->autofilter( 'A1:D51' );
1359
1360           $worksheet4->filter_column( 'A', 'x eq East' );
1361           $worksheet4->filter_column( 'C', 'x > 3000 and x < 8000' );
1362
1363           #
1364           # Hide the rows that don't match the filter criteria.
1365           #
1366           $row = 1;
1367
1368           for my $row_data ( @data ) {
1369               my $region = $row_data->[0];
1370               my $volume = $row_data->[2];
1371
1372               if (    $region eq 'East'
1373                   and $volume > 3000
1374                   and $volume < 8000 )
1375               {
1376
1377                   # Row is visible.
1378               }
1379               else {
1380
1381                   # Hide row.
1382                   $worksheet4->set_row( $row, undef, undef, 1 );
1383               }
1384
1385               $worksheet4->write( $row++, 0, $row_data );
1386           }
1387
1388
1389           ###############################################################################
1390           #
1391           #
1392           # Example 5. Autofilter with filter for blanks.
1393           #
1394
1395           # Create a blank cell in our test data.
1396           $data[5]->[0] = '';
1397
1398
1399           $worksheet5->autofilter( 'A1:D51' );
1400           $worksheet5->filter_column( 'A', 'x == Blanks' );
1401
1402           #
1403           # Hide the rows that don't match the filter criteria.
1404           #
1405           $row = 1;
1406
1407           for my $row_data ( @data ) {
1408               my $region = $row_data->[0];
1409
1410               if ( $region eq '' ) {
1411
1412                   # Row is visible.
1413               }
1414               else {
1415
1416                   # Hide row.
1417                   $worksheet5->set_row( $row, undef, undef, 1 );
1418               }
1419
1420               $worksheet5->write( $row++, 0, $row_data );
1421           }
1422
1423
1424           ###############################################################################
1425           #
1426           #
1427           # Example 6. Autofilter with filter for non-blanks.
1428           #
1429
1430
1431           $worksheet6->autofilter( 'A1:D51' );
1432           $worksheet6->filter_column( 'A', 'x == NonBlanks' );
1433
1434           #
1435           # Hide the rows that don't match the filter criteria.
1436           #
1437           $row = 1;
1438
1439           for my $row_data ( @data ) {
1440               my $region = $row_data->[0];
1441
1442               if ( $region ne '' ) {
1443
1444                   # Row is visible.
1445               }
1446               else {
1447
1448                   # Hide row.
1449                   $worksheet6->set_row( $row, undef, undef, 1 );
1450               }
1451
1452               $worksheet6->write( $row++, 0, $row_data );
1453           }
1454
1455           $workbook->close();
1456
1457           __DATA__
1458           Region    Item      Volume    Month
1459           East      Apple     9000      July
1460           East      Apple     5000      July
1461           South     Orange    9000      September
1462           North     Apple     2000      November
1463           West      Apple     9000      November
1464           South     Pear      7000      October
1465           North     Pear      9000      August
1466           West      Orange    1000      December
1467           West      Grape     1000      November
1468           South     Pear      10000     April
1469           West      Grape     6000      January
1470           South     Orange    3000      May
1471           North     Apple     3000      December
1472           South     Apple     7000      February
1473           West      Grape     1000      December
1474           East      Grape     8000      February
1475           South     Grape     10000     June
1476           West      Pear      7000      December
1477           South     Apple     2000      October
1478           East      Grape     7000      December
1479           North     Grape     6000      April
1480           East      Pear      8000      February
1481           North     Apple     7000      August
1482           North     Orange    7000      July
1483           North     Apple     6000      June
1484           South     Grape     8000      September
1485           West      Apple     3000      October
1486           South     Orange    10000     November
1487           West      Grape     4000      July
1488           North     Orange    5000      August
1489           East      Orange    1000      November
1490           East      Orange    4000      October
1491           North     Grape     5000      August
1492           East      Apple     1000      December
1493           South     Apple     10000     March
1494           East      Grape     7000      October
1495           West      Grape     1000      September
1496           East      Grape     10000     October
1497           South     Orange    8000      March
1498           North     Apple     4000      July
1499           South     Orange    5000      July
1500           West      Apple     4000      June
1501           East      Apple     5000      April
1502           North     Pear      3000      August
1503           East      Grape     9000      November
1504           North     Orange    8000      October
1505           East      Apple     10000     June
1506           South     Pear      1000      December
1507           North     Grape     10000     July
1508           East      Grape     6000      February
1509
1510       Download this example:
1511       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/autofilter.pl>
1512
1513   Example: array_formula.pl
1514       Example of how to use the Excel::Writer::XLSX module to write simple
1515       array formulas.
1516
1517       Source code for this example:
1518
1519           #!/usr/bin/perl
1520
1521           #######################################################################
1522           #
1523           # Example of how to use the Excel::Writer::XLSX module to write simple
1524           # array formulas.
1525           #
1526           # reverse ('(c)'), August 2004, John McNamara, jmcnamara@cpan.org
1527           #
1528
1529           use strict;
1530           use warnings;
1531           use Excel::Writer::XLSX;
1532
1533           # Create a new workbook and add a worksheet
1534           my $workbook  = Excel::Writer::XLSX->new( 'array_formula.xlsx' );
1535           my $worksheet = $workbook->add_worksheet();
1536
1537           # Write some test data.
1538           $worksheet->write( 'B1', [ [ 500, 10 ], [ 300, 15 ] ] );
1539           $worksheet->write( 'B5', [ [ 1, 2, 3 ], [ 20234, 21003, 10000 ] ] );
1540
1541           # Write an array formula that returns a single value
1542           $worksheet->write( 'A1', '{=SUM(B1:C1*B2:C2)}' );
1543
1544           # Same as above but more verbose.
1545           $worksheet->write_array_formula( 'A2:A2', '{=SUM(B1:C1*B2:C2)}' );
1546
1547           # Write an array formula that returns a range of values
1548           $worksheet->write_array_formula( 'A5:A7', '{=TREND(C5:C7,B5:B7)}' );
1549
1550           $workbook->close();
1551
1552           __END__
1553
1554       Download this example:
1555       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/array_formula.pl>
1556
1557   Example: cgi.pl
1558       Example of how to use the Excel::Writer::XLSX module to send an Excel
1559       file to a browser in a CGI program.
1560
1561       On Windows the hash-bang line should be something like:
1562
1563           #!C:\Perl\bin\perl.exe
1564
1565       The "Content-Disposition" line will cause a prompt to be generated to
1566       save the file. If you want to stream the file to the browser instead,
1567       comment out that line as shown below.
1568
1569           #!/usr/bin/perl
1570
1571           ###############################################################################
1572           #
1573           # Example of how to use the Excel::Writer::XLSX module to send an Excel
1574           # file to a browser in a CGI program.
1575           #
1576           # On Windows the hash-bang line should be something like:
1577           #
1578           #     #!C:\Perl\bin\perl.exe
1579           #
1580           # The "Content-Disposition" line will cause a prompt to be generated to save
1581           # the file. If you want to stream the file to the browser instead, comment out
1582           # that line as shown below.
1583           #
1584           # reverse ('(c)'), March 2001, John McNamara, jmcnamara@cpan.org
1585           #
1586
1587           use strict;
1588           use warnings;
1589           use Excel::Writer::XLSX;
1590
1591           # Set the filename and send the content type
1592           my $filename = "cgitest.xlsx";
1593
1594           print "Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n";
1595
1596           # The Content-Disposition will generate a prompt to save the file. If you want
1597           # to stream the file to the browser, comment out the following line.
1598           print "Content-Disposition: attachment; filename=$filename\n";
1599           print "\n";
1600
1601           # Redirect the output to STDOUT. Binmode the filehandle in case it is needed.
1602           binmode STDOUT;
1603
1604           my $workbook  = Excel::Writer::XLSX->new( \*STDOUT );
1605           my $worksheet = $workbook->add_worksheet();
1606
1607
1608           # Set the column width for column 1
1609           $worksheet->set_column( 0, 0, 20 );
1610
1611
1612           # Create a format
1613           my $format = $workbook->add_format();
1614           $format->set_bold();
1615           $format->set_size( 15 );
1616           $format->set_color( 'blue' );
1617
1618
1619           # Write to the workbook
1620           $worksheet->write( 0, 0, "Hi Excel!", $format );
1621
1622           $workbook->close();
1623
1624           __END__
1625
1626       Download this example:
1627       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/cgi.pl>
1628
1629   Example: chart_area.pl
1630       A demo of an Area chart in Excel::Writer::XLSX.
1631
1632       Source code for this example:
1633
1634           #!/usr/bin/perl
1635
1636           #######################################################################
1637           #
1638           # A demo of an Area chart in Excel::Writer::XLSX.
1639           #
1640           # reverse ('(c)'), March 2011, John McNamara, jmcnamara@cpan.org
1641           #
1642
1643           use strict;
1644           use warnings;
1645           use Excel::Writer::XLSX;
1646
1647           my $workbook  = Excel::Writer::XLSX->new( 'chart_area.xlsx' );
1648           my $worksheet = $workbook->add_worksheet();
1649           my $bold      = $workbook->add_format( bold => 1 );
1650
1651           # Add the worksheet data that the charts will refer to.
1652           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
1653           my $data = [
1654               [ 2,  3,  4,  5,  6,  7 ],
1655               [ 40, 40, 50, 30, 25, 50 ],
1656               [ 30, 25, 30, 10, 5,  10 ],
1657
1658           ];
1659
1660           $worksheet->write( 'A1', $headings, $bold );
1661           $worksheet->write( 'A2', $data );
1662
1663           # Create a new chart object. In this case an embedded chart.
1664           my $chart1 = $workbook->add_chart( type => 'area', embedded => 1 );
1665
1666           # Configure the first series.
1667           $chart1->add_series(
1668               name       => '=Sheet1!$B$1',
1669               categories => '=Sheet1!$A$2:$A$7',
1670               values     => '=Sheet1!$B$2:$B$7',
1671           );
1672
1673           # Configure second series. Note alternative use of array ref to define
1674           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
1675           $chart1->add_series(
1676               name       => '=Sheet1!$C$1',
1677               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1678               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1679           );
1680
1681           # Add a chart title and some axis labels.
1682           $chart1->set_title ( name => 'Results of sample analysis' );
1683           $chart1->set_x_axis( name => 'Test number' );
1684           $chart1->set_y_axis( name => 'Sample length (mm)' );
1685
1686           # Set an Excel chart style. Blue colors with white outline and shadow.
1687           $chart1->set_style( 11 );
1688
1689           # Insert the chart into the worksheet (with an offset).
1690           $worksheet->insert_chart( 'D2', $chart1, 25, 10 );
1691
1692
1693           #
1694           # Create a stacked chart sub-type
1695           #
1696           my $chart2 = $workbook->add_chart(
1697               type     => 'area',
1698               embedded => 1,
1699               subtype  => 'stacked'
1700           );
1701
1702           # Configure the first series.
1703           $chart2->add_series(
1704               name       => '=Sheet1!$B$1',
1705               categories => '=Sheet1!$A$2:$A$7',
1706               values     => '=Sheet1!$B$2:$B$7',
1707           );
1708
1709           # Configure second series.
1710           $chart2->add_series(
1711               name       => '=Sheet1!$C$1',
1712               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1713               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1714           );
1715
1716           # Add a chart title and some axis labels.
1717           $chart2->set_title ( name => 'Stacked Chart' );
1718           $chart2->set_x_axis( name => 'Test number' );
1719           $chart2->set_y_axis( name => 'Sample length (mm)' );
1720
1721           # Set an Excel chart style. Blue colors with white outline and shadow.
1722           $chart2->set_style( 12 );
1723
1724           # Insert the chart into the worksheet (with an offset).
1725           $worksheet->insert_chart( 'D18', $chart2, 25, 11 );
1726
1727
1728           #
1729           # Create a percent stacked chart sub-type
1730           #
1731           my $chart3 = $workbook->add_chart(
1732               type     => 'area',
1733               embedded => 1,
1734               subtype  => 'percent_stacked'
1735           );
1736
1737           # Configure the first series.
1738           $chart3->add_series(
1739               name       => '=Sheet1!$B$1',
1740               categories => '=Sheet1!$A$2:$A$7',
1741               values     => '=Sheet1!$B$2:$B$7',
1742           );
1743
1744           # Configure second series.
1745           $chart3->add_series(
1746               name       => '=Sheet1!$C$1',
1747               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1748               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1749           );
1750
1751           # Add a chart title and some axis labels.
1752           $chart3->set_title ( name => 'Percent Stacked Chart' );
1753           $chart3->set_x_axis( name => 'Test number' );
1754           $chart3->set_y_axis( name => 'Sample length (mm)' );
1755
1756           # Set an Excel chart style. Blue colors with white outline and shadow.
1757           $chart3->set_style( 13 );
1758
1759           # Insert the chart into the worksheet (with an offset).
1760           $worksheet->insert_chart( 'D34', $chart3, 25, 11 );
1761
1762           $workbook->close();
1763
1764           __END__
1765
1766       Download this example:
1767       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_area.pl>
1768
1769   Example: chart_bar.pl
1770       A demo of an Bar chart in Excel::Writer::XLSX.
1771
1772       Source code for this example:
1773
1774           #!/usr/bin/perl
1775
1776           #######################################################################
1777           #
1778           # A demo of an Bar chart in Excel::Writer::XLSX.
1779           #
1780           # reverse ('(c)'), March 2011, John McNamara, jmcnamara@cpan.org
1781           #
1782
1783           use strict;
1784           use warnings;
1785           use Excel::Writer::XLSX;
1786
1787           my $workbook  = Excel::Writer::XLSX->new( 'chart_bar.xlsx' );
1788           my $worksheet = $workbook->add_worksheet();
1789           my $bold      = $workbook->add_format( bold => 1 );
1790
1791           # Add the worksheet data that the charts will refer to.
1792           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
1793           my $data = [
1794               [ 2,  3,  4,  5,  6,  7 ],
1795               [ 10, 40, 50, 20, 10, 50 ],
1796               [ 30, 60, 70, 50, 40, 30 ],
1797
1798           ];
1799
1800           $worksheet->write( 'A1', $headings, $bold );
1801           $worksheet->write( 'A2', $data );
1802
1803           # Create a new chart object. In this case an embedded chart.
1804           my $chart1 = $workbook->add_chart( type => 'bar', embedded => 1 );
1805
1806           # Configure the first series.
1807           $chart1->add_series(
1808               name       => '=Sheet1!$B$1',
1809               categories => '=Sheet1!$A$2:$A$7',
1810               values     => '=Sheet1!$B$2:$B$7',
1811           );
1812
1813           # Configure second series. Note alternative use of array ref to define
1814           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
1815           $chart1->add_series(
1816               name       => '=Sheet1!$C$1',
1817               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1818               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1819           );
1820
1821           # Add a chart title and some axis labels.
1822           $chart1->set_title ( name => 'Results of sample analysis' );
1823           $chart1->set_x_axis( name => 'Test number' );
1824           $chart1->set_y_axis( name => 'Sample length (mm)' );
1825
1826           # Set an Excel chart style. Blue colors with white outline and shadow.
1827           $chart1->set_style( 11 );
1828
1829           # Insert the chart into the worksheet (with an offset).
1830           $worksheet->insert_chart( 'D2', $chart1, 25, 10 );
1831
1832
1833           #
1834           # Create a stacked chart sub-type
1835           #
1836           my $chart2 = $workbook->add_chart(
1837               type     => 'bar',
1838               embedded => 1,
1839               subtype  => 'stacked'
1840           );
1841
1842           # Configure the first series.
1843           $chart2->add_series(
1844               name       => '=Sheet1!$B$1',
1845               categories => '=Sheet1!$A$2:$A$7',
1846               values     => '=Sheet1!$B$2:$B$7',
1847           );
1848
1849           # Configure second series.
1850           $chart2->add_series(
1851               name       => '=Sheet1!$C$1',
1852               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1853               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1854           );
1855
1856           # Add a chart title and some axis labels.
1857           $chart2->set_title ( name => 'Stacked Chart' );
1858           $chart2->set_x_axis( name => 'Test number' );
1859           $chart2->set_y_axis( name => 'Sample length (mm)' );
1860
1861           # Set an Excel chart style. Blue colors with white outline and shadow.
1862           $chart2->set_style( 12 );
1863
1864           # Insert the chart into the worksheet (with an offset).
1865           $worksheet->insert_chart( 'D18', $chart2, 25, 11 );
1866
1867
1868           #
1869           # Create a percent stacked chart sub-type
1870           #
1871           my $chart3 = $workbook->add_chart(
1872               type     => 'bar',
1873               embedded => 1,
1874               subtype  => 'percent_stacked'
1875           );
1876
1877           # Configure the first series.
1878           $chart3->add_series(
1879               name       => '=Sheet1!$B$1',
1880               categories => '=Sheet1!$A$2:$A$7',
1881               values     => '=Sheet1!$B$2:$B$7',
1882           );
1883
1884           # Configure second series.
1885           $chart3->add_series(
1886               name       => '=Sheet1!$C$1',
1887               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1888               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1889           );
1890
1891           # Add a chart title and some axis labels.
1892           $chart3->set_title ( name => 'Percent Stacked Chart' );
1893           $chart3->set_x_axis( name => 'Test number' );
1894           $chart3->set_y_axis( name => 'Sample length (mm)' );
1895
1896           # Set an Excel chart style. Blue colors with white outline and shadow.
1897           $chart3->set_style( 13 );
1898
1899           # Insert the chart into the worksheet (with an offset).
1900           $worksheet->insert_chart( 'D34', $chart3, 25, 11 );
1901
1902           $workbook->close();
1903
1904           __END__
1905
1906       Download this example:
1907       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_bar.pl>
1908
1909   Example: chart_column.pl
1910       A demo of a Column chart in Excel::Writer::XLSX.
1911
1912       Source code for this example:
1913
1914           #!/usr/bin/perl
1915
1916           #######################################################################
1917           #
1918           # A demo of a Column chart in Excel::Writer::XLSX.
1919           #
1920           # reverse ('(c)'), March 2011, John McNamara, jmcnamara@cpan.org
1921           #
1922
1923           use strict;
1924           use warnings;
1925           use Excel::Writer::XLSX;
1926
1927           my $workbook  = Excel::Writer::XLSX->new( 'chart_column.xlsx' );
1928           my $worksheet = $workbook->add_worksheet();
1929           my $bold      = $workbook->add_format( bold => 1 );
1930
1931           # Add the worksheet data that the charts will refer to.
1932           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
1933           my $data = [
1934               [ 2,  3,  4,  5,  6,  7 ],
1935               [ 10, 40, 50, 20, 10, 50 ],
1936               [ 30, 60, 70, 50, 40, 30 ],
1937
1938           ];
1939
1940           $worksheet->write( 'A1', $headings, $bold );
1941           $worksheet->write( 'A2', $data );
1942
1943           # Create a new chart object. In this case an embedded chart.
1944           my $chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
1945
1946           # Configure the first series.
1947           $chart1->add_series(
1948               name       => '=Sheet1!$B$1',
1949               categories => '=Sheet1!$A$2:$A$7',
1950               values     => '=Sheet1!$B$2:$B$7',
1951           );
1952
1953           # Configure second series. Note alternative use of array ref to define
1954           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
1955           $chart1->add_series(
1956               name       => '=Sheet1!$C$1',
1957               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1958               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1959           );
1960
1961           # Add a chart title and some axis labels.
1962           $chart1->set_title ( name => 'Results of sample analysis' );
1963           $chart1->set_x_axis( name => 'Test number' );
1964           $chart1->set_y_axis( name => 'Sample length (mm)' );
1965
1966           # Set an Excel chart style. Blue colors with white outline and shadow.
1967           $chart1->set_style( 11 );
1968
1969           # Insert the chart into the worksheet (with an offset).
1970           $worksheet->insert_chart( 'D2', $chart1, 25, 10 );
1971
1972
1973           #
1974           # Create a stacked chart sub-type
1975           #
1976           my $chart2 = $workbook->add_chart(
1977               type     => 'column',
1978               embedded => 1,
1979               subtype  => 'stacked'
1980           );
1981
1982           # Configure the first series.
1983           $chart2->add_series(
1984               name       => '=Sheet1!$B$1',
1985               categories => '=Sheet1!$A$2:$A$7',
1986               values     => '=Sheet1!$B$2:$B$7',
1987           );
1988
1989           # Configure second series.
1990           $chart2->add_series(
1991               name       => '=Sheet1!$C$1',
1992               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1993               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1994           );
1995
1996           # Add a chart title and some axis labels.
1997           $chart2->set_title ( name => 'Stacked Chart' );
1998           $chart2->set_x_axis( name => 'Test number' );
1999           $chart2->set_y_axis( name => 'Sample length (mm)' );
2000
2001           # Set an Excel chart style. Blue colors with white outline and shadow.
2002           $chart2->set_style( 12 );
2003
2004           # Insert the chart into the worksheet (with an offset).
2005           $worksheet->insert_chart( 'D18', $chart2, 25, 11 );
2006
2007
2008           #
2009           # Create a percent stacked chart sub-type
2010           #
2011           my $chart3 = $workbook->add_chart(
2012               type     => 'column',
2013               embedded => 1,
2014               subtype  => 'percent_stacked'
2015           );
2016
2017           # Configure the first series.
2018           $chart3->add_series(
2019               name       => '=Sheet1!$B$1',
2020               categories => '=Sheet1!$A$2:$A$7',
2021               values     => '=Sheet1!$B$2:$B$7',
2022           );
2023
2024           # Configure second series.
2025           $chart3->add_series(
2026               name       => '=Sheet1!$C$1',
2027               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2028               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2029           );
2030
2031           # Add a chart title and some axis labels.
2032           $chart3->set_title ( name => 'Percent Stacked Chart' );
2033           $chart3->set_x_axis( name => 'Test number' );
2034           $chart3->set_y_axis( name => 'Sample length (mm)' );
2035
2036           # Set an Excel chart style. Blue colors with white outline and shadow.
2037           $chart3->set_style( 13 );
2038
2039           # Insert the chart into the worksheet (with an offset).
2040           $worksheet->insert_chart( 'D34', $chart3, 25, 11 );
2041
2042           $workbook->close();
2043
2044           __END__
2045
2046       Download this example:
2047       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_column.pl>
2048
2049   Example: chart_line.pl
2050       A demo of a Line chart in Excel::Writer::XLSX.
2051
2052       Source code for this example:
2053
2054           #!/usr/bin/perl
2055
2056           #######################################################################
2057           #
2058           # A demo of a Line chart in Excel::Writer::XLSX.
2059           #
2060           # reverse ('(c)'), March 2011, John McNamara, jmcnamara@cpan.org
2061           #
2062
2063           use strict;
2064           use warnings;
2065           use Excel::Writer::XLSX;
2066
2067           my $workbook  = Excel::Writer::XLSX->new( 'chart_line.xlsx' );
2068           my $worksheet = $workbook->add_worksheet();
2069           my $bold      = $workbook->add_format( bold => 1 );
2070
2071           # Add the worksheet data that the charts will refer to.
2072           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2073           my $data = [
2074               [ 2, 3, 4, 5, 6, 7 ],
2075               [ 10, 40, 50, 20, 10, 50 ],
2076               [ 30, 60, 70, 50, 40, 30 ],
2077
2078           ];
2079
2080           $worksheet->write( 'A1', $headings, $bold );
2081           $worksheet->write( 'A2', $data );
2082
2083           # Create a new chart object. In this case an embedded chart.
2084           my $chart = $workbook->add_chart( type => 'line', embedded => 1 );
2085
2086           # Configure the first series.
2087           $chart->add_series(
2088               name       => '=Sheet1!$B$1',
2089               categories => '=Sheet1!$A$2:$A$7',
2090               values     => '=Sheet1!$B$2:$B$7',
2091           );
2092
2093           # Configure second series. Note alternative use of array ref to define
2094           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2095           $chart->add_series(
2096               name       => '=Sheet1!$C$1',
2097               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2098               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2099           );
2100
2101           # Add a chart title and some axis labels.
2102           $chart->set_title ( name => 'Results of sample analysis' );
2103           $chart->set_x_axis( name => 'Test number' );
2104           $chart->set_y_axis( name => 'Sample length (mm)' );
2105
2106           # Set an Excel chart style. Colors with white outline and shadow.
2107           $chart->set_style( 10 );
2108
2109           # Insert the chart into the worksheet (with an offset).
2110           $worksheet->insert_chart( 'D2', $chart, 25, 10 );
2111
2112           $workbook->close();
2113
2114           __END__
2115
2116       Download this example:
2117       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_line.pl>
2118
2119   Example: chart_pie.pl
2120       A demo of a Pie chart in Excel::Writer::XLSX.
2121
2122       The demo also shows how to set segment colours. It is possible to
2123       define chart colors for most types of Excel::Writer::XLSX charts via
2124       the add_series() method. However, Pie and Doughtnut charts are a
2125       special case since each segment is represented as a point so it is
2126       necessary to assign formatting to each point in the series.
2127
2128       Source code for this example:
2129
2130           #!/usr/bin/perl
2131
2132           #######################################################################
2133           #
2134           # A demo of a Pie chart in Excel::Writer::XLSX.
2135           #
2136           # The demo also shows how to set segment colours. It is possible to define
2137           # chart colors for most types of Excel::Writer::XLSX charts via the
2138           # add_series() method. However, Pie and Doughtnut charts are a special case
2139           # since each segment is represented as a point so it is necessary to assign
2140           # formatting to each point in the series.
2141           #
2142           # reverse ('(c)'), March 2011, John McNamara, jmcnamara@cpan.org
2143           #
2144
2145           use strict;
2146           use warnings;
2147           use Excel::Writer::XLSX;
2148
2149           my $workbook  = Excel::Writer::XLSX->new( 'chart_pie.xlsx' );
2150           my $worksheet = $workbook->add_worksheet();
2151           my $bold      = $workbook->add_format( bold => 1 );
2152
2153           # Add the worksheet data that the charts will refer to.
2154           my $headings = [ 'Category', 'Values' ];
2155           my $data = [
2156               [ 'Apple', 'Cherry', 'Pecan' ],
2157               [ 60,       30,       10     ],
2158           ];
2159
2160           $worksheet->write( 'A1', $headings, $bold );
2161           $worksheet->write( 'A2', $data );
2162
2163           # Create a new chart object. In this case an embedded chart.
2164           my $chart1 = $workbook->add_chart( type => 'pie', embedded => 1 );
2165
2166           # Configure the series. Note the use of the array ref to define ranges:
2167           # [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2168           # See below for an alternative syntax.
2169           $chart1->add_series(
2170               name       => 'Pie sales data',
2171               categories => [ 'Sheet1', 1, 3, 0, 0 ],
2172               values     => [ 'Sheet1', 1, 3, 1, 1 ],
2173           );
2174
2175           # Add a title.
2176           $chart1->set_title( name => 'Popular Pie Types' );
2177
2178           # Set an Excel chart style. Colors with white outline and shadow.
2179           $chart1->set_style( 10 );
2180
2181           # Insert the chart into the worksheet (with an offset).
2182           $worksheet->insert_chart( 'C2', $chart1, 25, 10 );
2183
2184
2185           #
2186           # Create a Pie chart with user defined segment colors.
2187           #
2188
2189           # Create an example Pie chart like above.
2190           my $chart2 = $workbook->add_chart( type => 'pie', embedded => 1 );
2191
2192           # Configure the series and add user defined segment colours.
2193           $chart2->add_series(
2194               name       => 'Pie sales data',
2195               categories => '=Sheet1!$A$2:$A$4',
2196               values     => '=Sheet1!$B$2:$B$4',
2197               points     => [
2198                   { fill => { color => '#5ABA10' } },
2199                   { fill => { color => '#FE110E' } },
2200                   { fill => { color => '#CA5C05' } },
2201               ],
2202           );
2203
2204           # Add a title.
2205           $chart2->set_title( name => 'Pie Chart with user defined colors' );
2206
2207
2208           # Insert the chart into the worksheet (with an offset).
2209           $worksheet->insert_chart( 'C18', $chart2, 25, 10 );
2210
2211
2212           #
2213           # Create a Pie chart with rotation of the segments.
2214           #
2215
2216           # Create an example Pie chart like above.
2217           my $chart3 = $workbook->add_chart( type => 'pie', embedded => 1 );
2218
2219           # Configure the series.
2220           $chart3->add_series(
2221               name       => 'Pie sales data',
2222               categories => '=Sheet1!$A$2:$A$4',
2223               values     => '=Sheet1!$B$2:$B$4',
2224           );
2225
2226           # Add a title.
2227           $chart3->set_title( name => 'Pie Chart with segment rotation' );
2228
2229           # Change the angle/rotation of the first segment.
2230           $chart3->set_rotation(90);
2231
2232           # Insert the chart into the worksheet (with an offset).
2233           $worksheet->insert_chart( 'C34', $chart3, 25, 10 );
2234
2235           $workbook->close();
2236
2237           __END__
2238
2239       Download this example:
2240       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_pie.pl>
2241
2242   Example: chart_doughnut.pl
2243       A demo of a Doughnut chart in Excel::Writer::XLSX.
2244
2245       The demo also shows how to set segment colours. It is possible to
2246       define chart colors for most types of Excel::Writer::XLSX charts via
2247       the add_series() method. However, Pie and Doughtnut charts are a
2248       special case since each segment is represented as a point so it is
2249       necessary to assign formatting to each point in the series.
2250
2251       Source code for this example:
2252
2253           #!/usr/bin/perl
2254
2255           #######################################################################
2256           #
2257           # A demo of a Doughnut chart in Excel::Writer::XLSX.
2258           #
2259           # The demo also shows how to set segment colours. It is possible to define
2260           # chart colors for most types of Excel::Writer::XLSX charts via the
2261           # add_series() method. However, Pie and Doughtnut charts are a special case
2262           # since each segment is represented as a point so it is necessary to assign
2263           # formatting to each point in the series.
2264           #
2265           # reverse ('(c)'), March 2011, John McNamara, jmcnamara@cpan.org
2266           #
2267
2268           use strict;
2269           use warnings;
2270           use Excel::Writer::XLSX;
2271
2272           my $workbook  = Excel::Writer::XLSX->new( 'chart_doughnut.xlsx' );
2273           my $worksheet = $workbook->add_worksheet();
2274           my $bold      = $workbook->add_format( bold => 1 );
2275
2276           # Add the worksheet data that the charts will refer to.
2277           my $headings = [ 'Category', 'Values' ];
2278           my $data = [
2279               [ 'Glazed', 'Chocolate', 'Cream' ],
2280               [ 50,       35,          15      ],
2281           ];
2282
2283           $worksheet->write( 'A1', $headings, $bold );
2284           $worksheet->write( 'A2', $data );
2285
2286           # Create a new chart object. In this case an embedded chart.
2287           my $chart1 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2288
2289           # Configure the series. Note the use of the array ref to define ranges:
2290           # [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2291           # See below for an alternative syntax.
2292           $chart1->add_series(
2293               name       => 'Doughnut sales data',
2294               categories => [ 'Sheet1', 1, 3, 0, 0 ],
2295               values     => [ 'Sheet1', 1, 3, 1, 1 ],
2296           );
2297
2298           # Add a title.
2299           $chart1->set_title( name => 'Popular Doughnut Types' );
2300
2301           # Set an Excel chart style. Colors with white outline and shadow.
2302           $chart1->set_style( 10 );
2303
2304           # Insert the chart into the worksheet (with an offset).
2305           $worksheet->insert_chart( 'C2', $chart1, 25, 10 );
2306
2307
2308           #
2309           # Create a Doughnut chart with user defined segment colors.
2310           #
2311
2312           # Create an example Doughnut chart like above.
2313           my $chart2 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2314
2315           # Configure the series and add user defined segment colours.
2316           $chart2->add_series(
2317               name       => 'Doughnut sales data',
2318               categories => '=Sheet1!$A$2:$A$4',
2319               values     => '=Sheet1!$B$2:$B$4',
2320               points     => [
2321                   { fill => { color => '#FA58D0' } },
2322                   { fill => { color => '#61210B' } },
2323                   { fill => { color => '#F5F6CE' } },
2324               ],
2325           );
2326
2327           # Add a title.
2328           $chart2->set_title( name => 'Doughnut Chart with user defined colors' );
2329
2330
2331           # Insert the chart into the worksheet (with an offset).
2332           $worksheet->insert_chart( 'C18', $chart2, 25, 10 );
2333
2334
2335           #
2336           # Create a Doughnut chart with rotation of the segments.
2337           #
2338
2339           # Create an example Doughnut chart like above.
2340           my $chart3 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2341
2342           # Configure the series.
2343           $chart3->add_series(
2344               name       => 'Doughnut sales data',
2345               categories => '=Sheet1!$A$2:$A$4',
2346               values     => '=Sheet1!$B$2:$B$4',
2347           );
2348
2349           # Add a title.
2350           $chart3->set_title( name => 'Doughnut Chart with segment rotation' );
2351
2352           # Change the angle/rotation of the first segment.
2353           $chart3->set_rotation(90);
2354
2355           # Insert the chart into the worksheet (with an offset).
2356           $worksheet->insert_chart( 'C34', $chart3, 25, 10 );
2357
2358
2359           #
2360           # Create a Doughnut chart with user defined hole size.
2361           #
2362
2363           # Create an example Doughnut chart like above.
2364           my $chart4 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2365
2366           # Configure the series.
2367           $chart4->add_series(
2368               name       => 'Doughnut sales data',
2369               categories => '=Sheet1!$A$2:$A$4',
2370               values     => '=Sheet1!$B$2:$B$4',
2371           );
2372
2373           # Add a title.
2374           $chart4->set_title( name => 'Doughnut Chart with user defined hole size' );
2375
2376           # Change the hole size.
2377           $chart4->set_hole_size(33);
2378
2379           # Insert the chart into the worksheet (with an offset).
2380           $worksheet->insert_chart( 'C50', $chart4, 25, 10 );
2381
2382           $workbook->close();
2383
2384           __END__
2385
2386       Download this example:
2387       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_doughnut.pl>
2388
2389   Example: chart_radar.pl
2390       A demo of an Radar chart in Excel::Writer::XLSX.
2391
2392       Source code for this example:
2393
2394           #!/usr/bin/perl
2395
2396           #######################################################################
2397           #
2398           # A demo of an Radar chart in Excel::Writer::XLSX.
2399           #
2400           # reverse ('(c)'), October 2012, John McNamara, jmcnamara@cpan.org
2401           #
2402
2403           use strict;
2404           use warnings;
2405           use Excel::Writer::XLSX;
2406
2407           my $workbook  = Excel::Writer::XLSX->new( 'chart_radar.xlsx' );
2408           my $worksheet = $workbook->add_worksheet();
2409           my $bold      = $workbook->add_format( bold => 1 );
2410
2411           # Add the worksheet data that the charts will refer to.
2412           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2413           my $data = [
2414               [ 2,  3,  4,  5,  6,  7 ],
2415               [ 30, 60, 70, 50, 40, 30 ],
2416               [ 25, 40, 50, 30, 50, 40 ],
2417
2418           ];
2419
2420           $worksheet->write( 'A1', $headings, $bold );
2421           $worksheet->write( 'A2', $data );
2422
2423           # Create a new chart object. In this case an embedded chart.
2424           my $chart1 = $workbook->add_chart( type => 'radar', embedded => 1 );
2425
2426           # Configure the first series.
2427           $chart1->add_series(
2428               name       => '=Sheet1!$B$1',
2429               categories => '=Sheet1!$A$2:$A$7',
2430               values     => '=Sheet1!$B$2:$B$7',
2431           );
2432
2433           # Configure second series. Note alternative use of array ref to define
2434           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2435           $chart1->add_series(
2436               name       => '=Sheet1!$C$1',
2437               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2438               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2439           );
2440
2441           # Add a chart title and some axis labels.
2442           $chart1->set_title ( name => 'Results of sample analysis' );
2443           $chart1->set_x_axis( name => 'Test number' );
2444           $chart1->set_y_axis( name => 'Sample length (mm)' );
2445
2446           # Set an Excel chart style. Blue colors with white outline and shadow.
2447           $chart1->set_style( 11 );
2448
2449           # Insert the chart into the worksheet (with an offset).
2450           $worksheet->insert_chart( 'D2', $chart1, 25, 10 );
2451
2452
2453           #
2454           # Create a with_markers chart sub-type
2455           #
2456           my $chart2 = $workbook->add_chart(
2457               type     => 'radar',
2458               embedded => 1,
2459               subtype  => 'with_markers'
2460           );
2461
2462           # Configure the first series.
2463           $chart2->add_series(
2464               name       => '=Sheet1!$B$1',
2465               categories => '=Sheet1!$A$2:$A$7',
2466               values     => '=Sheet1!$B$2:$B$7',
2467           );
2468
2469           # Configure second series.
2470           $chart2->add_series(
2471               name       => '=Sheet1!$C$1',
2472               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2473               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2474           );
2475
2476           # Add a chart title and some axis labels.
2477           $chart2->set_title ( name => 'Stacked Chart' );
2478           $chart2->set_x_axis( name => 'Test number' );
2479           $chart2->set_y_axis( name => 'Sample length (mm)' );
2480
2481           # Set an Excel chart style. Blue colors with white outline and shadow.
2482           $chart2->set_style( 12 );
2483
2484           # Insert the chart into the worksheet (with an offset).
2485           $worksheet->insert_chart( 'D18', $chart2, 25, 11 );
2486
2487
2488           #
2489           # Create a filled chart sub-type
2490           #
2491           my $chart3 = $workbook->add_chart(
2492               type     => 'radar',
2493               embedded => 1,
2494               subtype  => 'filled'
2495           );
2496
2497           # Configure the first series.
2498           $chart3->add_series(
2499               name       => '=Sheet1!$B$1',
2500               categories => '=Sheet1!$A$2:$A$7',
2501               values     => '=Sheet1!$B$2:$B$7',
2502           );
2503
2504           # Configure second series.
2505           $chart3->add_series(
2506               name       => '=Sheet1!$C$1',
2507               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2508               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2509           );
2510
2511           # Add a chart title and some axis labels.
2512           $chart3->set_title ( name => 'Percent Stacked Chart' );
2513           $chart3->set_x_axis( name => 'Test number' );
2514           $chart3->set_y_axis( name => 'Sample length (mm)' );
2515
2516           # Set an Excel chart style. Blue colors with white outline and shadow.
2517           $chart3->set_style( 13 );
2518
2519           # Insert the chart into the worksheet (with an offset).
2520           $worksheet->insert_chart( 'D34', $chart3, 25, 11 );
2521
2522           $workbook->close();
2523
2524           __END__
2525
2526       Download this example:
2527       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_radar.pl>
2528
2529   Example: chart_scatter.pl
2530       A demo of a Scatter chart in Excel::Writer::XLSX. Other subtypes are
2531       also supported such as markers_only (the default),
2532       straight_with_markers, straight, smooth_with_markers and smooth. See
2533       the main documentation for more details.
2534
2535       Source code for this example:
2536
2537           #!/usr/bin/perl
2538
2539           #######################################################################
2540           #
2541           # A demo of a Scatter chart in Excel::Writer::XLSX. Other subtypes are
2542           # also supported such as markers_only (the default), straight_with_markers,
2543           # straight, smooth_with_markers and smooth. See the main documentation for
2544           # more details.
2545           #
2546           # reverse ('(c)'), March 2011, John McNamara, jmcnamara@cpan.org
2547           #
2548
2549           use strict;
2550           use warnings;
2551           use Excel::Writer::XLSX;
2552
2553           my $workbook  = Excel::Writer::XLSX->new( 'chart_scatter.xlsx' );
2554           my $worksheet = $workbook->add_worksheet();
2555           my $bold      = $workbook->add_format( bold => 1 );
2556
2557           # Add the worksheet data that the charts will refer to.
2558           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2559           my $data = [
2560               [ 2,  3,  4,  5,  6,  7 ],
2561               [ 10, 40, 50, 20, 10, 50 ],
2562               [ 30, 60, 70, 50, 40, 30 ],
2563
2564           ];
2565
2566           $worksheet->write( 'A1', $headings, $bold );
2567           $worksheet->write( 'A2', $data );
2568
2569           # Create a new chart object. In this case an embedded chart.
2570           my $chart1 = $workbook->add_chart( type => 'scatter', embedded => 1 );
2571
2572           # Configure the first series.
2573           $chart1->add_series(
2574               name       => '=Sheet1!$B$1',
2575               categories => '=Sheet1!$A$2:$A$7',
2576               values     => '=Sheet1!$B$2:$B$7',
2577           );
2578
2579           # Configure second series. Note alternative use of array ref to define
2580           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2581           $chart1->add_series(
2582               name       => '=Sheet1!$C$1',
2583               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2584               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2585           );
2586
2587           # Add a chart title and some axis labels.
2588           $chart1->set_title ( name => 'Results of sample analysis' );
2589           $chart1->set_x_axis( name => 'Test number' );
2590           $chart1->set_y_axis( name => 'Sample length (mm)' );
2591
2592           # Set an Excel chart style. Blue colors with white outline and shadow.
2593           $chart1->set_style( 11 );
2594
2595           # Insert the chart into the worksheet (with an offset).
2596           $worksheet->insert_chart( 'D2', $chart1, 25, 10 );
2597
2598
2599           #
2600           # Create a scatter chart sub-type with straight lines and markers.
2601           #
2602           my $chart2 = $workbook->add_chart(
2603               type     => 'scatter',
2604               embedded => 1,
2605               subtype  => 'straight_with_markers'
2606           );
2607
2608           # Configure the first series.
2609           $chart2->add_series(
2610               name       => '=Sheet1!$B$1',
2611               categories => '=Sheet1!$A$2:$A$7',
2612               values     => '=Sheet1!$B$2:$B$7',
2613           );
2614
2615           # Configure second series.
2616           $chart2->add_series(
2617               name       => '=Sheet1!$C$1',
2618               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2619               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2620           );
2621
2622           # Add a chart title and some axis labels.
2623           $chart2->set_title ( name => 'Straight line with markers' );
2624           $chart2->set_x_axis( name => 'Test number' );
2625           $chart2->set_y_axis( name => 'Sample length (mm)' );
2626
2627           # Set an Excel chart style. Blue colors with white outline and shadow.
2628           $chart2->set_style( 12 );
2629
2630           # Insert the chart into the worksheet (with an offset).
2631           $worksheet->insert_chart( 'D18', $chart2, 25, 11 );
2632
2633
2634           #
2635           # Create a scatter chart sub-type with straight lines and no markers.
2636           #
2637           my $chart3 = $workbook->add_chart(
2638               type     => 'scatter',
2639               embedded => 1,
2640               subtype  => 'straight'
2641           );
2642
2643           # Configure the first series.
2644           $chart3->add_series(
2645               name       => '=Sheet1!$B$1',
2646               categories => '=Sheet1!$A$2:$A$7',
2647               values     => '=Sheet1!$B$2:$B$7',
2648           );
2649
2650           # Configure second series.
2651           $chart3->add_series(
2652               name       => '=Sheet1!$C$1',
2653               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2654               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2655           );
2656
2657           # Add a chart title and some axis labels.
2658           $chart3->set_title ( name => 'Straight line' );
2659           $chart3->set_x_axis( name => 'Test number' );
2660           $chart3->set_y_axis( name => 'Sample length (mm)' );
2661
2662           # Set an Excel chart style. Blue colors with white outline and shadow.
2663           $chart3->set_style( 13 );
2664
2665           # Insert the chart into the worksheet (with an offset).
2666           $worksheet->insert_chart( 'D34', $chart3, 25, 11 );
2667
2668
2669           #
2670           # Create a scatter chart sub-type with smooth lines and markers.
2671           #
2672           my $chart4 = $workbook->add_chart(
2673               type     => 'scatter',
2674               embedded => 1,
2675               subtype  => 'smooth_with_markers'
2676           );
2677
2678           # Configure the first series.
2679           $chart4->add_series(
2680               name       => '=Sheet1!$B$1',
2681               categories => '=Sheet1!$A$2:$A$7',
2682               values     => '=Sheet1!$B$2:$B$7',
2683           );
2684
2685           # Configure second series.
2686           $chart4->add_series(
2687               name       => '=Sheet1!$C$1',
2688               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2689               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2690           );
2691
2692           # Add a chart title and some axis labels.
2693           $chart4->set_title ( name => 'Smooth line with markers' );
2694           $chart4->set_x_axis( name => 'Test number' );
2695           $chart4->set_y_axis( name => 'Sample length (mm)' );
2696
2697           # Set an Excel chart style. Blue colors with white outline and shadow.
2698           $chart4->set_style( 14 );
2699
2700           # Insert the chart into the worksheet (with an offset).
2701           $worksheet->insert_chart( 'D51', $chart4, 25, 11 );
2702
2703
2704           #
2705           # Create a scatter chart sub-type with smooth lines and no markers.
2706           #
2707           my $chart5 = $workbook->add_chart(
2708               type     => 'scatter',
2709               embedded => 1,
2710               subtype  => 'smooth'
2711           );
2712
2713           # Configure the first series.
2714           $chart5->add_series(
2715               name       => '=Sheet1!$B$1',
2716               categories => '=Sheet1!$A$2:$A$7',
2717               values     => '=Sheet1!$B$2:$B$7',
2718           );
2719
2720           # Configure second series.
2721           $chart5->add_series(
2722               name       => '=Sheet1!$C$1',
2723               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2724               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2725           );
2726
2727           # Add a chart title and some axis labels.
2728           $chart5->set_title ( name => 'Smooth line' );
2729           $chart5->set_x_axis( name => 'Test number' );
2730           $chart5->set_y_axis( name => 'Sample length (mm)' );
2731
2732           # Set an Excel chart style. Blue colors with white outline and shadow.
2733           $chart5->set_style( 15 );
2734
2735           # Insert the chart into the worksheet (with an offset).
2736           $worksheet->insert_chart( 'D66', $chart5, 25, 11 );
2737
2738
2739           $workbook->close();
2740
2741           __END__
2742
2743       Download this example:
2744       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_scatter.pl>
2745
2746   Example: chart_secondary_axis.pl
2747       A demo of a Line chart with a secondary axis in Excel::Writer::XLSX.
2748
2749       Source code for this example:
2750
2751           #!/usr/bin/perl
2752
2753           #######################################################################
2754           #
2755           # A demo of a Line chart with a secondary axis in Excel::Writer::XLSX.
2756           #
2757           # reverse ('(c)'), March 2011, John McNamara, jmcnamara@cpan.org
2758           #
2759
2760           use strict;
2761           use warnings;
2762           use Excel::Writer::XLSX;
2763
2764           my $workbook  = Excel::Writer::XLSX->new( 'chart_secondary_axis.xlsx' );
2765           my $worksheet = $workbook->add_worksheet();
2766           my $bold      = $workbook->add_format( bold => 1 );
2767
2768           # Add the worksheet data that the charts will refer to.
2769           my $headings = [ 'Aliens', 'Humans', ];
2770           my $data = [
2771               [ 2,  3,  4,  5,  6,  7 ],
2772               [ 10, 40, 50, 20, 10, 50 ],
2773
2774           ];
2775
2776
2777           $worksheet->write( 'A1', $headings, $bold );
2778           $worksheet->write( 'A2', $data );
2779
2780           # Create a new chart object. In this case an embedded chart.
2781           my $chart = $workbook->add_chart( type => 'line', embedded => 1 );
2782
2783           # Configure a series with a secondary axis
2784           $chart->add_series(
2785               name    => '=Sheet1!$A$1',
2786               values  => '=Sheet1!$A$2:$A$7',
2787               y2_axis => 1,
2788           );
2789
2790           $chart->add_series(
2791               name   => '=Sheet1!$B$1',
2792               values => '=Sheet1!$B$2:$B$7',
2793           );
2794
2795           $chart->set_legend( position => 'right' );
2796
2797           # Add a chart title and some axis labels.
2798           $chart->set_title( name => 'Survey results' );
2799           $chart->set_x_axis( name => 'Days', );
2800           $chart->set_y_axis( name => 'Population', major_gridlines => { visible => 0 } );
2801           $chart->set_y2_axis( name => 'Laser wounds' );
2802
2803           # Insert the chart into the worksheet (with an offset).
2804           $worksheet->insert_chart( 'D2', $chart, 25, 10 );
2805
2806           $workbook->close();
2807
2808           __END__
2809
2810       Download this example:
2811       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_secondary_axis.pl>
2812
2813   Example: chart_combined.pl
2814       An example of a Combined chart in Excel::Writer::XLSX.
2815
2816           #!/usr/bin/perl
2817
2818           #######################################################################
2819           #
2820           # An example of a Combined chart in Excel::Writer::XLSX.
2821           #
2822           # reverse ('(c)'), March 2015, John McNamara, jmcnamara@cpan.org
2823           #
2824
2825           use strict;
2826           use warnings;
2827           use Excel::Writer::XLSX;
2828
2829           my $workbook  = Excel::Writer::XLSX->new( 'chart_combined.xlsx' );
2830           my $worksheet = $workbook->add_worksheet();
2831           my $bold      = $workbook->add_format( bold => 1 );
2832
2833           # Add the worksheet data that the charts will refer to.
2834           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2835           my $data = [
2836               [ 2,  3,  4,  5,  6,  7 ],
2837               [ 10, 40, 50, 20, 10, 50 ],
2838               [ 30, 60, 70, 50, 40, 30 ],
2839
2840           ];
2841
2842           $worksheet->write( 'A1', $headings, $bold );
2843           $worksheet->write( 'A2', $data );
2844
2845           #
2846           # In the first example we will create a combined column and line chart.
2847           # They will share the same X and Y axes.
2848           #
2849
2850           # Create a new column chart. This will use this as the primary chart.
2851           my $column_chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
2852
2853           # Configure the data series for the primary chart.
2854           $column_chart1->add_series(
2855               name       => '=Sheet1!$B$1',
2856               categories => '=Sheet1!$A$2:$A$7',
2857               values     => '=Sheet1!$B$2:$B$7',
2858           );
2859
2860           # Create a new column chart. This will use this as the secondary chart.
2861           my $line_chart1 = $workbook->add_chart( type => 'line', embedded => 1 );
2862
2863           # Configure the data series for the secondary chart.
2864           $line_chart1->add_series(
2865               name       => '=Sheet1!$C$1',
2866               categories => '=Sheet1!$A$2:$A$7',
2867               values     => '=Sheet1!$C$2:$C$7',
2868           );
2869
2870           # Combine the charts.
2871           $column_chart1->combine( $line_chart1 );
2872
2873           # Add a chart title and some axis labels. Note, this is done via the
2874           # primary chart.
2875           $column_chart1->set_title( name => 'Combined chart - same Y axis' );
2876           $column_chart1->set_x_axis( name => 'Test number' );
2877           $column_chart1->set_y_axis( name => 'Sample length (mm)' );
2878
2879
2880           # Insert the chart into the worksheet
2881           $worksheet->insert_chart( 'E2', $column_chart1 );
2882
2883           #
2884           # In the second example we will create a similar combined column and line
2885           # chart except that the secondary chart will have a secondary Y axis.
2886           #
2887
2888           # Create a new column chart. This will use this as the primary chart.
2889           my $column_chart2 = $workbook->add_chart( type => 'column', embedded => 1 );
2890
2891           # Configure the data series for the primary chart.
2892           $column_chart2->add_series(
2893               name       => '=Sheet1!$B$1',
2894               categories => '=Sheet1!$A$2:$A$7',
2895               values     => '=Sheet1!$B$2:$B$7',
2896           );
2897
2898           # Create a new column chart. This will use this as the secondary chart.
2899           my $line_chart2 = $workbook->add_chart( type => 'line', embedded => 1 );
2900
2901           # Configure the data series for the secondary chart. We also set a
2902           # secondary Y axis via (y2_axis). This is the only difference between
2903           # this and the first example, apart from the axis label below.
2904           $line_chart2->add_series(
2905               name       => '=Sheet1!$C$1',
2906               categories => '=Sheet1!$A$2:$A$7',
2907               values     => '=Sheet1!$C$2:$C$7',
2908               y2_axis    => 1,
2909           );
2910
2911           # Combine the charts.
2912           $column_chart2->combine( $line_chart2 );
2913
2914           # Add a chart title and some axis labels.
2915           $column_chart2->set_title(  name => 'Combine chart - secondary Y axis' );
2916           $column_chart2->set_x_axis( name => 'Test number' );
2917           $column_chart2->set_y_axis( name => 'Sample length (mm)' );
2918
2919           # Note: the y2 properites are on the secondary chart.
2920           $line_chart2->set_y2_axis( name => 'Target length (mm)' );
2921
2922
2923           # Insert the chart into the worksheet
2924           $worksheet->insert_chart( 'E18', $column_chart2 );
2925
2926           $workbook->close();
2927
2928           __END__
2929
2930       Download this example:
2931       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_combined.pl>
2932
2933   Example: chart_pareto.pl
2934       A demo of a Pareto chart in Excel::Writer::XLSX.
2935
2936           #!/usr/bin/perl
2937
2938           #######################################################################
2939           #
2940           # A demo of a Pareto chart in Excel::Writer::XLSX.
2941           #
2942           # reverse ('(c)'), March 2015, John McNamara, jmcnamara@cpan.org
2943           #
2944
2945           use strict;
2946           use warnings;
2947           use Excel::Writer::XLSX;
2948
2949           my $workbook  = Excel::Writer::XLSX->new( 'chart_pareto.xlsx' );
2950           my $worksheet = $workbook->add_worksheet();
2951
2952           # Formats used in the workbook.
2953           my $bold           = $workbook->add_format( bold       => 1 );
2954           my $percent_format = $workbook->add_format( num_format => '0.0%' );
2955
2956
2957           # Widen the columns for visibility.
2958           $worksheet->set_column( 'A:A', 15 );
2959           $worksheet->set_column( 'B:C', 10 );
2960
2961           # Add the worksheet data that the charts will refer to.
2962           my $headings = [ 'Reason', 'Number', 'Percentage' ];
2963
2964           my $reasons = [
2965               'Traffic',   'Child care', 'Public Transport', 'Weather',
2966               'Overslept', 'Emergency',
2967           ];
2968
2969           my $numbers  = [ 60,   40,    20,  15,  10,    5 ];
2970           my $percents = [ 0.44, 0.667, 0.8, 0.9, 0.967, 1 ];
2971
2972           $worksheet->write_row( 'A1', $headings, $bold );
2973           $worksheet->write_col( 'A2', $reasons );
2974           $worksheet->write_col( 'B2', $numbers );
2975           $worksheet->write_col( 'C2', $percents, $percent_format );
2976
2977
2978           # Create a new column chart. This will be the primary chart.
2979           my $column_chart = $workbook->add_chart( type => 'column', embedded => 1 );
2980
2981           # Add a series.
2982           $column_chart->add_series(
2983               categories => '=Sheet1!$A$2:$A$7',
2984               values     => '=Sheet1!$B$2:$B$7',
2985           );
2986
2987           # Add a chart title.
2988           $column_chart->set_title( name => 'Reasons for lateness' );
2989
2990           # Turn off the chart legend.
2991           $column_chart->set_legend( position => 'none' );
2992
2993           # Set the title and scale of the Y axes. Note, the secondary axis is set from
2994           # the primary chart.
2995           $column_chart->set_y_axis(
2996               name => 'Respondents (number)',
2997               min  => 0,
2998               max  => 120
2999           );
3000           $column_chart->set_y2_axis( max => 1 );
3001
3002           # Create a new line chart. This will be the secondary chart.
3003           my $line_chart = $workbook->add_chart( type => 'line', embedded => 1 );
3004
3005           # Add a series, on the secondary axis.
3006           $line_chart->add_series(
3007               categories => '=Sheet1!$A$2:$A$7',
3008               values     => '=Sheet1!$C$2:$C$7',
3009               marker     => { type => 'automatic' },
3010               y2_axis    => 1,
3011           );
3012
3013
3014           # Combine the charts.
3015           $column_chart->combine( $line_chart );
3016
3017           # Insert the chart into the worksheet.
3018           $worksheet->insert_chart( 'F2', $column_chart );
3019
3020           $workbook->close();
3021
3022           __END__
3023
3024       Download this example:
3025       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_pareto.pl>
3026
3027   Example: chart_stock.pl
3028       A demo of a Stock chart in Excel::Writer::XLSX.
3029
3030       Source code for this example:
3031
3032           #!/usr/bin/perl
3033
3034           #######################################################################
3035           #
3036           # A demo of a Stock chart in Excel::Writer::XLSX.
3037           #
3038           # reverse ('(c)'), March 2011, John McNamara, jmcnamara@cpan.org
3039           #
3040
3041           use strict;
3042           use warnings;
3043           use Excel::Writer::XLSX;
3044           use Excel::Writer::XLSX;
3045
3046           my $workbook    = Excel::Writer::XLSX->new( 'chart_stock.xlsx' );
3047           my $worksheet   = $workbook->add_worksheet();
3048           my $bold        = $workbook->add_format( bold => 1 );
3049           my $date_format = $workbook->add_format( num_format => 'dd/mm/yyyy' );
3050           my $chart       = $workbook->add_chart( type => 'stock', embedded => 1 );
3051
3052
3053           # Add the worksheet data that the charts will refer to.
3054           my $headings = [ 'Date', 'High', 'Low', 'Close' ];
3055           my $data = [
3056
3057               [ '2007-01-01T', '2007-01-02T', '2007-01-03T', '2007-01-04T', '2007-01-05T' ],
3058               [ 27.2,  25.03, 19.05, 20.34, 18.5 ],
3059               [ 23.49, 19.55, 15.12, 17.84, 16.34 ],
3060               [ 25.45, 23.05, 17.32, 20.45, 17.34 ],
3061
3062           ];
3063
3064           $worksheet->write( 'A1', $headings, $bold );
3065
3066           for my $row ( 0 .. 4 ) {
3067               $worksheet->write_date_time( $row+1, 0, $data->[0]->[$row], $date_format );
3068               $worksheet->write( $row+1, 1, $data->[1]->[$row] );
3069               $worksheet->write( $row+1, 2, $data->[2]->[$row] );
3070               $worksheet->write( $row+1, 3, $data->[3]->[$row] );
3071
3072           }
3073
3074           $worksheet->set_column( 'A:D', 11 );
3075
3076           # Add a series for each of the High-Low-Close columns.
3077           $chart->add_series(
3078               categories => '=Sheet1!$A$2:$A$6',
3079               values     => '=Sheet1!$B$2:$B$6',
3080           );
3081
3082           $chart->add_series(
3083               categories => '=Sheet1!$A$2:$A$6',
3084               values     => '=Sheet1!$C$2:$C$6',
3085           );
3086
3087           $chart->add_series(
3088               categories => '=Sheet1!$A$2:$A$6',
3089               values     => '=Sheet1!$D$2:$D$6',
3090           );
3091
3092           # Add a chart title and some axis labels.
3093           $chart->set_title ( name => 'High-Low-Close', );
3094           $chart->set_x_axis( name => 'Date', );
3095           $chart->set_y_axis( name => 'Share price', );
3096
3097
3098           $worksheet->insert_chart( 'E9', $chart );
3099
3100           $workbook->close();
3101
3102           __END__
3103
3104       Download this example:
3105       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_stock.pl>
3106
3107   Example: chart_data_table.pl
3108       A demo of an Column chart with a data table on the X-axis using
3109       Excel::Writer::XLSX.
3110
3111       Source code for this example:
3112
3113           #!/usr/bin/perl
3114
3115           #######################################################################
3116           #
3117           # A demo of an Column chart with a data table on the X-axis using
3118           # Excel::Writer::XLSX.
3119           #
3120           # reverse ('(c)'), December 2012, John McNamara, jmcnamara@cpan.org
3121           #
3122
3123           use strict;
3124           use warnings;
3125           use Excel::Writer::XLSX;
3126
3127           my $workbook  = Excel::Writer::XLSX->new( 'chart_data_table.xlsx' );
3128           my $worksheet = $workbook->add_worksheet();
3129           my $bold      = $workbook->add_format( bold => 1 );
3130
3131           # Add the worksheet data that the charts will refer to.
3132           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
3133           my $data = [
3134               [ 2,  3,  4,  5,  6,  7 ],
3135               [ 10, 40, 50, 20, 10, 50 ],
3136               [ 30, 60, 70, 50, 40, 30 ],
3137
3138           ];
3139
3140           $worksheet->write( 'A1', $headings, $bold );
3141           $worksheet->write( 'A2', $data );
3142
3143           # Create a column chart with a data table.
3144           my $chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
3145
3146           # Configure the first series.
3147           $chart1->add_series(
3148               name       => '=Sheet1!$B$1',
3149               categories => '=Sheet1!$A$2:$A$7',
3150               values     => '=Sheet1!$B$2:$B$7',
3151           );
3152
3153           # Configure second series. Note alternative use of array ref to define
3154           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
3155           $chart1->add_series(
3156               name       => '=Sheet1!$C$1',
3157               categories => [ 'Sheet1', 1, 6, 0, 0 ],
3158               values     => [ 'Sheet1', 1, 6, 2, 2 ],
3159           );
3160
3161           # Add a chart title and some axis labels.
3162           $chart1->set_title( name => 'Chart with Data Table' );
3163           $chart1->set_x_axis( name => 'Test number' );
3164           $chart1->set_y_axis( name => 'Sample length (mm)' );
3165
3166           # Set a default data table on the X-Axis.
3167           $chart1->set_table();
3168
3169           # Insert the chart into the worksheet (with an offset).
3170           $worksheet->insert_chart( 'D2', $chart1, 25, 10 );
3171
3172
3173           #
3174           # Create a second chart.
3175           #
3176           my $chart2 = $workbook->add_chart( type => 'column', embedded => 1 );
3177
3178           # Configure the first series.
3179           $chart2->add_series(
3180               name       => '=Sheet1!$B$1',
3181               categories => '=Sheet1!$A$2:$A$7',
3182               values     => '=Sheet1!$B$2:$B$7',
3183           );
3184
3185           # Configure second series.
3186           $chart2->add_series(
3187               name       => '=Sheet1!$C$1',
3188               categories => [ 'Sheet1', 1, 6, 0, 0 ],
3189               values     => [ 'Sheet1', 1, 6, 2, 2 ],
3190           );
3191
3192           # Add a chart title and some axis labels.
3193           $chart2->set_title( name => 'Data Table with legend keys' );
3194           $chart2->set_x_axis( name => 'Test number' );
3195           $chart2->set_y_axis( name => 'Sample length (mm)' );
3196
3197           # Set a data table on the X-Axis with the legend keys showm.
3198           $chart2->set_table( show_keys => 1 );
3199
3200           # Hide the chart legend since the keys are show on the data table.
3201           $chart2->set_legend( position => 'none' );
3202
3203           # Insert the chart into the worksheet (with an offset).
3204           $worksheet->insert_chart( 'D18', $chart2, 25, 11 );
3205
3206           $workbook->close();
3207
3208           __END__
3209
3210       Download this example:
3211       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_data_table.pl>
3212
3213   Example: chart_data_tools.pl
3214       A demo of an various Excel chart data tools that are available via an
3215       Excel::Writer::XLSX chart.
3216
3217       These include, Trendlines, Data Labels, Error Bars, Drop Lines, High-
3218       Low Lines and Up-Down Bars.
3219
3220       Source code for this example:
3221
3222           #!/usr/bin/perl
3223
3224           #######################################################################
3225           #
3226           # A demo of an various Excel chart data tools that are available via
3227           # an Excel::Writer::XLSX chart.
3228           #
3229           # These include, Trendlines, Data Labels, Error Bars, Drop Lines,
3230           # High-Low Lines and Up-Down Bars.
3231           #
3232           # reverse ('(c)'), December 2012, John McNamara, jmcnamara@cpan.org
3233           #
3234
3235           use strict;
3236           use warnings;
3237           use Excel::Writer::XLSX;
3238
3239           my $workbook  = Excel::Writer::XLSX->new( 'chart_data_tools.xlsx' );
3240           my $worksheet = $workbook->add_worksheet();
3241           my $bold      = $workbook->add_format( bold => 1 );
3242
3243           # Add the worksheet data that the charts will refer to.
3244           my $headings = [ 'Number', 'Data 1', 'Data 2' ];
3245           my $data = [
3246               [ 2,  3,  4,  5,  6,  7 ],
3247               [ 10, 40, 50, 20, 10, 50 ],
3248               [ 30, 60, 70, 50, 40, 30 ],
3249
3250           ];
3251
3252           $worksheet->write( 'A1', $headings, $bold );
3253           $worksheet->write( 'A2', $data );
3254
3255
3256           #######################################################################
3257           #
3258           # Trendline example.
3259           #
3260
3261           # Create a Line chart.
3262           my $chart1 = $workbook->add_chart( type => 'line', embedded => 1 );
3263
3264           # Configure the first series with a polynomial trendline.
3265           $chart1->add_series(
3266               categories => '=Sheet1!$A$2:$A$7',
3267               values     => '=Sheet1!$B$2:$B$7',
3268               trendline  => {
3269                   type  => 'polynomial',
3270                   order => 3,
3271               },
3272           );
3273
3274           # Configure the second series with a moving average trendline.
3275           $chart1->add_series(
3276               categories => '=Sheet1!$A$2:$A$7',
3277               values     => '=Sheet1!$C$2:$C$7',
3278               trendline  => { type => 'linear' },
3279           );
3280
3281           # Add a chart title. and some axis labels.
3282           $chart1->set_title( name => 'Chart with Trendlines' );
3283
3284           # Insert the chart into the worksheet (with an offset).
3285           $worksheet->insert_chart( 'D2', $chart1, 25, 10 );
3286
3287
3288           #######################################################################
3289           #
3290           # Data Labels and Markers example.
3291           #
3292
3293           # Create a Line chart.
3294           my $chart2 = $workbook->add_chart( type => 'line', embedded => 1 );
3295
3296           # Configure the first series.
3297           $chart2->add_series(
3298               categories  => '=Sheet1!$A$2:$A$7',
3299               values      => '=Sheet1!$B$2:$B$7',
3300               data_labels => { value => 1 },
3301               marker      => { type => 'automatic' },
3302           );
3303
3304           # Configure the second series.
3305           $chart2->add_series(
3306               categories => '=Sheet1!$A$2:$A$7',
3307               values     => '=Sheet1!$C$2:$C$7',
3308           );
3309
3310           # Add a chart title. and some axis labels.
3311           $chart2->set_title( name => 'Chart with Data Labels and Markers' );
3312
3313           # Insert the chart into the worksheet (with an offset).
3314           $worksheet->insert_chart( 'D18', $chart2, 25, 10 );
3315
3316
3317           #######################################################################
3318           #
3319           # Error Bars example.
3320           #
3321
3322           # Create a Line chart.
3323           my $chart3 = $workbook->add_chart( type => 'line', embedded => 1 );
3324
3325           # Configure the first series.
3326           $chart3->add_series(
3327               categories   => '=Sheet1!$A$2:$A$7',
3328               values       => '=Sheet1!$B$2:$B$7',
3329               y_error_bars => { type => 'standard_error' },
3330           );
3331
3332           # Configure the second series.
3333           $chart3->add_series(
3334               categories => '=Sheet1!$A$2:$A$7',
3335               values     => '=Sheet1!$C$2:$C$7',
3336           );
3337
3338           # Add a chart title. and some axis labels.
3339           $chart3->set_title( name => 'Chart with Error Bars' );
3340
3341           # Insert the chart into the worksheet (with an offset).
3342           $worksheet->insert_chart( 'D34', $chart3, 25, 10 );
3343
3344
3345           #######################################################################
3346           #
3347           # Up-Down Bars example.
3348           #
3349
3350           # Create a Line chart.
3351           my $chart4 = $workbook->add_chart( type => 'line', embedded => 1 );
3352
3353           # Add the Up-Down Bars.
3354           $chart4->set_up_down_bars();
3355
3356           # Configure the first series.
3357           $chart4->add_series(
3358               categories => '=Sheet1!$A$2:$A$7',
3359               values     => '=Sheet1!$B$2:$B$7',
3360           );
3361
3362           # Configure the second series.
3363           $chart4->add_series(
3364               categories => '=Sheet1!$A$2:$A$7',
3365               values     => '=Sheet1!$C$2:$C$7',
3366           );
3367
3368           # Add a chart title. and some axis labels.
3369           $chart4->set_title( name => 'Chart with Up-Down Bars' );
3370
3371           # Insert the chart into the worksheet (with an offset).
3372           $worksheet->insert_chart( 'D50', $chart4, 25, 10 );
3373
3374
3375           #######################################################################
3376           #
3377           # High-Low Lines example.
3378           #
3379
3380           # Create a Line chart.
3381           my $chart5 = $workbook->add_chart( type => 'line', embedded => 1 );
3382
3383           # Add the High-Low lines.
3384           $chart5->set_high_low_lines();
3385
3386           # Configure the first series.
3387           $chart5->add_series(
3388               categories => '=Sheet1!$A$2:$A$7',
3389               values     => '=Sheet1!$B$2:$B$7',
3390           );
3391
3392           # Configure the second series.
3393           $chart5->add_series(
3394               categories => '=Sheet1!$A$2:$A$7',
3395               values     => '=Sheet1!$C$2:$C$7',
3396           );
3397
3398           # Add a chart title. and some axis labels.
3399           $chart5->set_title( name => 'Chart with High-Low Lines' );
3400
3401           # Insert the chart into the worksheet (with an offset).
3402           $worksheet->insert_chart( 'D66', $chart5, 25, 10 );
3403
3404
3405           #######################################################################
3406           #
3407           # Drop Lines example.
3408           #
3409
3410           # Create a Line chart.
3411           my $chart6 = $workbook->add_chart( type => 'line', embedded => 1 );
3412
3413           # Add Drop Lines.
3414           $chart6->set_drop_lines();
3415
3416           # Configure the first series.
3417           $chart6->add_series(
3418               categories => '=Sheet1!$A$2:$A$7',
3419               values     => '=Sheet1!$B$2:$B$7',
3420           );
3421
3422           # Configure the second series.
3423           $chart6->add_series(
3424               categories => '=Sheet1!$A$2:$A$7',
3425               values     => '=Sheet1!$C$2:$C$7',
3426           );
3427
3428           # Add a chart title. and some axis labels.
3429           $chart6->set_title( name => 'Chart with Drop Lines' );
3430
3431           # Insert the chart into the worksheet (with an offset).
3432           $worksheet->insert_chart( 'D82', $chart6, 25, 10 );
3433
3434           $workbook->close();
3435
3436           __END__
3437
3438       Download this example:
3439       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_data_tools.pl>
3440
3441   Example: chart_clustered.pl
3442       A demo of a clustered category chart in Excel::Writer::XLSX.
3443
3444           #!/usr/bin/perl
3445
3446           #######################################################################
3447           #
3448           # A demo of a clustered category chart in Excel::Writer::XLSX.
3449           #
3450           # reverse ('(c)'), March 2015, John McNamara, jmcnamara@cpan.org
3451           #
3452
3453           use strict;
3454           use warnings;
3455           use Excel::Writer::XLSX;
3456
3457           my $workbook  = Excel::Writer::XLSX->new( 'chart_clustered.xlsx' );
3458           my $worksheet = $workbook->add_worksheet();
3459           my $bold      = $workbook->add_format( bold => 1 );
3460
3461           # Add the worksheet data that the charts will refer to.
3462           my $headings = [ 'Types',  'Sub Type',   'Value 1', 'Value 2', 'Value 3' ];
3463           my $data = [
3464               [ 'Type 1', 'Sub Type A', 5000,      8000,      6000 ],
3465               [ '',       'Sub Type B', 2000,      3000,      4000 ],
3466               [ '',       'Sub Type C', 250,       1000,      2000 ],
3467               [ 'Type 2', 'Sub Type D', 6000,      6000,      6500 ],
3468               [ '',       'Sub Type E', 500,       300,       200 ],
3469           ];
3470
3471           $worksheet->write( 'A1', $headings, $bold );
3472           $worksheet->write_col( 'A2', $data );
3473
3474           # Create a new chart object. In this case an embedded chart.
3475           my $chart = $workbook->add_chart( type => 'column', embedded => 1 );
3476
3477           # Configure the series. Note, that the categories are 2D ranges (from column A
3478           # to column B). This creates the clusters. The series are shown as formula
3479           # strings for clarity but you can also use the array syntax. See the docs.
3480           $chart->add_series(
3481               name       => '=Sheet1!$C$1',
3482               categories => '=Sheet1!$A$2:$B$6',
3483               values     => '=Sheet1!$C$2:$C$6',
3484           );
3485
3486           $chart->add_series(
3487               name       => '=Sheet1!$D$1',
3488               categories => '=Sheet1!$A$2:$B$6',
3489               values     => '=Sheet1!$D$2:$D$6',
3490           );
3491
3492           $chart->add_series(
3493               name       => '=Sheet1!$E$1',
3494               categories => '=Sheet1!$A$2:$B$6',
3495               values     => '=Sheet1!$E$2:$E$6',
3496           );
3497
3498           # Set the Excel chart style.
3499           $chart->set_style( 37 );
3500
3501           # Turn off the legend.
3502           $chart->set_legend( position => 'none' );
3503
3504           # Insert the chart into the worksheet.
3505           $worksheet->insert_chart( 'G3', $chart );
3506
3507           $workbook->close();
3508
3509           __END__
3510
3511       Download this example:
3512       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_clustered.pl>
3513
3514   Example: chart_styles.pl
3515       An example showing all 48 default chart styles available in Excel 2007
3516       using Excel::Writer::XLSX.. Note, these styles are not the same as the
3517       styles available in Excel 2013.
3518
3519           #!/usr/bin/perl
3520
3521           #######################################################################
3522           #
3523           # An example showing all 48 default chart styles available in Excel 2007
3524           # using Excel::Writer::XLSX.. Note, these styles are not the same as the
3525           # styles available in Excel 2013.
3526           #
3527           # reverse ('(c)'), March 2015, John McNamara, jmcnamara@cpan.org
3528           #
3529
3530           use strict;
3531           use warnings;
3532           use Excel::Writer::XLSX;
3533
3534           my $workbook = Excel::Writer::XLSX->new( 'chart_styles.xlsx' );
3535
3536           # Show the styles for all of these chart types.
3537           my @chart_types = ( 'column', 'area', 'line', 'pie' );
3538
3539
3540           for my $chart_type ( @chart_types ) {
3541
3542               # Add a worksheet for each chart type.
3543               my $worksheet = $workbook->add_worksheet( ucfirst( $chart_type ) );
3544               $worksheet->set_zoom( 30 );
3545               my $style_number = 1;
3546
3547               # Create 48 charts, each with a different style.
3548               for ( my $row_num = 0 ; $row_num < 90 ; $row_num += 15 ) {
3549                   for ( my $col_num = 0 ; $col_num < 64 ; $col_num += 8 ) {
3550
3551                       my $chart = $workbook->add_chart(
3552                           type     => $chart_type,
3553                           embedded => 1
3554                       );
3555
3556                       $chart->add_series( values => '=Data!$A$1:$A$6' );
3557                       $chart->set_title( name => 'Style ' . $style_number );
3558                       $chart->set_legend( none => 1 );
3559                       $chart->set_style( $style_number );
3560
3561                       $worksheet->insert_chart( $row_num, $col_num, $chart );
3562                       $style_number++;
3563                   }
3564               }
3565           }
3566
3567           # Create a worksheet with data for the charts.
3568           my $data = [ 10, 40, 50, 20, 10, 50 ];
3569           my $data_worksheet = $workbook->add_worksheet( 'Data' );
3570           $data_worksheet->write_col( 'A1', $data );
3571           $data_worksheet->hide();
3572
3573           $workbook->close();
3574
3575           __END__
3576
3577       Download this example:
3578       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/chart_styles.pl>
3579
3580   Example: colors.pl
3581       Demonstrates Excel::Writer::XLSX's named colours and the Excel colour
3582       palette.
3583
3584       The set_custom_color() Worksheet method can be used to override one of
3585       the built-in palette values with a more suitable colour. See the main
3586       docs.
3587
3588       Source code for this example:
3589
3590           #!/usr/bin/perl -w
3591
3592           ################################################################################
3593           #
3594           # Demonstrates Excel::Writer::XLSX's named colours and the Excel colour
3595           # palette.
3596           #
3597           # The set_custom_color() Worksheet method can be used to override one of the
3598           # built-in palette values with a more suitable colour. See the main docs.
3599           #
3600           # reverse ('(c)'), March 2002, John McNamara, jmcnamara@cpan.org
3601           #
3602
3603           use strict;
3604           use Excel::Writer::XLSX;
3605
3606           my $workbook = Excel::Writer::XLSX->new( 'colors.xlsx' );
3607
3608           # Some common formats
3609           my $center = $workbook->add_format( align => 'center' );
3610           my $heading = $workbook->add_format( align => 'center', bold => 1 );
3611
3612
3613           ######################################################################
3614           #
3615           # Demonstrate the named colors.
3616           #
3617
3618           my %colors = (
3619               0x08, 'black',
3620               0x0C, 'blue',
3621               0x10, 'brown',
3622               0x0F, 'cyan',
3623               0x17, 'gray',
3624               0x11, 'green',
3625               0x0B, 'lime',
3626               0x0E, 'magenta',
3627               0x12, 'navy',
3628               0x35, 'orange',
3629               0x21, 'pink',
3630               0x14, 'purple',
3631               0x0A, 'red',
3632               0x16, 'silver',
3633               0x09, 'white',
3634               0x0D, 'yellow',
3635
3636           );
3637
3638           my $worksheet1 = $workbook->add_worksheet( 'Named colors' );
3639
3640           $worksheet1->set_column( 0, 3, 15 );
3641
3642           $worksheet1->write( 0, 0, "Index", $heading );
3643           $worksheet1->write( 0, 1, "Index", $heading );
3644           $worksheet1->write( 0, 2, "Name",  $heading );
3645           $worksheet1->write( 0, 3, "Color", $heading );
3646
3647           my $i = 1;
3648
3649           while ( my ( $index, $color ) = each %colors ) {
3650               my $format = $workbook->add_format(
3651                   fg_color => $color,
3652                   pattern  => 1,
3653                   border   => 1
3654               );
3655
3656               $worksheet1->write( $i + 1, 0, $index, $center );
3657               $worksheet1->write( $i + 1, 1, sprintf( "0x%02X", $index ), $center );
3658               $worksheet1->write( $i + 1, 2, $color, $center );
3659               $worksheet1->write( $i + 1, 3, '',     $format );
3660               $i++;
3661           }
3662
3663
3664           ######################################################################
3665           #
3666           # Demonstrate the standard Excel colors in the range 8..63.
3667           #
3668
3669           my $worksheet2 = $workbook->add_worksheet( 'Standard colors' );
3670
3671           $worksheet2->set_column( 0, 3, 15 );
3672
3673           $worksheet2->write( 0, 0, "Index", $heading );
3674           $worksheet2->write( 0, 1, "Index", $heading );
3675           $worksheet2->write( 0, 2, "Color", $heading );
3676           $worksheet2->write( 0, 3, "Name",  $heading );
3677
3678           for my $i ( 8 .. 63 ) {
3679               my $format = $workbook->add_format(
3680                   fg_color => $i,
3681                   pattern  => 1,
3682                   border   => 1
3683               );
3684
3685               $worksheet2->write( ( $i - 7 ), 0, $i, $center );
3686               $worksheet2->write( ( $i - 7 ), 1, sprintf( "0x%02X", $i ), $center );
3687               $worksheet2->write( ( $i - 7 ), 2, '', $format );
3688
3689               # Add the  color names
3690               if ( exists $colors{$i} ) {
3691                   $worksheet2->write( ( $i - 7 ), 3, $colors{$i}, $center );
3692
3693               }
3694           }
3695
3696
3697           ######################################################################
3698           #
3699           # Demonstrate the Html colors.
3700           #
3701
3702
3703
3704           %colors = (
3705               '#000000',  'black',
3706               '#0000FF',  'blue',
3707               '#800000',  'brown',
3708               '#00FFFF',  'cyan',
3709               '#808080',  'gray',
3710               '#008000',  'green',
3711               '#00FF00',  'lime',
3712               '#FF00FF',  'magenta',
3713               '#000080',  'navy',
3714               '#FF6600',  'orange',
3715               '#FF00FF',  'pink',
3716               '#800080',  'purple',
3717               '#FF0000',  'red',
3718               '#C0C0C0',  'silver',
3719               '#FFFFFF',  'white',
3720               '#FFFF00',  'yellow',
3721           );
3722
3723           my $worksheet3 = $workbook->add_worksheet( 'Html colors' );
3724
3725           $worksheet3->set_column( 0, 3, 15 );
3726
3727           $worksheet3->write( 0, 0, "Html", $heading );
3728           $worksheet3->write( 0, 1, "Name",  $heading );
3729           $worksheet3->write( 0, 2, "Color", $heading );
3730
3731           $i = 1;
3732
3733           while ( my ( $html_color, $color ) = each %colors ) {
3734               my $format = $workbook->add_format(
3735                   fg_color => $html_color,
3736                   pattern  => 1,
3737                   border   => 1
3738               );
3739
3740               $worksheet3->write( $i + 1, 1, $html_color, $center );
3741               $worksheet3->write( $i + 1, 2, $color,      $center );
3742               $worksheet3->write( $i + 1, 3, '',          $format );
3743               $i++;
3744           }
3745
3746           $workbook->close();
3747
3748           __END__
3749
3750       Download this example:
3751       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/colors.pl>
3752
3753   Example: comments1.pl
3754       This example demonstrates writing cell comments.
3755
3756       A cell comment is indicated in Excel by a small red triangle in the
3757       upper right-hand corner of the cell.
3758
3759       For more advanced comment options see comments2.pl.
3760
3761       Source code for this example:
3762
3763           #!/usr/bin/perl
3764
3765           ###############################################################################
3766           #
3767           # This example demonstrates writing cell comments.
3768           #
3769           # A cell comment is indicated in Excel by a small red triangle in the upper
3770           # right-hand corner of the cell.
3771           #
3772           # For more advanced comment options see comments2.pl.
3773           #
3774           # reverse ('(c)'), November 2005, John McNamara, jmcnamara@cpan.org
3775           #
3776
3777           use strict;
3778           use warnings;
3779           use Excel::Writer::XLSX;
3780
3781           my $workbook  = Excel::Writer::XLSX->new( 'comments1.xlsx' );
3782           my $worksheet = $workbook->add_worksheet();
3783
3784
3785           $worksheet->write( 'A1', 'Hello' );
3786           $worksheet->write_comment( 'A1', 'This is a comment' );
3787
3788           $workbook->close();
3789
3790           __END__
3791
3792       Download this example:
3793       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/comments1.pl>
3794
3795   Example: comments2.pl
3796       This example demonstrates writing cell comments.
3797
3798       A cell comment is indicated in Excel by a small red triangle in the
3799       upper right-hand corner of the cell.
3800
3801       Each of the worksheets demonstrates different features of cell
3802       comments.
3803
3804       Source code for this example:
3805
3806           #!/usr/bin/perl
3807
3808           ###############################################################################
3809           #
3810           # This example demonstrates writing cell comments.
3811           #
3812           # A cell comment is indicated in Excel by a small red triangle in the upper
3813           # right-hand corner of the cell.
3814           #
3815           # Each of the worksheets demonstrates different features of cell comments.
3816           #
3817           # reverse ('(c)'), November 2005, John McNamara, jmcnamara@cpan.org
3818           #
3819
3820           use strict;
3821           use warnings;
3822           use Excel::Writer::XLSX;
3823
3824           my $workbook   = Excel::Writer::XLSX->new( 'comments2.xlsx' );
3825           my $text_wrap  = $workbook->add_format( text_wrap => 1, valign => 'top' );
3826           my $worksheet1 = $workbook->add_worksheet();
3827           my $worksheet2 = $workbook->add_worksheet();
3828           my $worksheet3 = $workbook->add_worksheet();
3829           my $worksheet4 = $workbook->add_worksheet();
3830           my $worksheet5 = $workbook->add_worksheet();
3831           my $worksheet6 = $workbook->add_worksheet();
3832           my $worksheet7 = $workbook->add_worksheet();
3833           my $worksheet8 = $workbook->add_worksheet();
3834
3835
3836           # Variables that we will use in each example.
3837           my $cell_text = '';
3838           my $comment   = '';
3839
3840
3841           ###############################################################################
3842           #
3843           # Example 1. Demonstrates a simple cell comments without formatting.
3844           #            comments.
3845           #
3846
3847           # Set up some formatting.
3848           $worksheet1->set_column( 'C:C', 25 );
3849           $worksheet1->set_row( 2, 50 );
3850           $worksheet1->set_row( 5, 50 );
3851
3852
3853           # Simple ascii string.
3854           $cell_text = 'Hold the mouse over this cell to see the comment.';
3855
3856           $comment = 'This is a comment.';
3857
3858           $worksheet1->write( 'C3', $cell_text, $text_wrap );
3859           $worksheet1->write_comment( 'C3', $comment );
3860
3861           $cell_text = 'This is a UTF-8 string.';
3862           $comment   = chr 0x263a;
3863
3864           $worksheet1->write( 'C6', $cell_text, $text_wrap );
3865           $worksheet1->write_comment( 'C6', $comment );
3866
3867
3868
3869           ###############################################################################
3870           #
3871           # Example 2. Demonstrates visible and hidden comments.
3872           #
3873
3874           # Set up some formatting.
3875           $worksheet2->set_column( 'C:C', 25 );
3876           $worksheet2->set_row( 2, 50 );
3877           $worksheet2->set_row( 5, 50 );
3878
3879
3880           $cell_text = 'This cell comment is visible.';
3881
3882           $comment = 'Hello.';
3883
3884           $worksheet2->write( 'C3', $cell_text, $text_wrap );
3885           $worksheet2->write_comment( 'C3', $comment, visible => 1 );
3886
3887
3888           $cell_text = "This cell comment isn't visible (the default).";
3889
3890           $comment = 'Hello.';
3891
3892           $worksheet2->write( 'C6', $cell_text, $text_wrap );
3893           $worksheet2->write_comment( 'C6', $comment );
3894
3895
3896           ###############################################################################
3897           #
3898           # Example 3. Demonstrates visible and hidden comments set at the worksheet
3899           #            level.
3900           #
3901
3902           # Set up some formatting.
3903           $worksheet3->set_column( 'C:C', 25 );
3904           $worksheet3->set_row( 2, 50 );
3905           $worksheet3->set_row( 5, 50 );
3906           $worksheet3->set_row( 8, 50 );
3907
3908           # Make all comments on the worksheet visible.
3909           $worksheet3->show_comments();
3910
3911           $cell_text = 'This cell comment is visible, explicitly.';
3912
3913           $comment = 'Hello.';
3914
3915           $worksheet3->write( 'C3', $cell_text, $text_wrap );
3916           $worksheet3->write_comment( 'C3', $comment, visible => 1 );
3917
3918
3919           $cell_text =
3920             'This cell comment is also visible because ' . 'we used show_comments().';
3921
3922           $comment = 'Hello.';
3923
3924           $worksheet3->write( 'C6', $cell_text, $text_wrap );
3925           $worksheet3->write_comment( 'C6', $comment );
3926
3927
3928           $cell_text = 'However, we can still override it locally.';
3929
3930           $comment = 'Hello.';
3931
3932           $worksheet3->write( 'C9', $cell_text, $text_wrap );
3933           $worksheet3->write_comment( 'C9', $comment, visible => 0 );
3934
3935
3936           ###############################################################################
3937           #
3938           # Example 4. Demonstrates changes to the comment box dimensions.
3939           #
3940
3941           # Set up some formatting.
3942           $worksheet4->set_column( 'C:C', 25 );
3943           $worksheet4->set_row( 2,  50 );
3944           $worksheet4->set_row( 5,  50 );
3945           $worksheet4->set_row( 8,  50 );
3946           $worksheet4->set_row( 15, 50 );
3947
3948           $worksheet4->show_comments();
3949
3950           $cell_text = 'This cell comment is default size.';
3951
3952           $comment = 'Hello.';
3953
3954           $worksheet4->write( 'C3', $cell_text, $text_wrap );
3955           $worksheet4->write_comment( 'C3', $comment );
3956
3957
3958           $cell_text = 'This cell comment is twice as wide.';
3959
3960           $comment = 'Hello.';
3961
3962           $worksheet4->write( 'C6', $cell_text, $text_wrap );
3963           $worksheet4->write_comment( 'C6', $comment, x_scale => 2 );
3964
3965
3966           $cell_text = 'This cell comment is twice as high.';
3967
3968           $comment = 'Hello.';
3969
3970           $worksheet4->write( 'C9', $cell_text, $text_wrap );
3971           $worksheet4->write_comment( 'C9', $comment, y_scale => 2 );
3972
3973
3974           $cell_text = 'This cell comment is scaled in both directions.';
3975
3976           $comment = 'Hello.';
3977
3978           $worksheet4->write( 'C16', $cell_text, $text_wrap );
3979           $worksheet4->write_comment( 'C16', $comment, x_scale => 1.2, y_scale => 0.8 );
3980
3981
3982           $cell_text = 'This cell comment has width and height specified in pixels.';
3983
3984           $comment = 'Hello.';
3985
3986           $worksheet4->write( 'C19', $cell_text, $text_wrap );
3987           $worksheet4->write_comment( 'C19', $comment, width => 200, height => 20 );
3988
3989
3990           ###############################################################################
3991           #
3992           # Example 5. Demonstrates changes to the cell comment position.
3993           #
3994
3995           $worksheet5->set_column( 'C:C', 25 );
3996           $worksheet5->set_row( 2,  50 );
3997           $worksheet5->set_row( 5,  50 );
3998           $worksheet5->set_row( 8,  50 );
3999           $worksheet5->set_row( 11, 50 );
4000
4001           $worksheet5->show_comments();
4002
4003           $cell_text = 'This cell comment is in the default position.';
4004
4005           $comment = 'Hello.';
4006
4007           $worksheet5->write( 'C3', $cell_text, $text_wrap );
4008           $worksheet5->write_comment( 'C3', $comment );
4009
4010
4011           $cell_text = 'This cell comment has been moved to another cell.';
4012
4013           $comment = 'Hello.';
4014
4015           $worksheet5->write( 'C6', $cell_text, $text_wrap );
4016           $worksheet5->write_comment( 'C6', $comment, start_cell => 'E4' );
4017
4018
4019           $cell_text = 'This cell comment has been moved to another cell.';
4020
4021           $comment = 'Hello.';
4022
4023           $worksheet5->write( 'C9', $cell_text, $text_wrap );
4024           $worksheet5->write_comment( 'C9', $comment, start_row => 8, start_col => 4 );
4025
4026
4027           $cell_text = 'This cell comment has been shifted within its default cell.';
4028
4029           $comment = 'Hello.';
4030
4031           $worksheet5->write( 'C12', $cell_text, $text_wrap );
4032           $worksheet5->write_comment( 'C12', $comment, x_offset => 30, y_offset => 12 );
4033
4034
4035           ###############################################################################
4036           #
4037           # Example 6. Demonstrates changes to the comment background colour.
4038           #
4039
4040           $worksheet6->set_column( 'C:C', 25 );
4041           $worksheet6->set_row( 2, 50 );
4042           $worksheet6->set_row( 5, 50 );
4043           $worksheet6->set_row( 8, 50 );
4044
4045           $worksheet6->show_comments();
4046
4047           $cell_text = 'This cell comment has a different colour.';
4048
4049           $comment = 'Hello.';
4050
4051           $worksheet6->write( 'C3', $cell_text, $text_wrap );
4052           $worksheet6->write_comment( 'C3', $comment, color => 'green' );
4053
4054
4055           $cell_text = 'This cell comment has the default colour.';
4056
4057           $comment = 'Hello.';
4058
4059           $worksheet6->write( 'C6', $cell_text, $text_wrap );
4060           $worksheet6->write_comment( 'C6', $comment );
4061
4062
4063           $cell_text = 'This cell comment has a different colour.';
4064
4065           $comment = 'Hello.';
4066
4067           $worksheet6->write( 'C9', $cell_text, $text_wrap );
4068           $worksheet6->write_comment( 'C9', $comment, color => '#FF6600' );
4069
4070
4071           ###############################################################################
4072           #
4073           # Example 7. Demonstrates how to set the cell comment author.
4074           #
4075
4076           $worksheet7->set_column( 'C:C', 30 );
4077           $worksheet7->set_row( 2,  50 );
4078           $worksheet7->set_row( 5,  50 );
4079           $worksheet7->set_row( 8,  50 );
4080
4081           my $author = '';
4082           my $cell   = 'C3';
4083
4084           $cell_text = "Move the mouse over this cell and you will see 'Cell commented "
4085             . "by $author' (blank) in the status bar at the bottom";
4086
4087           $comment = 'Hello.';
4088
4089           $worksheet7->write( $cell, $cell_text, $text_wrap );
4090           $worksheet7->write_comment( $cell, $comment );
4091
4092
4093           $author    = 'Perl';
4094           $cell      = 'C6';
4095           $cell_text = "Move the mouse over this cell and you will see 'Cell commented "
4096             . "by $author' in the status bar at the bottom";
4097
4098           $comment = 'Hello.';
4099
4100           $worksheet7->write( $cell, $cell_text, $text_wrap );
4101           $worksheet7->write_comment( $cell, $comment, author => $author );
4102
4103
4104           $author    = chr 0x20AC;
4105           $cell      = 'C9';
4106           $cell_text = "Move the mouse over this cell and you will see 'Cell commented "
4107             . "by $author' in the status bar at the bottom";
4108           $comment = 'Hello.';
4109
4110           $worksheet7->write( $cell, $cell_text, $text_wrap );
4111           $worksheet7->write_comment( $cell, $comment, author => $author );
4112
4113
4114
4115
4116           ###############################################################################
4117           #
4118           # Example 8. Demonstrates the need to explicitly set the row height.
4119           #
4120
4121           # Set up some formatting.
4122           $worksheet8->set_column( 'C:C', 25 );
4123           $worksheet8->set_row( 2, 80 );
4124
4125           $worksheet8->show_comments();
4126
4127
4128           $cell_text =
4129               'The height of this row has been adjusted explicitly using '
4130             . 'set_row(). The size of the comment box is adjusted '
4131             . 'accordingly by Excel::Writer::XLSX.';
4132
4133           $comment = 'Hello.';
4134
4135           $worksheet8->write( 'C3', $cell_text, $text_wrap );
4136           $worksheet8->write_comment( 'C3', $comment );
4137
4138
4139           $cell_text =
4140               'The height of this row has been adjusted by Excel due to the '
4141             . 'text wrap property being set. Unfortunately this means that '
4142             . 'the height of the row is unknown to Excel::Writer::XLSX at '
4143             . "run time and thus the comment box is stretched as well.\n\n"
4144             . 'Use set_row() to specify the row height explicitly to avoid '
4145             . 'this problem.';
4146
4147           $comment = 'Hello.';
4148
4149           $worksheet8->write( 'C6', $cell_text, $text_wrap );
4150           $worksheet8->write_comment( 'C6', $comment );
4151
4152           $workbook->close();
4153
4154           __END__
4155
4156       Download this example:
4157       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/comments2.pl>
4158
4159   Example: conditional_format.pl
4160       Example of how to add conditional formatting to an Excel::Writer::XLSX
4161       file.
4162
4163       Conditional formatting allows you to apply a format to a cell or a
4164       range of cells based on certain criteria.
4165
4166       Source code for this example:
4167
4168           #!/usr/bin/perl
4169
4170           ###############################################################################
4171           #
4172           # Example of how to add conditional formatting to an Excel::Writer::XLSX file.
4173           #
4174           # Conditional formatting allows you to apply a format to a cell or a range of
4175           # cells based on certain criteria.
4176           #
4177           # reverse ('(c)'), October 2011, John McNamara, jmcnamara@cpan.org
4178           #
4179
4180           use strict;
4181           use warnings;
4182           use Excel::Writer::XLSX;
4183
4184           my $workbook   = Excel::Writer::XLSX->new( 'conditional_format.xlsx' );
4185           my $worksheet1 = $workbook->add_worksheet();
4186           my $worksheet2 = $workbook->add_worksheet();
4187           my $worksheet3 = $workbook->add_worksheet();
4188           my $worksheet4 = $workbook->add_worksheet();
4189           my $worksheet5 = $workbook->add_worksheet();
4190           my $worksheet6 = $workbook->add_worksheet();
4191           my $worksheet7 = $workbook->add_worksheet();
4192           my $worksheet8 = $workbook->add_worksheet();
4193           my $worksheet9 = $workbook->add_worksheet();
4194
4195
4196           # Light red fill with dark red text.
4197           my $format1 = $workbook->add_format(
4198               bg_color => '#FFC7CE',
4199               color    => '#9C0006',
4200
4201           );
4202
4203           # Green fill with dark green text.
4204           my $format2 = $workbook->add_format(
4205               bg_color => '#C6EFCE',
4206               color    => '#006100',
4207
4208           );
4209
4210           # Some sample data to run the conditional formatting against.
4211           my $data = [
4212               [ 34, 72,  38, 30, 75, 48, 75, 66, 84, 86 ],
4213               [ 6,  24,  1,  84, 54, 62, 60, 3,  26, 59 ],
4214               [ 28, 79,  97, 13, 85, 93, 93, 22, 5,  14 ],
4215               [ 27, 71,  40, 17, 18, 79, 90, 93, 29, 47 ],
4216               [ 88, 25,  33, 23, 67, 1,  59, 79, 47, 36 ],
4217               [ 24, 100, 20, 88, 29, 33, 38, 54, 54, 88 ],
4218               [ 6,  57,  88, 28, 10, 26, 37, 7,  41, 48 ],
4219               [ 52, 78,  1,  96, 26, 45, 47, 33, 96, 36 ],
4220               [ 60, 54,  81, 66, 81, 90, 80, 93, 12, 55 ],
4221               [ 70, 5,   46, 14, 71, 19, 66, 36, 41, 21 ],
4222           ];
4223
4224
4225           ###############################################################################
4226           #
4227           # Example 1.
4228           #
4229           my $caption = 'Cells with values >= 50 are in light red. '
4230             . 'Values < 50 are in light green.';
4231
4232           # Write the data.
4233           $worksheet1->write( 'A1', $caption );
4234           $worksheet1->write_col( 'B3', $data );
4235
4236           # Write a conditional format over a range.
4237           $worksheet1->conditional_formatting( 'B3:K12',
4238               {
4239                   type     => 'cell',
4240                   criteria => '>=',
4241                   value    => 50,
4242                   format   => $format1,
4243               }
4244           );
4245
4246           # Write another conditional format over the same range.
4247           $worksheet1->conditional_formatting( 'B3:K12',
4248               {
4249                   type     => 'cell',
4250                   criteria => '<',
4251                   value    => 50,
4252                   format   => $format2,
4253               }
4254           );
4255
4256
4257           ###############################################################################
4258           #
4259           # Example 2.
4260           #
4261           $caption = 'Values between 30 and 70 are in light red. '
4262             . 'Values outside that range are in light green.';
4263
4264           $worksheet2->write( 'A1', $caption );
4265           $worksheet2->write_col( 'B3', $data );
4266
4267           $worksheet2->conditional_formatting( 'B3:K12',
4268               {
4269                   type     => 'cell',
4270                   criteria => 'between',
4271                   minimum  => 30,
4272                   maximum  => 70,
4273                   format   => $format1,
4274               }
4275           );
4276
4277           $worksheet2->conditional_formatting( 'B3:K12',
4278               {
4279                   type     => 'cell',
4280                   criteria => 'not between',
4281                   minimum  => 30,
4282                   maximum  => 70,
4283                   format   => $format2,
4284               }
4285           );
4286
4287
4288           ###############################################################################
4289           #
4290           # Example 3.
4291           #
4292           $caption = 'Duplicate values are in light red. '
4293             . 'Unique values are in light green.';
4294
4295           $worksheet3->write( 'A1', $caption );
4296           $worksheet3->write_col( 'B3', $data );
4297
4298           $worksheet3->conditional_formatting( 'B3:K12',
4299               {
4300                   type     => 'duplicate',
4301                   format   => $format1,
4302               }
4303           );
4304
4305           $worksheet3->conditional_formatting( 'B3:K12',
4306               {
4307                   type     => 'unique',
4308                   format   => $format2,
4309               }
4310           );
4311
4312
4313           ###############################################################################
4314           #
4315           # Example 4.
4316           #
4317           $caption = 'Above average values are in light red. '
4318             . 'Below average values are in light green.';
4319
4320           $worksheet4->write( 'A1', $caption );
4321           $worksheet4->write_col( 'B3', $data );
4322
4323           $worksheet4->conditional_formatting( 'B3:K12',
4324               {
4325                   type     => 'average',
4326                   criteria => 'above',
4327                   format   => $format1,
4328               }
4329           );
4330
4331           $worksheet4->conditional_formatting( 'B3:K12',
4332               {
4333                   type     => 'average',
4334                   criteria => 'below',
4335                   format   => $format2,
4336               }
4337           );
4338
4339
4340           ###############################################################################
4341           #
4342           # Example 5.
4343           #
4344           $caption = 'Top 10 values are in light red. '
4345             . 'Bottom 10 values are in light green.';
4346
4347           $worksheet5->write( 'A1', $caption );
4348           $worksheet5->write_col( 'B3', $data );
4349
4350           $worksheet5->conditional_formatting( 'B3:K12',
4351               {
4352                   type     => 'top',
4353                   value    => '10',
4354                   format   => $format1,
4355               }
4356           );
4357
4358           $worksheet5->conditional_formatting( 'B3:K12',
4359               {
4360                   type     => 'bottom',
4361                   value    => '10',
4362                   format   => $format2,
4363               }
4364           );
4365
4366
4367           ###############################################################################
4368           #
4369           # Example 6.
4370           #
4371           $caption = 'Cells with values >= 50 are in light red. '
4372             . 'Values < 50 are in light green. Non-contiguous ranges.';
4373
4374           # Write the data.
4375           $worksheet6->write( 'A1', $caption );
4376           $worksheet6->write_col( 'B3', $data );
4377
4378           # Write a conditional format over a range.
4379           $worksheet6->conditional_formatting( 'B3:K6,B9:K12',
4380               {
4381                   type     => 'cell',
4382                   criteria => '>=',
4383                   value    => 50,
4384                   format   => $format1,
4385               }
4386           );
4387
4388           # Write another conditional format over the same range.
4389           $worksheet6->conditional_formatting( 'B3:K6,B9:K12',
4390               {
4391                   type     => 'cell',
4392                   criteria => '<',
4393                   value    => 50,
4394                   format   => $format2,
4395               }
4396           );
4397
4398
4399           ###############################################################################
4400           #
4401           # Example 7.
4402           #
4403           $caption = 'Examples of color scales with default and user colors.';
4404
4405           $data = [ 1 .. 12 ];
4406
4407           $worksheet7->write( 'A1', $caption );
4408
4409           $worksheet7->write    ( 'B2', "2 Color Scale" );
4410           $worksheet7->write_col( 'B3', $data );
4411
4412           $worksheet7->write    ( 'D2', "2 Color Scale + user colors" );
4413           $worksheet7->write_col( 'D3', $data );
4414
4415           $worksheet7->write    ( 'G2', "3 Color Scale" );
4416           $worksheet7->write_col( 'G3', $data );
4417
4418           $worksheet7->write    ( 'I2', "3 Color Scale + user colors" );
4419           $worksheet7->write_col( 'I3', $data );
4420
4421
4422           $worksheet7->conditional_formatting( 'B3:B14',
4423               {
4424                   type => '2_color_scale',
4425               }
4426           );
4427
4428           $worksheet7->conditional_formatting( 'D3:D14',
4429               {
4430                   type => '3_color_scale',
4431               }
4432           );
4433
4434           $worksheet7->conditional_formatting( 'G3:G14',
4435               {
4436                   type      => '2_color_scale',
4437                   min_color => "#FF0000",
4438                   max_color => "#00FF00",
4439
4440               }
4441           );
4442
4443           $worksheet7->conditional_formatting( 'I3:I14',
4444               {
4445                   type      => '3_color_scale',
4446                   min_color => "#C5D9F1",
4447                   mid_color => "#8DB4E3",
4448                   max_color => "#538ED5",
4449               }
4450           );
4451
4452
4453           ###############################################################################
4454           #
4455           # Example 8.
4456           #
4457           $caption = 'Examples of data bars.';
4458
4459           $data = [ 1 .. 12 ];
4460
4461           $worksheet8->write( 'A1', $caption );
4462
4463           $worksheet8->write    ( 'B2', "Default data bars" );
4464           $worksheet8->write_col( 'B3', $data );
4465
4466           $worksheet8->write    ( 'D2', "Bars only" );
4467           $worksheet8->write_col( 'D3', $data );
4468
4469           $worksheet8->write    ( 'F2', "With user color" );
4470           $worksheet8->write_col( 'F3', $data );
4471
4472           $worksheet8->write    ( 'H2', "Solid bars" );
4473           $worksheet8->write_col( 'H3', $data );
4474
4475           $worksheet8->write    ( 'J2', "Right to left" );
4476           $worksheet8->write_col( 'J3', $data );
4477
4478           $data = [-1, -2, -3, -2, -1, 0, 1, 2, 3, 2, 1, 0];
4479
4480           $worksheet8->write    ( 'L2', "Excel 2010 style" );
4481           $worksheet8->write_col( 'L3', $data );
4482
4483           $worksheet8->write    ( 'N2', "Negative same as positive" );
4484           $worksheet8->write_col( 'N3', $data );
4485
4486
4487           $worksheet8->conditional_formatting( 'B3:B14',
4488               {
4489                   type      => 'data_bar'
4490               }
4491           );
4492
4493           $worksheet8->conditional_formatting( 'D3:D14',
4494               {
4495                   type     => 'data_bar',
4496                   bar_only => 1
4497               }
4498           );
4499
4500           $worksheet8->conditional_formatting( 'F3:F14',
4501               {
4502                   type      => 'data_bar',
4503                   bar_color => '#63C384'
4504               }
4505           );
4506
4507           $worksheet8->conditional_formatting( 'H3:H14',
4508               {
4509                   type      => 'data_bar',
4510                   bar_solid => 1
4511               }
4512           );
4513
4514           $worksheet8->conditional_formatting( 'J3:J14',
4515               {
4516                   type          => 'data_bar',
4517                   bar_direction => 'right'
4518               }
4519           );
4520
4521           $worksheet8->conditional_formatting( 'L3:L14',
4522               {
4523                   type          => 'data_bar',
4524                   data_bar_2010 => 1
4525               }
4526           );
4527
4528           $worksheet8->conditional_formatting( 'N3:N14',
4529               {
4530                   type                           => 'data_bar',
4531                   bar_negative_color_same        => 1,
4532                   bar_negative_border_color_same => 1
4533               }
4534           );
4535
4536
4537           ###############################################################################
4538           #
4539           # Example 9.
4540           #
4541           $caption = 'Examples of conditional formats with icon sets.';
4542
4543           $data = [
4544               [ 1, 2, 3 ],
4545               [ 1, 2, 3 ],
4546               [ 1, 2, 3 ],
4547               [ 1, 2, 3 ],
4548               [ 1, 2, 3, 4 ],
4549               [ 1, 2, 3, 4, 5 ],
4550               [ 1, 2, 3, 4, 5 ],
4551           ];
4552
4553           $worksheet9->write( 'A1', $caption );
4554           $worksheet9->write_col( 'B3', $data );
4555
4556           $worksheet9->conditional_formatting( 'B3:D3',
4557               {
4558                   type         => 'icon_set',
4559                   icon_style   => '3_traffic_lights',
4560               }
4561           );
4562
4563           $worksheet9->conditional_formatting( 'B4:D4',
4564               {
4565                   type         => 'icon_set',
4566                   icon_style   => '3_traffic_lights',
4567                   reverse_icons => 1,
4568               }
4569           );
4570
4571           $worksheet9->conditional_formatting( 'B5:D5',
4572               {
4573                   type         => 'icon_set',
4574                   icon_style   => '3_traffic_lights',
4575                   icons_only   => 1,
4576               }
4577           );
4578
4579           $worksheet9->conditional_formatting( 'B6:D6',
4580               {
4581                   type         => 'icon_set',
4582                   icon_style   => '3_arrows',
4583               }
4584           );
4585
4586           $worksheet9->conditional_formatting( 'B7:E8',
4587               {
4588                   type         => 'icon_set',
4589                   icon_style   => '4_arrows',
4590               }
4591           );
4592
4593           $worksheet9->conditional_formatting( 'B8:F8',
4594               {
4595                   type         => 'icon_set',
4596                   icon_style   => '5_arrows',
4597               }
4598           );
4599
4600
4601           $worksheet9->conditional_formatting( 'B9:F9',
4602               {
4603                   type         => 'icon_set',
4604                   icon_style   => '5_ratings',
4605               }
4606           );
4607
4608           $workbook->close();
4609
4610           __END__
4611
4612       Download this example:
4613       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/conditional_format.pl>
4614
4615   Example: data_validate.pl
4616       Example of how to add data validation and dropdown lists to an
4617       Excel::Writer::XLSX file.
4618
4619       Data validation is a feature of Excel which allows you to restrict the
4620       data that a user enters in a cell and to display help and warning
4621       messages. It also allows you to restrict input to values in a drop down
4622       list.
4623
4624       Source code for this example:
4625
4626           #!/usr/bin/perl
4627
4628           ###############################################################################
4629           #
4630           # Example of how to add data validation and dropdown lists to an
4631           # Excel::Writer::XLSX file.
4632           #
4633           # Data validation is a feature of Excel which allows you to restrict the data
4634           # that a user enters in a cell and to display help and warning messages. It
4635           # also allows you to restrict input to values in a drop down list.
4636           #
4637           # reverse ('(c)'), August 2008, John McNamara, jmcnamara@cpan.org
4638           #
4639
4640           use strict;
4641           use warnings;
4642           use Excel::Writer::XLSX;
4643
4644           my $workbook  = Excel::Writer::XLSX->new( 'data_validate.xlsx' );
4645           my $worksheet = $workbook->add_worksheet();
4646
4647           # Add a format for the header cells.
4648           my $header_format = $workbook->add_format(
4649               border    => 1,
4650               bg_color  => '#C6EFCE',
4651               bold      => 1,
4652               text_wrap => 1,
4653               valign    => 'vcenter',
4654               indent    => 1,
4655           );
4656
4657           # Set up layout of the worksheet.
4658           $worksheet->set_column( 'A:A', 68 );
4659           $worksheet->set_column( 'B:B', 15 );
4660           $worksheet->set_column( 'D:D', 15 );
4661           $worksheet->set_row( 0, 36 );
4662           $worksheet->set_selection( 'B3' );
4663
4664
4665           # Write the header cells and some data that will be used in the examples.
4666           my $row = 0;
4667           my $txt;
4668           my $heading1 = 'Some examples of data validation in Excel::Writer::XLSX';
4669           my $heading2 = 'Enter values in this column';
4670           my $heading3 = 'Sample Data';
4671
4672           $worksheet->write( 'A1', $heading1, $header_format );
4673           $worksheet->write( 'B1', $heading2, $header_format );
4674           $worksheet->write( 'D1', $heading3, $header_format );
4675
4676           $worksheet->write( 'D3', [ 'Integers', 1, 10 ] );
4677           $worksheet->write( 'D4', [ 'List data', 'open', 'high', 'close' ] );
4678           $worksheet->write( 'D5', [ 'Formula', '=AND(F5=50,G5=60)', 50, 60 ] );
4679
4680
4681           #
4682           # Example 1. Limiting input to an integer in a fixed range.
4683           #
4684           $txt = 'Enter an integer between 1 and 10';
4685           $row += 2;
4686
4687           $worksheet->write( $row, 0, $txt );
4688           $worksheet->data_validation(
4689               $row, 1,
4690               {
4691                   validate => 'integer',
4692                   criteria => 'between',
4693                   minimum  => 1,
4694                   maximum  => 10,
4695               }
4696           );
4697
4698
4699           #
4700           # Example 2. Limiting input to an integer outside a fixed range.
4701           #
4702           $txt = 'Enter an integer that is not between 1 and 10 (using cell references)';
4703           $row += 2;
4704
4705           $worksheet->write( $row, 0, $txt );
4706           $worksheet->data_validation(
4707               $row, 1,
4708               {
4709                   validate => 'integer',
4710                   criteria => 'not between',
4711                   minimum  => '=E3',
4712                   maximum  => '=F3',
4713               }
4714           );
4715
4716
4717           #
4718           # Example 3. Limiting input to an integer greater than a fixed value.
4719           #
4720           $txt = 'Enter an integer greater than 0';
4721           $row += 2;
4722
4723           $worksheet->write( $row, 0, $txt );
4724           $worksheet->data_validation(
4725               $row, 1,
4726               {
4727                   validate => 'integer',
4728                   criteria => '>',
4729                   value    => 0,
4730               }
4731           );
4732
4733
4734           #
4735           # Example 4. Limiting input to an integer less than a fixed value.
4736           #
4737           $txt = 'Enter an integer less than 10';
4738           $row += 2;
4739
4740           $worksheet->write( $row, 0, $txt );
4741           $worksheet->data_validation(
4742               $row, 1,
4743               {
4744                   validate => 'integer',
4745                   criteria => '<',
4746                   value    => 10,
4747               }
4748           );
4749
4750
4751           #
4752           # Example 5. Limiting input to a decimal in a fixed range.
4753           #
4754           $txt = 'Enter a decimal between 0.1 and 0.5';
4755           $row += 2;
4756
4757           $worksheet->write( $row, 0, $txt );
4758           $worksheet->data_validation(
4759               $row, 1,
4760               {
4761                   validate => 'decimal',
4762                   criteria => 'between',
4763                   minimum  => 0.1,
4764                   maximum  => 0.5,
4765               }
4766           );
4767
4768
4769           #
4770           # Example 6. Limiting input to a value in a dropdown list.
4771           #
4772           $txt = 'Select a value from a drop down list';
4773           $row += 2;
4774
4775           $worksheet->write( $row, 0, $txt );
4776           $worksheet->data_validation(
4777               $row, 1,
4778               {
4779                   validate => 'list',
4780                   source   => [ 'open', 'high', 'close' ],
4781               }
4782           );
4783
4784
4785           #
4786           # Example 6. Limiting input to a value in a dropdown list.
4787           #
4788           $txt = 'Select a value from a drop down list (using a cell range)';
4789           $row += 2;
4790
4791           $worksheet->write( $row, 0, $txt );
4792           $worksheet->data_validation(
4793               $row, 1,
4794               {
4795                   validate => 'list',
4796                   source   => '=$E$4:$G$4',
4797               }
4798           );
4799
4800
4801           #
4802           # Example 7. Limiting input to a date in a fixed range.
4803           #
4804           $txt = 'Enter a date between 1/1/2008 and 12/12/2008';
4805           $row += 2;
4806
4807           $worksheet->write( $row, 0, $txt );
4808           $worksheet->data_validation(
4809               $row, 1,
4810               {
4811                   validate => 'date',
4812                   criteria => 'between',
4813                   minimum  => '2008-01-01T',
4814                   maximum  => '2008-12-12T',
4815               }
4816           );
4817
4818
4819           #
4820           # Example 8. Limiting input to a time in a fixed range.
4821           #
4822           $txt = 'Enter a time between 6:00 and 12:00';
4823           $row += 2;
4824
4825           $worksheet->write( $row, 0, $txt );
4826           $worksheet->data_validation(
4827               $row, 1,
4828               {
4829                   validate => 'time',
4830                   criteria => 'between',
4831                   minimum  => 'T06:00',
4832                   maximum  => 'T12:00',
4833               }
4834           );
4835
4836
4837           #
4838           # Example 9. Limiting input to a string greater than a fixed length.
4839           #
4840           $txt = 'Enter a string longer than 3 characters';
4841           $row += 2;
4842
4843           $worksheet->write( $row, 0, $txt );
4844           $worksheet->data_validation(
4845               $row, 1,
4846               {
4847                   validate => 'length',
4848                   criteria => '>',
4849                   value    => 3,
4850               }
4851           );
4852
4853
4854           #
4855           # Example 10. Limiting input based on a formula.
4856           #
4857           $txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"';
4858           $row += 2;
4859
4860           $worksheet->write( $row, 0, $txt );
4861           $worksheet->data_validation(
4862               $row, 1,
4863               {
4864                   validate => 'custom',
4865                   value    => '=AND(F5=50,G5=60)',
4866               }
4867           );
4868
4869
4870           #
4871           # Example 11. Displaying and modify data validation messages.
4872           #
4873           $txt = 'Displays a message when you select the cell';
4874           $row += 2;
4875
4876           $worksheet->write( $row, 0, $txt );
4877           $worksheet->data_validation(
4878               $row, 1,
4879               {
4880                   validate      => 'integer',
4881                   criteria      => 'between',
4882                   minimum       => 1,
4883                   maximum       => 100,
4884                   input_title   => 'Enter an integer:',
4885                   input_message => 'between 1 and 100',
4886               }
4887           );
4888
4889
4890           #
4891           # Example 12. Displaying and modify data validation messages.
4892           #
4893           $txt = 'Display a custom error message when integer isn\'t between 1 and 100';
4894           $row += 2;
4895
4896           $worksheet->write( $row, 0, $txt );
4897           $worksheet->data_validation(
4898               $row, 1,
4899               {
4900                   validate      => 'integer',
4901                   criteria      => 'between',
4902                   minimum       => 1,
4903                   maximum       => 100,
4904                   input_title   => 'Enter an integer:',
4905                   input_message => 'between 1 and 100',
4906                   error_title   => 'Input value is not valid!',
4907                   error_message => 'It should be an integer between 1 and 100',
4908               }
4909           );
4910
4911
4912           #
4913           # Example 13. Displaying and modify data validation messages.
4914           #
4915           $txt =
4916             'Display a custom information message when integer isn\'t between 1 and 100';
4917           $row += 2;
4918
4919           $worksheet->write( $row, 0, $txt );
4920           $worksheet->data_validation(
4921               $row, 1,
4922               {
4923                   validate      => 'integer',
4924                   criteria      => 'between',
4925                   minimum       => 1,
4926                   maximum       => 100,
4927                   input_title   => 'Enter an integer:',
4928                   input_message => 'between 1 and 100',
4929                   error_title   => 'Input value is not valid!',
4930                   error_message => 'It should be an integer between 1 and 100',
4931                   error_type    => 'information',
4932               }
4933           );
4934
4935           $workbook->close();
4936
4937           __END__
4938
4939       Download this example:
4940       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/data_validate.pl>
4941
4942   Example: date_time.pl
4943       Excel::Writer::XLSX example of writing dates and times using the
4944       write_date_time() Worksheet method.
4945
4946       Source code for this example:
4947
4948           #!/usr/bin/perl
4949
4950           ###############################################################################
4951           #
4952           # Excel::Writer::XLSX example of writing dates and times using the
4953           # write_date_time() Worksheet method.
4954           #
4955           # reverse ('(c)'), August 2004, John McNamara, jmcnamara@cpan.org
4956           #
4957
4958           use strict;
4959           use warnings;
4960           use Excel::Writer::XLSX;
4961
4962
4963           # Create a new workbook and add a worksheet
4964           my $workbook  = Excel::Writer::XLSX->new( 'date_time.xlsx' );
4965           my $worksheet = $workbook->add_worksheet();
4966           my $bold      = $workbook->add_format( bold => 1 );
4967
4968
4969           # Expand the first columns so that the date is visible.
4970           $worksheet->set_column( "A:B", 30 );
4971
4972
4973           # Write the column headers
4974           $worksheet->write( 'A1', 'Formatted date', $bold );
4975           $worksheet->write( 'B1', 'Format',         $bold );
4976
4977
4978           # Examples date and time formats. In the output file compare how changing
4979           # the format codes change the appearance of the date.
4980           #
4981           my @date_formats = (
4982               'dd/mm/yy',
4983               'mm/dd/yy',
4984               '',
4985               'd mm yy',
4986               'dd mm yy',
4987               '',
4988               'dd m yy',
4989               'dd mm yy',
4990               'dd mmm yy',
4991               'dd mmmm yy',
4992               '',
4993               'dd mm y',
4994               'dd mm yyy',
4995               'dd mm yyyy',
4996               '',
4997               'd mmmm yyyy',
4998               '',
4999               'dd/mm/yy',
5000               'dd/mm/yy hh:mm',
5001               'dd/mm/yy hh:mm:ss',
5002               'dd/mm/yy hh:mm:ss.000',
5003               '',
5004               'hh:mm',
5005               'hh:mm:ss',
5006               'hh:mm:ss.000',
5007           );
5008
5009
5010           # Write the same date and time using each of the above formats. The empty
5011           # string formats create a blank line to make the example clearer.
5012           #
5013           my $row = 0;
5014           for my $date_format ( @date_formats ) {
5015               $row++;
5016               next if $date_format eq '';
5017
5018               # Create a format for the date or time.
5019               my $format = $workbook->add_format(
5020                   num_format => $date_format,
5021                   align      => 'left'
5022               );
5023
5024               # Write the same date using different formats.
5025               $worksheet->write_date_time( $row, 0, '2004-08-01T12:30:45.123', $format );
5026               $worksheet->write( $row, 1, $date_format );
5027           }
5028
5029
5030           # The following is an example of an invalid date. It is written as a string
5031           # instead of a number. This is also Excel's default behaviour.
5032           #
5033           $row += 2;
5034           $worksheet->write_date_time( $row, 0, '2004-13-01T12:30:45.123' );
5035           $worksheet->write( $row, 1, 'Invalid date. Written as string.', $bold );
5036
5037           $workbook->close();
5038
5039           __END__
5040
5041       Download this example:
5042       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/date_time.pl>
5043
5044   Example: defined_name.pl
5045       Example of how to create defined names in an Excel::Writer::XLSX file.
5046
5047       This method is used to define a user friendly name to represent a
5048       value, a single cell or a range of cells in a workbook.
5049
5050       Source code for this example:
5051
5052           #!/usr/bin/perl
5053
5054           ##############################################################################
5055           #
5056           # Example of how to create defined names in an Excel::Writer::XLSX file.
5057           #
5058           # This method is used to define a user friendly name to represent a value,
5059           # a single cell or a range of cells in a workbook.
5060           #
5061           # reverse ('(c)'), September 2008, John McNamara, jmcnamara@cpan.org
5062           #
5063
5064           use strict;
5065           use warnings;
5066           use Excel::Writer::XLSX;
5067
5068           my $workbook   = Excel::Writer::XLSX->new( 'defined_name.xlsx' );
5069           my $worksheet1 = $workbook->add_worksheet();
5070           my $worksheet2 = $workbook->add_worksheet();
5071
5072           # Define some global/workbook names.
5073           $workbook->define_name( 'Exchange_rate', '=0.96' );
5074           $workbook->define_name( 'Sales',         '=Sheet1!$G$1:$H$10' );
5075
5076           # Define a local/worksheet name.
5077           $workbook->define_name( 'Sheet2!Sales', '=Sheet2!$G$1:$G$10' );
5078
5079           # Write some text in the file and one of the defined names in a formula.
5080           for my $worksheet ( $workbook->sheets() ) {
5081               $worksheet->set_column( 'A:A', 45 );
5082               $worksheet->write( 'A1', 'This worksheet contains some defined names.' );
5083               $worksheet->write( 'A2', 'See Formulas -> Name Manager above.' );
5084               $worksheet->write( 'A3', 'Example formula in cell B3 ->' );
5085
5086               $worksheet->write( 'B3', '=Exchange_rate' );
5087           }
5088
5089           $workbook->close();
5090
5091           __END__
5092
5093       Download this example:
5094       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/defined_name.pl>
5095
5096   Example: diag_border.pl
5097       A simple formatting example that demonstrates how to add a diagonal
5098       cell border with Excel::Writer::XLSX
5099
5100       Source code for this example:
5101
5102           #!/usr/bin/perl -w
5103
5104           ##############################################################################
5105           #
5106           # A simple formatting example that demonstrates how to add a diagonal cell
5107           # border with Excel::Writer::XLSX
5108           #
5109           # reverse ('(c)'), May 2004, John McNamara, jmcnamara@cpan.org
5110           #
5111
5112           use strict;
5113           use Excel::Writer::XLSX;
5114
5115
5116           my $workbook  = Excel::Writer::XLSX->new( 'diag_border.xlsx' );
5117           my $worksheet = $workbook->add_worksheet();
5118
5119
5120           my $format1 = $workbook->add_format( diag_type => 1 );
5121
5122           my $format2 = $workbook->add_format( diag_type => 2 );
5123
5124           my $format3 = $workbook->add_format( diag_type => 3 );
5125
5126           my $format4 = $workbook->add_format(
5127               diag_type   => 3,
5128               diag_border => 7,
5129               diag_color  => 'red',
5130           );
5131
5132
5133           $worksheet->write( 'B3',  'Text', $format1 );
5134           $worksheet->write( 'B6',  'Text', $format2 );
5135           $worksheet->write( 'B9',  'Text', $format3 );
5136           $worksheet->write( 'B12', 'Text', $format4 );
5137
5138           $workbook->close();
5139
5140           __END__
5141
5142       Download this example:
5143       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/diag_border.pl>
5144
5145   Example: filehandle.pl
5146       Example of using Excel::Writer::XLSX to write Excel files to different
5147       filehandles.
5148
5149       Source code for this example:
5150
5151           #!/usr/bin/perl
5152
5153           ###############################################################################
5154           #
5155           # Example of using Excel::Writer::XLSX to write Excel files to different
5156           # filehandles.
5157           #
5158           # reverse ('(c)'), April 2003, John McNamara, jmcnamara@cpan.org
5159           #
5160
5161           use strict;
5162           use warnings;
5163           use Excel::Writer::XLSX;
5164           use IO::Scalar;
5165
5166
5167           ###############################################################################
5168           #
5169           # Example 1. This demonstrates the standard way of creating an Excel file by
5170           # specifying a file name.
5171           #
5172
5173           my $workbook1  = Excel::Writer::XLSX->new( 'fh_01.xlsx' );
5174           my $worksheet1 = $workbook1->add_worksheet();
5175
5176           $worksheet1->write( 0, 0, 'Hi Excel 1' );
5177
5178           $workbook1->close();
5179
5180
5181           ###############################################################################
5182           #
5183           # Example 2. Write an Excel file to an existing filehandle.
5184           #
5185
5186           open TEST, '>', 'fh_02.xlsx' or die "Couldn't open file: $!";
5187           binmode TEST;   # Always do this regardless of whether the platform requires it.
5188
5189           my $workbook2  = Excel::Writer::XLSX->new( \*TEST );
5190           my $worksheet2 = $workbook2->add_worksheet();
5191
5192           $worksheet2->write( 0, 0, 'Hi Excel 2' );
5193
5194           $workbook2->close();
5195
5196           ###############################################################################
5197           #
5198           # Example 3. Write an Excel file to an existing OO style filehandle.
5199           #
5200
5201           my $fh = FileHandle->new( '> fh_03.xlsx' ) or die "Couldn't open file: $!";
5202
5203           binmode( $fh );
5204
5205           my $workbook3  = Excel::Writer::XLSX->new( $fh );
5206           my $worksheet3 = $workbook3->add_worksheet();
5207
5208           $worksheet3->write( 0, 0, 'Hi Excel 3' );
5209
5210           $workbook3->close();
5211
5212
5213           ###############################################################################
5214           #
5215           # Example 4. Write an Excel file to a string via IO::Scalar. Please refer to
5216           # the IO::Scalar documentation for further details.
5217           #
5218
5219           my $xlsx_str;
5220
5221           tie *XLSX, 'IO::Scalar', \$xlsx_str;
5222
5223           my $workbook4  = Excel::Writer::XLSX->new( \*XLSX );
5224           my $worksheet4 = $workbook4->add_worksheet();
5225
5226           $worksheet4->write( 0, 0, 'Hi Excel 4' );
5227           $workbook4->close();    # This is required before we use the scalar
5228
5229
5230           # The Excel file is now in $xlsx_str. As a demonstration, print it to a file.
5231           open TMP, '>', 'fh_04.xlsx' or die "Couldn't open file: $!";
5232           binmode TMP;
5233           print TMP $xlsx_str;
5234           close TMP;
5235
5236
5237           ###############################################################################
5238           #
5239           # Example 5. Write an Excel file to a string via IO::Scalar's newer interface.
5240           # Please refer to the IO::Scalar documentation for further details.
5241           #
5242           my $xlsx_str2;
5243
5244           my $fh5 = IO::Scalar->new( \$xlsx_str2 );
5245
5246           my $workbook5  = Excel::Writer::XLSX->new( $fh5 );
5247           my $worksheet5 = $workbook5->add_worksheet();
5248
5249           $worksheet5->write( 0, 0, 'Hi Excel 5' );
5250           $workbook5->close();    # This is required before we use the scalar
5251
5252           # The Excel file is now in $xlsx_str. As a demonstration, print it to a file.
5253           open TMP, '>', 'fh_05.xlsx' or die "Couldn't open file: $!";
5254           binmode TMP;
5255           print TMP $xlsx_str2;
5256           close TMP;
5257
5258           __END__
5259
5260       Download this example:
5261       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/filehandle.pl>
5262
5263   Example: headers.pl
5264       This program shows several examples of how to set up headers and
5265       footers with Excel::Writer::XLSX.
5266
5267       The control characters used in the header/footer strings are:
5268
5269           Control             Category            Description
5270           =======             ========            ===========
5271           &L                  Justification       Left
5272           &C                                      Center
5273           &R                                      Right
5274
5275           &P                  Information         Page number
5276           &N                                      Total number of pages
5277           &D                                      Date
5278           &T                                      Time
5279           &F                                      File name
5280           &A                                      Worksheet name
5281
5282           &fontsize           Font                Font size
5283           &"font,style"                           Font name and style
5284           &U                                      Single underline
5285           &E                                      Double underline
5286           &S                                      Strikethrough
5287           &X                                      Superscript
5288           &Y                                      Subscript
5289
5290           &[Picture]          Images              Image placeholder
5291           &G                                      Same as &[Picture]
5292
5293           &&                  Miscellaneous       Literal ampersand &
5294
5295       See the main Excel::Writer::XLSX documentation for more information.
5296
5297       Source code for this example:
5298
5299           #!/usr/bin/perl
5300
5301           ######################################################################
5302           #
5303           # This program shows several examples of how to set up headers and
5304           # footers with Excel::Writer::XLSX.
5305           #
5306           # The control characters used in the header/footer strings are:
5307           #
5308           #     Control             Category            Description
5309           #     =======             ========            ===========
5310           #     &L                  Justification       Left
5311           #     &C                                      Center
5312           #     &R                                      Right
5313           #
5314           #     &P                  Information         Page number
5315           #     &N                                      Total number of pages
5316           #     &D                                      Date
5317           #     &T                                      Time
5318           #     &F                                      File name
5319           #     &A                                      Worksheet name
5320           #
5321           #     &fontsize           Font                Font size
5322           #     &"font,style"                           Font name and style
5323           #     &U                                      Single underline
5324           #     &E                                      Double underline
5325           #     &S                                      Strikethrough
5326           #     &X                                      Superscript
5327           #     &Y                                      Subscript
5328           #
5329           #     &[Picture]          Images              Image placeholder
5330           #     &G                                      Same as &[Picture]
5331           #
5332           #     &&                  Miscellaneous       Literal ampersand &
5333           #
5334           # See the main Excel::Writer::XLSX documentation for more information.
5335           #
5336           # reverse ('(c)'), March 2002, John McNamara, jmcnamara@cpan.org
5337           #
5338
5339
5340           use strict;
5341           use warnings;
5342           use Excel::Writer::XLSX;
5343
5344           my $workbook = Excel::Writer::XLSX->new( 'headers.xlsx' );
5345           my $preview  = 'Select Print Preview to see the header and footer';
5346
5347
5348           ######################################################################
5349           #
5350           # A simple example to start
5351           #
5352           my $worksheet1 = $workbook->add_worksheet( 'Simple' );
5353           my $header1    = '&CHere is some centred text.';
5354           my $footer1    = '&LHere is some left aligned text.';
5355
5356           $worksheet1->set_header( $header1 );
5357           $worksheet1->set_footer( $footer1 );
5358
5359           $worksheet1->set_column( 'A:A', 50 );
5360           $worksheet1->write( 'A1', $preview );
5361
5362
5363           ######################################################################
5364           #
5365           # A simple example to start
5366           #
5367           my $worksheet2 = $workbook->add_worksheet( 'Image' );
5368           my $header2    = '&L&[Picture]';
5369
5370           # Adjust the page top margin to allow space for the header image.
5371           $worksheet2->set_margin_top(1.75);
5372
5373           $worksheet2->set_header( $header2, 0.3, {image_left => 'republic.png'});
5374
5375           $worksheet2->set_column( 'A:A', 50 );
5376           $worksheet2->write( 'A1', $preview );
5377
5378
5379           ######################################################################
5380           #
5381           # This is an example of some of the header/footer variables.
5382           #
5383           my $worksheet3 = $workbook->add_worksheet( 'Variables' );
5384           my $header3    = '&LPage &P of &N' . '&CFilename: &F' . '&RSheetname: &A';
5385           my $footer3    = '&LCurrent date: &D' . '&RCurrent time: &T';
5386
5387           $worksheet3->set_header( $header3 );
5388           $worksheet3->set_footer( $footer3 );
5389
5390           $worksheet3->set_column( 'A:A', 50 );
5391           $worksheet3->write( 'A1',  $preview );
5392           $worksheet3->write( 'A21', 'Next sheet' );
5393           $worksheet3->set_h_pagebreaks( 20 );
5394
5395
5396           ######################################################################
5397           #
5398           # This example shows how to use more than one font
5399           #
5400           my $worksheet4 = $workbook->add_worksheet( 'Mixed fonts' );
5401           my $header4    = q(&C&"Courier New,Bold"Hello &"Arial,Italic"World);
5402           my $footer4    = q(&C&"Symbol"e&"Arial" = mc&X2);
5403
5404           $worksheet4->set_header( $header4 );
5405           $worksheet4->set_footer( $footer4 );
5406
5407           $worksheet4->set_column( 'A:A', 50 );
5408           $worksheet4->write( 'A1', $preview );
5409
5410
5411           ######################################################################
5412           #
5413           # Example of line wrapping
5414           #
5415           my $worksheet5 = $workbook->add_worksheet( 'Word wrap' );
5416           my $header5    = "&CHeading 1\nHeading 2";
5417
5418           $worksheet5->set_header( $header5 );
5419
5420           $worksheet5->set_column( 'A:A', 50 );
5421           $worksheet5->write( 'A1', $preview );
5422
5423
5424           ######################################################################
5425           #
5426           # Example of inserting a literal ampersand &
5427           #
5428           my $worksheet6 = $workbook->add_worksheet( 'Ampersand' );
5429           my $header6    = '&CCuriouser && Curiouser - Attorneys at Law';
5430
5431           $worksheet6->set_header( $header6 );
5432
5433           $worksheet6->set_column( 'A:A', 50 );
5434           $worksheet6->write( 'A1', $preview );
5435
5436           $workbook->close();
5437
5438           __END__
5439
5440       Download this example:
5441       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/headers.pl>
5442
5443   Example: hide_row_col.pl
5444       Example of how to hide rows and columns in Excel::Writer::XLSX. In
5445       order to hide rows without setting each one, (of approximately 1
5446       million rows), Excel uses an optimisation to hide all rows that don't
5447       have data.
5448
5449       Source code for this example:
5450
5451           #!/usr/bin/perl
5452
5453           ###############################################################################
5454           #
5455           # Example of how to hide rows and columns in Excel::Writer::XLSX. In order to
5456           # hide rows without setting each one, (of approximately 1 million rows),
5457           # Excel uses an optimisation to hide all rows that don't have data.
5458           #
5459           # reverse ('(c)'), December 2012, John McNamara, jmcnamara@cpan.org
5460           #
5461
5462           use strict;
5463           use warnings;
5464           use Excel::Writer::XLSX;
5465
5466           my $workbook  = Excel::Writer::XLSX->new( 'hide_row_col.xlsx' );
5467           my $worksheet = $workbook->add_worksheet();
5468
5469
5470           # Write some data.
5471           $worksheet->write( 'D1', 'Some hidden columns.' );
5472           $worksheet->write( 'A8', 'Some hidden rows.' );
5473
5474           # Hide all rows without data.
5475           $worksheet->set_default_row( undef, 1 );
5476
5477           # Set emptys row that we do want to display. All other will be hidden.
5478           for my $row (1 .. 6) {
5479               $worksheet->set_row( $row, 15 );
5480           }
5481
5482           # Hide a range of columns.
5483           $worksheet->set_column( 'G:XFD', undef, undef, 1);
5484
5485           $workbook->close();
5486
5487           __END__
5488
5489       Download this example:
5490       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/hide_row_col.pl>
5491
5492   Example: hide_sheet.pl
5493       Example of how to hide a worksheet with Excel::Writer::XLSX.
5494
5495       Source code for this example:
5496
5497           #!/usr/bin/perl
5498
5499           #######################################################################
5500           #
5501           # Example of how to hide a worksheet with Excel::Writer::XLSX.
5502           #
5503           # reverse ('(c)'), April 2005, John McNamara, jmcnamara@cpan.org
5504           #
5505
5506           use strict;
5507           use warnings;
5508           use Excel::Writer::XLSX;
5509
5510           my $workbook   = Excel::Writer::XLSX->new( 'hide_sheet.xlsx' );
5511           my $worksheet1 = $workbook->add_worksheet();
5512           my $worksheet2 = $workbook->add_worksheet();
5513           my $worksheet3 = $workbook->add_worksheet();
5514
5515           $worksheet1->set_column( 'A:A', 30 );
5516           $worksheet2->set_column( 'A:A', 30 );
5517           $worksheet3->set_column( 'A:A', 30 );
5518
5519           # Sheet2 won't be visible until it is unhidden in Excel.
5520           $worksheet2->hide();
5521
5522           $worksheet1->write( 0, 0, 'Sheet2 is hidden' );
5523           $worksheet2->write( 0, 0, "Now it's my turn to find you." );
5524           $worksheet3->write( 0, 0, 'Sheet2 is hidden' );
5525
5526           $workbook->close();
5527
5528           __END__
5529
5530       Download this example:
5531       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/hide_sheet.pl>
5532
5533   Example: hyperlink1.pl
5534       Example of how to use the Excel::Writer::XLSX module to write
5535       hyperlinks
5536
5537       See also hyperlink2.pl for worksheet URL examples.
5538
5539       Source code for this example:
5540
5541           #!/usr/bin/perl
5542
5543           ###############################################################################
5544           #
5545           # Example of how to use the Excel::Writer::XLSX module to write hyperlinks
5546           #
5547           # See also hyperlink2.pl for worksheet URL examples.
5548           #
5549           # reverse ('(c)'), May 2004, John McNamara, jmcnamara@cpan.org
5550           #
5551
5552           use strict;
5553           use warnings;
5554           use Excel::Writer::XLSX;
5555
5556           # Create a new workbook and add a worksheet
5557           my $workbook = Excel::Writer::XLSX->new( 'hyperlink.xlsx' );
5558
5559
5560           my $worksheet = $workbook->add_worksheet( 'Hyperlinks' );
5561
5562           # Format the first column
5563           $worksheet->set_column( 'A:A', 30 );
5564           $worksheet->set_selection( 'B1' );
5565
5566           # Add a user defined hyperlink format.
5567           my $red_format = $workbook->add_format(
5568               color     => 'red',
5569               bold      => 1,
5570               underline => 1,
5571               size      => 12,
5572           );
5573
5574           # Add an alternate description string to the URL.
5575           my $str = 'Perl home.';
5576
5577           # Add a "tool tip" to the URL.
5578           my $tip = 'Get the latest Perl news here.';
5579
5580
5581           # Write some hyperlinks. Unspecified or undefined format paraamters will be
5582           # replace with the defuault Excel hyperlink style.
5583           $worksheet->write( 'A1', 'http://www.perl.com/' );
5584           $worksheet->write( 'A3', 'http://www.perl.com/', undef, $str );
5585           $worksheet->write( 'A5', 'http://www.perl.com/', undef, $str, $tip );
5586           $worksheet->write( 'A7', 'http://www.perl.com/', $red_format );
5587           $worksheet->write( 'A9', 'mailto:jmcnamara@cpan.org', undef, 'Mail me' );
5588
5589           # Write a URL that isn't a hyperlink
5590           $worksheet->write_string( 'A11', 'http://www.perl.com/' );
5591
5592           $workbook->close();
5593
5594           __END__
5595
5596       Download this example:
5597       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/hyperlink1.pl>
5598
5599   Example: hyperlink2.pl
5600       Example of how to use the Excel::Writer::XLSX module to write internal
5601       and external hyperlinks.
5602
5603       If you wish to run this program and follow the hyperlinks you should
5604       create the following directory structure:
5605
5606       C:\ -- Temp --+-- Europe
5607                     |
5608                     \-- Asia
5609
5610       See also hyperlink1.pl for web URL examples.
5611
5612           #!/usr/bin/perl
5613
5614           ###############################################################################
5615           #
5616           # Example of how to use the Excel::Writer::XLSX module to write internal and
5617           # external hyperlinks.
5618           #
5619           # If you wish to run this program and follow the hyperlinks you should create
5620           # the following directory structure:
5621           #
5622           # C:\ -- Temp --+-- Europe
5623           #               |
5624           #               \-- Asia
5625           #
5626           #
5627           # See also hyperlink1.pl for web URL examples.
5628           #
5629           # reverse ('(c)'), February 2002, John McNamara, jmcnamara@cpan.org
5630           #
5631
5632
5633           use strict;
5634           use warnings;
5635           use Excel::Writer::XLSX;
5636
5637           # Create three workbooks:
5638           #   C:\Temp\Europe\Ireland.xlsx
5639           #   C:\Temp\Europe\Italy.xlsx
5640           #   C:\Temp\Asia\China.xlsx
5641           #
5642
5643           my $ireland = Excel::Writer::XLSX->new( 'C:\Temp\Europe\Ireland.xlsx' );
5644
5645           my $ire_links      = $ireland->add_worksheet( 'Links' );
5646           my $ire_sales      = $ireland->add_worksheet( 'Sales' );
5647           my $ire_data       = $ireland->add_worksheet( 'Product Data' );
5648           my $ire_url_format = $ireland->get_default_url_format();
5649
5650
5651           my $italy = Excel::Writer::XLSX->new( 'C:\Temp\Europe\Italy.xlsx' );
5652
5653           my $ita_links      = $italy->add_worksheet( 'Links' );
5654           my $ita_sales      = $italy->add_worksheet( 'Sales' );
5655           my $ita_data       = $italy->add_worksheet( 'Product Data' );
5656           my $ita_url_format = $italy->get_default_url_format();
5657
5658
5659           my $china = Excel::Writer::XLSX->new( 'C:\Temp\Asia\China.xlsx' );
5660
5661           my $cha_links      = $china->add_worksheet( 'Links' );
5662           my $cha_sales      = $china->add_worksheet( 'Sales' );
5663           my $cha_data       = $china->add_worksheet( 'Product Data' );
5664           my $cha_url_format = $china->get_default_url_format();
5665
5666
5667           # Add an alternative format
5668           my $format = $ireland->add_format( color => 'green', bold => 1 );
5669           $ire_links->set_column( 'A:B', 25 );
5670
5671
5672           ###############################################################################
5673           #
5674           # Examples of internal links
5675           #
5676           $ire_links->write( 'A1', 'Internal links', $format );
5677
5678           # Internal link
5679           $ire_links->write_url( 'A2', 'internal:Sales!A2', $ire_url_format );
5680
5681           # Internal link to a range
5682           $ire_links->write_url( 'A3', 'internal:Sales!A3:D3', $ire_url_format );
5683
5684           # Internal link with an alternative string
5685           $ire_links->write_url( 'A4', 'internal:Sales!A4', $ire_url_format, 'Link' );
5686
5687           # Internal link with an alternative format
5688           $ire_links->write_url( 'A5', 'internal:Sales!A5', $format );
5689
5690           # Internal link with an alternative string and format
5691           $ire_links->write_url( 'A6', 'internal:Sales!A6', $ire_url_format, 'Link' );
5692
5693           # Internal link (spaces in worksheet name)
5694           $ire_links->write_url( 'A7', q{internal:'Product Data'!A7}, $ire_url_format );
5695
5696
5697           ###############################################################################
5698           #
5699           # Examples of external links
5700           #
5701           $ire_links->write( 'B1', 'External links', $format );
5702
5703           # External link to a local file
5704           $ire_links->write_url( 'B2', 'external:Italy.xlsx', $ire_url_format );
5705
5706           # External link to a local file with worksheet
5707           $ire_links->write_url( 'B3', 'external:Italy.xlsx#Sales!B3', $ire_url_format );
5708
5709           # External link to a local file with worksheet and alternative string
5710           $ire_links->write_url( 'B4', 'external:Italy.xlsx#Sales!B4', $ire_url_format, 'Link' );
5711
5712           # External link to a local file with worksheet and format
5713           $ire_links->write_url( 'B5', 'external:Italy.xlsx#Sales!B5', $format );
5714
5715           # External link to a remote file, absolute path
5716           $ire_links->write_url( 'B6', 'external:C:/Temp/Asia/China.xlsx', $ire_url_format );
5717
5718           # External link to a remote file, relative path
5719           $ire_links->write_url( 'B7', 'external:../Asia/China.xlsx', $ire_url_format );
5720
5721           # External link to a remote file with worksheet
5722           $ire_links->write_url( 'B8', 'external:C:/Temp/Asia/China.xlsx#Sales!B8', $ire_url_format );
5723
5724           # External link to a remote file with worksheet (with spaces in the name)
5725           $ire_links->write_url( 'B9', q{external:C:/Temp/Asia/China.xlsx#'Product Data'!B9}, $ire_url_format );
5726
5727
5728           ###############################################################################
5729           #
5730           # Some utility links to return to the main sheet
5731           #
5732           $ire_sales->write_url( 'A2', 'internal:Links!A2', $ire_url_format, 'Back' );
5733           $ire_sales->write_url( 'A3', 'internal:Links!A3', $ire_url_format, 'Back' );
5734           $ire_sales->write_url( 'A4', 'internal:Links!A4', $ire_url_format, 'Back' );
5735           $ire_sales->write_url( 'A5', 'internal:Links!A5', $ire_url_format, 'Back' );
5736           $ire_sales->write_url( 'A6', 'internal:Links!A6', $ire_url_format, 'Back' );
5737           $ire_data->write_url ( 'A7', 'internal:Links!A7', $ire_url_format, 'Back' );
5738
5739           $ita_links->write_url( 'A1', 'external:Ireland.xlsx#Links!B2', $ita_url_format, 'Back' );
5740           $ita_sales->write_url( 'B3', 'external:Ireland.xlsx#Links!B3', $ita_url_format, 'Back' );
5741           $ita_sales->write_url( 'B4', 'external:Ireland.xlsx#Links!B4', $ita_url_format, 'Back' );
5742           $ita_sales->write_url( 'B5', 'external:Ireland.xlsx#Links!B5', $ita_url_format, 'Back' );
5743           $cha_links->write_url( 'A1', 'external:C:/Temp/Europe/Ireland.xlsx#Links!B6', $cha_url_format, 'Back' );
5744           $cha_sales->write_url( 'B8', 'external:C:/Temp/Europe/Ireland.xlsx#Links!B8', $cha_url_format, 'Back' );
5745           $cha_data->write_url ( 'B9', 'external:C:/Temp/Europe/Ireland.xlsx#Links!B9', $cha_url_format, 'Back' );
5746
5747           $ireland->close();
5748           $italy->close();
5749           $china->close();
5750
5751           __END__
5752
5753       Download this example:
5754       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/hyperlink2.pl>
5755
5756   Example: indent.pl
5757       A simple formatting example using Excel::Writer::XLSX.
5758
5759       This program demonstrates the indentation cell format.
5760
5761       Source code for this example:
5762
5763           #!/usr/bin/perl -w
5764
5765           ##############################################################################
5766           #
5767           # A simple formatting example using Excel::Writer::XLSX.
5768           #
5769           # This program demonstrates the indentation cell format.
5770           #
5771           # reverse ('(c)'), May 2004, John McNamara, jmcnamara@cpan.org
5772           #
5773
5774
5775           use strict;
5776           use Excel::Writer::XLSX;
5777
5778           my $workbook = Excel::Writer::XLSX->new( 'indent.xlsx' );
5779
5780           my $worksheet = $workbook->add_worksheet();
5781           my $indent1   = $workbook->add_format( indent => 1 );
5782           my $indent2   = $workbook->add_format( indent => 2 );
5783
5784           $worksheet->set_column( 'A:A', 40 );
5785
5786
5787           $worksheet->write( 'A1', "This text is indented 1 level",  $indent1 );
5788           $worksheet->write( 'A2', "This text is indented 2 levels", $indent2 );
5789
5790           $workbook->close();
5791
5792           __END__
5793
5794       Download this example:
5795       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/indent.pl>
5796
5797   Example: macros.pl
5798       An example of adding macros to an Excel::Writer::XLSX file using a VBA
5799       project file extracted from an existing Excel xlsm file.
5800
5801       The "extract_vba" utility supplied with Excel::Writer::XLSX can be used
5802       to extract the vbaProject.bin file.
5803
5804       An embedded macro is connected to a form button on the worksheet.
5805
5806       Source code for this example:
5807
5808           #!/usr/bin/perl
5809
5810           #######################################################################
5811           #
5812           # An example of adding macros to an Excel::Writer::XLSX file using
5813           # a VBA project file extracted from an existing Excel xlsm file.
5814           #
5815           # The C<extract_vba> utility supplied with Excel::Writer::XLSX can be
5816           # used to extract the vbaProject.bin file.
5817           #
5818           # An embedded macro is connected to a form button on the worksheet.
5819           #
5820           # reverse('(c)'), November 2012, John McNamara, jmcnamara@cpan.org
5821           #
5822
5823           use strict;
5824           use warnings;
5825           use Excel::Writer::XLSX;
5826
5827           # Note the file extension should be .xlsm.
5828           my $workbook  = Excel::Writer::XLSX->new( 'macros.xlsm' );
5829           my $worksheet = $workbook->add_worksheet();
5830
5831           $worksheet->set_column( 'A:A', 30 );
5832
5833           # Add the VBA project binary.
5834           $workbook->add_vba_project( './vbaProject.bin' );
5835
5836           # Show text for the end user.
5837           $worksheet->write( 'A3', 'Press the button to say hello.' );
5838
5839           # Add a button tied to a macro in the VBA project.
5840           $worksheet->insert_button(
5841               'B3',
5842               {
5843                   macro   => 'say_hello',
5844                   caption => 'Press Me',
5845                   width   => 80,
5846                   height  => 30
5847               }
5848           );
5849
5850           $workbook->close();
5851
5852           __END__
5853
5854       Download this example:
5855       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/macros.pl>
5856
5857   Example: merge1.pl
5858       Simple example of merging cells using the Excel::Writer::XLSX module.
5859
5860       This example merges three cells using the "Centre Across Selection"
5861       alignment which was the Excel 5 method of achieving a merge. For a more
5862       modern approach use the merge_range() worksheet method instead.  See
5863       the merge3.pl - merge6.pl programs.
5864
5865       Source code for this example:
5866
5867           #!/usr/bin/perl
5868
5869           ###############################################################################
5870           #
5871           # Simple example of merging cells using the Excel::Writer::XLSX module.
5872           #
5873           # This example merges three cells using the "Centre Across Selection"
5874           # alignment which was the Excel 5 method of achieving a merge. For a more
5875           # modern approach use the merge_range() worksheet method instead.
5876           # See the merge3.pl - merge6.pl programs.
5877           #
5878           # reverse ('(c)'), August 2002, John McNamara, jmcnamara@cpan.org
5879           #
5880
5881           use strict;
5882           use warnings;
5883           use Excel::Writer::XLSX;
5884
5885           # Create a new workbook and add a worksheet
5886           my $workbook  = Excel::Writer::XLSX->new( 'merge1.xlsx' );
5887           my $worksheet = $workbook->add_worksheet();
5888
5889
5890           # Increase the cell size of the merged cells to highlight the formatting.
5891           $worksheet->set_column( 'B:D', 20 );
5892           $worksheet->set_row( 2, 30 );
5893
5894
5895           # Create a merge format
5896           my $format = $workbook->add_format( center_across => 1 );
5897
5898
5899           # Only one cell should contain text, the others should be blank.
5900           $worksheet->write( 2, 1, "Center across selection", $format );
5901           $worksheet->write_blank( 2, 2, $format );
5902           $worksheet->write_blank( 2, 3, $format );
5903
5904           $workbook->close();
5905
5906           __END__
5907
5908       Download this example:
5909       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/merge1.pl>
5910
5911   Example: merge2.pl
5912       Simple example of merging cells using the Excel::Writer::XLSX module
5913
5914       This example merges three cells using the "Centre Across Selection"
5915       alignment which was the Excel 5 method of achieving a merge. For a more
5916       modern approach use the merge_range() worksheet method instead.  See
5917       the merge3.pl - merge6.pl programs.
5918
5919       Source code for this example:
5920
5921           #!/usr/bin/perl
5922
5923           ###############################################################################
5924           #
5925           # Simple example of merging cells using the Excel::Writer::XLSX module
5926           #
5927           # This example merges three cells using the "Centre Across Selection"
5928           # alignment which was the Excel 5 method of achieving a merge. For a more
5929           # modern approach use the merge_range() worksheet method instead.
5930           # See the merge3.pl - merge6.pl programs.
5931           #
5932           # reverse ('(c)'), August 2002, John McNamara, jmcnamara@cpan.org
5933           #
5934
5935           use strict;
5936           use warnings;
5937           use Excel::Writer::XLSX;
5938
5939           # Create a new workbook and add a worksheet
5940           my $workbook  = Excel::Writer::XLSX->new( 'merge2.xlsx' );
5941           my $worksheet = $workbook->add_worksheet();
5942
5943
5944           # Increase the cell size of the merged cells to highlight the formatting.
5945           $worksheet->set_column( 1, 2, 30 );
5946           $worksheet->set_row( 2, 40 );
5947
5948
5949           # Create a merged format
5950           my $format = $workbook->add_format(
5951               center_across => 1,
5952               bold          => 1,
5953               size          => 15,
5954               pattern       => 1,
5955               border        => 6,
5956               color         => 'white',
5957               fg_color      => 'green',
5958               border_color  => 'yellow',
5959               align         => 'vcenter',
5960           );
5961
5962
5963           # Only one cell should contain text, the others should be blank.
5964           $worksheet->write( 2, 1, "Center across selection", $format );
5965           $worksheet->write_blank( 2, 2, $format );
5966
5967           $workbook->close();
5968
5969           __END__
5970
5971       Download this example:
5972       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/merge2.pl>
5973
5974   Example: merge3.pl
5975       Example of how to use Excel::Writer::XLSX to write a hyperlink in a
5976       merged cell.
5977
5978       Source code for this example:
5979
5980           #!/usr/bin/perl
5981
5982           ###############################################################################
5983           #
5984           # Example of how to use Excel::Writer::XLSX to write a hyperlink in a
5985           # merged cell.
5986           #
5987           # reverse ('(c)'), September 2002, John McNamara, jmcnamara@cpan.org
5988           #
5989
5990           use strict;
5991           use warnings;
5992           use Excel::Writer::XLSX;
5993
5994           # Create a new workbook and add a worksheet
5995           my $workbook  = Excel::Writer::XLSX->new( 'merge3.xlsx' );
5996           my $worksheet = $workbook->add_worksheet();
5997
5998
5999           # Increase the cell size of the merged cells to highlight the formatting.
6000           $worksheet->set_row( $_, 30 ) for ( 3, 6, 7 );
6001           $worksheet->set_column( 'B:D', 20 );
6002
6003
6004           ###############################################################################
6005           #
6006           # Example: Merge cells containing a hyperlink using merge_range().
6007           #
6008           my $format = $workbook->add_format(
6009               border    => 1,
6010               underline => 1,
6011               color     => 'blue',
6012               align     => 'center',
6013               valign    => 'vcenter',
6014           );
6015
6016           # Merge 3 cells
6017           $worksheet->merge_range( 'B4:D4', 'http://www.perl.com', $format );
6018
6019
6020           # Merge 3 cells over two rows
6021           $worksheet->merge_range( 'B7:D8', 'http://www.perl.com', $format );
6022
6023
6024           $workbook->close();
6025
6026           __END__
6027
6028       Download this example:
6029       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/merge3.pl>
6030
6031   Example: merge4.pl
6032       Example of how to use the Excel::Writer::XLSX merge_range() workbook
6033       method with complex formatting.
6034
6035       Source code for this example:
6036
6037           #!/usr/bin/perl
6038
6039           ###############################################################################
6040           #
6041           # Example of how to use the Excel::Writer::XLSX merge_range() workbook
6042           # method with complex formatting.
6043           #
6044           # reverse ('(c)'), September 2002, John McNamara, jmcnamara@cpan.org
6045           #
6046
6047           use strict;
6048           use warnings;
6049           use Excel::Writer::XLSX;
6050
6051           # Create a new workbook and add a worksheet
6052           my $workbook  = Excel::Writer::XLSX->new( 'merge4.xlsx' );
6053           my $worksheet = $workbook->add_worksheet();
6054
6055
6056           # Increase the cell size of the merged cells to highlight the formatting.
6057           $worksheet->set_row( $_, 30 ) for ( 1 .. 11 );
6058           $worksheet->set_column( 'B:D', 20 );
6059
6060
6061           ###############################################################################
6062           #
6063           # Example 1: Text centered vertically and horizontally
6064           #
6065           my $format1 = $workbook->add_format(
6066               border => 6,
6067               bold   => 1,
6068               color  => 'red',
6069               valign => 'vcenter',
6070               align  => 'center',
6071           );
6072
6073
6074           $worksheet->merge_range( 'B2:D3', 'Vertical and horizontal', $format1 );
6075
6076
6077           ###############################################################################
6078           #
6079           # Example 2: Text aligned to the top and left
6080           #
6081           my $format2 = $workbook->add_format(
6082               border => 6,
6083               bold   => 1,
6084               color  => 'red',
6085               valign => 'top',
6086               align  => 'left',
6087           );
6088
6089
6090           $worksheet->merge_range( 'B5:D6', 'Aligned to the top and left', $format2 );
6091
6092
6093           ###############################################################################
6094           #
6095           # Example 3:  Text aligned to the bottom and right
6096           #
6097           my $format3 = $workbook->add_format(
6098               border => 6,
6099               bold   => 1,
6100               color  => 'red',
6101               valign => 'bottom',
6102               align  => 'right',
6103           );
6104
6105
6106           $worksheet->merge_range( 'B8:D9', 'Aligned to the bottom and right', $format3 );
6107
6108
6109           ###############################################################################
6110           #
6111           # Example 4:  Text justified (i.e. wrapped) in the cell
6112           #
6113           my $format4 = $workbook->add_format(
6114               border => 6,
6115               bold   => 1,
6116               color  => 'red',
6117               valign => 'top',
6118               align  => 'justify',
6119           );
6120
6121
6122           $worksheet->merge_range( 'B11:D12', 'Justified: ' . 'so on and ' x 18,
6123               $format4 );
6124
6125           $workbook->close();
6126
6127           __END__
6128
6129       Download this example:
6130       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/merge4.pl>
6131
6132   Example: merge5.pl
6133       Example of how to use the Excel::Writer::XLSX merge_cells() workbook
6134       method with complex formatting and rotation.
6135
6136       Source code for this example:
6137
6138           #!/usr/bin/perl
6139
6140           ###############################################################################
6141           #
6142           # Example of how to use the Excel::Writer::XLSX merge_cells() workbook
6143           # method with complex formatting and rotation.
6144           #
6145           #
6146           # reverse ('(c)'), September 2002, John McNamara, jmcnamara@cpan.org
6147           #
6148
6149           use strict;
6150           use warnings;
6151           use Excel::Writer::XLSX;
6152
6153           # Create a new workbook and add a worksheet
6154           my $workbook  = Excel::Writer::XLSX->new( 'merge5.xlsx' );
6155           my $worksheet = $workbook->add_worksheet();
6156
6157
6158           # Increase the cell size of the merged cells to highlight the formatting.
6159           $worksheet->set_row( $_, 36 ) for ( 3 .. 8 );
6160           $worksheet->set_column( $_, $_, 15 ) for ( 1, 3, 5 );
6161
6162
6163           ###############################################################################
6164           #
6165           # Rotation 1, letters run from top to bottom
6166           #
6167           my $format1 = $workbook->add_format(
6168               border   => 6,
6169               bold     => 1,
6170               color    => 'red',
6171               valign   => 'vcentre',
6172               align    => 'centre',
6173               rotation => 270,
6174           );
6175
6176
6177           $worksheet->merge_range( 'B4:B9', 'Rotation 270', $format1 );
6178
6179
6180           ###############################################################################
6181           #
6182           # Rotation 2, 90° anticlockwise
6183           #
6184           my $format2 = $workbook->add_format(
6185               border   => 6,
6186               bold     => 1,
6187               color    => 'red',
6188               valign   => 'vcentre',
6189               align    => 'centre',
6190               rotation => 90,
6191           );
6192
6193
6194           $worksheet->merge_range( 'D4:D9', 'Rotation 90°', $format2 );
6195
6196
6197           ###############################################################################
6198           #
6199           # Rotation 3, 90° clockwise
6200           #
6201           my $format3 = $workbook->add_format(
6202               border   => 6,
6203               bold     => 1,
6204               color    => 'red',
6205               valign   => 'vcentre',
6206               align    => 'centre',
6207               rotation => -90,
6208           );
6209
6210
6211           $worksheet->merge_range( 'F4:F9', 'Rotation -90°', $format3 );
6212
6213           $workbook->close();
6214
6215           __END__
6216
6217       Download this example:
6218       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/merge5.pl>
6219
6220   Example: merge6.pl
6221       Example of how to use the Excel::Writer::XLSX merge_cells() workbook
6222       method with Unicode strings.
6223
6224       Source code for this example:
6225
6226           #!/usr/bin/perl
6227
6228           ###############################################################################
6229           #
6230           # Example of how to use the Excel::Writer::XLSX merge_cells() workbook
6231           # method with Unicode strings.
6232           #
6233           #
6234           # reverse ('(c)'), December 2005, John McNamara, jmcnamara@cpan.org
6235           #
6236
6237           use strict;
6238           use warnings;
6239           use Excel::Writer::XLSX;
6240
6241           # Create a new workbook and add a worksheet
6242           my $workbook  = Excel::Writer::XLSX->new( 'merge6.xlsx' );
6243           my $worksheet = $workbook->add_worksheet();
6244
6245
6246           # Increase the cell size of the merged cells to highlight the formatting.
6247           $worksheet->set_row( $_, 36 ) for 2 .. 9;
6248           $worksheet->set_column( 'B:D', 25 );
6249
6250
6251           # Format for the merged cells.
6252           my $format = $workbook->add_format(
6253               border => 6,
6254               bold   => 1,
6255               color  => 'red',
6256               size   => 20,
6257               valign => 'vcentre',
6258               align  => 'left',
6259               indent => 1,
6260           );
6261
6262
6263           ###############################################################################
6264           #
6265           # Write an Ascii string.
6266           #
6267           $worksheet->merge_range( 'B3:D4', 'ASCII: A simple string', $format );
6268
6269
6270           ###############################################################################
6271           #
6272           # Write a UTF-8 Unicode string.
6273           #
6274           my $smiley = chr 0x263a;
6275           $worksheet->merge_range( 'B6:D7', "UTF-8: A Unicode smiley $smiley", $format );
6276
6277           $workbook->close();
6278
6279           __END__
6280
6281       Download this example:
6282       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/merge6.pl>
6283
6284   Example: mod_perl1.pl
6285       Example of how to use the Excel::Writer::XLSX module to send an Excel
6286       file to a browser using mod_perl 1 and Apache
6287
6288       This module ties *XLSX directly to Apache, and with the correct
6289       content-disposition/types it will prompt the user to save the file, or
6290       open it at this location.
6291
6292       This script is a modification of the Excel::Writer::XLSX cgi.pl
6293       example.
6294
6295       Change the name of this file to Cgi.pm.  Change the package location to
6296       wherever you locate this package.  In the example below it is located
6297       in the Excel::Writer::XLSX directory.
6298
6299       Your httpd.conf entry for this module, should you choose to use it as a
6300       stand alone app, should look similar to the following:
6301
6302           <Location /spreadsheet-test>
6303             SetHandler perl-script
6304             PerlHandler Excel::Writer::XLSX::Cgi
6305             PerlSendHeader On
6306           </Location>
6307
6308       The PerlHandler name above and the package name below *have* to match.
6309
6310           ###############################################################################
6311           #
6312           # Example of how to use the Excel::Writer::XLSX module to send an Excel
6313           # file to a browser using mod_perl 1 and Apache
6314           #
6315           # This module ties *XLSX directly to Apache, and with the correct
6316           # content-disposition/types it will prompt the user to save
6317           # the file, or open it at this location.
6318           #
6319           # This script is a modification of the Excel::Writer::XLSX cgi.pl example.
6320           #
6321           # Change the name of this file to Cgi.pm.
6322           # Change the package location to wherever you locate this package.
6323           # In the example below it is located in the Excel::Writer::XLSX directory.
6324           #
6325           # Your httpd.conf entry for this module, should you choose to use it
6326           # as a stand alone app, should look similar to the following:
6327           #
6328           #     <Location /spreadsheet-test>
6329           #       SetHandler perl-script
6330           #       PerlHandler Excel::Writer::XLSX::Cgi
6331           #       PerlSendHeader On
6332           #     </Location>
6333           #
6334           # The PerlHandler name above and the package name below *have* to match.
6335
6336           # Apr 2001, Thomas Sullivan, webmaster@860.org
6337           # Feb 2001, John McNamara, jmcnamara@cpan.org
6338
6339           package Excel::Writer::XLSX::Cgi;
6340
6341           ##########################################
6342           # Pragma Definitions
6343           ##########################################
6344           use strict;
6345
6346           ##########################################
6347           # Required Modules
6348           ##########################################
6349           use Apache::Constants qw(:common);
6350           use Apache::Request;
6351           use Apache::URI;    # This may not be needed
6352           use Excel::Writer::XLSX;
6353
6354           ##########################################
6355           # Main App Body
6356           ##########################################
6357           sub handler {
6358
6359               # New apache object
6360               # Should you decide to use it.
6361               my $r = Apache::Request->new( shift );
6362
6363               # Set the filename and send the content type
6364               # This will appear when they save the spreadsheet
6365               my $filename = "cgitest.xlsx";
6366
6367               ####################################################
6368               ## Send the content type headers
6369               ####################################################
6370               print "Content-disposition: attachment;filename=$filename\n";
6371               print "Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n\n";
6372
6373               ####################################################
6374               # Tie a filehandle to Apache's STDOUT.
6375               # Create a new workbook and add a worksheet.
6376               ####################################################
6377               tie *XLSX => 'Apache';
6378               binmode( *XLSX );
6379
6380               my $workbook  = Excel::Writer::XLSX->new( \*XLSX );
6381               my $worksheet = $workbook->add_worksheet();
6382
6383
6384               # Set the column width for column 1
6385               $worksheet->set_column( 0, 0, 20 );
6386
6387
6388               # Create a format
6389               my $format = $workbook->add_format();
6390               $format->set_bold();
6391               $format->set_size( 15 );
6392               $format->set_color( 'blue' );
6393
6394
6395               # Write to the workbook
6396               $worksheet->write( 0, 0, "Hi Excel!", $format );
6397
6398               # You must close the workbook for Content-disposition
6399               $workbook->close();
6400           }
6401
6402           1;
6403
6404       Download this example:
6405       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/mod_perl1.pl>
6406
6407   Example: mod_perl2.pl
6408       Example of how to use the Excel::Writer::XLSX module to send an Excel
6409       file to a browser using mod_perl 2 and Apache.
6410
6411       This module ties *XLSX directly to Apache, and with the correct
6412       content-disposition/types it will prompt the user to save the file, or
6413       open it at this location.
6414
6415       This script is a modification of the Excel::Writer::XLSX cgi.pl
6416       example.
6417
6418       Change the name of this file to MP2Test.pm.  Change the package
6419       location to wherever you locate this package.  In the example below it
6420       is located in the Excel::Writer::XLSX directory.
6421
6422       Your httpd.conf entry for this module, should you choose to use it as a
6423       stand alone app, should look similar to the following:
6424
6425           PerlModule Apache2::RequestRec
6426           PerlModule APR::Table
6427           PerlModule Apache2::RequestIO
6428
6429           <Location /spreadsheet-test>
6430              SetHandler perl-script
6431              PerlResponseHandler Excel::Writer::XLSX::MP2Test
6432           </Location>
6433
6434       The PerlResponseHandler must match the package name below.
6435
6436           ###############################################################################
6437           #
6438           # Example of how to use the Excel::Writer::XLSX module to send an Excel
6439           # file to a browser using mod_perl 2 and Apache.
6440           #
6441           # This module ties *XLSX directly to Apache, and with the correct
6442           # content-disposition/types it will prompt the user to save
6443           # the file, or open it at this location.
6444           #
6445           # This script is a modification of the Excel::Writer::XLSX cgi.pl example.
6446           #
6447           # Change the name of this file to MP2Test.pm.
6448           # Change the package location to wherever you locate this package.
6449           # In the example below it is located in the Excel::Writer::XLSX directory.
6450           #
6451           # Your httpd.conf entry for this module, should you choose to use it
6452           # as a stand alone app, should look similar to the following:
6453           #
6454           #     PerlModule Apache2::RequestRec
6455           #     PerlModule APR::Table
6456           #     PerlModule Apache2::RequestIO
6457           #
6458           #     <Location /spreadsheet-test>
6459           #        SetHandler perl-script
6460           #        PerlResponseHandler Excel::Writer::XLSX::MP2Test
6461           #     </Location>
6462           #
6463           # The PerlResponseHandler must match the package name below.
6464
6465           # Jun 2004, Matisse Enzer, matisse@matisse.net  (mod_perl 2 version)
6466           # Apr 2001, Thomas Sullivan, webmaster@860.org
6467           # Feb 2001, John McNamara, jmcnamara@cpan.org
6468
6469           package Excel::Writer::XLSX::MP2Test;
6470
6471           ##########################################
6472           # Pragma Definitions
6473           ##########################################
6474           use strict;
6475
6476           ##########################################
6477           # Required Modules
6478           ##########################################
6479           use Apache2::Const -compile => qw( :common );
6480           use Excel::Writer::XLSX;
6481
6482           ##########################################
6483           # Main App Body
6484           ##########################################
6485           sub handler {
6486               my ( $r ) = @_;   # Apache request object is passed to handler in mod_perl 2
6487
6488               # Set the filename and send the content type
6489               # This will appear when they save the spreadsheet
6490               my $filename = "mod_perl2_test.xlsx";
6491
6492               ####################################################
6493               ## Send the content type headers the mod_perl 2 way
6494               ####################################################
6495               $r->headers_out->{'Content-Disposition'} = "attachment;filename=$filename";
6496               $r->content_type( 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
6497
6498               ####################################################
6499               # Tie a filehandle to Apache's STDOUT.
6500               # Create a new workbook and add a worksheet.
6501               ####################################################
6502               tie *XLSX => $r;  # The mod_perl 2 way. Tie to the Apache::RequestRec object
6503               binmode( *XLSX );
6504
6505               my $workbook  = Excel::Writer::XLSX->new( \*XLSX );
6506               my $worksheet = $workbook->add_worksheet();
6507
6508
6509               # Set the column width for column 1
6510               $worksheet->set_column( 0, 0, 20 );
6511
6512
6513               # Create a format
6514               my $format = $workbook->add_format();
6515               $format->set_bold();
6516               $format->set_size( 15 );
6517               $format->set_color( 'blue' );
6518
6519
6520               # Write to the workbook
6521               $worksheet->write( 0, 0, 'Hi Excel! from ' . $r->hostname, $format );
6522
6523               # You must close the workbook for Content-disposition
6524               $workbook->close();
6525               return Apache2::Const::OK;
6526           }
6527
6528           1;
6529
6530       Download this example:
6531       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/mod_perl2.pl>
6532
6533   Example: outline.pl
6534       Example of how use Excel::Writer::XLSX to generate Excel outlines and
6535       grouping.
6536
6537       Excel allows you to group rows or columns so that they can be hidden or
6538       displayed with a single mouse click. This feature is referred to as
6539       outlines.
6540
6541       Outlines can reduce complex data down to a few salient sub-totals or
6542       summaries.
6543
6544       This feature is best viewed in Excel but the following is an ASCII
6545       representation of what a worksheet with three outlines might look like.
6546       Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
6547       level 1. The lines at the left hand side are called outline level bars.
6548
6549                   ------------------------------------------
6550            1 2 3 |   |   A   |   B   |   C   |   D   |  ...
6551                   ------------------------------------------
6552             _    | 1 |   A   |       |       |       |  ...
6553            |  _  | 2 |   B   |       |       |       |  ...
6554            | |   | 3 |  (C)  |       |       |       |  ...
6555            | |   | 4 |  (D)  |       |       |       |  ...
6556            | -   | 5 |   E   |       |       |       |  ...
6557            |  _  | 6 |   F   |       |       |       |  ...
6558            | |   | 7 |  (G)  |       |       |       |  ...
6559            | |   | 8 |  (H)  |       |       |       |  ...
6560            | -   | 9 |   I   |       |       |       |  ...
6561            -     | . |  ...  |  ...  |  ...  |  ...  |  ...
6562
6563       Clicking the minus sign on each of the level 2 outlines will collapse
6564       and hide the data as shown in the next figure. The minus sign changes
6565       to a plus sign to indicate that the data in the outline is hidden.
6566
6567                   ------------------------------------------
6568            1 2 3 |   |   A   |   B   |   C   |   D   |  ...
6569                   ------------------------------------------
6570             _    | 1 |   A   |       |       |       |  ...
6571            |     | 2 |   B   |       |       |       |  ...
6572            | +   | 5 |   E   |       |       |       |  ...
6573            |     | 6 |   F   |       |       |       |  ...
6574            | +   | 9 |   I   |       |       |       |  ...
6575            -     | . |  ...  |  ...  |  ...  |  ...  |  ...
6576
6577       Clicking on the minus sign on the level 1 outline will collapse the
6578       remaining rows as follows:
6579
6580                   ------------------------------------------
6581            1 2 3 |   |   A   |   B   |   C   |   D   |  ...
6582                   ------------------------------------------
6583                  | 1 |   A   |       |       |       |  ...
6584            +     | . |  ...  |  ...  |  ...  |  ...  |  ...
6585
6586       See the main Excel::Writer::XLSX documentation for more information.
6587
6588       Source code for this example:
6589
6590           #!/usr/bin/perl
6591
6592           ###############################################################################
6593           #
6594           # Example of how use Excel::Writer::XLSX to generate Excel outlines and
6595           # grouping.
6596           #
6597           #
6598           # Excel allows you to group rows or columns so that they can be hidden or
6599           # displayed with a single mouse click. This feature is referred to as outlines.
6600           #
6601           # Outlines can reduce complex data down to a few salient sub-totals or
6602           # summaries.
6603           #
6604           # This feature is best viewed in Excel but the following is an ASCII
6605           # representation of what a worksheet with three outlines might look like.
6606           # Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
6607           # level 1. The lines at the left hand side are called outline level bars.
6608           #
6609           #
6610           #             ------------------------------------------
6611           #      1 2 3 |   |   A   |   B   |   C   |   D   |  ...
6612           #             ------------------------------------------
6613           #       _    | 1 |   A   |       |       |       |  ...
6614           #      |  _  | 2 |   B   |       |       |       |  ...
6615           #      | |   | 3 |  (C)  |       |       |       |  ...
6616           #      | |   | 4 |  (D)  |       |       |       |  ...
6617           #      | -   | 5 |   E   |       |       |       |  ...
6618           #      |  _  | 6 |   F   |       |       |       |  ...
6619           #      | |   | 7 |  (G)  |       |       |       |  ...
6620           #      | |   | 8 |  (H)  |       |       |       |  ...
6621           #      | -   | 9 |   I   |       |       |       |  ...
6622           #      -     | . |  ...  |  ...  |  ...  |  ...  |  ...
6623           #
6624           #
6625           # Clicking the minus sign on each of the level 2 outlines will collapse and
6626           # hide the data as shown in the next figure. The minus sign changes to a plus
6627           # sign to indicate that the data in the outline is hidden.
6628           #
6629           #             ------------------------------------------
6630           #      1 2 3 |   |   A   |   B   |   C   |   D   |  ...
6631           #             ------------------------------------------
6632           #       _    | 1 |   A   |       |       |       |  ...
6633           #      |     | 2 |   B   |       |       |       |  ...
6634           #      | +   | 5 |   E   |       |       |       |  ...
6635           #      |     | 6 |   F   |       |       |       |  ...
6636           #      | +   | 9 |   I   |       |       |       |  ...
6637           #      -     | . |  ...  |  ...  |  ...  |  ...  |  ...
6638           #
6639           #
6640           # Clicking on the minus sign on the level 1 outline will collapse the remaining
6641           # rows as follows:
6642           #
6643           #             ------------------------------------------
6644           #      1 2 3 |   |   A   |   B   |   C   |   D   |  ...
6645           #             ------------------------------------------
6646           #            | 1 |   A   |       |       |       |  ...
6647           #      +     | . |  ...  |  ...  |  ...  |  ...  |  ...
6648           #
6649           # See the main Excel::Writer::XLSX documentation for more information.
6650           #
6651           # reverse ('(c)'), April 2003, John McNamara, jmcnamara@cpan.org
6652           #
6653
6654
6655           use strict;
6656           use warnings;
6657           use Excel::Writer::XLSX;
6658
6659           # Create a new workbook and add some worksheets
6660           my $workbook   = Excel::Writer::XLSX->new( 'outline.xlsx' );
6661           my $worksheet1 = $workbook->add_worksheet( 'Outlined Rows' );
6662           my $worksheet2 = $workbook->add_worksheet( 'Collapsed Rows' );
6663           my $worksheet3 = $workbook->add_worksheet( 'Outline Columns' );
6664           my $worksheet4 = $workbook->add_worksheet( 'Outline levels' );
6665
6666           # Add a general format
6667           my $bold = $workbook->add_format( bold => 1 );
6668
6669
6670           ###############################################################################
6671           #
6672           # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
6673           # functions so that it looks like the type of automatic outlines that are
6674           # generated when you use the Excel Data->SubTotals menu item.
6675           #
6676
6677
6678           # For outlines the important parameters are $hidden and $level. Rows with the
6679           # same $level are grouped together. The group will be collapsed if $hidden is
6680           # non-zero. $height and $XF are assigned default values if they are undef.
6681           #
6682           # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
6683           #
6684           $worksheet1->set_row( 1, undef, undef, 0, 2 );
6685           $worksheet1->set_row( 2, undef, undef, 0, 2 );
6686           $worksheet1->set_row( 3, undef, undef, 0, 2 );
6687           $worksheet1->set_row( 4, undef, undef, 0, 2 );
6688           $worksheet1->set_row( 5, undef, undef, 0, 1 );
6689
6690           $worksheet1->set_row( 6,  undef, undef, 0, 2 );
6691           $worksheet1->set_row( 7,  undef, undef, 0, 2 );
6692           $worksheet1->set_row( 8,  undef, undef, 0, 2 );
6693           $worksheet1->set_row( 9,  undef, undef, 0, 2 );
6694           $worksheet1->set_row( 10, undef, undef, 0, 1 );
6695
6696
6697           # Add a column format for clarity
6698           $worksheet1->set_column( 'A:A', 20 );
6699
6700           # Add the data, labels and formulas
6701           $worksheet1->write( 'A1', 'Region', $bold );
6702           $worksheet1->write( 'A2', 'North' );
6703           $worksheet1->write( 'A3', 'North' );
6704           $worksheet1->write( 'A4', 'North' );
6705           $worksheet1->write( 'A5', 'North' );
6706           $worksheet1->write( 'A6', 'North Total', $bold );
6707
6708           $worksheet1->write( 'B1', 'Sales', $bold );
6709           $worksheet1->write( 'B2', 1000 );
6710           $worksheet1->write( 'B3', 1200 );
6711           $worksheet1->write( 'B4', 900 );
6712           $worksheet1->write( 'B5', 1200 );
6713           $worksheet1->write( 'B6', '=SUBTOTAL(9,B2:B5)', $bold );
6714
6715           $worksheet1->write( 'A7',  'South' );
6716           $worksheet1->write( 'A8',  'South' );
6717           $worksheet1->write( 'A9',  'South' );
6718           $worksheet1->write( 'A10', 'South' );
6719           $worksheet1->write( 'A11', 'South Total', $bold );
6720
6721           $worksheet1->write( 'B7',  400 );
6722           $worksheet1->write( 'B8',  600 );
6723           $worksheet1->write( 'B9',  500 );
6724           $worksheet1->write( 'B10', 600 );
6725           $worksheet1->write( 'B11', '=SUBTOTAL(9,B7:B10)', $bold );
6726
6727           $worksheet1->write( 'A12', 'Grand Total',         $bold );
6728           $worksheet1->write( 'B12', '=SUBTOTAL(9,B2:B10)', $bold );
6729
6730
6731           ###############################################################################
6732           #
6733           # Example 2: Create a worksheet with outlined rows. This is the same as the
6734           # previous example except that the rows are collapsed.
6735           # Note: We need to indicate the row that contains the collapsed symbol '+'
6736           # with the optional parameter, $collapsed.
6737
6738           # The group will be collapsed if $hidden is non-zero.
6739           # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
6740           #
6741           $worksheet2->set_row( 1, undef, undef, 1, 2 );
6742           $worksheet2->set_row( 2, undef, undef, 1, 2 );
6743           $worksheet2->set_row( 3, undef, undef, 1, 2 );
6744           $worksheet2->set_row( 4, undef, undef, 1, 2 );
6745           $worksheet2->set_row( 5, undef, undef, 1, 1 );
6746
6747           $worksheet2->set_row( 6,  undef, undef, 1, 2 );
6748           $worksheet2->set_row( 7,  undef, undef, 1, 2 );
6749           $worksheet2->set_row( 8,  undef, undef, 1, 2 );
6750           $worksheet2->set_row( 9,  undef, undef, 1, 2 );
6751           $worksheet2->set_row( 10, undef, undef, 1, 1 );
6752           $worksheet2->set_row( 11, undef, undef, 0, 0, 1 );
6753
6754
6755           # Add a column format for clarity
6756           $worksheet2->set_column( 'A:A', 20 );
6757
6758           # Add the data, labels and formulas
6759           $worksheet2->write( 'A1', 'Region', $bold );
6760           $worksheet2->write( 'A2', 'North' );
6761           $worksheet2->write( 'A3', 'North' );
6762           $worksheet2->write( 'A4', 'North' );
6763           $worksheet2->write( 'A5', 'North' );
6764           $worksheet2->write( 'A6', 'North Total', $bold );
6765
6766           $worksheet2->write( 'B1', 'Sales', $bold );
6767           $worksheet2->write( 'B2', 1000 );
6768           $worksheet2->write( 'B3', 1200 );
6769           $worksheet2->write( 'B4', 900 );
6770           $worksheet2->write( 'B5', 1200 );
6771           $worksheet2->write( 'B6', '=SUBTOTAL(9,B2:B5)', $bold );
6772
6773           $worksheet2->write( 'A7',  'South' );
6774           $worksheet2->write( 'A8',  'South' );
6775           $worksheet2->write( 'A9',  'South' );
6776           $worksheet2->write( 'A10', 'South' );
6777           $worksheet2->write( 'A11', 'South Total', $bold );
6778
6779           $worksheet2->write( 'B7',  400 );
6780           $worksheet2->write( 'B8',  600 );
6781           $worksheet2->write( 'B9',  500 );
6782           $worksheet2->write( 'B10', 600 );
6783           $worksheet2->write( 'B11', '=SUBTOTAL(9,B7:B10)', $bold );
6784
6785           $worksheet2->write( 'A12', 'Grand Total',         $bold );
6786           $worksheet2->write( 'B12', '=SUBTOTAL(9,B2:B10)', $bold );
6787
6788
6789           ###############################################################################
6790           #
6791           # Example 3: Create a worksheet with outlined columns.
6792           #
6793           my $data = [
6794               [ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ' Total' ],
6795               [ 'North', 50,    20,    15,    25,    65,    80,    '=SUM(B2:G2)' ],
6796               [ 'South', 10,    20,    30,    50,    50,    50,    '=SUM(B3:G3)' ],
6797               [ 'East',  45,    75,    50,    15,    75,    100,   '=SUM(B4:G4)' ],
6798               [ 'West',  15,    15,    55,    35,    20,    50,    '=SUM(B5:G5)' ],
6799           ];
6800
6801           # Add bold format to the first row
6802           $worksheet3->set_row( 0, undef, $bold );
6803
6804           # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
6805           $worksheet3->set_column( 'A:A', 10, $bold );
6806           $worksheet3->set_column( 'B:G', 5, undef, 0, 1 );
6807           $worksheet3->set_column( 'H:H', 10 );
6808
6809           # Write the data and a formula
6810           $worksheet3->write_col( 'A1', $data );
6811           $worksheet3->write( 'H6', '=SUM(H2:H5)', $bold );
6812
6813
6814           ###############################################################################
6815           #
6816           # Example 4: Show all possible outline levels.
6817           #
6818           my $levels = [
6819               "Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6",
6820               "Level 7", "Level 6", "Level 5", "Level 4", "Level 3", "Level 2",
6821               "Level 1"
6822           ];
6823
6824
6825           $worksheet4->write_col( 'A1', $levels );
6826
6827           $worksheet4->set_row( 0,  undef, undef, undef, 1 );
6828           $worksheet4->set_row( 1,  undef, undef, undef, 2 );
6829           $worksheet4->set_row( 2,  undef, undef, undef, 3 );
6830           $worksheet4->set_row( 3,  undef, undef, undef, 4 );
6831           $worksheet4->set_row( 4,  undef, undef, undef, 5 );
6832           $worksheet4->set_row( 5,  undef, undef, undef, 6 );
6833           $worksheet4->set_row( 6,  undef, undef, undef, 7 );
6834           $worksheet4->set_row( 7,  undef, undef, undef, 6 );
6835           $worksheet4->set_row( 8,  undef, undef, undef, 5 );
6836           $worksheet4->set_row( 9,  undef, undef, undef, 4 );
6837           $worksheet4->set_row( 10, undef, undef, undef, 3 );
6838           $worksheet4->set_row( 11, undef, undef, undef, 2 );
6839           $worksheet4->set_row( 12, undef, undef, undef, 1 );
6840
6841           $workbook->close();
6842
6843           __END__
6844
6845       Download this example:
6846       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/outline.pl>
6847
6848   Example: outline_collapsed.pl
6849       Example of how to use Excel::Writer::XLSX to generate Excel outlines
6850       and grouping.
6851
6852       These examples focus mainly on collapsed outlines. See also the
6853       outlines.pl example program for more general examples.
6854
6855       Source code for this example:
6856
6857           #!/usr/bin/perl
6858
6859           ###############################################################################
6860           #
6861           # Example of how to use Excel::Writer::XLSX to generate Excel outlines and
6862           # grouping.
6863           #
6864           # These examples focus mainly on collapsed outlines. See also the
6865           # outlines.pl example program for more general examples.
6866           #
6867           # reverse ('(c)'), March 2008, John McNamara, jmcnamara@cpan.org
6868           #
6869
6870           use strict;
6871           use warnings;
6872           use Excel::Writer::XLSX;
6873
6874           # Create a new workbook and add some worksheets
6875           my $workbook   = Excel::Writer::XLSX->new( 'outline_collapsed.xlsx' );
6876           my $worksheet1 = $workbook->add_worksheet( 'Outlined Rows' );
6877           my $worksheet2 = $workbook->add_worksheet( 'Collapsed Rows 1' );
6878           my $worksheet3 = $workbook->add_worksheet( 'Collapsed Rows 2' );
6879           my $worksheet4 = $workbook->add_worksheet( 'Collapsed Rows 3' );
6880           my $worksheet5 = $workbook->add_worksheet( 'Outline Columns' );
6881           my $worksheet6 = $workbook->add_worksheet( 'Collapsed Columns' );
6882
6883
6884           # Add a general format
6885           my $bold = $workbook->add_format( bold => 1 );
6886
6887
6888           #
6889           # This function will generate the same data and sub-totals on each worksheet.
6890           #
6891           sub create_sub_totals {
6892
6893               my $worksheet = $_[0];
6894
6895               # Add a column format for clarity
6896               $worksheet->set_column( 'A:A', 20 );
6897
6898               # Add the data, labels and formulas
6899               $worksheet->write( 'A1', 'Region', $bold );
6900               $worksheet->write( 'A2', 'North' );
6901               $worksheet->write( 'A3', 'North' );
6902               $worksheet->write( 'A4', 'North' );
6903               $worksheet->write( 'A5', 'North' );
6904               $worksheet->write( 'A6', 'North Total', $bold );
6905
6906               $worksheet->write( 'B1', 'Sales', $bold );
6907               $worksheet->write( 'B2', 1000 );
6908               $worksheet->write( 'B3', 1200 );
6909               $worksheet->write( 'B4', 900 );
6910               $worksheet->write( 'B5', 1200 );
6911               $worksheet->write( 'B6', '=SUBTOTAL(9,B2:B5)', $bold );
6912
6913               $worksheet->write( 'A7',  'South' );
6914               $worksheet->write( 'A8',  'South' );
6915               $worksheet->write( 'A9',  'South' );
6916               $worksheet->write( 'A10', 'South' );
6917               $worksheet->write( 'A11', 'South Total', $bold );
6918
6919               $worksheet->write( 'B7',  400 );
6920               $worksheet->write( 'B8',  600 );
6921               $worksheet->write( 'B9',  500 );
6922               $worksheet->write( 'B10', 600 );
6923               $worksheet->write( 'B11', '=SUBTOTAL(9,B7:B10)', $bold );
6924
6925               $worksheet->write( 'A12', 'Grand Total',         $bold );
6926               $worksheet->write( 'B12', '=SUBTOTAL(9,B2:B10)', $bold );
6927
6928           }
6929
6930
6931           ###############################################################################
6932           #
6933           # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
6934           # functions so that it looks like the type of automatic outlines that are
6935           # generated when you use the Excel Data->SubTotals menu item.
6936           #
6937
6938           # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
6939           $worksheet1->set_row( 1, undef, undef, 0, 2 );
6940           $worksheet1->set_row( 2, undef, undef, 0, 2 );
6941           $worksheet1->set_row( 3, undef, undef, 0, 2 );
6942           $worksheet1->set_row( 4, undef, undef, 0, 2 );
6943           $worksheet1->set_row( 5, undef, undef, 0, 1 );
6944
6945           $worksheet1->set_row( 6,  undef, undef, 0, 2 );
6946           $worksheet1->set_row( 7,  undef, undef, 0, 2 );
6947           $worksheet1->set_row( 8,  undef, undef, 0, 2 );
6948           $worksheet1->set_row( 9,  undef, undef, 0, 2 );
6949           $worksheet1->set_row( 10, undef, undef, 0, 1 );
6950
6951           # Write the sub-total data that is common to the row examples.
6952           create_sub_totals( $worksheet1 );
6953
6954
6955           ###############################################################################
6956           #
6957           # Example 2: Create a worksheet with collapsed outlined rows.
6958           # This is the same as the example 1  except that the all rows are collapsed.
6959           # Note: We need to indicate the row that contains the collapsed symbol '+' with
6960           # the optional parameter, $collapsed.
6961
6962           $worksheet2->set_row( 1, undef, undef, 1, 2 );
6963           $worksheet2->set_row( 2, undef, undef, 1, 2 );
6964           $worksheet2->set_row( 3, undef, undef, 1, 2 );
6965           $worksheet2->set_row( 4, undef, undef, 1, 2 );
6966           $worksheet2->set_row( 5, undef, undef, 1, 1 );
6967
6968           $worksheet2->set_row( 6,  undef, undef, 1, 2 );
6969           $worksheet2->set_row( 7,  undef, undef, 1, 2 );
6970           $worksheet2->set_row( 8,  undef, undef, 1, 2 );
6971           $worksheet2->set_row( 9,  undef, undef, 1, 2 );
6972           $worksheet2->set_row( 10, undef, undef, 1, 1 );
6973
6974           $worksheet2->set_row( 11, undef, undef, 0, 0, 1 );
6975
6976           # Write the sub-total data that is common to the row examples.
6977           create_sub_totals( $worksheet2 );
6978
6979
6980           ###############################################################################
6981           #
6982           # Example 3: Create a worksheet with collapsed outlined rows.
6983           # Same as the example 1  except that the two sub-totals are collapsed.
6984
6985           $worksheet3->set_row( 1, undef, undef, 1, 2 );
6986           $worksheet3->set_row( 2, undef, undef, 1, 2 );
6987           $worksheet3->set_row( 3, undef, undef, 1, 2 );
6988           $worksheet3->set_row( 4, undef, undef, 1, 2 );
6989           $worksheet3->set_row( 5, undef, undef, 0, 1, 1 );
6990
6991           $worksheet3->set_row( 6,  undef, undef, 1, 2 );
6992           $worksheet3->set_row( 7,  undef, undef, 1, 2 );
6993           $worksheet3->set_row( 8,  undef, undef, 1, 2 );
6994           $worksheet3->set_row( 9,  undef, undef, 1, 2 );
6995           $worksheet3->set_row( 10, undef, undef, 0, 1, 1 );
6996
6997
6998           # Write the sub-total data that is common to the row examples.
6999           create_sub_totals( $worksheet3 );
7000
7001
7002           ###############################################################################
7003           #
7004           # Example 4: Create a worksheet with outlined rows.
7005           # Same as the example 1  except that the two sub-totals are collapsed.
7006
7007           $worksheet4->set_row( 1, undef, undef, 1, 2 );
7008           $worksheet4->set_row( 2, undef, undef, 1, 2 );
7009           $worksheet4->set_row( 3, undef, undef, 1, 2 );
7010           $worksheet4->set_row( 4, undef, undef, 1, 2 );
7011           $worksheet4->set_row( 5, undef, undef, 1, 1, 1 );
7012
7013           $worksheet4->set_row( 6,  undef, undef, 1, 2 );
7014           $worksheet4->set_row( 7,  undef, undef, 1, 2 );
7015           $worksheet4->set_row( 8,  undef, undef, 1, 2 );
7016           $worksheet4->set_row( 9,  undef, undef, 1, 2 );
7017           $worksheet4->set_row( 10, undef, undef, 1, 1, 1 );
7018
7019           $worksheet4->set_row( 11, undef, undef, 0, 0, 1 );
7020
7021           # Write the sub-total data that is common to the row examples.
7022           create_sub_totals( $worksheet4 );
7023
7024
7025           ###############################################################################
7026           #
7027           # Example 5: Create a worksheet with outlined columns.
7028           #
7029           my $data = [
7030               [ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Total' ],
7031               [ 'North', 50,    20,    15,    25,    65,    80,,   '=SUM(B2:G2)' ],
7032               [ 'South', 10,    20,    30,    50,    50,    50,,   '=SUM(B3:G3)' ],
7033               [ 'East',  45,    75,    50,    15,    75,    100,,  '=SUM(B4:G4)' ],
7034               [ 'West',  15,    15,    55,    35,    20,    50,,   '=SUM(B5:G6)' ],
7035           ];
7036
7037           # Add bold format to the first row
7038           $worksheet5->set_row( 0, undef, $bold );
7039
7040           # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
7041           $worksheet5->set_column( 'A:A', 10, $bold );
7042           $worksheet5->set_column( 'B:G', 5, undef, 0, 1 );
7043           $worksheet5->set_column( 'H:H', 10 );
7044
7045           # Write the data and a formula
7046           $worksheet5->write_col( 'A1', $data );
7047           $worksheet5->write( 'H6', '=SUM(H2:H5)', $bold );
7048
7049
7050           ###############################################################################
7051           #
7052           # Example 6: Create a worksheet with collapsed outlined columns.
7053           # This is the same as the previous example except collapsed columns.
7054
7055           # Add bold format to the first row
7056           $worksheet6->set_row( 0, undef, $bold );
7057
7058           # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
7059           $worksheet6->set_column( 'A:A', 10, $bold );
7060           $worksheet6->set_column( 'B:G', 5,  undef, 1, 1 );
7061           $worksheet6->set_column( 'H:H', 10, undef, 0, 0, 1 );
7062
7063           # Write the data and a formula
7064           $worksheet6->write_col( 'A1', $data );
7065           $worksheet6->write( 'H6', '=SUM(H2:H5)', $bold );
7066
7067           $workbook->close();
7068
7069           __END__
7070
7071       Download this example:
7072       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/outline_collapsed.pl>
7073
7074   Example: panes.pl
7075       Example of using the Excel::Writer::XLSX module to create worksheet
7076       panes.
7077
7078       Source code for this example:
7079
7080           #!/usr/bin/perl
7081
7082           #######################################################################
7083           #
7084           # Example of using the Excel::Writer::XLSX module to create worksheet panes.
7085           #
7086           # reverse ('(c)'), May 2001, John McNamara, jmcnamara@cpan.org
7087           #
7088
7089           use strict;
7090           use warnings;
7091           use Excel::Writer::XLSX;
7092
7093           my $workbook = Excel::Writer::XLSX->new( 'panes.xlsx' );
7094
7095           my $worksheet1 = $workbook->add_worksheet( 'Panes 1' );
7096           my $worksheet2 = $workbook->add_worksheet( 'Panes 2' );
7097           my $worksheet3 = $workbook->add_worksheet( 'Panes 3' );
7098           my $worksheet4 = $workbook->add_worksheet( 'Panes 4' );
7099
7100           # Freeze panes
7101           $worksheet1->freeze_panes( 1, 0 );    # 1 row
7102
7103           $worksheet2->freeze_panes( 0, 1 );    # 1 column
7104           $worksheet3->freeze_panes( 1, 1 );    # 1 row and column
7105
7106           # Split panes.
7107           # The divisions must be specified in terms of row and column dimensions.
7108           # The default row height is 15 and the default column width is 8.43
7109           #
7110           $worksheet4->split_panes( 15, 8.43 );    # 1 row and column
7111
7112
7113           #######################################################################
7114           #
7115           # Set up some formatting and text to highlight the panes
7116           #
7117
7118           my $header = $workbook->add_format(
7119               align    => 'center',
7120               valign   => 'vcenter',
7121               fg_color => '#C3FFC0',
7122           );
7123
7124           my $center = $workbook->add_format( align => 'center' );
7125
7126
7127           #######################################################################
7128           #
7129           # Sheet 1
7130           #
7131
7132           $worksheet1->set_column( 'A:I', 16 );
7133           $worksheet1->set_row( 0, 20 );
7134           $worksheet1->set_selection( 'C3' );
7135
7136           for my $i ( 0 .. 8 ) {
7137               $worksheet1->write( 0, $i, 'Scroll down', $header );
7138           }
7139
7140           for my $i ( 1 .. 100 ) {
7141               for my $j ( 0 .. 8 ) {
7142                   $worksheet1->write( $i, $j, $i + 1, $center );
7143               }
7144           }
7145
7146
7147           #######################################################################
7148           #
7149           # Sheet 2
7150           #
7151
7152           $worksheet2->set_column( 'A:A', 16 );
7153           $worksheet2->set_selection( 'C3' );
7154
7155           for my $i ( 0 .. 49 ) {
7156               $worksheet2->set_row( $i, 15 );
7157               $worksheet2->write( $i, 0, 'Scroll right', $header );
7158           }
7159
7160           for my $i ( 0 .. 49 ) {
7161               for my $j ( 1 .. 25 ) {
7162                   $worksheet2->write( $i, $j, $j, $center );
7163               }
7164           }
7165
7166
7167           #######################################################################
7168           #
7169           # Sheet 3
7170           #
7171
7172           $worksheet3->set_column( 'A:Z', 16 );
7173           $worksheet3->set_selection( 'C3' );
7174
7175           $worksheet3->write( 0, 0, '', $header );
7176
7177           for my $i ( 1 .. 25 ) {
7178               $worksheet3->write( 0, $i, 'Scroll down', $header );
7179           }
7180
7181           for my $i ( 1 .. 49 ) {
7182               $worksheet3->write( $i, 0, 'Scroll right', $header );
7183           }
7184
7185           for my $i ( 1 .. 49 ) {
7186               for my $j ( 1 .. 25 ) {
7187                   $worksheet3->write( $i, $j, $j, $center );
7188               }
7189           }
7190
7191
7192           #######################################################################
7193           #
7194           # Sheet 4
7195           #
7196
7197           $worksheet4->set_selection( 'C3' );
7198
7199           for my $i ( 1 .. 25 ) {
7200               $worksheet4->write( 0, $i, 'Scroll', $center );
7201           }
7202
7203           for my $i ( 1 .. 49 ) {
7204               $worksheet4->write( $i, 0, 'Scroll', $center );
7205           }
7206
7207           for my $i ( 1 .. 49 ) {
7208               for my $j ( 1 .. 25 ) {
7209                   $worksheet4->write( $i, $j, $j, $center );
7210               }
7211           }
7212
7213           $workbook->close();
7214
7215           __END__
7216
7217       Download this example:
7218       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/panes.pl>
7219
7220   Example: properties.pl
7221       An example of adding document properties to a Excel::Writer::XLSX file.
7222
7223       Source code for this example:
7224
7225           #!/usr/bin/perl
7226
7227           ##############################################################################
7228           #
7229           # An example of adding document properties to a Excel::Writer::XLSX file.
7230           #
7231           # reverse ('(c)'), August 2008, John McNamara, jmcnamara@cpan.org
7232           #
7233
7234           use strict;
7235           use warnings;
7236           use Excel::Writer::XLSX;
7237
7238           my $workbook  = Excel::Writer::XLSX->new( 'properties.xlsx' );
7239           my $worksheet = $workbook->add_worksheet();
7240
7241
7242           $workbook->set_properties(
7243               title    => 'This is an example spreadsheet',
7244               subject  => 'With document properties',
7245               author   => 'John McNamara',
7246               manager  => 'Dr. Heinz Doofenshmirtz',
7247               company  => 'of Wolves',
7248               category => 'Example spreadsheets',
7249               keywords => 'Sample, Example, Properties',
7250               comments => 'Created with Perl and Excel::Writer::XLSX',
7251               status   => 'Quo',
7252           );
7253
7254
7255           $worksheet->set_column( 'A:A', 70 );
7256           $worksheet->write( 'A1', qq{Select 'Office Button -> Prepare -> Properties' to see the file properties.} );
7257
7258           $workbook->close();
7259
7260           __END__
7261
7262       Download this example:
7263       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/properties.pl>
7264
7265   Example: protection.pl
7266       Example of cell locking and formula hiding in an Excel worksheet via
7267       the Excel::Writer::XLSX module.
7268
7269       Source code for this example:
7270
7271           #!/usr/bin/perl
7272
7273           ########################################################################
7274           #
7275           # Example of cell locking and formula hiding in an Excel worksheet via
7276           # the Excel::Writer::XLSX module.
7277           #
7278           # reverse ('(c)'), August 2001, John McNamara, jmcnamara@cpan.org
7279           #
7280
7281           use strict;
7282           use warnings;
7283           use Excel::Writer::XLSX;
7284
7285           my $workbook  = Excel::Writer::XLSX->new( 'protection.xlsx' );
7286           my $worksheet = $workbook->add_worksheet();
7287
7288           # Create some format objects
7289           my $unlocked = $workbook->add_format( locked => 0 );
7290           my $hidden   = $workbook->add_format( hidden => 1 );
7291
7292           # Format the columns
7293           $worksheet->set_column( 'A:A', 45 );
7294           $worksheet->set_selection( 'B3' );
7295
7296           # Protect the worksheet
7297           $worksheet->protect();
7298
7299           # Examples of cell locking and hiding.
7300           $worksheet->write( 'A1', 'Cell B1 is locked. It cannot be edited.' );
7301           $worksheet->write_formula( 'B1', '=1+2', undef, 3 );    # Locked by default.
7302
7303           $worksheet->write( 'A2', 'Cell B2 is unlocked. It can be edited.' );
7304           $worksheet->write_formula( 'B2', '=1+2', $unlocked, 3 );
7305
7306           $worksheet->write( 'A3', "Cell B3 is hidden. The formula isn't visible." );
7307           $worksheet->write_formula( 'B3', '=1+2', $hidden, 3 );
7308
7309           $worksheet->write( 'A5', 'Use Menu->Tools->Protection->Unprotect Sheet' );
7310           $worksheet->write( 'A6', 'to remove the worksheet protection.' );
7311
7312           $workbook->close();
7313
7314           __END__
7315
7316       Download this example:
7317       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/protection.pl>
7318
7319   Example: rich_strings.pl
7320       An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
7321       strings with multiple formatting.
7322
7323       Source code for this example:
7324
7325           #!/usr/bin/perl
7326
7327           #######################################################################
7328           #
7329           # An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
7330           # strings with multiple formatting.
7331           #
7332           # reverse ('(c)'), February 2011, John McNamara, jmcnamara@cpan.org
7333           #
7334
7335           use strict;
7336           use warnings;
7337           use Excel::Writer::XLSX;
7338
7339           my $workbook  = Excel::Writer::XLSX->new( 'rich_strings.xlsx' );
7340           my $worksheet = $workbook->add_worksheet();
7341
7342           $worksheet->set_column( 'A:A', 30 );
7343
7344           # Set some formats to use.
7345           my $bold   = $workbook->add_format( bold        => 1 );
7346           my $italic = $workbook->add_format( italic      => 1 );
7347           my $red    = $workbook->add_format( color       => 'red' );
7348           my $blue   = $workbook->add_format( color       => 'blue' );
7349           my $center = $workbook->add_format( align       => 'center' );
7350           my $super  = $workbook->add_format( font_script => 1 );
7351
7352
7353           # Write some strings with multiple formats.
7354           $worksheet->write_rich_string( 'A1',
7355               'This is ', $bold, 'bold', ' and this is ', $italic, 'italic' );
7356
7357           $worksheet->write_rich_string( 'A3',
7358               'This is ', $red, 'red', ' and this is ', $blue, 'blue' );
7359
7360           $worksheet->write_rich_string( 'A5',
7361               'Some ', $bold, 'bold text', ' centered', $center );
7362
7363           $worksheet->write_rich_string( 'A7',
7364               $italic, 'j = k', $super, '(n-1)', $center );
7365
7366           $workbook->close();
7367
7368           __END__
7369
7370       Download this example:
7371       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/rich_strings.pl>
7372
7373   Example: right_to_left.pl
7374       Example of how to change the default worksheet direction from left-to-
7375       right to right-to-left as required by some eastern verions of Excel.
7376
7377       Source code for this example:
7378
7379           #!/usr/bin/perl
7380
7381           #######################################################################
7382           #
7383           # Example of how to change the default worksheet direction from
7384           # left-to-right to right-to-left as required by some eastern verions
7385           # of Excel.
7386           #
7387           # reverse ('(c)'), January 2006, John McNamara, jmcnamara@cpan.org
7388           #
7389
7390           use strict;
7391           use warnings;
7392           use Excel::Writer::XLSX;
7393
7394           my $workbook   = Excel::Writer::XLSX->new( 'right_to_left.xlsx' );
7395           my $worksheet1 = $workbook->add_worksheet();
7396           my $worksheet2 = $workbook->add_worksheet();
7397
7398           $worksheet2->right_to_left();
7399
7400           $worksheet1->write( 0, 0, 'Hello' );    #  A1, B1, C1, ...
7401           $worksheet2->write( 0, 0, 'Hello' );    # ..., C1, B1, A1
7402
7403           $workbook->close();
7404
7405           __END__
7406
7407       Download this example:
7408       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/right_to_left.pl>
7409
7410   Example: sales.pl
7411       Example of a sales worksheet to demonstrate several different features.
7412       Also uses functions from the Excel::Writer::XLSX::Utility module.
7413
7414       Source code for this example:
7415
7416           #!/usr/bin/perl -w
7417
7418           ###############################################################################
7419           #
7420           # Example of a sales worksheet to demonstrate several different features.
7421           # Also uses functions from the L<Excel::Writer::XLSX::Utility> module.
7422           #
7423           # reverse ('(c)'), October 2001, John McNamara, jmcnamara@cpan.org
7424           #
7425
7426           use strict;
7427           use Excel::Writer::XLSX;
7428           use Excel::Writer::XLSX::Utility;
7429
7430           # Create a new workbook and add a worksheet
7431           my $workbook  = Excel::Writer::XLSX->new( 'sales.xlsx' );
7432           my $worksheet = $workbook->add_worksheet( 'May Sales' );
7433
7434
7435           # Set up some formats
7436           my %heading = (
7437               bold     => 1,
7438               pattern  => 1,
7439               fg_color => '#C3FFC0',
7440               border   => 1,
7441               align    => 'center',
7442           );
7443
7444           my %total = (
7445               bold       => 1,
7446               top        => 1,
7447               num_format => '$#,##0.00'
7448           );
7449
7450           my $heading      = $workbook->add_format( %heading );
7451           my $total_format = $workbook->add_format( %total );
7452           my $price_format = $workbook->add_format( num_format => '$#,##0.00' );
7453           my $date_format  = $workbook->add_format( num_format => 'mmm d yyy' );
7454
7455
7456           # Write the main headings
7457           $worksheet->freeze_panes( 1 );    # Freeze the first row
7458           $worksheet->write( 'A1', 'Item',     $heading );
7459           $worksheet->write( 'B1', 'Quantity', $heading );
7460           $worksheet->write( 'C1', 'Price',    $heading );
7461           $worksheet->write( 'D1', 'Total',    $heading );
7462           $worksheet->write( 'E1', 'Date',     $heading );
7463
7464           # Set the column widths
7465           $worksheet->set_column( 'A:A', 25 );
7466           $worksheet->set_column( 'B:B', 10 );
7467           $worksheet->set_column( 'C:E', 16 );
7468
7469
7470           # Extract the sales data from the __DATA__ section at the end of the file.
7471           # In reality this information would probably come from a database
7472           my @sales;
7473
7474           foreach my $line ( <DATA> ) {
7475               chomp $line;
7476               next if $line eq '';
7477
7478               # Simple-minded processing of CSV data. Refer to the Text::CSV_XS
7479               # and Text::xSV modules for a more complete CSV handling.
7480               my @items = split /,/, $line;
7481               push @sales, \@items;
7482           }
7483
7484
7485           # Write out the items from each row
7486           my $row = 1;
7487           foreach my $sale ( @sales ) {
7488
7489               $worksheet->write( $row, 0, @$sale[0] );
7490               $worksheet->write( $row, 1, @$sale[1] );
7491               $worksheet->write( $row, 2, @$sale[2], $price_format );
7492
7493               # Create a formula like '=B2*C2'
7494               my $formula =
7495                 '=' . xl_rowcol_to_cell( $row, 1 ) . "*" . xl_rowcol_to_cell( $row, 2 );
7496
7497               $worksheet->write( $row, 3, $formula, $price_format );
7498
7499               # Parse the date
7500               my $date = xl_decode_date_US( @$sale[3] );
7501               $worksheet->write( $row, 4, $date, $date_format );
7502               $row++;
7503           }
7504
7505           # Create a formula to sum the totals, like '=SUM(D2:D6)'
7506           my $total = '=SUM(D2:' . xl_rowcol_to_cell( $row - 1, 3 ) . ")";
7507
7508           $worksheet->write( $row, 3, $total, $total_format );
7509
7510           $workbook->close();
7511
7512           __DATA__
7513           586 card,20,125.50,5/12/01
7514           Flat Screen Monitor,1,1300.00,5/12/01
7515           64 MB dimms,45,49.99,5/13/01
7516           15 GB HD,12,300.00,5/13/01
7517           Speakers (pair),5,15.50,5/14/01
7518
7519       Download this example:
7520       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/sales.pl>
7521
7522   Example: shape1.pl
7523       A simple example of how to use the Excel::Writer::XLSX module to add
7524       shapes to an Excel xlsx file.
7525
7526       Source code for this example:
7527
7528           #!/usr/bin/perl
7529
7530           #######################################################################
7531           #
7532           # A simple example of how to use the Excel::Writer::XLSX module to
7533           # add shapes to an Excel xlsx file.
7534           #
7535           # reverse ('(c)'), May 2012, John McNamara, jmcnamara@cpan.org
7536           #
7537
7538           use strict;
7539           use warnings;
7540           use Excel::Writer::XLSX;
7541
7542           my $workbook  = Excel::Writer::XLSX->new( 'shape1.xlsx' );
7543           my $worksheet = $workbook->add_worksheet();
7544
7545           # Add a circle, with centered text.
7546           my $ellipse = $workbook->add_shape(
7547               type   => 'ellipse',
7548               text   => "Hello\nWorld",
7549               width  => 60,
7550               height => 60
7551           );
7552
7553           $worksheet->insert_shape( 'A1', $ellipse, 50, 50 );
7554
7555           # Add a plus sign.
7556           my $plus = $workbook->add_shape( type => 'plus', width => 20, height => 20 );
7557           $worksheet->insert_shape( 'D8', $plus );
7558
7559           $workbook->close();
7560
7561           __END__
7562
7563       Download this example:
7564       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/shape1.pl>
7565
7566   Example: shape2.pl
7567       A simple example of how to use the Excel::Writer::XLSX module to modify
7568       shape properties in an Excel xlsx file.
7569
7570       Source code for this example:
7571
7572           #!/usr/bin/perl
7573
7574           #######################################################################
7575           #
7576           # A simple example of how to use the Excel::Writer::XLSX module to
7577           # modify shape properties in an Excel xlsx file.
7578           #
7579           # reverse ('(c)'), May 2012, John McNamara, jmcnamara@cpan.org
7580           #
7581
7582           use strict;
7583           use warnings;
7584           use Excel::Writer::XLSX;
7585
7586           my $workbook  = Excel::Writer::XLSX->new( 'shape2.xlsx' );
7587           my $worksheet = $workbook->add_worksheet();
7588
7589           $worksheet->hide_gridlines( 2 );
7590
7591           my $plain = $workbook->add_shape(
7592               type   => 'smileyFace',
7593               text   => "Plain",
7594               width  => 100,
7595               height => 100,
7596           );
7597
7598           my $bbformat = $workbook->add_format(
7599               color => 'red',
7600               font  => 'Lucida Calligraphy',
7601           );
7602
7603           $bbformat->set_bold();
7604           $bbformat->set_underline();
7605           $bbformat->set_italic();
7606
7607           my $decor = $workbook->add_shape(
7608               type        => 'smileyFace',
7609               text        => "Decorated",
7610               rotation    => 45,
7611               width       => 200,
7612               height      => 100,
7613               format      => $bbformat,
7614               line_type   => 'sysDot',
7615               line_weight => 3,
7616               fill        => 'FFFF00',
7617               line        => '3366FF',
7618           );
7619
7620           $worksheet->insert_shape( 'A1', $plain, 50,  50 );
7621           $worksheet->insert_shape( 'A1', $decor, 250, 50 );
7622
7623           $workbook->close();
7624
7625           __END__
7626
7627       Download this example:
7628       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/shape2.pl>
7629
7630   Example: shape3.pl
7631       A simple example of how to use the Excel::Writer::XLSX module to scale
7632       shapes in an Excel xlsx file.
7633
7634       Source code for this example:
7635
7636           #!/usr/bin/perl
7637
7638           #######################################################################
7639           #
7640           # A simple example of how to use the Excel::Writer::XLSX module to
7641           # scale shapes in an Excel xlsx file.
7642           #
7643           # reverse ('(c)'), May 2012, John McNamara, jmcnamara@cpan.org
7644           #
7645
7646           use strict;
7647           use warnings;
7648           use Excel::Writer::XLSX;
7649
7650           my $workbook  = Excel::Writer::XLSX->new( 'shape3.xlsx' );
7651           my $worksheet = $workbook->add_worksheet();
7652
7653           my $normal = $workbook->add_shape(
7654               name   => 'chip',
7655               type   => 'diamond',
7656               text   => "Normal",
7657               width  => 100,
7658               height => 100,
7659           );
7660
7661           $worksheet->insert_shape( 'A1', $normal, 50, 50 );
7662           $normal->set_text( 'Scaled 3w x 2h' );
7663           $normal->set_name( 'Hope' );
7664           $worksheet->insert_shape( 'A1', $normal, 250, 50, 3, 2 );
7665
7666           $workbook->close();
7667
7668           __END__
7669
7670       Download this example:
7671       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/shape3.pl>
7672
7673   Example: shape4.pl
7674       A simple example of how to use the Excel::Writer::XLSX module to
7675       demonstrate stenciling in an Excel xlsx file.
7676
7677       Source code for this example:
7678
7679           #!/usr/bin/perl
7680
7681           #######################################################################
7682           #
7683           # A simple example of how to use the Excel::Writer::XLSX module to
7684           # demonstrate stenciling in an Excel xlsx file.
7685           #
7686           # reverse ('(c)'), May 2012, John McNamara, jmcnamara@cpan.org
7687           #
7688
7689           use strict;
7690           use warnings;
7691           use Excel::Writer::XLSX;
7692
7693           my $workbook  = Excel::Writer::XLSX->new( 'shape4.xlsx' );
7694           my $worksheet = $workbook->add_worksheet();
7695
7696           $worksheet->hide_gridlines( 2 );
7697
7698           my $type  = 'rect';
7699           my $shape = $workbook->add_shape(
7700               type   => $type,
7701               width  => 90,
7702               height => 90,
7703           );
7704
7705           for my $n ( 1 .. 10 ) {
7706
7707               # Change the last 5 rectangles to stars. Previously inserted shapes stay
7708               # as rectangles.
7709               $type = 'star5' if $n == 6;
7710               $shape->set_type( $type );
7711               $shape->set_text( "$type $n" );
7712               $worksheet->insert_shape( 'A1', $shape, $n * 100, 50 );
7713           }
7714
7715
7716           my $stencil = $workbook->add_shape(
7717               stencil => 1,                    # The default.
7718               width   => 90,
7719               height  => 90,
7720               text    => 'started as a box',
7721           );
7722           $worksheet->insert_shape( 'A1', $stencil, 100, 150 );
7723
7724           $stencil->set_stencil( 0 );
7725           $worksheet->insert_shape( 'A1', $stencil, 200, 150 );
7726           $worksheet->insert_shape( 'A1', $stencil, 300, 150 );
7727
7728           # Ooops!  Changed my mind.  Change the rectangle to an ellipse (circle),
7729           # for the last two shapes.
7730           $stencil->set_type( 'ellipse' );
7731           $stencil->set_text( 'Now its a circle' );
7732
7733           $workbook->close();
7734
7735           __END__
7736
7737       Download this example:
7738       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/shape4.pl>
7739
7740   Example: shape5.pl
7741       A simple example of how to use the Excel::Writer::XLSX module to add
7742       shapes (objects and top/bottom connectors) to an Excel xlsx file.
7743
7744       Source code for this example:
7745
7746           #!/usr/bin/perl
7747
7748           #######################################################################
7749           #
7750           # A simple example of how to use the Excel::Writer::XLSX module to
7751           # add shapes (objects and top/bottom connectors) to an Excel xlsx file.
7752           #
7753           # reverse ('(c)'), May 2012, John McNamara, jmcnamara@cpan.org
7754           #
7755
7756           use strict;
7757           use warnings;
7758           use Excel::Writer::XLSX;
7759
7760           my $workbook  = Excel::Writer::XLSX->new( 'shape5.xlsx' );
7761           my $worksheet = $workbook->add_worksheet();
7762
7763           my $s1 = $workbook->add_shape( type => 'ellipse', width => 60, height => 60 );
7764           $worksheet->insert_shape( 'A1', $s1, 50, 50 );
7765
7766           my $s2 = $workbook->add_shape( type => 'plus', width => 20, height => 20 );
7767           $worksheet->insert_shape( 'A1', $s2, 250, 200 );
7768
7769           # Create a connector to link the two shapes.
7770           my $cxn_shape = $workbook->add_shape( type => 'bentConnector3' );
7771
7772           # Link the start of the connector to the right side.
7773           $cxn_shape->set_start( $s1->get_id() );
7774           $cxn_shape->set_start_index( 4 );  # 4th connection pt, clockwise from top(0).
7775           $cxn_shape->set_start_side( 'b' ); # r)ight or b)ottom.
7776
7777           # Link the end of the connector to the left side.
7778           $cxn_shape->set_end( $s2->get_id() );
7779           $cxn_shape->set_end_index( 0 );     # clockwise from top(0).
7780           $cxn_shape->set_end_side( 't' );    # t)top.
7781
7782           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7783
7784           $workbook->close();
7785
7786           __END__
7787
7788       Download this example:
7789       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/shape5.pl>
7790
7791   Example: shape6.pl
7792       A simple example of how to use the Excel::Writer::XLSX module to add
7793       shapes (objects and right/left connectors) to an Excel xlsx file.
7794
7795       Source code for this example:
7796
7797           #!/usr/bin/perl
7798
7799           #######################################################################
7800           #
7801           # A simple example of how to use the Excel::Writer::XLSX module to
7802           # add shapes (objects and right/left connectors) to an Excel xlsx file.
7803           #
7804           # reverse ('(c)'), May 2012, John McNamara, jmcnamara@cpan.org
7805           #
7806
7807           use strict;
7808           use warnings;
7809           use Excel::Writer::XLSX;
7810
7811           my $workbook  = Excel::Writer::XLSX->new( 'shape6.xlsx' );
7812           my $worksheet = $workbook->add_worksheet();
7813
7814           my $s1 = $workbook->add_shape( type => 'chevron', width => 60, height => 60 );
7815           $worksheet->insert_shape( 'A1', $s1, 50, 50 );
7816
7817           my $s2 = $workbook->add_shape( type => 'pentagon', width => 20, height => 20 );
7818           $worksheet->insert_shape( 'A1', $s2, 250, 200 );
7819
7820           # Create a connector to link the two shapes.
7821           my $cxn_shape = $workbook->add_shape( type => 'curvedConnector3' );
7822
7823           # Link the start of the connector to the right side.
7824           $cxn_shape->set_start( $s1->get_id() );
7825           $cxn_shape->set_start_index( 2 );    # 2nd connection pt, clockwise from top(0).
7826           $cxn_shape->set_start_side( 'r' );   # r)ight or b)ottom.
7827
7828           # Link the end of the connector to the left side.
7829           $cxn_shape->set_end( $s2->get_id() );
7830           $cxn_shape->set_end_index( 4 );      # 4th connection pt, clockwise from top(0).
7831           $cxn_shape->set_end_side( 'l' );     # l)eft or t)op.
7832
7833           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7834
7835           $workbook->close();
7836
7837           __END__
7838
7839       Download this example:
7840       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/shape6.pl>
7841
7842   Example: shape7.pl
7843       A simple example of how to use the Excel::Writer::XLSX module to add
7844       shapes and one-to-many connectors to an Excel xlsx file.
7845
7846       Source code for this example:
7847
7848           #!/usr/bin/perl
7849
7850           #######################################################################
7851           #
7852           # A simple example of how to use the Excel::Writer::XLSX module to
7853           # add shapes and one-to-many connectors to an Excel xlsx file.
7854           #
7855           # reverse ('(c)'), May 2012, John McNamara, jmcnamara@cpan.org
7856           #
7857
7858           use strict;
7859           use warnings;
7860           use Excel::Writer::XLSX;
7861
7862           my $workbook  = Excel::Writer::XLSX->new( 'shape7.xlsx' );
7863           my $worksheet = $workbook->add_worksheet();
7864
7865           # Add a circle, with centered text. c is for circle, not center.
7866           my $cw = 60;
7867           my $ch = 60;
7868           my $cx = 210;
7869           my $cy = 190;
7870
7871           my $ellipse = $workbook->add_shape(
7872               type   => 'ellipse',
7873               id     => 2,
7874               text   => "Hello\nWorld",
7875               width  => $cw,
7876               height => $ch
7877           );
7878           $worksheet->insert_shape( 'A1', $ellipse, $cx, $cy );
7879
7880           # Add a plus sign at 4 different positions around the circle.
7881           my $pw = 20;
7882           my $ph = 20;
7883           my $px = 120;
7884           my $py = 250;
7885           my $plus =
7886             $workbook->add_shape( type => 'plus', id => 3, width => $pw, height => $ph );
7887           my $p1 = $worksheet->insert_shape( 'A1', $plus, 350, 350 );
7888           my $p2 = $worksheet->insert_shape( 'A1', $plus, 150, 350 );
7889           my $p3 = $worksheet->insert_shape( 'A1', $plus, 350, 150 );
7890           $plus->set_adjustments( 35 );    # change shape of plus symbol.
7891           my $p4 = $worksheet->insert_shape( 'A1', $plus, 150, 150 );
7892
7893           my $cxn_shape = $workbook->add_shape( type => 'bentConnector3', fill => 0 );
7894
7895           $cxn_shape->set_start( $ellipse->get_id() );
7896           $cxn_shape->set_start_index( 4 );    # 4nd connection pt, clockwise from top(0).
7897           $cxn_shape->set_start_side( 'b' );   # r)ight or b)ottom.
7898
7899           $cxn_shape->set_end( $p1->get_id() );
7900           $cxn_shape->set_end_index( 0 );
7901           $cxn_shape->set_end_side( 't' );
7902           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7903
7904           $cxn_shape->set_end( $p2->get_id() );
7905           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7906
7907           $cxn_shape->set_end( $p3->get_id() );
7908           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7909
7910           $cxn_shape->set_end( $p4->get_id() );
7911           $cxn_shape->set_adjustments( -50, 45, 120 );
7912           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7913
7914           $workbook->close();
7915
7916           __END__
7917
7918       Download this example:
7919       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/shape7.pl>
7920
7921   Example: shape8.pl
7922       A simple example of how to use the Excel::Writer::XLSX module to add
7923       shapes and one-to-many connectors to an Excel xlsx file.
7924
7925       Source code for this example:
7926
7927           #!/usr/bin/perl
7928
7929           #######################################################################
7930           #
7931           # A simple example of how to use the Excel::Writer::XLSX module to
7932           # add shapes and one-to-many connectors to an Excel xlsx file.
7933           #
7934           # reverse ('(c)'), May 2012, John McNamara, jmcnamara@cpan.org
7935           #
7936
7937           use strict;
7938           use warnings;
7939           use Excel::Writer::XLSX;
7940
7941           my $workbook  = Excel::Writer::XLSX->new( 'shape8.xlsx' );
7942           my $worksheet = $workbook->add_worksheet();
7943
7944           # Add a circle, with centered text. c is for circle, not center.
7945           my $cw = 60;
7946           my $ch = 60;
7947           my $cx = 210;
7948           my $cy = 190;
7949
7950           my $ellipse = $workbook->add_shape(
7951               type   => 'ellipse',
7952               id     => 2,
7953               text   => "Hello\nWorld",
7954               width  => $cw,
7955               height => $ch
7956           );
7957           $worksheet->insert_shape( 'A1', $ellipse, $cx, $cy );
7958
7959           # Add a plus sign at 4 different positions around the circle.
7960           my $pw = 20;
7961           my $ph = 20;
7962           my $px = 120;
7963           my $py = 250;
7964           my $plus =
7965             $workbook->add_shape( type => 'plus', id => 3, width => $pw, height => $ph );
7966           my $p1 = $worksheet->insert_shape( 'A1', $plus, 350, 150 );    #  2:00
7967           my $p2 = $worksheet->insert_shape( 'A1', $plus, 350, 350 );    #  4:00
7968           my $p3 = $worksheet->insert_shape( 'A1', $plus, 150, 350 );    #  8:00
7969           my $p4 = $worksheet->insert_shape( 'A1', $plus, 150, 150 );    # 10:00
7970
7971           my $cxn_shape = $workbook->add_shape( type => 'bentConnector3', fill => 0 );
7972
7973           $cxn_shape->set_start( $ellipse->get_id() );
7974           $cxn_shape->set_start_index( 2 );    # 2nd connection pt, clockwise from top(0).
7975           $cxn_shape->set_start_side( 'r' );   # r)ight or b)ottom.
7976
7977           $cxn_shape->set_end( $p1->get_id() );
7978           $cxn_shape->set_end_index( 3 );      # 3rd connection point on plus, right side
7979           $cxn_shape->set_end_side( 'l' );
7980           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7981
7982           $cxn_shape->set_end( $p2->get_id() );
7983           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7984
7985           $cxn_shape->set_end( $p3->get_id() );
7986           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7987
7988           $cxn_shape->set_end( $p4->get_id() );
7989           $cxn_shape->set_adjustments( -50, 45, 120 );
7990           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
7991
7992           $workbook->close();
7993
7994           __END__
7995
7996       Download this example:
7997       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/shape8.pl>
7998
7999   Example: shape_all.pl
8000       A simple example of how to use the Excel::Writer::XLSX module to add
8001       all shapes (as currently implemented) to an Excel xlsx file.
8002
8003       The list at the end consists of all the shape types defined as
8004       ST_ShapeType in ECMA-376, Office Open XML File Formats Part 4.
8005
8006       The grouping by worksheet name is for illustration only. It isn't part
8007       of the ECMA-376 standard.
8008
8009       Source code for this example:
8010
8011           #!/usr/bin/perl
8012
8013           #######################################################################
8014           #
8015           # A simple example of how to use the Excel::Writer::XLSX module to
8016           # add all shapes (as currently implemented) to an Excel xlsx file.
8017           #
8018           # The list at the end consists of all the shape types defined as
8019           # ST_ShapeType in ECMA-376, Office Open XML File Formats Part 4.
8020           #
8021           # The grouping by worksheet name is for illustration only. It isn't
8022           # part of the ECMA-376 standard.
8023           #
8024           # reverse ('(c)'), May 2012, John McNamara, jmcnamara@cpan.org
8025           #
8026
8027           use strict;
8028           use warnings;
8029           use Excel::Writer::XLSX;
8030
8031           my $workbook = Excel::Writer::XLSX->new( 'shape_all.xlsx' );
8032
8033           my ( $worksheet, $last_sheet, $shape, $r ) = ( 0, '', '', undef, 0 );
8034
8035           while ( <DATA> ) {
8036               chomp;
8037               next unless m/^\w/;    # Skip blank lines and comments.
8038
8039               my ( $sheet, $name ) = split( /\t/, $_ );
8040               if ( $last_sheet ne $sheet ) {
8041                   $worksheet = $workbook->add_worksheet( $sheet );
8042                   $r         = 2;
8043               }
8044               $last_sheet = $sheet;
8045               $shape      = $workbook->add_shape(
8046                   type   => $name,
8047                   text   => $name,
8048                   width  => 90,
8049                   height => 90
8050               );
8051
8052               # Connectors can not have labels, so write the connector name in the cell
8053               # to the left.
8054               $worksheet->write( $r, 0, $name ) if $sheet eq 'Connector';
8055               $worksheet->insert_shape( $r, 2, $shape, 0, 0 );
8056               $r += 5;
8057           }
8058
8059           $workbook->close();
8060
8061           __END__
8062           Action      actionButtonBackPrevious
8063           Action      actionButtonBeginning
8064           Action      actionButtonBlank
8065           Action      actionButtonDocument
8066           Action      actionButtonEnd
8067           Action      actionButtonForwardNext
8068           Action      actionButtonHelp
8069           Action      actionButtonHome
8070           Action      actionButtonInformation
8071           Action      actionButtonMovie
8072           Action      actionButtonReturn
8073           Action      actionButtonSound
8074           Arrow       bentArrow
8075           Arrow       bentUpArrow
8076           Arrow       circularArrow
8077           Arrow       curvedDownArrow
8078           Arrow       curvedLeftArrow
8079           Arrow       curvedRightArrow
8080           Arrow       curvedUpArrow
8081           Arrow       downArrow
8082           Arrow       leftArrow
8083           Arrow       leftCircularArrow
8084           Arrow       leftRightArrow
8085           Arrow       leftRightCircularArrow
8086           Arrow       leftRightUpArrow
8087           Arrow       leftUpArrow
8088           Arrow       notchedRightArrow
8089           Arrow       quadArrow
8090           Arrow       rightArrow
8091           Arrow       stripedRightArrow
8092           Arrow       swooshArrow
8093           Arrow       upArrow
8094           Arrow       upDownArrow
8095           Arrow       uturnArrow
8096           Basic       blockArc
8097           Basic       can
8098           Basic       chevron
8099           Basic       cube
8100           Basic       decagon
8101           Basic       diamond
8102           Basic       dodecagon
8103           Basic       donut
8104           Basic       ellipse
8105           Basic       funnel
8106           Basic       gear6
8107           Basic       gear9
8108           Basic       heart
8109           Basic       heptagon
8110           Basic       hexagon
8111           Basic       homePlate
8112           Basic       lightningBolt
8113           Basic       line
8114           Basic       lineInv
8115           Basic       moon
8116           Basic       nonIsoscelesTrapezoid
8117           Basic       noSmoking
8118           Basic       octagon
8119           Basic       parallelogram
8120           Basic       pentagon
8121           Basic       pie
8122           Basic       pieWedge
8123           Basic       plaque
8124           Basic       rect
8125           Basic       round1Rect
8126           Basic       round2DiagRect
8127           Basic       round2SameRect
8128           Basic       roundRect
8129           Basic       rtTriangle
8130           Basic       smileyFace
8131           Basic       snip1Rect
8132           Basic       snip2DiagRect
8133           Basic       snip2SameRect
8134           Basic       snipRoundRect
8135           Basic       star10
8136           Basic       star12
8137           Basic       star16
8138           Basic       star24
8139           Basic       star32
8140           Basic       star4
8141           Basic       star5
8142           Basic       star6
8143           Basic       star7
8144           Basic       star8
8145           Basic       sun
8146           Basic       teardrop
8147           Basic       trapezoid
8148           Basic       triangle
8149           Callout     accentBorderCallout1
8150           Callout     accentBorderCallout2
8151           Callout     accentBorderCallout3
8152           Callout     accentCallout1
8153           Callout     accentCallout2
8154           Callout     accentCallout3
8155           Callout     borderCallout1
8156           Callout     borderCallout2
8157           Callout     borderCallout3
8158           Callout     callout1
8159           Callout     callout2
8160           Callout     callout3
8161           Callout     cloudCallout
8162           Callout     downArrowCallout
8163           Callout     leftArrowCallout
8164           Callout     leftRightArrowCallout
8165           Callout     quadArrowCallout
8166           Callout     rightArrowCallout
8167           Callout     upArrowCallout
8168           Callout     upDownArrowCallout
8169           Callout     wedgeEllipseCallout
8170           Callout     wedgeRectCallout
8171           Callout     wedgeRoundRectCallout
8172           Chart       chartPlus
8173           Chart       chartStar
8174           Chart       chartX
8175           Connector   bentConnector2
8176           Connector   bentConnector3
8177           Connector   bentConnector4
8178           Connector   bentConnector5
8179           Connector   curvedConnector2
8180           Connector   curvedConnector3
8181           Connector   curvedConnector4
8182           Connector   curvedConnector5
8183           Connector   straightConnector1
8184           FlowChart   flowChartAlternateProcess
8185           FlowChart   flowChartCollate
8186           FlowChart   flowChartConnector
8187           FlowChart   flowChartDecision
8188           FlowChart   flowChartDelay
8189           FlowChart   flowChartDisplay
8190           FlowChart   flowChartDocument
8191           FlowChart   flowChartExtract
8192           FlowChart   flowChartInputOutput
8193           FlowChart   flowChartInternalStorage
8194           FlowChart   flowChartMagneticDisk
8195           FlowChart   flowChartMagneticDrum
8196           FlowChart   flowChartMagneticTape
8197           FlowChart   flowChartManualInput
8198           FlowChart   flowChartManualOperation
8199           FlowChart   flowChartMerge
8200           FlowChart   flowChartMultidocument
8201           FlowChart   flowChartOfflineStorage
8202           FlowChart   flowChartOffpageConnector
8203           FlowChart   flowChartOnlineStorage
8204           FlowChart   flowChartOr
8205           FlowChart   flowChartPredefinedProcess
8206           FlowChart   flowChartPreparation
8207           FlowChart   flowChartProcess
8208           FlowChart   flowChartPunchedCard
8209           FlowChart   flowChartPunchedTape
8210           FlowChart   flowChartSort
8211           FlowChart   flowChartSummingJunction
8212           FlowChart   flowChartTerminator
8213           Math        mathDivide
8214           Math        mathEqual
8215           Math        mathMinus
8216           Math        mathMultiply
8217           Math        mathNotEqual
8218           Math        mathPlus
8219           Star_Banner arc
8220           Star_Banner bevel
8221           Star_Banner bracePair
8222           Star_Banner bracketPair
8223           Star_Banner chord
8224           Star_Banner cloud
8225           Star_Banner corner
8226           Star_Banner diagStripe
8227           Star_Banner doubleWave
8228           Star_Banner ellipseRibbon
8229           Star_Banner ellipseRibbon2
8230           Star_Banner foldedCorner
8231           Star_Banner frame
8232           Star_Banner halfFrame
8233           Star_Banner horizontalScroll
8234           Star_Banner irregularSeal1
8235           Star_Banner irregularSeal2
8236           Star_Banner leftBrace
8237           Star_Banner leftBracket
8238           Star_Banner leftRightRibbon
8239           Star_Banner plus
8240           Star_Banner ribbon
8241           Star_Banner ribbon2
8242           Star_Banner rightBrace
8243           Star_Banner rightBracket
8244           Star_Banner verticalScroll
8245           Star_Banner wave
8246           Tabs        cornerTabs
8247           Tabs        plaqueTabs
8248           Tabs        squareTabs
8249
8250       Download this example:
8251       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/shape_all.pl>
8252
8253   Example: sparklines1.pl
8254       Example of how to add sparklines to an Excel::Writer::XLSX file.
8255
8256       Sparklines are small charts that fit in a single cell and are used to
8257       show trends in data. See sparklines2.pl for examples of more complex
8258       sparkline formatting.
8259
8260       Source code for this example:
8261
8262           #!/usr/bin/perl
8263
8264           ###############################################################################
8265           #
8266           # Example of how to add sparklines to an Excel::Writer::XLSX file.
8267           #
8268           # Sparklines are small charts that fit in a single cell and are
8269           # used to show trends in data. See sparklines2.pl for examples
8270           # of more complex sparkline formatting.
8271           #
8272           # reverse ('(c)'), November 2011, John McNamara, jmcnamara@cpan.org
8273           #
8274
8275           use strict;
8276           use warnings;
8277           use Excel::Writer::XLSX;
8278
8279           my $workbook  = Excel::Writer::XLSX->new( 'sparklines1.xlsx' );
8280           my $worksheet = $workbook->add_worksheet();
8281
8282           # Some sample data to plot.
8283           my $data = [
8284
8285               [ -2, 2,  3,  -1, 0 ],
8286               [ 30, 20, 33, 20, 15 ],
8287               [ 1,  -1, -1, 1,  -1 ],
8288
8289           ];
8290
8291           # Write the sample data to the worksheet.
8292           $worksheet->write_col( 'A1', $data );
8293
8294
8295           # Add a line sparkline (the default) with markers.
8296           $worksheet->add_sparkline(
8297               {
8298                   location => 'F1',
8299                   range    => 'Sheet1!A1:E1',
8300                   markers  => 1,
8301               }
8302           );
8303
8304           # Add a column sparkline with non-default style.
8305           $worksheet->add_sparkline(
8306               {
8307                   location => 'F2',
8308                   range    => 'Sheet1!A2:E2',
8309                   type     => 'column',
8310                   style    => 12,
8311               }
8312           );
8313
8314           # Add a win/loss sparkline with negative values highlighted.
8315           $worksheet->add_sparkline(
8316               {
8317                   location        => 'F3',
8318                   range           => 'Sheet1!A3:E3',
8319                   type            => 'win_loss',
8320                   negative_points => 1,
8321               }
8322           );
8323
8324           $workbook->close();
8325
8326           __END__
8327
8328       Download this example:
8329       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/sparklines1.pl>
8330
8331   Example: sparklines2.pl
8332       Example of how to add sparklines to an Excel::Writer::XLSX file.
8333
8334       Sparklines are small charts that fit in a single cell and are used to
8335       show trends in data. This example shows the majority of options that
8336       can be applied to sparklines.
8337
8338       Source code for this example:
8339
8340           #!/usr/bin/perl
8341
8342           ###############################################################################
8343           #
8344           # Example of how to add sparklines to an Excel::Writer::XLSX file.
8345           #
8346           # Sparklines are small charts that fit in a single cell and are
8347           # used to show trends in data. This example shows the majority of
8348           # options that can be applied to sparklines.
8349           #
8350           # reverse ('(c)'), November 2011, John McNamara, jmcnamara@cpan.org
8351           #
8352
8353           use strict;
8354           use warnings;
8355           use Excel::Writer::XLSX;
8356
8357           my $workbook    = Excel::Writer::XLSX->new( 'sparklines2.xlsx' );
8358           my $worksheet1  = $workbook->add_worksheet();
8359           my $worksheet2  = $workbook->add_worksheet();
8360           my $bold        = $workbook->add_format( bold => 1 );
8361           my $str;
8362           my $row = 1;
8363
8364           # Set the columns widths to make the output clearer.
8365           $worksheet1->set_column( 'A:A', 14 );
8366           $worksheet1->set_column( 'B:B', 50 );
8367           $worksheet1->set_zoom( 150 );
8368
8369           # Headings.
8370           $worksheet1->write( 'A1', 'Sparkline',   $bold );
8371           $worksheet1->write( 'B1', 'Description', $bold );
8372
8373
8374           ###############################################################################
8375           #
8376           $str = 'A default "line" sparkline.';
8377
8378           $worksheet1->add_sparkline(
8379               {
8380                   location => 'A2',
8381                   range    => 'Sheet2!A1:J1',
8382               }
8383           );
8384
8385           $worksheet1->write( $row++, 1, $str );
8386
8387
8388           ###############################################################################
8389           #
8390           $str = 'A default "column" sparkline.';
8391
8392           $worksheet1->add_sparkline(
8393               {
8394                   location => 'A3',
8395                   range    => 'Sheet2!A2:J2',
8396                   type     => 'column',
8397               }
8398           );
8399
8400           $worksheet1->write( $row++, 1, $str );
8401
8402
8403           ###############################################################################
8404           #
8405           $str = 'A default "win/loss" sparkline.';
8406
8407           $worksheet1->add_sparkline(
8408               {
8409                   location => 'A4',
8410                   range    => 'Sheet2!A3:J3',
8411                   type     => 'win_loss',
8412               }
8413           );
8414
8415           $worksheet1->write( $row++, 1, $str );
8416           $row++;
8417
8418
8419           ###############################################################################
8420           #
8421           $str = 'Line with markers.';
8422
8423           $worksheet1->add_sparkline(
8424               {
8425                   location => 'A6',
8426                   range    => 'Sheet2!A1:J1',
8427                   markers  => 1,
8428               }
8429           );
8430
8431           $worksheet1->write( $row++, 1, $str );
8432
8433
8434           ###############################################################################
8435           #
8436           $str = 'Line with high and low points.';
8437
8438           $worksheet1->add_sparkline(
8439               {
8440                   location   => 'A7',
8441                   range      => 'Sheet2!A1:J1',
8442                   high_point => 1,
8443                   low_point  => 1,
8444               }
8445           );
8446
8447           $worksheet1->write( $row++, 1, $str );
8448
8449
8450           ###############################################################################
8451           #
8452           $str = 'Line with first and last point markers.';
8453
8454           $worksheet1->add_sparkline(
8455               {
8456                   location    => 'A8',
8457                   range       => 'Sheet2!A1:J1',
8458                   first_point => 1,
8459                   last_point  => 1,
8460               }
8461           );
8462
8463           $worksheet1->write( $row++, 1, $str );
8464
8465
8466           ###############################################################################
8467           #
8468           $str = 'Line with negative point markers.';
8469
8470           $worksheet1->add_sparkline(
8471               {
8472                   location        => 'A9',
8473                   range           => 'Sheet2!A1:J1',
8474                   negative_points => 1,
8475               }
8476           );
8477
8478           $worksheet1->write( $row++, 1, $str );
8479
8480
8481           ###############################################################################
8482           #
8483           $str = 'Line with axis.';
8484
8485           $worksheet1->add_sparkline(
8486               {
8487                   location => 'A10',
8488                   range    => 'Sheet2!A1:J1',
8489                   axis     => 1,
8490               }
8491           );
8492
8493           $worksheet1->write( $row++, 1, $str );
8494           $row++;
8495
8496
8497           ###############################################################################
8498           #
8499           $str = 'Column with default style (1).';
8500
8501           $worksheet1->add_sparkline(
8502               {
8503                   location => 'A12',
8504                   range    => 'Sheet2!A2:J2',
8505                   type     => 'column',
8506               }
8507           );
8508
8509           $worksheet1->write( $row++, 1, $str );
8510
8511
8512           ###############################################################################
8513           #
8514           $str = 'Column with style 2.';
8515
8516           $worksheet1->add_sparkline(
8517               {
8518                   location => 'A13',
8519                   range    => 'Sheet2!A2:J2',
8520                   type     => 'column',
8521                   style    => 2,
8522               }
8523           );
8524
8525           $worksheet1->write( $row++, 1, $str );
8526
8527
8528           ###############################################################################
8529           #
8530           $str = 'Column with style 3.';
8531
8532           $worksheet1->add_sparkline(
8533               {
8534                   location => 'A14',
8535                   range    => 'Sheet2!A2:J2',
8536                   type     => 'column',
8537                   style    => 3,
8538               }
8539           );
8540
8541           $worksheet1->write( $row++, 1, $str );
8542
8543
8544           ###############################################################################
8545           #
8546           $str = 'Column with style 4.';
8547
8548           $worksheet1->add_sparkline(
8549               {
8550                   location => 'A15',
8551                   range    => 'Sheet2!A2:J2',
8552                   type     => 'column',
8553                   style    => 4,
8554               }
8555           );
8556
8557           $worksheet1->write( $row++, 1, $str );
8558
8559
8560           ###############################################################################
8561           #
8562           $str = 'Column with style 5.';
8563
8564           $worksheet1->add_sparkline(
8565               {
8566                   location => 'A16',
8567                   range    => 'Sheet2!A2:J2',
8568                   type     => 'column',
8569                   style    => 5,
8570               }
8571           );
8572
8573           $worksheet1->write( $row++, 1, $str );
8574
8575
8576           ###############################################################################
8577           #
8578           $str = 'Column with style 6.';
8579
8580           $worksheet1->add_sparkline(
8581               {
8582                   location => 'A17',
8583                   range    => 'Sheet2!A2:J2',
8584                   type     => 'column',
8585                   style    => 6,
8586               }
8587           );
8588
8589           $worksheet1->write( $row++, 1, $str );
8590
8591
8592           ###############################################################################
8593           #
8594           $str = 'Column with a user defined colour.';
8595
8596           $worksheet1->add_sparkline(
8597               {
8598                   location     => 'A18',
8599                   range        => 'Sheet2!A2:J2',
8600                   type         => 'column',
8601                   series_color => '#E965E0',
8602               }
8603           );
8604
8605           $worksheet1->write( $row++, 1, $str );
8606           $row++;
8607
8608
8609           ###############################################################################
8610           #
8611           $str = 'A win/loss sparkline.';
8612
8613           $worksheet1->add_sparkline(
8614               {
8615                   location => 'A20',
8616                   range    => 'Sheet2!A3:J3',
8617                   type     => 'win_loss',
8618               }
8619           );
8620
8621           $worksheet1->write( $row++, 1, $str );
8622
8623
8624           ###############################################################################
8625           #
8626           $str = 'A win/loss sparkline with negative points highlighted.';
8627
8628           $worksheet1->add_sparkline(
8629               {
8630                   location        => 'A21',
8631                   range           => 'Sheet2!A3:J3',
8632                   type            => 'win_loss',
8633                   negative_points => 1,
8634               }
8635           );
8636
8637           $worksheet1->write( $row++, 1, $str );
8638           $row++;
8639
8640
8641           ###############################################################################
8642           #
8643           $str = 'A left to right column (the default).';
8644
8645           $worksheet1->add_sparkline(
8646               {
8647                   location => 'A23',
8648                   range    => 'Sheet2!A4:J4',
8649                   type     => 'column',
8650                   style    => 20,
8651               }
8652           );
8653
8654           $worksheet1->write( $row++, 1, $str );
8655
8656
8657           ###############################################################################
8658           #
8659           $str = 'A right to left column.';
8660
8661           $worksheet1->add_sparkline(
8662               {
8663                   location => 'A24',
8664                   range    => 'Sheet2!A4:J4',
8665                   type     => 'column',
8666                   style    => 20,
8667                   reverse  => 1,
8668               }
8669           );
8670
8671           $worksheet1->write( $row++, 1, $str );
8672
8673
8674           ###############################################################################
8675           #
8676           $str = 'Sparkline and text in one cell.';
8677
8678           $worksheet1->add_sparkline(
8679               {
8680                   location => 'A25',
8681                   range    => 'Sheet2!A4:J4',
8682                   type     => 'column',
8683                   style    => 20,
8684               }
8685           );
8686
8687           $worksheet1->write( $row,   0, 'Growth' );
8688           $worksheet1->write( $row++, 1, $str );
8689           $row++;
8690
8691
8692           ###############################################################################
8693           #
8694           $str = 'A grouped sparkline. Changes are applied to all three.';
8695
8696           $worksheet1->add_sparkline(
8697               {
8698                   location => [ 'A27',          'A28',          'A29' ],
8699                   range    => [ 'Sheet2!A5:J5', 'Sheet2!A6:J6', 'Sheet2!A7:J7' ],
8700                   markers  => 1,
8701               }
8702           );
8703
8704           $worksheet1->write( $row++, 1, $str );
8705
8706
8707
8708
8709           ###############################################################################
8710           #
8711           # Create a second worksheet with data to plot.
8712           #
8713
8714           $worksheet2->set_column( 'A:J', 11 );
8715
8716           my $data = [
8717
8718               # Simple line data.
8719               [ -2, 2, 3, -1, 0, -2, 3, 2, 1, 0 ],
8720
8721               # Simple column data.
8722               [ 30, 20, 33, 20, 15, 5, 5, 15, 10, 15 ],
8723
8724               # Simple win/loss data.
8725               [ 1, 1, -1, -1, 1, -1, 1, 1, 1, -1 ],
8726
8727               # Unbalanced histogram.
8728               [ 5, 6, 7, 10, 15, 20, 30, 50, 70, 100 ],
8729
8730               # Data for the grouped sparkline example.
8731               [ -2, 2,  3, -1, 0, -2, 3, 2, 1, 0 ],
8732               [ 3,  -1, 0, -2, 3, 2,  1, 0, 2, 1 ],
8733               [ 0,  -2, 3, 2,  1, 0,  1, 2, 3, 1 ],
8734
8735
8736           ];
8737
8738           # Write the sample data to the worksheet.
8739           $worksheet2->write_col( 'A1', $data );
8740
8741           $workbook->close();
8742
8743           __END__
8744
8745       Download this example:
8746       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/sparklines2.pl>
8747
8748   Example: stats_ext.pl
8749       Example of formatting using the Excel::Writer::XLSX module
8750
8751       This is a simple example of how to use functions that reference cells
8752       in other worksheets within the same workbook.
8753
8754       Source code for this example:
8755
8756           #!/usr/bin/perl -w
8757
8758           ###############################################################################
8759           #
8760           # Example of formatting using the Excel::Writer::XLSX module
8761           #
8762           # This is a simple example of how to use functions that reference cells in
8763           # other worksheets within the same workbook.
8764           #
8765           # reverse ('(c)'), March 2001, John McNamara, jmcnamara@cpan.org
8766           #
8767
8768           use strict;
8769           use Excel::Writer::XLSX;
8770
8771           # Create a new workbook and add a worksheet
8772           my $workbook   = Excel::Writer::XLSX->new( 'stats_ext.xlsx' );
8773           my $worksheet1 = $workbook->add_worksheet( 'Test results' );
8774           my $worksheet2 = $workbook->add_worksheet( 'Data' );
8775
8776           # Set the column width for columns 1
8777           $worksheet1->set_column( 'A:A', 20 );
8778
8779
8780           # Create a format for the headings
8781           my $heading = $workbook->add_format();
8782           $heading->set_bold();
8783
8784           # Create a numerical format
8785           my $numformat = $workbook->add_format();
8786           $numformat->set_num_format( '0.00' );
8787
8788
8789           # Write some statistical functions
8790           $worksheet1->write( 'A1', 'Count', $heading );
8791           $worksheet1->write( 'B1', '=COUNT(Data!B2:B9)' );
8792
8793           $worksheet1->write( 'A2', 'Sum', $heading );
8794           $worksheet1->write( 'B2', '=SUM(Data!B2:B9)' );
8795
8796           $worksheet1->write( 'A3', 'Average', $heading );
8797           $worksheet1->write( 'B3', '=AVERAGE(Data!B2:B9)' );
8798
8799           $worksheet1->write( 'A4', 'Min', $heading );
8800           $worksheet1->write( 'B4', '=MIN(Data!B2:B9)' );
8801
8802           $worksheet1->write( 'A5', 'Max', $heading );
8803           $worksheet1->write( 'B5', '=MAX(Data!B2:B9)' );
8804
8805           $worksheet1->write( 'A6', 'Standard Deviation', $heading );
8806           $worksheet1->write( 'B6', '=STDEV(Data!B2:B9)' );
8807
8808           $worksheet1->write( 'A7', 'Kurtosis', $heading );
8809           $worksheet1->write( 'B7', '=KURT(Data!B2:B9)' );
8810
8811
8812           # Write the sample data
8813           $worksheet2->write( 'A1', 'Sample', $heading );
8814           $worksheet2->write( 'A2', 1 );
8815           $worksheet2->write( 'A3', 2 );
8816           $worksheet2->write( 'A4', 3 );
8817           $worksheet2->write( 'A5', 4 );
8818           $worksheet2->write( 'A6', 5 );
8819           $worksheet2->write( 'A7', 6 );
8820           $worksheet2->write( 'A8', 7 );
8821           $worksheet2->write( 'A9', 8 );
8822
8823           $worksheet2->write( 'B1', 'Length', $heading );
8824           $worksheet2->write( 'B2', 25.4,     $numformat );
8825           $worksheet2->write( 'B3', 25.4,     $numformat );
8826           $worksheet2->write( 'B4', 24.8,     $numformat );
8827           $worksheet2->write( 'B5', 25.0,     $numformat );
8828           $worksheet2->write( 'B6', 25.3,     $numformat );
8829           $worksheet2->write( 'B7', 24.9,     $numformat );
8830           $worksheet2->write( 'B8', 25.2,     $numformat );
8831           $worksheet2->write( 'B9', 24.8,     $numformat );
8832
8833           $workbook->close();
8834
8835           __END__
8836
8837       Download this example:
8838       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/stats_ext.pl>
8839
8840   Example: stocks.pl
8841       Example of formatting using the Excel::Writer::XLSX module
8842
8843       This example shows how to use a conditional numerical format with
8844       colours to indicate if a share price has gone up or down.
8845
8846       Source code for this example:
8847
8848           #!/usr/bin/perl -w
8849
8850           ###############################################################################
8851           #
8852           # Example of formatting using the Excel::Writer::XLSX module
8853           #
8854           # This example shows how to use a conditional numerical format
8855           # with colours to indicate if a share price has gone up or down.
8856           #
8857           # reverse ('(c)'), March 2001, John McNamara, jmcnamara@cpan.org
8858           #
8859
8860           use strict;
8861           use Excel::Writer::XLSX;
8862
8863           # Create a new workbook and add a worksheet
8864           my $workbook  = Excel::Writer::XLSX->new( 'stocks.xlsx' );
8865           my $worksheet = $workbook->add_worksheet();
8866
8867           # Set the column width for columns 1, 2, 3 and 4
8868           $worksheet->set_column( 0, 3, 15 );
8869
8870
8871           # Create a format for the column headings
8872           my $header = $workbook->add_format();
8873           $header->set_bold();
8874           $header->set_size( 12 );
8875           $header->set_color( 'blue' );
8876
8877
8878           # Create a format for the stock price
8879           my $f_price = $workbook->add_format();
8880           $f_price->set_align( 'left' );
8881           $f_price->set_num_format( '$0.00' );
8882
8883
8884           # Create a format for the stock volume
8885           my $f_volume = $workbook->add_format();
8886           $f_volume->set_align( 'left' );
8887           $f_volume->set_num_format( '#,##0' );
8888
8889
8890           # Create a format for the price change. This is an example of a conditional
8891           # format. The number is formatted as a percentage. If it is positive it is
8892           # formatted in green, if it is negative it is formatted in red and if it is
8893           # zero it is formatted as the default font colour (in this case black).
8894           # Note: the [Green] format produces an unappealing lime green. Try
8895           # [Color 10] instead for a dark green.
8896           #
8897           my $f_change = $workbook->add_format();
8898           $f_change->set_align( 'left' );
8899           $f_change->set_num_format( '[Green]0.0%;[Red]-0.0%;0.0%' );
8900
8901
8902           # Write out the data
8903           $worksheet->write( 0, 0, 'Company', $header );
8904           $worksheet->write( 0, 1, 'Price',   $header );
8905           $worksheet->write( 0, 2, 'Volume',  $header );
8906           $worksheet->write( 0, 3, 'Change',  $header );
8907
8908           $worksheet->write( 1, 0, 'Damage Inc.' );
8909           $worksheet->write( 1, 1, 30.25, $f_price );       # $30.25
8910           $worksheet->write( 1, 2, 1234567, $f_volume );    # 1,234,567
8911           $worksheet->write( 1, 3, 0.085, $f_change );      # 8.5% in green
8912
8913           $worksheet->write( 2, 0, 'Dump Corp.' );
8914           $worksheet->write( 2, 1, 1.56, $f_price );        # $1.56
8915           $worksheet->write( 2, 2, 7564, $f_volume );       # 7,564
8916           $worksheet->write( 2, 3, -0.015, $f_change );     # -1.5% in red
8917
8918           $worksheet->write( 3, 0, 'Rev Ltd.' );
8919           $worksheet->write( 3, 1, 0.13, $f_price );        # $0.13
8920           $worksheet->write( 3, 2, 321, $f_volume );        # 321
8921           $worksheet->write( 3, 3, 0, $f_change );          # 0 in the font color (black)
8922
8923
8924           $workbook->close();
8925
8926           __END__
8927
8928       Download this example:
8929       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/stocks.pl>
8930
8931   Example: tab_colors.pl
8932       Example of how to set Excel worksheet tab colours.
8933
8934       Source code for this example:
8935
8936           #!/usr/bin/perl
8937
8938           #######################################################################
8939           #
8940           # Example of how to set Excel worksheet tab colours.
8941           #
8942           # reverse ('(c)'), May 2006, John McNamara, jmcnamara@cpan.org
8943           #
8944
8945           use strict;
8946           use warnings;
8947           use Excel::Writer::XLSX;
8948
8949
8950           my $workbook = Excel::Writer::XLSX->new( 'tab_colors.xlsx' );
8951
8952           my $worksheet1 = $workbook->add_worksheet();
8953           my $worksheet2 = $workbook->add_worksheet();
8954           my $worksheet3 = $workbook->add_worksheet();
8955           my $worksheet4 = $workbook->add_worksheet();
8956
8957           # Worksheet1 will have the default tab colour.
8958           $worksheet2->set_tab_color( 'red' );
8959           $worksheet3->set_tab_color( 'green' );
8960           $worksheet4->set_tab_color( '#FF6600'); # Orange
8961
8962           $workbook->close();
8963
8964           __END__
8965
8966       Download this example:
8967       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/tab_colors.pl>
8968
8969   Example: tables.pl
8970       Example of how to add tables to an Excel::Writer::XLSX worksheet.
8971
8972       Tables in Excel are used to group rows and columns of data into a
8973       single structure that can be referenced in a formula or formatted
8974       collectively.
8975
8976       Source code for this example:
8977
8978           #!/usr/bin/perl
8979
8980           ###############################################################################
8981           #
8982           # Example of how to add tables to an Excel::Writer::XLSX worksheet.
8983           #
8984           # Tables in Excel are used to group rows and columns of data into a single
8985           # structure that can be referenced in a formula or formatted collectively.
8986           #
8987           # reverse ('(c)'), September 2012, John McNamara, jmcnamara@cpan.org
8988           #
8989
8990           use strict;
8991           use warnings;
8992           use Excel::Writer::XLSX;
8993
8994           my $workbook    = Excel::Writer::XLSX->new( 'tables.xlsx' );
8995           my $worksheet1  = $workbook->add_worksheet();
8996           my $worksheet2  = $workbook->add_worksheet();
8997           my $worksheet3  = $workbook->add_worksheet();
8998           my $worksheet4  = $workbook->add_worksheet();
8999           my $worksheet5  = $workbook->add_worksheet();
9000           my $worksheet6  = $workbook->add_worksheet();
9001           my $worksheet7  = $workbook->add_worksheet();
9002           my $worksheet8  = $workbook->add_worksheet();
9003           my $worksheet9  = $workbook->add_worksheet();
9004           my $worksheet10 = $workbook->add_worksheet();
9005           my $worksheet11 = $workbook->add_worksheet();
9006           my $worksheet12 = $workbook->add_worksheet();
9007
9008           my $currency_format = $workbook->add_format( num_format => '$#,##0' );
9009
9010
9011           # Some sample data for the table.
9012           my $data = [
9013               [ 'Apples',  10000, 5000, 8000, 6000 ],
9014               [ 'Pears',   2000,  3000, 4000, 5000 ],
9015               [ 'Bananas', 6000,  6000, 6500, 6000 ],
9016               [ 'Oranges', 500,   300,  200,  700 ],
9017
9018           ];
9019
9020
9021           ###############################################################################
9022           #
9023           # Example 1.
9024           #
9025           my $caption = 'Default table with no data.';
9026
9027           # Set the columns widths.
9028           $worksheet1->set_column( 'B:G', 12 );
9029
9030           # Write the caption.
9031           $worksheet1->write( 'B1', $caption );
9032
9033           # Add a table to the worksheet.
9034           $worksheet1->add_table( 'B3:F7' );
9035
9036
9037           ###############################################################################
9038           #
9039           # Example 2.
9040           #
9041           $caption = 'Default table with data.';
9042
9043           # Set the columns widths.
9044           $worksheet2->set_column( 'B:G', 12 );
9045
9046           # Write the caption.
9047           $worksheet2->write( 'B1', $caption );
9048
9049           # Add a table to the worksheet.
9050           $worksheet2->add_table( 'B3:F7', { data => $data } );
9051
9052
9053           ###############################################################################
9054           #
9055           # Example 3.
9056           #
9057           $caption = 'Table without default autofilter.';
9058
9059           # Set the columns widths.
9060           $worksheet3->set_column( 'B:G', 12 );
9061
9062           # Write the caption.
9063           $worksheet3->write( 'B1', $caption );
9064
9065           # Add a table to the worksheet.
9066           $worksheet3->add_table( 'B3:F7', { autofilter => 0 } );
9067
9068           # Table data can also be written separately, as an array or individual cells.
9069           $worksheet3->write_col( 'B4', $data );
9070
9071
9072           ###############################################################################
9073           #
9074           # Example 4.
9075           #
9076           $caption = 'Table without default header row.';
9077
9078           # Set the columns widths.
9079           $worksheet4->set_column( 'B:G', 12 );
9080
9081           # Write the caption.
9082           $worksheet4->write( 'B1', $caption );
9083
9084           # Add a table to the worksheet.
9085           $worksheet4->add_table( 'B4:F7', { header_row => 0 } );
9086
9087           # Table data can also be written separately, as an array or individual cells.
9088           $worksheet4->write_col( 'B4', $data );
9089
9090
9091           ###############################################################################
9092           #
9093           # Example 5.
9094           #
9095           $caption = 'Default table with "First Column" and "Last Column" options.';
9096
9097           # Set the columns widths.
9098           $worksheet5->set_column( 'B:G', 12 );
9099
9100           # Write the caption.
9101           $worksheet5->write( 'B1', $caption );
9102
9103           # Add a table to the worksheet.
9104           $worksheet5->add_table( 'B3:F7', { first_column => 1, last_column => 1 } );
9105
9106           # Table data can also be written separately, as an array or individual cells.
9107           $worksheet5->write_col( 'B4', $data );
9108
9109
9110           ###############################################################################
9111           #
9112           # Example 6.
9113           #
9114           $caption = 'Table with banded columns but without default banded rows.';
9115
9116           # Set the columns widths.
9117           $worksheet6->set_column( 'B:G', 12 );
9118
9119           # Write the caption.
9120           $worksheet6->write( 'B1', $caption );
9121
9122           # Add a table to the worksheet.
9123           $worksheet6->add_table( 'B3:F7', { banded_rows => 0, banded_columns => 1 } );
9124
9125           # Table data can also be written separately, as an array or individual cells.
9126           $worksheet6->write_col( 'B4', $data );
9127
9128
9129           ###############################################################################
9130           #
9131           # Example 7.
9132           #
9133           $caption = 'Table with user defined column headers';
9134
9135           # Set the columns widths.
9136           $worksheet7->set_column( 'B:G', 12 );
9137
9138           # Write the caption.
9139           $worksheet7->write( 'B1', $caption );
9140
9141           # Add a table to the worksheet.
9142           $worksheet7->add_table(
9143               'B3:F7',
9144               {
9145                   data    => $data,
9146                   columns => [
9147                       { header => 'Product' },
9148                       { header => 'Quarter 1' },
9149                       { header => 'Quarter 2' },
9150                       { header => 'Quarter 3' },
9151                       { header => 'Quarter 4' },
9152                   ]
9153               }
9154           );
9155
9156
9157           ###############################################################################
9158           #
9159           # Example 8.
9160           #
9161           $caption = 'Table with user defined column headers';
9162
9163           # Set the columns widths.
9164           $worksheet8->set_column( 'B:G', 12 );
9165
9166           # Write the caption.
9167           $worksheet8->write( 'B1', $caption );
9168
9169           # Add a table to the worksheet.
9170           $worksheet8->add_table(
9171               'B3:G7',
9172               {
9173                   data    => $data,
9174                   columns => [
9175                       { header => 'Product' },
9176                       { header => 'Quarter 1' },
9177                       { header => 'Quarter 2' },
9178                       { header => 'Quarter 3' },
9179                       { header => 'Quarter 4' },
9180                       {
9181                           header  => 'Year',
9182                           formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])'
9183                       },
9184                   ]
9185               }
9186           );
9187
9188
9189           ###############################################################################
9190           #
9191           # Example 9.
9192           #
9193           $caption = 'Table with totals row (but no caption or totals).';
9194
9195           # Set the columns widths.
9196           $worksheet9->set_column( 'B:G', 12 );
9197
9198           # Write the caption.
9199           $worksheet9->write( 'B1', $caption );
9200
9201           # Add a table to the worksheet.
9202           $worksheet9->add_table(
9203               'B3:G8',
9204               {
9205                   data      => $data,
9206                   total_row => 1,
9207                   columns   => [
9208                       { header => 'Product' },
9209                       { header => 'Quarter 1' },
9210                       { header => 'Quarter 2' },
9211                       { header => 'Quarter 3' },
9212                       { header => 'Quarter 4' },
9213                       {
9214                           header  => 'Year',
9215                           formula => '=SUM(Table9[@[Quarter 1]:[Quarter 4]])'
9216                       },
9217                   ]
9218               }
9219           );
9220
9221
9222           ###############################################################################
9223           #
9224           # Example 10.
9225           #
9226           $caption = 'Table with totals row with user captions and functions.';
9227
9228           # Set the columns widths.
9229           $worksheet10->set_column( 'B:G', 12 );
9230
9231           # Write the caption.
9232           $worksheet10->write( 'B1', $caption );
9233
9234           # Add a table to the worksheet.
9235           $worksheet10->add_table(
9236               'B3:G8',
9237               {
9238                   data      => $data,
9239                   total_row => 1,
9240                   columns   => [
9241                       { header => 'Product',   total_string   => 'Totals' },
9242                       { header => 'Quarter 1', total_function => 'sum' },
9243                       { header => 'Quarter 2', total_function => 'sum' },
9244                       { header => 'Quarter 3', total_function => 'sum' },
9245                       { header => 'Quarter 4', total_function => 'sum' },
9246                       {
9247                           header         => 'Year',
9248                           formula        => '=SUM(Table10[@[Quarter 1]:[Quarter 4]])',
9249                           total_function => 'sum'
9250                       },
9251                   ]
9252               }
9253           );
9254
9255
9256           ###############################################################################
9257           #
9258           # Example 11.
9259           #
9260           $caption = 'Table with alternative Excel style.';
9261
9262           # Set the columns widths.
9263           $worksheet11->set_column( 'B:G', 12 );
9264
9265           # Write the caption.
9266           $worksheet11->write( 'B1', $caption );
9267
9268           # Add a table to the worksheet.
9269           $worksheet11->add_table(
9270               'B3:G8',
9271               {
9272                   data      => $data,
9273                   style     => 'Table Style Light 11',
9274                   total_row => 1,
9275                   columns   => [
9276                       { header => 'Product',   total_string   => 'Totals' },
9277                       { header => 'Quarter 1', total_function => 'sum' },
9278                       { header => 'Quarter 2', total_function => 'sum' },
9279                       { header => 'Quarter 3', total_function => 'sum' },
9280                       { header => 'Quarter 4', total_function => 'sum' },
9281                       {
9282                           header         => 'Year',
9283                           formula        => '=SUM(Table11[@[Quarter 1]:[Quarter 4]])',
9284                           total_function => 'sum'
9285                       },
9286                   ]
9287               }
9288           );
9289
9290
9291           ###############################################################################
9292           #
9293           # Example 12.
9294           #
9295           $caption = 'Table with column formats.';
9296
9297           # Set the columns widths.
9298           $worksheet12->set_column( 'B:G', 12 );
9299
9300           # Write the caption.
9301           $worksheet12->write( 'B1', $caption );
9302
9303           # Add a table to the worksheet.
9304           $worksheet12->add_table(
9305               'B3:G8',
9306               {
9307                   data      => $data,
9308                   total_row => 1,
9309                   columns   => [
9310                       { header => 'Product', total_string => 'Totals' },
9311                       {
9312                           header         => 'Quarter 1',
9313                           total_function => 'sum',
9314                           format         => $currency_format,
9315                       },
9316                       {
9317                           header         => 'Quarter 2',
9318                           total_function => 'sum',
9319                           format         => $currency_format,
9320                       },
9321                       {
9322                           header         => 'Quarter 3',
9323                           total_function => 'sum',
9324                           format         => $currency_format,
9325                       },
9326                       {
9327                           header         => 'Quarter 4',
9328                           total_function => 'sum',
9329                           format         => $currency_format,
9330                       },
9331                       {
9332                           header         => 'Year',
9333                           formula        => '=SUM(Table12[@[Quarter 1]:[Quarter 4]])',
9334                           total_function => 'sum',
9335                           format         => $currency_format,
9336                       },
9337                   ]
9338               }
9339           );
9340
9341
9342           $workbook->close();
9343
9344           __END__
9345
9346       Download this example:
9347       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/tables.pl>
9348
9349   Example: write_handler1.pl
9350       Example of how to add a user defined data handler to the
9351       Excel::Writer::XLSX write() method.
9352
9353       The following example shows how to add a handler for a 7 digit ID
9354       number.
9355
9356       Source code for this example:
9357
9358           #!/usr/bin/perl -w
9359
9360           ###############################################################################
9361           #
9362           # Example of how to add a user defined data handler to the
9363           # Excel::Writer::XLSX write() method.
9364           #
9365           # The following example shows how to add a handler for a 7 digit ID number.
9366           #
9367           #
9368           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9369           #
9370
9371           use strict;
9372           use Excel::Writer::XLSX;
9373
9374
9375           my $workbook  = Excel::Writer::XLSX->new( 'write_handler1.xlsx' );
9376           my $worksheet = $workbook->add_worksheet();
9377
9378
9379           ###############################################################################
9380           #
9381           # Add a handler for 7 digit id numbers. This is useful when you want a string
9382           # such as 0000001 written as a string instead of a number and thus preserve
9383           # the leading zeroes.
9384           #
9385           # Note: you can get the same effect using the keep_leading_zeros() method but
9386           # this serves as a simple example.
9387           #
9388           $worksheet->add_write_handler( qr[^\d{7}$], \&write_my_id );
9389
9390
9391           ###############################################################################
9392           #
9393           # The following function processes the data when a match is found.
9394           #
9395           sub write_my_id {
9396
9397               my $worksheet = shift;
9398
9399               return $worksheet->write_string( @_ );
9400           }
9401
9402
9403           # This format maintains the cell as text even if it is edited.
9404           my $id_format = $workbook->add_format( num_format => '@' );
9405
9406
9407           # Write some numbers in the user defined format
9408           $worksheet->write( 'A1', '0000000', $id_format );
9409           $worksheet->write( 'A2', '0000001', $id_format );
9410           $worksheet->write( 'A3', '0004000', $id_format );
9411           $worksheet->write( 'A4', '1234567', $id_format );
9412
9413           # Write some numbers that don't match the defined format
9414           $worksheet->write( 'A6', '000000', $id_format );
9415           $worksheet->write( 'A7', '000001', $id_format );
9416           $worksheet->write( 'A8', '004000', $id_format );
9417           $worksheet->write( 'A9', '123456', $id_format );
9418
9419           $workbook->close();
9420
9421           __END__
9422
9423       Download this example:
9424       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/write_handler1.pl>
9425
9426   Example: write_handler2.pl
9427       Example of how to add a user defined data handler to the
9428       Excel::Writer::XLSX write() method.
9429
9430       The following example shows how to add a handler for a 7 digit ID
9431       number.  It adds an additional constraint to the write_handler1.pl in
9432       that it only filters data that isn't in the third column.
9433
9434       Source code for this example:
9435
9436           #!/usr/bin/perl -w
9437
9438           ###############################################################################
9439           #
9440           # Example of how to add a user defined data handler to the
9441           # Excel::Writer::XLSX write() method.
9442           #
9443           # The following example shows how to add a handler for a 7 digit ID number.
9444           # It adds an additional constraint to the write_handler1.pl in that it only
9445           # filters data that isn't in the third column.
9446           #
9447           #
9448           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9449           #
9450
9451           use strict;
9452           use Excel::Writer::XLSX;
9453
9454
9455           my $workbook  = Excel::Writer::XLSX->new( 'write_handler2.xlsx' );
9456           my $worksheet = $workbook->add_worksheet();
9457
9458
9459           ###############################################################################
9460           #
9461           # Add a handler for 7 digit id numbers. This is useful when you want a string
9462           # such as 0000001 written as a string instead of a number and thus preserve
9463           # the leading zeroes.
9464           #
9465           # Note: you can get the same effect using the keep_leading_zeros() method but
9466           # this serves as a simple example.
9467           #
9468           $worksheet->add_write_handler( qr[^\d{7}$], \&write_my_id );
9469
9470
9471           ###############################################################################
9472           #
9473           # The following function processes the data when a match is found. The handler
9474           # is set up so that it only filters data if it is in the third column.
9475           #
9476           sub write_my_id {
9477
9478               my $worksheet = shift;
9479               my $col       = $_[1];
9480
9481               # col is zero based
9482               if ( $col != 2 ) {
9483                   return $worksheet->write_string( @_ );
9484               }
9485               else {
9486
9487                   # Reject the match and return control to write()
9488                   return undef;
9489               }
9490
9491           }
9492
9493
9494           # This format maintains the cell as text even if it is edited.
9495           my $id_format = $workbook->add_format( num_format => '@' );
9496
9497
9498           # Write some numbers in the user defined format
9499           $worksheet->write( 'A1', '0000000', $id_format );
9500           $worksheet->write( 'B1', '0000001', $id_format );
9501           $worksheet->write( 'C1', '0000002', $id_format );
9502           $worksheet->write( 'D1', '0000003', $id_format );
9503
9504           $workbook->close();
9505
9506           __END__
9507
9508       Download this example:
9509       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/write_handler2.pl>
9510
9511   Example: write_handler3.pl
9512       Example of how to add a user defined data handler to the
9513       Excel::Writer::XLSX write() method.
9514
9515       The following example shows how to add a handler for dates in a
9516       specific format.
9517
9518       See write_handler4.pl for a more rigorous example with error handling.
9519
9520       Source code for this example:
9521
9522           #!/usr/bin/perl -w
9523
9524           ###############################################################################
9525           #
9526           # Example of how to add a user defined data handler to the
9527           # Excel::Writer::XLSX write() method.
9528           #
9529           # The following example shows how to add a handler for dates in a specific
9530           # format.
9531           #
9532           # See write_handler4.pl for a more rigorous example with error handling.
9533           #
9534           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9535           #
9536
9537           use strict;
9538           use Excel::Writer::XLSX;
9539
9540
9541           my $workbook    = Excel::Writer::XLSX->new( 'write_handler3.xlsx' );
9542           my $worksheet   = $workbook->add_worksheet();
9543           my $date_format = $workbook->add_format( num_format => 'dd/mm/yy' );
9544
9545
9546           ###############################################################################
9547           #
9548           # Add a handler to match dates in the following format: d/m/yyyy
9549           #
9550           # The day and month can be single or double digits.
9551           #
9552           $worksheet->add_write_handler( qr[^\d{1,2}/\d{1,2}/\d{4}$], \&write_my_date );
9553
9554
9555           ###############################################################################
9556           #
9557           # The following function processes the data when a match is found.
9558           # See write_handler4.pl for a more rigorous example with error handling.
9559           #
9560           sub write_my_date {
9561
9562               my $worksheet = shift;
9563               my @args      = @_;
9564
9565               my $token = $args[2];
9566               $token =~ qr[^(\d{1,2})/(\d{1,2})/(\d{4})$];
9567
9568               # Change to the date format required by write_date_time().
9569               my $date = sprintf "%4d-%02d-%02dT", $3, $2, $1;
9570
9571               $args[2] = $date;
9572
9573               return $worksheet->write_date_time( @args );
9574           }
9575
9576
9577           # Write some dates in the user defined format
9578           $worksheet->write( 'A1', '22/12/2004', $date_format );
9579           $worksheet->write( 'A2', '1/1/1995',   $date_format );
9580           $worksheet->write( 'A3', '01/01/1995', $date_format );
9581
9582           $workbook->close();
9583
9584           __END__
9585
9586       Download this example:
9587       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/write_handler3.pl>
9588
9589   Example: write_handler4.pl
9590       Example of how to add a user defined data handler to the
9591       Excel::Writer::XLSX write() method.
9592
9593       The following example shows how to add a handler for dates in a
9594       specific format.
9595
9596       This is a more rigorous version of write_handler3.pl.
9597
9598       Source code for this example:
9599
9600           #!/usr/bin/perl -w
9601
9602           ###############################################################################
9603           #
9604           # Example of how to add a user defined data handler to the
9605           # Excel::Writer::XLSX write() method.
9606           #
9607           # The following example shows how to add a handler for dates in a specific
9608           # format.
9609           #
9610           # This is a more rigorous version of write_handler3.pl.
9611           #
9612           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9613           #
9614
9615           use strict;
9616           use Excel::Writer::XLSX;
9617
9618
9619           my $workbook    = Excel::Writer::XLSX->new( 'write_handler4.xlsx' );
9620           my $worksheet   = $workbook->add_worksheet();
9621           my $date_format = $workbook->add_format( num_format => 'dd/mm/yy' );
9622
9623
9624           ###############################################################################
9625           #
9626           # Add a handler to match dates in the following formats: d/m/yy, d/m/yyyy
9627           #
9628           # The day and month can be single or double digits and the year can be  2 or 4
9629           # digits.
9630           #
9631           $worksheet->add_write_handler( qr[^\d{1,2}/\d{1,2}/\d{2,4}$], \&write_my_date );
9632
9633
9634           ###############################################################################
9635           #
9636           # The following function processes the data when a match is found.
9637           #
9638           sub write_my_date {
9639
9640               my $worksheet = shift;
9641               my @args      = @_;
9642
9643               my $token = $args[2];
9644
9645               if ( $token =~ qr[^(\d{1,2})/(\d{1,2})/(\d{2,4})$] ) {
9646
9647                   my $day  = $1;
9648                   my $mon  = $2;
9649                   my $year = $3;
9650
9651                   # Use a window for 2 digit dates. This will keep some ragged Perl
9652                   # programmer employed in thirty years time. :-)
9653                   if ( length $year == 2 ) {
9654                       if ( $year < 50 ) {
9655                           $year += 2000;
9656                       }
9657                       else {
9658                           $year += 1900;
9659                       }
9660                   }
9661
9662                   my $date = sprintf "%4d-%02d-%02dT", $year, $mon, $day;
9663
9664                   # Convert the ISO ISO8601 style string to an Excel date
9665                   $date = $worksheet->convert_date_time( $date );
9666
9667                   if ( defined $date ) {
9668
9669                       # Date was valid
9670                       $args[2] = $date;
9671                       return $worksheet->write_number( @args );
9672                   }
9673                   else {
9674
9675                       # Not a valid date therefore write as a string
9676                       return $worksheet->write_string( @args );
9677                   }
9678               }
9679               else {
9680
9681                   # Shouldn't happen if the same match is used in the re and sub.
9682                   return undef;
9683               }
9684           }
9685
9686
9687           # Write some dates in the user defined format
9688           $worksheet->write( 'A1', '22/12/2004', $date_format );
9689           $worksheet->write( 'A2', '22/12/04',   $date_format );
9690           $worksheet->write( 'A3', '2/12/04',    $date_format );
9691           $worksheet->write( 'A4', '2/5/04',     $date_format );
9692           $worksheet->write( 'A5', '2/5/95',     $date_format );
9693           $worksheet->write( 'A6', '2/5/1995',   $date_format );
9694
9695           # Some erroneous dates
9696           $worksheet->write( 'A8', '2/5/1895',  $date_format ); # Date out of Excel range
9697           $worksheet->write( 'A9', '29/2/2003', $date_format ); # Invalid leap day
9698           $worksheet->write( 'A10', '50/50/50', $date_format ); # Matches but isn't a date
9699
9700           $workbook->close();
9701
9702           __END__
9703
9704       Download this example:
9705       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/write_handler4.pl>
9706
9707   Example: write_to_scalar.pl
9708       An example of writing an Excel::Writer::XLSX file to a perl scalar.
9709
9710           #!/usr/bin/perl
9711
9712           ##############################################################################
9713           #
9714           # An example of writing an Excel::Writer::XLSX file to a perl scalar.
9715           #
9716           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9717           #
9718
9719           use strict;
9720           use warnings;
9721           use Excel::Writer::XLSX;
9722
9723           # Use a scalar as a filehandle.
9724           open my $fh, '>', \my $str or die "Failed to open filehandle: $!";
9725
9726
9727           # Spreadsheet::WriteExce accepts filehandle as well as file names.
9728           my $workbook  = Excel::Writer::XLSX->new( $fh );
9729           my $worksheet = $workbook->add_worksheet();
9730
9731           $worksheet->write( 0, 0, 'Hi Excel!' );
9732
9733           $workbook->close();
9734
9735
9736           # The Excel file in now in $str. Remember to binmode() the output
9737           # filehandle before printing it.
9738           open my $out_fh, '>', 'write_to_scalar.xlsx'
9739             or die "Failed to open out filehandle: $!";
9740
9741           binmode $out_fh;
9742           print   $out_fh $str;
9743           close   $out_fh;
9744
9745           __END__
9746
9747       Download this example:
9748       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/write_to_scalar.pl>
9749
9750   Example: unicode_2022_jp.pl
9751       A simple example of converting some Unicode text to an Excel file using
9752       Excel::Writer::XLSX.
9753
9754       This example generates some Japanese from a file with ISO-2022-JP
9755       encoded text.
9756
9757       Source code for this example:
9758
9759           #!/usr/bin/perl
9760
9761           ##############################################################################
9762           #
9763           # A simple example of converting some Unicode text to an Excel file using
9764           # Excel::Writer::XLSX.
9765           #
9766           # This example generates some Japanese from a file with ISO-2022-JP
9767           # encoded text.
9768           #
9769           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9770           #
9771
9772           use strict;
9773           use warnings;
9774           use Excel::Writer::XLSX;
9775
9776
9777           my $workbook = Excel::Writer::XLSX->new( 'unicode_2022_jp.xlsx' );
9778
9779           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
9780
9781           my $worksheet = $workbook->add_worksheet();
9782           $worksheet->set_column( 'A:A', 50 );
9783
9784
9785           my $file = 'unicode_2022_jp.txt';
9786
9787           open FH, '<:encoding(iso-2022-jp)', $file or die "Couldn't open $file: $!\n";
9788
9789           my $row = 0;
9790
9791           while ( <FH> ) {
9792               next if /^#/;    # Ignore the comments in the sample file.
9793               chomp;
9794               $worksheet->write( $row++, 0, $_ );
9795           }
9796
9797           $workbook->close();
9798
9799           __END__
9800
9801       Download this example:
9802       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_2022_jp.pl>
9803
9804   Example: unicode_8859_11.pl
9805       A simple example of converting some Unicode text to an Excel file using
9806       Excel::Writer::XLSX.
9807
9808       This example generates some Thai from a file with ISO-8859-11 encoded
9809       text.
9810
9811       Source code for this example:
9812
9813           #!/usr/bin/perl
9814
9815           ##############################################################################
9816           #
9817           # A simple example of converting some Unicode text to an Excel file using
9818           # Excel::Writer::XLSX.
9819           #
9820           # This example generates some Thai from a file with ISO-8859-11 encoded text.
9821           #
9822           #
9823           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9824           #
9825
9826           use strict;
9827           use warnings;
9828           use Excel::Writer::XLSX;
9829
9830
9831           my $workbook = Excel::Writer::XLSX->new( 'unicode_8859_11.xlsx' );
9832
9833           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
9834
9835           my $worksheet = $workbook->add_worksheet();
9836           $worksheet->set_column( 'A:A', 50 );
9837
9838
9839           my $file = 'unicode_8859_11.txt';
9840
9841           open FH, '<:encoding(iso-8859-11)', $file or die "Couldn't open $file: $!\n";
9842
9843           my $row = 0;
9844
9845           while ( <FH> ) {
9846               next if /^#/;    # Ignore the comments in the sample file.
9847               chomp;
9848               $worksheet->write( $row++, 0, $_ );
9849           }
9850
9851           $workbook->close();
9852
9853           __END__
9854
9855       Download this example:
9856       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_8859_11.pl>
9857
9858   Example: unicode_8859_7.pl
9859       A simple example of converting some Unicode text to an Excel file using
9860       Excel::Writer::XLSX.
9861
9862       This example generates some Greek from a file with ISO-8859-7 encoded
9863       text.
9864
9865       Source code for this example:
9866
9867           #!/usr/bin/perl
9868
9869           ##############################################################################
9870           #
9871           # A simple example of converting some Unicode text to an Excel file using
9872           # Excel::Writer::XLSX.
9873           #
9874           # This example generates some Greek from a file with ISO-8859-7 encoded text.
9875           #
9876           #
9877           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9878           #
9879
9880           use strict;
9881           use warnings;
9882           use Excel::Writer::XLSX;
9883
9884
9885           my $workbook = Excel::Writer::XLSX->new( 'unicode_8859_7.xlsx' );
9886
9887           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
9888
9889           my $worksheet = $workbook->add_worksheet();
9890           $worksheet->set_column( 'A:A', 50 );
9891
9892
9893           my $file = 'unicode_8859_7.txt';
9894
9895           open FH, '<:encoding(iso-8859-7)', $file or die "Couldn't open $file: $!\n";
9896
9897           my $row = 0;
9898
9899           while ( <FH> ) {
9900               next if /^#/;    # Ignore the comments in the sample file.
9901               chomp;
9902               $worksheet->write( $row++, 0, $_ );
9903           }
9904
9905           $workbook->close();
9906
9907           __END__
9908
9909       Download this example:
9910       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_8859_7.pl>
9911
9912   Example: unicode_big5.pl
9913       A simple example of converting some Unicode text to an Excel file using
9914       Excel::Writer::XLSX.
9915
9916       This example generates some Chinese from a file with BIG5 encoded text.
9917
9918       Source code for this example:
9919
9920           #!/usr/bin/perl
9921
9922           ##############################################################################
9923           #
9924           # A simple example of converting some Unicode text to an Excel file using
9925           # Excel::Writer::XLSX.
9926           #
9927           # This example generates some Chinese from a file with BIG5 encoded text.
9928           #
9929           #
9930           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9931           #
9932
9933           use strict;
9934           use warnings;
9935           use Excel::Writer::XLSX;
9936
9937
9938           my $workbook = Excel::Writer::XLSX->new( 'unicode_big5.xlsx' );
9939
9940           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
9941
9942           my $worksheet = $workbook->add_worksheet();
9943           $worksheet->set_column( 'A:A', 80 );
9944
9945
9946           my $file = 'unicode_big5.txt';
9947
9948           open FH, '<:encoding(big5)', $file or die "Couldn't open $file: $!\n";
9949
9950           my $row = 0;
9951
9952           while ( <FH> ) {
9953               next if /^#/;    # Ignore the comments in the sample file.
9954               chomp;
9955               $worksheet->write( $row++, 0, $_ );
9956           }
9957
9958           $workbook->close();
9959
9960           __END__
9961
9962       Download this example:
9963       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_big5.pl>
9964
9965   Example: unicode_cp1251.pl
9966       A simple example of converting some Unicode text to an Excel file using
9967       Excel::Writer::XLSX.
9968
9969       This example generates some Russian from a file with CP1251 encoded
9970       text.
9971
9972       Source code for this example:
9973
9974           #!/usr/bin/perl
9975
9976           ##############################################################################
9977           #
9978           # A simple example of converting some Unicode text to an Excel file using
9979           # Excel::Writer::XLSX.
9980           #
9981           # This example generates some Russian from a file with CP1251 encoded text.
9982           #
9983           #
9984           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
9985           #
9986
9987           use strict;
9988           use warnings;
9989           use Excel::Writer::XLSX;
9990
9991
9992           my $workbook = Excel::Writer::XLSX->new( 'unicode_cp1251.xlsx' );
9993
9994           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
9995
9996           my $worksheet = $workbook->add_worksheet();
9997           $worksheet->set_column( 'A:A', 50 );
9998
9999
10000           my $file = 'unicode_cp1251.txt';
10001
10002           open FH, '<:encoding(cp1251)', $file or die "Couldn't open $file: $!\n";
10003
10004           my $row = 0;
10005
10006           while ( <FH> ) {
10007               next if /^#/;    # Ignore the comments in the sample file.
10008               chomp;
10009               $worksheet->write( $row++, 0, $_ );
10010           }
10011
10012           $workbook->close();
10013
10014           __END__
10015
10016       Download this example:
10017       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_cp1251.pl>
10018
10019   Example: unicode_cp1256.pl
10020       A simple example of converting some Unicode text to an Excel file using
10021       Excel::Writer::XLSX.
10022
10023       This example generates some Arabic text from a CP-1256 encoded file.
10024
10025       Source code for this example:
10026
10027           #!/usr/bin/perl
10028
10029           ##############################################################################
10030           #
10031           # A simple example of converting some Unicode text to an Excel file using
10032           # Excel::Writer::XLSX.
10033           #
10034           # This example generates some Arabic text from a CP-1256 encoded file.
10035           #
10036           #
10037           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
10038           #
10039
10040           use strict;
10041           use warnings;
10042           use Excel::Writer::XLSX;
10043
10044
10045           my $workbook = Excel::Writer::XLSX->new( 'unicode_cp1256.xlsx' );
10046
10047           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10048
10049           my $worksheet = $workbook->add_worksheet();
10050           $worksheet->set_column( 'A:A', 50 );
10051
10052
10053           my $file = 'unicode_cp1256.txt';
10054
10055           open FH, '<:encoding(cp1256)', $file or die "Couldn't open $file: $!\n";
10056
10057           my $row = 0;
10058
10059           while ( <FH> ) {
10060               next if /^#/;    # Ignore the comments in the sample file.
10061               chomp;
10062               $worksheet->write( $row++, 0, $_ );
10063           }
10064
10065           $workbook->close();
10066
10067           __END__
10068
10069       Download this example:
10070       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_cp1256.pl>
10071
10072   Example: unicode_cyrillic.pl
10073       A simple example of writing some Russian cyrillic text using
10074       Excel::Writer::XLSX.
10075
10076       Source code for this example:
10077
10078           #!/usr/bin/perl
10079
10080           ##############################################################################
10081           #
10082           # A simple example of writing some Russian cyrillic text using
10083           # Excel::Writer::XLSX.
10084           #
10085           #
10086           #
10087           #
10088           # reverse ('(c)'), March 2005, John McNamara, jmcnamara@cpan.org
10089           #
10090
10091           use strict;
10092           use warnings;
10093           use Excel::Writer::XLSX;
10094
10095
10096           # In this example we generate utf8 strings from character data but in a
10097           # real application we would expect them to come from an external source.
10098           #
10099
10100
10101           # Create a Russian worksheet name in utf8.
10102           my $sheet = pack "U*", 0x0421, 0x0442, 0x0440, 0x0430, 0x043D, 0x0438,
10103             0x0446, 0x0430;
10104
10105
10106           # Create a Russian string.
10107           my $str = pack "U*", 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441,
10108             0x0442, 0x0432, 0x0443, 0x0439, 0x0020, 0x041C,
10109             0x0438, 0x0440, 0x0021;
10110
10111
10112           my $workbook = Excel::Writer::XLSX->new( 'unicode_cyrillic.xlsx' );
10113
10114           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10115
10116           my $worksheet = $workbook->add_worksheet( $sheet . '1' );
10117
10118           $worksheet->set_column( 'A:A', 18 );
10119           $worksheet->write( 'A1', $str );
10120
10121           $workbook->close();
10122
10123           __END__
10124
10125       Download this example:
10126       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_cyrillic.pl>
10127
10128   Example: unicode_koi8r.pl
10129       A simple example of converting some Unicode text to an Excel file using
10130       Excel::Writer::XLSX.
10131
10132       This example generates some Russian from a file with KOI8-R encoded
10133       text.
10134
10135       Source code for this example:
10136
10137           #!/usr/bin/perl
10138
10139           ##############################################################################
10140           #
10141           # A simple example of converting some Unicode text to an Excel file using
10142           # Excel::Writer::XLSX.
10143           #
10144           # This example generates some Russian from a file with KOI8-R encoded text.
10145           #
10146           #
10147           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
10148           #
10149
10150           use strict;
10151           use warnings;
10152           use Excel::Writer::XLSX;
10153
10154
10155           my $workbook = Excel::Writer::XLSX->new( 'unicode_koi8r.xlsx' );
10156
10157           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10158
10159           my $worksheet = $workbook->add_worksheet();
10160           $worksheet->set_column( 'A:A', 50 );
10161
10162
10163           my $file = 'unicode_koi8r.txt';
10164
10165           open FH, '<:encoding(koi8-r)', $file or die "Couldn't open $file: $!\n";
10166
10167           my $row = 0;
10168
10169           while ( <FH> ) {
10170               next if /^#/;    # Ignore the comments in the sample file.
10171               chomp;
10172               $worksheet->write( $row++, 0, $_ );
10173           }
10174
10175           $workbook->close();
10176
10177           __END__
10178
10179       Download this example:
10180       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_koi8r.pl>
10181
10182   Example: unicode_polish_utf8.pl
10183       A simple example of converting some Unicode text to an Excel file using
10184       Excel::Writer::XLSX.
10185
10186       This example generates some Polish from a file with UTF8 encoded text.
10187
10188       Source code for this example:
10189
10190           #!/usr/bin/perl
10191
10192           ##############################################################################
10193           #
10194           # A simple example of converting some Unicode text to an Excel file using
10195           # Excel::Writer::XLSX.
10196           #
10197           # This example generates some Polish from a file with UTF8 encoded text.
10198           #
10199           #
10200           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
10201           #
10202
10203           use strict;
10204           use warnings;
10205           use Excel::Writer::XLSX;
10206
10207
10208           my $workbook = Excel::Writer::XLSX->new( 'unicode_polish_utf8.xlsx' );
10209
10210           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10211
10212           my $worksheet = $workbook->add_worksheet();
10213           $worksheet->set_column( 'A:A', 50 );
10214
10215
10216           my $file = 'unicode_polish_utf8.txt';
10217
10218           open FH, '<:encoding(utf8)', $file or die "Couldn't open $file: $!\n";
10219
10220           my $row = 0;
10221
10222           while ( <FH> ) {
10223               next if /^#/;    # Ignore the comments in the sample file.
10224               chomp;
10225               $worksheet->write( $row++, 0, $_ );
10226           }
10227
10228           $workbook->close();
10229
10230           __END__
10231
10232       Download this example:
10233       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_polish_utf8.pl>
10234
10235   Example: unicode_shift_jis.pl
10236       A simple example of converting some Unicode text to an Excel file using
10237       Excel::Writer::XLSX.
10238
10239       This example generates some Japenese text from a file with Shift-JIS
10240       encoded text.
10241
10242       Source code for this example:
10243
10244           #!/usr/bin/perl
10245
10246           ##############################################################################
10247           #
10248           # A simple example of converting some Unicode text to an Excel file using
10249           # Excel::Writer::XLSX.
10250           #
10251           # This example generates some Japenese text from a file with Shift-JIS
10252           # encoded text.
10253           #
10254           # reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
10255           #
10256
10257           use strict;
10258           use warnings;
10259           use Excel::Writer::XLSX;
10260
10261
10262           my $workbook = Excel::Writer::XLSX->new( 'unicode_shift_jis.xlsx' );
10263
10264           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10265
10266           my $worksheet = $workbook->add_worksheet();
10267           $worksheet->set_column( 'A:A', 50 );
10268
10269
10270           my $file = 'unicode_shift_jis.txt';
10271
10272           open FH, '<:encoding(shiftjis)', $file or die "Couldn't open $file: $!\n";
10273
10274           my $row = 0;
10275
10276           while ( <FH> ) {
10277               next if /^#/;    # Ignore the comments in the sample file.
10278               chomp;
10279               $worksheet->write( $row++, 0, $_ );
10280           }
10281
10282           $workbook->close();
10283
10284           __END__
10285
10286       Download this example:
10287       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-0.98/examples/unicode_shift_jis.pl>
10288

AUTHOR

10290       John McNamara jmcnamara@cpan.org
10291
10292       Contributed examples contain the original author's name.
10293
10295       Copyright MM-MMXVI, John McNamara.
10296
10297       All Rights Reserved. This module is free software. It may be used,
10298       redistributed and/or modified under the same terms as Perl itself.
10299
10300
10301
10302perl v5.28.0                      2018-04-14  Excel::Writer::XLSX::Examples(3)
Impressum