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 89 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 doughnut 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_data_labels.pl" A demo of standard and custom chart
74           data labels.
75
76       ·   "Example: chart_clustered.pl" A demo of a chart with a clustered
77           axis.
78
79       ·   "Example: chart_styles.pl" A demo of the available chart styles.
80
81       ·   "Example: chart_gauge.pl" A demo of a gauge style chart.
82
83       ·   "Example: colors.pl" A demo of the colour palette and named
84           colours.
85
86       ·   "Example: comments1.pl" Add comments to worksheet cells.
87
88       ·   "Example: comments2.pl" Add comments with advanced options.
89
90       ·   "Example: conditional_format.pl" Add conditional formats to a range
91           of cells.
92
93       ·   "Example: data_validate.pl" An example of data validation and
94           dropdown lists.
95
96       ·   "Example: date_time.pl" Write dates and times with
97           write_date_time().
98
99       ·   "Example: defined_name.pl" Example of how to create defined names.
100
101       ·   "Example: diag_border.pl" A simple example of diagonal cell
102           borders.
103
104       ·   "Example: filehandle.pl" Examples of working with filehandles.
105
106       ·   "Example: headers.pl" Examples of worksheet headers and footers.
107
108       ·   "Example: hide_row_col.pl" Example of hiding rows and columns.
109
110       ·   "Example: hide_sheet.pl" Simple example of hiding a worksheet.
111
112       ·   "Example: hyperlink1.pl" Shows how to create web hyperlinks.
113
114       ·   "Example: hyperlink2.pl" Examples of internal and external
115           hyperlinks.
116
117       ·   "Example: indent.pl" An example of cell indentation.
118
119       ·   "Example: macros.pl" An example of adding macros from an existing
120           file.
121
122       ·   "Example: merge1.pl" A simple example of cell merging.
123
124       ·   "Example: merge2.pl" A simple example of cell merging with
125           formatting.
126
127       ·   "Example: merge3.pl" Add hyperlinks to merged cells.
128
129       ·   "Example: merge4.pl" An advanced example of merging with
130           formatting.
131
132       ·   "Example: merge5.pl" An advanced example of merging with
133           formatting.
134
135       ·   "Example: merge6.pl" An example of merging with Unicode strings.
136
137       ·   "Example: mod_perl1.pl" A simple mod_perl 1 program.
138
139       ·   "Example: mod_perl2.pl" A simple mod_perl 2 program.
140
141       ·   "Example: outline.pl" An example of outlines and grouping.
142
143       ·   "Example: outline_collapsed.pl" An example of collapsed outlines.
144
145       ·   "Example: panes.pl" An example of how to create panes.
146
147       ·   "Example: properties.pl" Add document properties to a workbook.
148
149       ·   "Example: protection.pl" Example of cell locking and formula
150           hiding.
151
152       ·   "Example: rich_strings.pl" Example of strings with multiple
153           formats.
154
155       ·   "Example: right_to_left.pl" Change default sheet direction to right
156           to left.
157
158       ·   "Example: sales.pl" An example of a simple sales spreadsheet.
159
160       ·   "Example: shape1.pl" Insert shapes in worksheet.
161
162       ·   "Example: shape2.pl" Insert shapes in worksheet. With properties.
163
164       ·   "Example: shape3.pl" Insert shapes in worksheet. Scaled.
165
166       ·   "Example: shape4.pl" Insert shapes in worksheet. With modification.
167
168       ·   "Example: shape5.pl" Insert shapes in worksheet. With connections.
169
170       ·   "Example: shape6.pl" Insert shapes in worksheet. With connections.
171
172       ·   "Example: shape7.pl" Insert shapes in worksheet. One to many
173           connections.
174
175       ·   "Example: shape8.pl" Insert shapes in worksheet. One to many
176           connections.
177
178       ·   "Example: shape_all.pl" Demo of all the available shape and
179           connector types.
180
181       ·   "Example: sparklines1.pl" Simple sparklines demo.
182
183       ·   "Example: sparklines2.pl" Sparklines demo showing formatting
184           options.
185
186       ·   "Example: stats_ext.pl" Same as stats.pl with external references.
187
188       ·   "Example: stocks.pl" Demonstrates conditional formatting.
189
190       ·   "Example: tab_colors.pl" Example of how to set worksheet tab
191           colours.
192
193       ·   "Example: tables.pl" Add Excel tables to a worksheet.
194
195       ·   "Example: write_handler1.pl" Example of extending the write()
196           method. Step 1.
197
198       ·   "Example: write_handler2.pl" Example of extending the write()
199           method. Step 2.
200
201       ·   "Example: write_handler3.pl" Example of extending the write()
202           method. Step 3.
203
204       ·   "Example: write_handler4.pl" Example of extending the write()
205           method. Step 4.
206
207       ·   "Example: write_to_scalar.pl" Example of writing an Excel file to a
208           Perl scalar.
209
210       ·   "Example: unicode_2022_jp.pl" Japanese: ISO-2022-JP.
211
212       ·   "Example: unicode_8859_11.pl" Thai:     ISO-8859_11.
213
214       ·   "Example: unicode_8859_7.pl" Greek:    ISO-8859_7.
215
216       ·   "Example: unicode_big5.pl" Chinese:  BIG5.
217
218       ·   "Example: unicode_cp1251.pl" Russian:  CP1251.
219
220       ·   "Example: unicode_cp1256.pl" Arabic:   CP1256.
221
222       ·   "Example: unicode_cyrillic.pl" Russian:  Cyrillic.
223
224       ·   "Example: unicode_koi8r.pl" Russian:  KOI8-R.
225
226       ·   "Example: unicode_polish_utf8.pl" Polish :  UTF8.
227
228       ·   "Example: unicode_shift_jis.pl" Japanese: Shift JIS.
229
230   Example: a_simple.pl
231       A simple example of how to use the Excel::Writer::XLSX module to write
232       text and numbers to an Excel xlsx file.
233
234       Source code for this example:
235
236           #!/usr/bin/perl -w
237
238           #######################################################################
239           #
240           # A simple example of how to use the Excel::Writer::XLSX module to
241           # write text and numbers to an Excel xlsx file.
242           #
243           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
244           #
245
246           use strict;
247           use Excel::Writer::XLSX;
248
249           # Create a new workbook called simple.xls and add a worksheet
250           my $workbook  = Excel::Writer::XLSX->new( 'a_simple.xlsx' );
251           my $worksheet = $workbook->add_worksheet();
252
253           # The general syntax is write($row, $column, $token). Note that row and
254           # column are zero indexed
255           #
256
257           # Write some text
258           $worksheet->write( 0, 0, "Hi Excel!" );
259
260
261           # Write some numbers
262           $worksheet->write( 2, 0, 3 );          # Writes 3
263           $worksheet->write( 3, 0, 3.00000 );    # Writes 3
264           $worksheet->write( 4, 0, 3.00001 );    # Writes 3.00001
265           $worksheet->write( 5, 0, 3.14159 );    # TeX revision no.?
266
267
268           # Write some formulas
269           $worksheet->write( 7, 0, '=A3 + A6' );
270           $worksheet->write( 8, 0, '=IF(A5>3,"Yes", "No")' );
271
272
273           # Write a hyperlink
274           $worksheet->write( 10, 0, 'http://www.perl.com/' );
275
276           $workbook->close();
277
278           __END__
279
280       Download this example:
281       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/a_simple.pl>
282
283   Example: bug_report.pl
284       A template for submitting a bug report.
285
286       Run this program and read the output from the command line.
287
288           #!/usr/bin/perl -w
289
290           ###############################################################################
291           #
292           # A template for submitting a bug report.
293           #
294           # Run this program and read the output from the command line.
295           #
296           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
297           #
298
299
300           use strict;
301
302           print << 'HINTS_1';
303
304           REPORTING A BUG OR ASKING A QUESTION
305
306               Feel free to report bugs or ask questions. However, to save time
307               consider the following steps first:
308
309               Read the documentation:
310
311                   The Excel::Writer::XLSX documentation has been refined in
312                   response to user questions. Therefore, if you have a question it is
313                   possible that someone else has asked it before you and that it is
314                   already addressed in the documentation. Since there is a lot of
315                   documentation to get through you should at least read the table of
316                   contents and search for keywords that you are interested in.
317
318               Look at the example programs:
319
320                   There are over 80 example programs shipped with the standard
321                   Excel::Writer::XLSX distribution. Many of these were created
322                   in response to user questions. Try to identify an example program
323                   that corresponds to your query and adapt it to your needs.
324
325           HINTS_1
326           print "Press enter ..."; <STDIN>;
327
328           print << 'HINTS_2';
329
330               If you submit a bug report here are some pointers.
331
332               1.  Put "Excel::Writer::XLSX:" at the beginning of the subject line.
333                   This helps to filter genuine messages from spam.
334
335               2.  Describe the problems as clearly and as concisely as possible.
336
337               3.  Send a sample program. It is often easier to describe a problem in
338                   code than in written prose.
339
340               4.  The sample program should be as small as possible to demonstrate the
341                   problem. Don't copy and past large sections of your program. The
342                   program should also be self contained and working.
343
344               A sample bug report is generated below. If you use this format then it
345               will help to analyse your question and respond to it more quickly.
346
347               Please don't send patches without contacting the author first.
348
349
350           HINTS_2
351           print "Press enter ..."; <STDIN>;
352
353
354           print << 'EMAIL';
355
356           =======================================================================
357
358           To:      John McNamara <jmcnamara@cpan.org>
359           Subject: Excel::Writer::XLSX: Problem with something.
360
361           Hi John,
362
363           I am using Excel::Writer::XLSX and I have encountered a problem. I
364           want it to do SOMETHING but the module appears to do SOMETHING_ELSE.
365
366           Here is some code that demonstrates the problem.
367
368               #!/usr/bin/perl -w
369
370               use strict;
371               use Excel::Writer::XLSX;
372
373               my $workbook  = Excel::Writer::XLSX->new("reload.xls");
374               my $worksheet = $workbook->add_worksheet();
375
376               $worksheet->write(0, 0, "Hi Excel!");
377
378               $workbook->close();
379
380               __END__
381
382           My automatically generated system details are as follows:
383           EMAIL
384
385
386           print "\n    Perl version   : $]";
387           print "\n    OS name        : $^O";
388           print "\n    Module versions: (not all are required)\n";
389
390
391           my @modules = qw(
392                             Excel::Writer::XLSX
393                             Spreadsheet::WriteExcel
394                             Archive::Zip
395                             XML::Writer
396                             IO::File
397                             File::Temp
398                           );
399
400
401           for my $module (@modules) {
402               my $version;
403               eval "require $module";
404
405               if (not $@) {
406                   $version = $module->VERSION;
407                   $version = '(unknown)' if not defined $version;
408               }
409               else {
410                   $version = '(not installed)';
411               }
412
413               printf "%21s%-24s\t%s\n", "", $module, $version;
414           }
415
416
417           print << "BYE";
418           Yours etc.,
419
420           A. Person
421           --
422
423           BYE
424
425           __END__
426
427       Download this example:
428       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/bug_report.pl>
429
430   Example: demo.pl
431       A simple demo of some of the features of Excel::Writer::XLSX.
432
433       This program is used to create the project screenshot for Freshmeat:
434       <http://freshmeat.net/projects/writeexcel/>
435
436       Source code for this example:
437
438           #!/usr/bin/perl -w
439
440           #######################################################################
441           #
442           # A simple demo of some of the features of Excel::Writer::XLSX.
443           #
444           # This program is used to create the project screenshot for Freshmeat:
445           # L<http://freshmeat.net/projects/writeexcel/>
446           #
447           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
448           #
449
450           use strict;
451           use Excel::Writer::XLSX;
452
453           my $workbook   = Excel::Writer::XLSX->new( 'demo.xlsx' );
454           my $worksheet  = $workbook->add_worksheet( 'Demo' );
455           my $worksheet2 = $workbook->add_worksheet( 'Another sheet' );
456           my $worksheet3 = $workbook->add_worksheet( 'And another' );
457
458           my $bold = $workbook->add_format( bold => 1 );
459
460
461           #######################################################################
462           #
463           # Write a general heading
464           #
465           $worksheet->set_column( 'A:A', 36, $bold );
466           $worksheet->set_column( 'B:B', 20 );
467           $worksheet->set_row( 0, 40 );
468
469           my $heading = $workbook->add_format(
470               bold  => 1,
471               color => 'blue',
472               size  => 16,
473               merge => 1,
474               align => 'vcenter',
475           );
476
477           my @headings = ( 'Features of Excel::Writer::XLSX', '' );
478           $worksheet->write_row( 'A1', \@headings, $heading );
479
480
481           #######################################################################
482           #
483           # Some text examples
484           #
485           my $text_format = $workbook->add_format(
486               bold   => 1,
487               italic => 1,
488               color  => 'red',
489               size   => 18,
490               font   => 'Lucida Calligraphy'
491           );
492
493
494           $worksheet->write( 'A2', "Text" );
495           $worksheet->write( 'B2', "Hello Excel" );
496           $worksheet->write( 'A3', "Formatted text" );
497           $worksheet->write( 'B3', "Hello Excel", $text_format );
498           $worksheet->write( 'A4', "Unicode text" );
499           $worksheet->write( 'B4', "\x{0410} \x{0411} \x{0412} \x{0413} \x{0414}" );
500
501           #######################################################################
502           #
503           # Some numeric examples
504           #
505           my $num1_format = $workbook->add_format( num_format => '$#,##0.00' );
506           my $num2_format = $workbook->add_format( num_format => ' d mmmm yyy' );
507
508
509           $worksheet->write( 'A5', "Numbers" );
510           $worksheet->write( 'B5', 1234.56 );
511           $worksheet->write( 'A6', "Formatted numbers" );
512           $worksheet->write( 'B6', 1234.56, $num1_format );
513           $worksheet->write( 'A7', "Formatted numbers" );
514           $worksheet->write( 'B7', 37257, $num2_format );
515
516
517           #######################################################################
518           #
519           # Formulae
520           #
521           $worksheet->set_selection( 'B8' );
522           $worksheet->write( 'A8', 'Formulas and functions, "=SIN(PI()/4)"' );
523           $worksheet->write( 'B8', '=SIN(PI()/4)' );
524
525
526           #######################################################################
527           #
528           # Hyperlinks
529           #
530           $worksheet->write( 'A9', "Hyperlinks" );
531           $worksheet->write( 'B9', 'http://www.perl.com/' );
532
533
534           #######################################################################
535           #
536           # Images
537           #
538           $worksheet->write( 'A10', "Images" );
539           $worksheet->insert_image( 'B10', 'republic.png',
540                                            { x_offset => 16, y_offset => 8 } );
541
542
543           #######################################################################
544           #
545           # Misc
546           #
547           $worksheet->write( 'A18', "Page/printer setup" );
548           $worksheet->write( 'A19', "Multiple worksheets" );
549
550           $workbook->close();
551
552           __END__
553
554       Download this example:
555       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/demo.pl>
556
557   Example: formats.pl
558       Examples of formatting using the Excel::Writer::XLSX module.
559
560       This program demonstrates almost all possible formatting options. It is
561       worth running this program and viewing the output Excel file if you are
562       interested in the various formatting possibilities.
563
564       Source code for this example:
565
566           #!/usr/bin/perl -w
567
568           ###############################################################################
569           #
570           # Examples of formatting using the Excel::Writer::XLSX module.
571           #
572           # This program demonstrates almost all possible formatting options. It is worth
573           # running this program and viewing the output Excel file if you are interested
574           # in the various formatting possibilities.
575           #
576           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
577           #
578
579           use strict;
580           use Excel::Writer::XLSX;
581
582           my $workbook = Excel::Writer::XLSX->new( 'formats.xlsx' );
583
584           # Some common formats
585           my $center = $workbook->add_format( align => 'center' );
586           my $heading = $workbook->add_format( align => 'center', bold => 1 );
587
588           # The named colors
589           my %colors = (
590               0x08, 'black',
591               0x0C, 'blue',
592               0x10, 'brown',
593               0x0F, 'cyan',
594               0x17, 'gray',
595               0x11, 'green',
596               0x0B, 'lime',
597               0x0E, 'magenta',
598               0x12, 'navy',
599               0x35, 'orange',
600               0x21, 'pink',
601               0x14, 'purple',
602               0x0A, 'red',
603               0x16, 'silver',
604               0x09, 'white',
605               0x0D, 'yellow',
606
607           );
608
609           # Call these subroutines to demonstrate different formatting options
610           intro();
611           fonts();
612           named_colors();
613           standard_colors();
614           numeric_formats();
615           borders();
616           patterns();
617           alignment();
618           misc();
619
620           # Note: this is required
621           $workbook->close();
622
623
624           ######################################################################
625           #
626           # Intro.
627           #
628           sub intro {
629
630               my $worksheet = $workbook->add_worksheet( 'Introduction' );
631
632               $worksheet->set_column( 0, 0, 60 );
633
634               my $format = $workbook->add_format();
635               $format->set_bold();
636               $format->set_size( 14 );
637               $format->set_color( 'blue' );
638               $format->set_align( 'center' );
639
640               my $format2 = $workbook->add_format();
641               $format2->set_bold();
642               $format2->set_color( 'blue' );
643
644               my $format3 = $workbook->add_format(
645                   color     => 'blue',
646                   underline => 1,
647               );
648
649               $worksheet->write( 2, 0, 'This workbook demonstrates some of', $format );
650               $worksheet->write( 3, 0, 'the formatting options provided by', $format );
651               $worksheet->write( 4, 0, 'the Excel::Writer::XLSX module.',    $format );
652               $worksheet->write( 'A7', 'Sections:', $format2 );
653
654               $worksheet->write( 'A8', "internal:Fonts!A1", 'Fonts', $format3 );
655
656               $worksheet->write( 'A9', "internal:'Named colors'!A1",
657                   'Named colors', $format3 );
658
659               $worksheet->write(
660                   'A10',
661                   "internal:'Standard colors'!A1",
662                   'Standard colors', $format3
663               );
664
665               $worksheet->write(
666                   'A11',
667                   "internal:'Numeric formats'!A1",
668                   'Numeric formats', $format3
669               );
670
671               $worksheet->write( 'A12', "internal:Borders!A1", 'Borders', $format3 );
672               $worksheet->write( 'A13', "internal:Patterns!A1", 'Patterns', $format3 );
673               $worksheet->write( 'A14', "internal:Alignment!A1", 'Alignment', $format3 );
674               $worksheet->write( 'A15', "internal:Miscellaneous!A1", 'Miscellaneous',
675                   $format3 );
676
677           }
678
679
680           ######################################################################
681           #
682           # Demonstrate the named colors.
683           #
684           sub named_colors {
685
686               my $worksheet = $workbook->add_worksheet( 'Named colors' );
687
688               $worksheet->set_column( 0, 3, 15 );
689
690               $worksheet->write( 0, 0, "Index", $heading );
691               $worksheet->write( 0, 1, "Index", $heading );
692               $worksheet->write( 0, 2, "Name",  $heading );
693               $worksheet->write( 0, 3, "Color", $heading );
694
695               my $i = 1;
696
697               while ( my ( $index, $color ) = each %colors ) {
698                   my $format = $workbook->add_format(
699                       bg_color => $color,
700                       pattern  => 1,
701                       border   => 1
702                   );
703
704                   $worksheet->write( $i + 1, 0, $index, $center );
705                   $worksheet->write( $i + 1, 1, sprintf( "0x%02X", $index ), $center );
706                   $worksheet->write( $i + 1, 2, $color, $center );
707                   $worksheet->write( $i + 1, 3, '',     $format );
708                   $i++;
709               }
710           }
711
712
713           ######################################################################
714           #
715           # Demonstrate the standard Excel colors in the range 8..63.
716           #
717           sub standard_colors {
718
719               my $worksheet = $workbook->add_worksheet( 'Standard colors' );
720
721               $worksheet->set_column( 0, 3, 15 );
722
723               $worksheet->write( 0, 0, "Index", $heading );
724               $worksheet->write( 0, 1, "Index", $heading );
725               $worksheet->write( 0, 2, "Color", $heading );
726               $worksheet->write( 0, 3, "Name",  $heading );
727
728               for my $i ( 8 .. 63 ) {
729                   my $format = $workbook->add_format(
730                       bg_color => $i,
731                       pattern  => 1,
732                       border   => 1
733                   );
734
735                   $worksheet->write( ( $i - 7 ), 0, $i, $center );
736                   $worksheet->write( ( $i - 7 ), 1, sprintf( "0x%02X", $i ), $center );
737                   $worksheet->write( ( $i - 7 ), 2, '', $format );
738
739                   # Add the  color names
740                   if ( exists $colors{$i} ) {
741                       $worksheet->write( ( $i - 7 ), 3, $colors{$i}, $center );
742
743                   }
744               }
745           }
746
747
748           ######################################################################
749           #
750           # Demonstrate the standard numeric formats.
751           #
752           sub numeric_formats {
753
754               my $worksheet = $workbook->add_worksheet( 'Numeric formats' );
755
756               $worksheet->set_column( 0, 4, 15 );
757               $worksheet->set_column( 5, 5, 45 );
758
759               $worksheet->write( 0, 0, "Index",       $heading );
760               $worksheet->write( 0, 1, "Index",       $heading );
761               $worksheet->write( 0, 2, "Unformatted", $heading );
762               $worksheet->write( 0, 3, "Formatted",   $heading );
763               $worksheet->write( 0, 4, "Negative",    $heading );
764               $worksheet->write( 0, 5, "Format",      $heading );
765
766               #<<<
767               my @formats;
768               push @formats, [ 0x00, 1234.567,   0,         'General' ];
769               push @formats, [ 0x01, 1234.567,   0,         '0' ];
770               push @formats, [ 0x02, 1234.567,   0,         '0.00' ];
771               push @formats, [ 0x03, 1234.567,   0,         '#,##0' ];
772               push @formats, [ 0x04, 1234.567,   0,         '#,##0.00' ];
773               push @formats, [ 0x05, 1234.567,   -1234.567, '($#,##0_);($#,##0)' ];
774               push @formats, [ 0x06, 1234.567,   -1234.567, '($#,##0_);[Red]($#,##0)' ];
775               push @formats, [ 0x07, 1234.567,   -1234.567, '($#,##0.00_);($#,##0.00)' ];
776               push @formats, [ 0x08, 1234.567,   -1234.567, '($#,##0.00_);[Red]($#,##0.00)' ];
777               push @formats, [ 0x09, 0.567,      0,         '0%' ];
778               push @formats, [ 0x0a, 0.567,      0,         '0.00%' ];
779               push @formats, [ 0x0b, 1234.567,   0,         '0.00E+00' ];
780               push @formats, [ 0x0c, 0.75,       0,         '# ?/?' ];
781               push @formats, [ 0x0d, 0.3125,     0,         '# ??/??' ];
782               push @formats, [ 0x0e, 36892.521,  0,         'm/d/yy' ];
783               push @formats, [ 0x0f, 36892.521,  0,         'd-mmm-yy' ];
784               push @formats, [ 0x10, 36892.521,  0,         'd-mmm' ];
785               push @formats, [ 0x11, 36892.521,  0,         'mmm-yy' ];
786               push @formats, [ 0x12, 36892.521,  0,         'h:mm AM/PM' ];
787               push @formats, [ 0x13, 36892.521,  0,         'h:mm:ss AM/PM' ];
788               push @formats, [ 0x14, 36892.521,  0,         'h:mm' ];
789               push @formats, [ 0x15, 36892.521,  0,         'h:mm:ss' ];
790               push @formats, [ 0x16, 36892.521,  0,         'm/d/yy h:mm' ];
791               push @formats, [ 0x25, 1234.567,   -1234.567, '(#,##0_);(#,##0)' ];
792               push @formats, [ 0x26, 1234.567,   -1234.567, '(#,##0_);[Red](#,##0)' ];
793               push @formats, [ 0x27, 1234.567,   -1234.567, '(#,##0.00_);(#,##0.00)' ];
794               push @formats, [ 0x28, 1234.567,   -1234.567, '(#,##0.00_);[Red](#,##0.00)' ];
795               push @formats, [ 0x29, 1234.567,   -1234.567, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' ];
796               push @formats, [ 0x2a, 1234.567,   -1234.567, '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' ];
797               push @formats, [ 0x2b, 1234.567,   -1234.567, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' ];
798               push @formats, [ 0x2c, 1234.567,   -1234.567, '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' ];
799               push @formats, [ 0x2d, 36892.521,  0,         'mm:ss' ];
800               push @formats, [ 0x2e, 3.0153,     0,         '[h]:mm:ss' ];
801               push @formats, [ 0x2f, 36892.521,  0,         'mm:ss.0' ];
802               push @formats, [ 0x30, 1234.567,   0,         '##0.0E+0' ];
803               push @formats, [ 0x31, 1234.567,   0,         '@' ];
804               #>>>
805
806               my $i;
807               foreach my $format ( @formats ) {
808                   my $style = $workbook->add_format();
809                   $style->set_num_format( $format->[0] );
810
811                   $i++;
812                   $worksheet->write( $i, 0, $format->[0], $center );
813                   $worksheet->write( $i, 1, sprintf( "0x%02X", $format->[0] ), $center );
814                   $worksheet->write( $i, 2, $format->[1], $center );
815                   $worksheet->write( $i, 3, $format->[1], $style );
816
817                   if ( $format->[2] ) {
818                       $worksheet->write( $i, 4, $format->[2], $style );
819                   }
820
821                   $worksheet->write_string( $i, 5, $format->[3] );
822               }
823           }
824
825
826           ######################################################################
827           #
828           # Demonstrate the font options.
829           #
830           sub fonts {
831
832               my $worksheet = $workbook->add_worksheet( 'Fonts' );
833
834               $worksheet->set_column( 0, 0, 30 );
835               $worksheet->set_column( 1, 1, 10 );
836
837               $worksheet->write( 0, 0, "Font name", $heading );
838               $worksheet->write( 0, 1, "Font size", $heading );
839
840               my @fonts;
841               push @fonts, [ 10, 'Arial' ];
842               push @fonts, [ 12, 'Arial' ];
843               push @fonts, [ 14, 'Arial' ];
844               push @fonts, [ 12, 'Arial Black' ];
845               push @fonts, [ 12, 'Arial Narrow' ];
846               push @fonts, [ 12, 'Century Schoolbook' ];
847               push @fonts, [ 12, 'Courier' ];
848               push @fonts, [ 12, 'Courier New' ];
849               push @fonts, [ 12, 'Garamond' ];
850               push @fonts, [ 12, 'Impact' ];
851               push @fonts, [ 12, 'Lucida Handwriting' ];
852               push @fonts, [ 12, 'Times New Roman' ];
853               push @fonts, [ 12, 'Symbol' ];
854               push @fonts, [ 12, 'Wingdings' ];
855               push @fonts, [ 12, 'A font that doesn\'t exist' ];
856
857               my $i;
858               foreach my $font ( @fonts ) {
859                   my $format = $workbook->add_format();
860
861                   $format->set_size( $font->[0] );
862                   $format->set_font( $font->[1] );
863
864                   $i++;
865                   $worksheet->write( $i, 0, $font->[1], $format );
866                   $worksheet->write( $i, 1, $font->[0], $format );
867               }
868
869           }
870
871
872           ######################################################################
873           #
874           # Demonstrate the standard Excel border styles.
875           #
876           sub borders {
877
878               my $worksheet = $workbook->add_worksheet( 'Borders' );
879
880               $worksheet->set_column( 0, 4, 10 );
881               $worksheet->set_column( 5, 5, 40 );
882
883               $worksheet->write( 0, 0, "Index",                                $heading );
884               $worksheet->write( 0, 1, "Index",                                $heading );
885               $worksheet->write( 0, 3, "Style",                                $heading );
886               $worksheet->write( 0, 5, "The style is highlighted in red for ", $heading );
887               $worksheet->write( 1, 5, "emphasis, the default color is black.",
888                   $heading );
889
890               for my $i ( 0 .. 13 ) {
891                   my $format = $workbook->add_format();
892                   $format->set_border( $i );
893                   $format->set_border_color( 'red' );
894                   $format->set_align( 'center' );
895
896                   $worksheet->write( ( 2 * ( $i + 1 ) ), 0, $i, $center );
897                   $worksheet->write( ( 2 * ( $i + 1 ) ),
898                       1, sprintf( "0x%02X", $i ), $center );
899
900                   $worksheet->write( ( 2 * ( $i + 1 ) ), 3, "Border", $format );
901               }
902
903               $worksheet->write( 30, 0, "Diag type",              $heading );
904               $worksheet->write( 30, 1, "Index",                  $heading );
905               $worksheet->write( 30, 3, "Style",                  $heading );
906               $worksheet->write( 30, 5, "Diagonal Border styles", $heading );
907
908               for my $i ( 1 .. 3 ) {
909                   my $format = $workbook->add_format();
910                   $format->set_diag_type( $i );
911                   $format->set_diag_border( 1 );
912                   $format->set_diag_color( 'red' );
913                   $format->set_align( 'center' );
914
915                   $worksheet->write( ( 2 * ( $i + 15 ) ), 0, $i, $center );
916                   $worksheet->write( ( 2 * ( $i + 15 ) ),
917                       1, sprintf( "0x%02X", $i ), $center );
918
919                   $worksheet->write( ( 2 * ( $i + 15 ) ), 3, "Border", $format );
920               }
921           }
922
923
924           ######################################################################
925           #
926           # Demonstrate the standard Excel cell patterns.
927           #
928           sub patterns {
929
930               my $worksheet = $workbook->add_worksheet( 'Patterns' );
931
932               $worksheet->set_column( 0, 4, 10 );
933               $worksheet->set_column( 5, 5, 50 );
934
935               $worksheet->write( 0, 0, "Index",   $heading );
936               $worksheet->write( 0, 1, "Index",   $heading );
937               $worksheet->write( 0, 3, "Pattern", $heading );
938
939               $worksheet->write( 0, 5, "The background colour has been set to silver.",
940                   $heading );
941               $worksheet->write( 1, 5, "The foreground colour has been set to green.",
942                   $heading );
943
944               for my $i ( 0 .. 18 ) {
945                   my $format = $workbook->add_format();
946
947                   $format->set_pattern( $i );
948                   $format->set_bg_color( 'silver' );
949                   $format->set_fg_color( 'green' );
950                   $format->set_align( 'center' );
951
952                   $worksheet->write( ( 2 * ( $i + 1 ) ), 0, $i, $center );
953                   $worksheet->write( ( 2 * ( $i + 1 ) ),
954                       1, sprintf( "0x%02X", $i ), $center );
955
956                   $worksheet->write( ( 2 * ( $i + 1 ) ), 3, "Pattern", $format );
957
958                   if ( $i == 1 ) {
959                       $worksheet->write( ( 2 * ( $i + 1 ) ),
960                           5, "This is solid colour, the most useful pattern.", $heading );
961                   }
962               }
963           }
964
965
966           ######################################################################
967           #
968           # Demonstrate the standard Excel cell alignments.
969           #
970           sub alignment {
971
972               my $worksheet = $workbook->add_worksheet( 'Alignment' );
973
974               $worksheet->set_column( 0, 7, 12 );
975               $worksheet->set_row( 0, 40 );
976               $worksheet->set_selection( 7, 0 );
977
978               my $format01 = $workbook->add_format();
979               my $format02 = $workbook->add_format();
980               my $format03 = $workbook->add_format();
981               my $format04 = $workbook->add_format();
982               my $format05 = $workbook->add_format();
983               my $format06 = $workbook->add_format();
984               my $format07 = $workbook->add_format();
985               my $format08 = $workbook->add_format();
986               my $format09 = $workbook->add_format();
987               my $format10 = $workbook->add_format();
988               my $format11 = $workbook->add_format();
989               my $format12 = $workbook->add_format();
990               my $format13 = $workbook->add_format();
991               my $format14 = $workbook->add_format();
992               my $format15 = $workbook->add_format();
993               my $format16 = $workbook->add_format();
994               my $format17 = $workbook->add_format();
995
996               $format02->set_align( 'top' );
997               $format03->set_align( 'bottom' );
998               $format04->set_align( 'vcenter' );
999               $format05->set_align( 'vjustify' );
1000               $format06->set_text_wrap();
1001
1002               $format07->set_align( 'left' );
1003               $format08->set_align( 'right' );
1004               $format09->set_align( 'center' );
1005               $format10->set_align( 'fill' );
1006               $format11->set_align( 'justify' );
1007               $format12->set_merge();
1008
1009               $format13->set_rotation( 45 );
1010               $format14->set_rotation( -45 );
1011               $format15->set_rotation( 270 );
1012
1013               $format16->set_shrink();
1014               $format17->set_indent( 1 );
1015
1016               $worksheet->write( 0, 0, 'Vertical',   $heading );
1017               $worksheet->write( 0, 1, 'top',        $format02 );
1018               $worksheet->write( 0, 2, 'bottom',     $format03 );
1019               $worksheet->write( 0, 3, 'vcenter',    $format04 );
1020               $worksheet->write( 0, 4, 'vjustify',   $format05 );
1021               $worksheet->write( 0, 5, "text\nwrap", $format06 );
1022
1023               $worksheet->write( 2, 0, 'Horizontal', $heading );
1024               $worksheet->write( 2, 1, 'left',       $format07 );
1025               $worksheet->write( 2, 2, 'right',      $format08 );
1026               $worksheet->write( 2, 3, 'center',     $format09 );
1027               $worksheet->write( 2, 4, 'fill',       $format10 );
1028               $worksheet->write( 2, 5, 'justify',    $format11 );
1029
1030               $worksheet->write( 3, 1, 'merge', $format12 );
1031               $worksheet->write( 3, 2, '',      $format12 );
1032
1033               $worksheet->write( 3, 3, 'Shrink ' x 3, $format16 );
1034               $worksheet->write( 3, 4, 'Indent',      $format17 );
1035
1036
1037               $worksheet->write( 5, 0, 'Rotation',   $heading );
1038               $worksheet->write( 5, 1, 'Rotate 45',  $format13 );
1039               $worksheet->write( 6, 1, 'Rotate -45', $format14 );
1040               $worksheet->write( 7, 1, 'Rotate 270', $format15 );
1041           }
1042
1043
1044           ######################################################################
1045           #
1046           # Demonstrate other miscellaneous features.
1047           #
1048           sub misc {
1049
1050               my $worksheet = $workbook->add_worksheet( 'Miscellaneous' );
1051
1052               $worksheet->set_column( 2, 2, 25 );
1053
1054               my $format01 = $workbook->add_format();
1055               my $format02 = $workbook->add_format();
1056               my $format03 = $workbook->add_format();
1057               my $format04 = $workbook->add_format();
1058               my $format05 = $workbook->add_format();
1059               my $format06 = $workbook->add_format();
1060               my $format07 = $workbook->add_format();
1061
1062               $format01->set_underline( 0x01 );
1063               $format02->set_underline( 0x02 );
1064               $format03->set_underline( 0x21 );
1065               $format04->set_underline( 0x22 );
1066               $format05->set_font_strikeout();
1067               $format06->set_font_outline();
1068               $format07->set_font_shadow();
1069
1070               $worksheet->write( 1,  2, 'Underline  0x01',          $format01 );
1071               $worksheet->write( 3,  2, 'Underline  0x02',          $format02 );
1072               $worksheet->write( 5,  2, 'Underline  0x21',          $format03 );
1073               $worksheet->write( 7,  2, 'Underline  0x22',          $format04 );
1074               $worksheet->write( 9,  2, 'Strikeout',                $format05 );
1075               $worksheet->write( 11, 2, 'Outline (Macintosh only)', $format06 );
1076               $worksheet->write( 13, 2, 'Shadow (Macintosh only)',  $format07 );
1077           }
1078
1079
1080           $workbook->close();
1081
1082           __END__
1083
1084       Download this example:
1085       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/formats.pl>
1086
1087   Example: regions.pl
1088       An example of how to use the Excel::Writer::XLSX module to write a
1089       basic Excel workbook with multiple worksheets.
1090
1091       Source code for this example:
1092
1093           #!/usr/bin/perl -w
1094
1095           ###############################################################################
1096           #
1097           # An example of how to use the Excel::Writer::XLSX module to write a basic
1098           # Excel workbook with multiple worksheets.
1099           #
1100           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
1101           #
1102
1103           use strict;
1104           use Excel::Writer::XLSX;
1105
1106           # Create a new Excel workbook
1107           my $workbook = Excel::Writer::XLSX->new( 'regions.xlsx' );
1108
1109           # Add some worksheets
1110           my $north = $workbook->add_worksheet( "North" );
1111           my $south = $workbook->add_worksheet( "South" );
1112           my $east  = $workbook->add_worksheet( "East" );
1113           my $west  = $workbook->add_worksheet( "West" );
1114
1115           # Add a Format
1116           my $format = $workbook->add_format();
1117           $format->set_bold();
1118           $format->set_color( 'blue' );
1119
1120           # Add a caption to each worksheet
1121           foreach my $worksheet ( $workbook->sheets() ) {
1122               $worksheet->write( 0, 0, "Sales", $format );
1123           }
1124
1125           # Write some data
1126           $north->write( 0, 1, 200000 );
1127           $south->write( 0, 1, 100000 );
1128           $east->write( 0, 1, 150000 );
1129           $west->write( 0, 1, 100000 );
1130
1131           # Set the active worksheet
1132           $south->activate();
1133
1134           # Set the width of the first column
1135           $south->set_column( 0, 0, 20 );
1136
1137           # Set the active cell
1138           $south->set_selection( 0, 1 );
1139
1140           $workbook->close();
1141
1142           __END__
1143
1144       Download this example:
1145       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/regions.pl>
1146
1147   Example: stats.pl
1148       A simple example of how to use functions with the Excel::Writer::XLSX
1149       module.
1150
1151       Source code for this example:
1152
1153           #!/usr/bin/perl -w
1154
1155           ###############################################################################
1156           #
1157           # A simple example of how to use functions with the Excel::Writer::XLSX
1158           # module.
1159           #
1160           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
1161           #
1162
1163           use strict;
1164           use Excel::Writer::XLSX;
1165
1166           # Create a new workbook and add a worksheet
1167           my $workbook  = Excel::Writer::XLSX->new( 'stats.xlsx' );
1168           my $worksheet = $workbook->add_worksheet( 'Test data' );
1169
1170           # Set the column width for columns 1
1171           $worksheet->set_column( 0, 0, 20 );
1172
1173
1174           # Create a format for the headings
1175           my $format = $workbook->add_format();
1176           $format->set_bold();
1177
1178
1179           # Write the sample data
1180           $worksheet->write( 0, 0, 'Sample', $format );
1181           $worksheet->write( 0, 1, 1 );
1182           $worksheet->write( 0, 2, 2 );
1183           $worksheet->write( 0, 3, 3 );
1184           $worksheet->write( 0, 4, 4 );
1185           $worksheet->write( 0, 5, 5 );
1186           $worksheet->write( 0, 6, 6 );
1187           $worksheet->write( 0, 7, 7 );
1188           $worksheet->write( 0, 8, 8 );
1189
1190           $worksheet->write( 1, 0, 'Length', $format );
1191           $worksheet->write( 1, 1, 25.4 );
1192           $worksheet->write( 1, 2, 25.4 );
1193           $worksheet->write( 1, 3, 24.8 );
1194           $worksheet->write( 1, 4, 25.0 );
1195           $worksheet->write( 1, 5, 25.3 );
1196           $worksheet->write( 1, 6, 24.9 );
1197           $worksheet->write( 1, 7, 25.2 );
1198           $worksheet->write( 1, 8, 24.8 );
1199
1200           # Write some statistical functions
1201           $worksheet->write( 4, 0, 'Count', $format );
1202           $worksheet->write( 4, 1, '=COUNT(B1:I1)' );
1203
1204           $worksheet->write( 5, 0, 'Sum', $format );
1205           $worksheet->write( 5, 1, '=SUM(B2:I2)' );
1206
1207           $worksheet->write( 6, 0, 'Average', $format );
1208           $worksheet->write( 6, 1, '=AVERAGE(B2:I2)' );
1209
1210           $worksheet->write( 7, 0, 'Min', $format );
1211           $worksheet->write( 7, 1, '=MIN(B2:I2)' );
1212
1213           $worksheet->write( 8, 0, 'Max', $format );
1214           $worksheet->write( 8, 1, '=MAX(B2:I2)' );
1215
1216           $worksheet->write( 9, 0, 'Standard Deviation', $format );
1217           $worksheet->write( 9, 1, '=STDEV(B2:I2)' );
1218
1219           $worksheet->write( 10, 0, 'Kurtosis', $format );
1220           $worksheet->write( 10, 1, '=KURT(B2:I2)' );
1221
1222           $workbook->close();
1223
1224           __END__
1225
1226       Download this example:
1227       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/stats.pl>
1228
1229   Example: autofilter.pl
1230       An example of how to create autofilters with Excel::Writer::XLSX.
1231
1232       An autofilter is a way of adding drop down lists to the headers of a 2D
1233       range of worksheet data. This allows users to filter the data based on
1234       simple criteria so that some data is shown and some is hidden.
1235
1236       Source code for this example:
1237
1238           #!/usr/bin/perl
1239
1240           ###############################################################################
1241           #
1242           # An example of how to create autofilters with Excel::Writer::XLSX.
1243           #
1244           # An autofilter is a way of adding drop down lists to the headers of a 2D range
1245           # of worksheet data. This allows users to filter the data based on
1246           # simple criteria so that some data is shown and some is hidden.
1247           #
1248           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
1249           #
1250
1251           use strict;
1252           use warnings;
1253           use Excel::Writer::XLSX;
1254
1255           my $workbook = Excel::Writer::XLSX->new( 'autofilter.xlsx' );
1256
1257           my $worksheet1 = $workbook->add_worksheet();
1258           my $worksheet2 = $workbook->add_worksheet();
1259           my $worksheet3 = $workbook->add_worksheet();
1260           my $worksheet4 = $workbook->add_worksheet();
1261           my $worksheet5 = $workbook->add_worksheet();
1262           my $worksheet6 = $workbook->add_worksheet();
1263
1264           my $bold = $workbook->add_format( bold => 1 );
1265
1266
1267           # Extract the data embedded at the end of this file.
1268           my @headings = split ' ', <DATA>;
1269           my @data;
1270           push @data, [split] while <DATA>;
1271
1272
1273           # Set up several sheets with the same data.
1274           for my $worksheet ( $workbook->sheets() ) {
1275               $worksheet->set_column( 'A:D', 12 );
1276               $worksheet->set_row( 0, 20, $bold );
1277               $worksheet->write( 'A1', \@headings );
1278           }
1279
1280
1281           ###############################################################################
1282           #
1283           # Example 1. Autofilter without conditions.
1284           #
1285
1286           $worksheet1->autofilter( 'A1:D51' );
1287           $worksheet1->write( 'A2', [ [@data] ] );
1288
1289
1290           ###############################################################################
1291           #
1292           #
1293           # Example 2. Autofilter with a filter condition in the first column.
1294           #
1295
1296           # The range in this example is the same as above but in row-column notation.
1297           $worksheet2->autofilter( 0, 0, 50, 3 );
1298
1299           # The placeholder "Region" in the filter is ignored and can be any string
1300           # that adds clarity to the expression.
1301           #
1302           $worksheet2->filter_column( 0, 'Region eq East' );
1303
1304           #
1305           # Hide the rows that don't match the filter criteria.
1306           #
1307           my $row = 1;
1308
1309           for my $row_data ( @data ) {
1310               my $region = $row_data->[0];
1311
1312               if ( $region eq 'East' ) {
1313
1314                   # Row is visible.
1315               }
1316               else {
1317
1318                   # Hide row.
1319                   $worksheet2->set_row( $row, undef, undef, 1 );
1320               }
1321
1322               $worksheet2->write( $row++, 0, $row_data );
1323           }
1324
1325
1326           ###############################################################################
1327           #
1328           #
1329           # Example 3. Autofilter with a dual filter condition in one of the columns.
1330           #
1331
1332           $worksheet3->autofilter( 'A1:D51' );
1333
1334           $worksheet3->filter_column( 'A', 'x eq East or x eq South' );
1335
1336           #
1337           # Hide the rows that don't match the filter criteria.
1338           #
1339           $row = 1;
1340
1341           for my $row_data ( @data ) {
1342               my $region = $row_data->[0];
1343
1344               if ( $region eq 'East' or $region eq 'South' ) {
1345
1346                   # Row is visible.
1347               }
1348               else {
1349
1350                   # Hide row.
1351                   $worksheet3->set_row( $row, undef, undef, 1 );
1352               }
1353
1354               $worksheet3->write( $row++, 0, $row_data );
1355           }
1356
1357
1358           ###############################################################################
1359           #
1360           #
1361           # Example 4. Autofilter with filter conditions in two columns.
1362           #
1363
1364           $worksheet4->autofilter( 'A1:D51' );
1365
1366           $worksheet4->filter_column( 'A', 'x eq East' );
1367           $worksheet4->filter_column( 'C', 'x > 3000 and x < 8000' );
1368
1369           #
1370           # Hide the rows that don't match the filter criteria.
1371           #
1372           $row = 1;
1373
1374           for my $row_data ( @data ) {
1375               my $region = $row_data->[0];
1376               my $volume = $row_data->[2];
1377
1378               if (    $region eq 'East'
1379                   and $volume > 3000
1380                   and $volume < 8000 )
1381               {
1382
1383                   # Row is visible.
1384               }
1385               else {
1386
1387                   # Hide row.
1388                   $worksheet4->set_row( $row, undef, undef, 1 );
1389               }
1390
1391               $worksheet4->write( $row++, 0, $row_data );
1392           }
1393
1394
1395           ###############################################################################
1396           #
1397           #
1398           # Example 5. Autofilter with filter for blanks.
1399           #
1400
1401           # Create a blank cell in our test data.
1402           $data[5]->[0] = '';
1403
1404
1405           $worksheet5->autofilter( 'A1:D51' );
1406           $worksheet5->filter_column( 'A', 'x == Blanks' );
1407
1408           #
1409           # Hide the rows that don't match the filter criteria.
1410           #
1411           $row = 1;
1412
1413           for my $row_data ( @data ) {
1414               my $region = $row_data->[0];
1415
1416               if ( $region eq '' ) {
1417
1418                   # Row is visible.
1419               }
1420               else {
1421
1422                   # Hide row.
1423                   $worksheet5->set_row( $row, undef, undef, 1 );
1424               }
1425
1426               $worksheet5->write( $row++, 0, $row_data );
1427           }
1428
1429
1430           ###############################################################################
1431           #
1432           #
1433           # Example 6. Autofilter with filter for non-blanks.
1434           #
1435
1436
1437           $worksheet6->autofilter( 'A1:D51' );
1438           $worksheet6->filter_column( 'A', 'x == NonBlanks' );
1439
1440           #
1441           # Hide the rows that don't match the filter criteria.
1442           #
1443           $row = 1;
1444
1445           for my $row_data ( @data ) {
1446               my $region = $row_data->[0];
1447
1448               if ( $region ne '' ) {
1449
1450                   # Row is visible.
1451               }
1452               else {
1453
1454                   # Hide row.
1455                   $worksheet6->set_row( $row, undef, undef, 1 );
1456               }
1457
1458               $worksheet6->write( $row++, 0, $row_data );
1459           }
1460
1461           $workbook->close();
1462
1463           __DATA__
1464           Region    Item      Volume    Month
1465           East      Apple     9000      July
1466           East      Apple     5000      July
1467           South     Orange    9000      September
1468           North     Apple     2000      November
1469           West      Apple     9000      November
1470           South     Pear      7000      October
1471           North     Pear      9000      August
1472           West      Orange    1000      December
1473           West      Grape     1000      November
1474           South     Pear      10000     April
1475           West      Grape     6000      January
1476           South     Orange    3000      May
1477           North     Apple     3000      December
1478           South     Apple     7000      February
1479           West      Grape     1000      December
1480           East      Grape     8000      February
1481           South     Grape     10000     June
1482           West      Pear      7000      December
1483           South     Apple     2000      October
1484           East      Grape     7000      December
1485           North     Grape     6000      April
1486           East      Pear      8000      February
1487           North     Apple     7000      August
1488           North     Orange    7000      July
1489           North     Apple     6000      June
1490           South     Grape     8000      September
1491           West      Apple     3000      October
1492           South     Orange    10000     November
1493           West      Grape     4000      July
1494           North     Orange    5000      August
1495           East      Orange    1000      November
1496           East      Orange    4000      October
1497           North     Grape     5000      August
1498           East      Apple     1000      December
1499           South     Apple     10000     March
1500           East      Grape     7000      October
1501           West      Grape     1000      September
1502           East      Grape     10000     October
1503           South     Orange    8000      March
1504           North     Apple     4000      July
1505           South     Orange    5000      July
1506           West      Apple     4000      June
1507           East      Apple     5000      April
1508           North     Pear      3000      August
1509           East      Grape     9000      November
1510           North     Orange    8000      October
1511           East      Apple     10000     June
1512           South     Pear      1000      December
1513           North     Grape     10000     July
1514           East      Grape     6000      February
1515
1516       Download this example:
1517       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/autofilter.pl>
1518
1519   Example: array_formula.pl
1520       Example of how to use the Excel::Writer::XLSX module to write simple
1521       array formulas.
1522
1523       Source code for this example:
1524
1525           #!/usr/bin/perl
1526
1527           #######################################################################
1528           #
1529           # Example of how to use the Excel::Writer::XLSX module to write simple
1530           # array formulas.
1531           #
1532           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
1533           #
1534
1535           use strict;
1536           use warnings;
1537           use Excel::Writer::XLSX;
1538
1539           # Create a new workbook and add a worksheet
1540           my $workbook  = Excel::Writer::XLSX->new( 'array_formula.xlsx' );
1541           my $worksheet = $workbook->add_worksheet();
1542
1543           # Write some test data.
1544           $worksheet->write( 'B1', [ [ 500, 10 ], [ 300, 15 ] ] );
1545           $worksheet->write( 'B5', [ [ 1, 2, 3 ], [ 20234, 21003, 10000 ] ] );
1546
1547           # Write an array formula that returns a single value
1548           $worksheet->write( 'A1', '{=SUM(B1:C1*B2:C2)}' );
1549
1550           # Same as above but more verbose.
1551           $worksheet->write_array_formula( 'A2:A2', '{=SUM(B1:C1*B2:C2)}' );
1552
1553           # Write an array formula that returns a range of values
1554           $worksheet->write_array_formula( 'A5:A7', '{=TREND(C5:C7,B5:B7)}' );
1555
1556           $workbook->close();
1557
1558           __END__
1559
1560       Download this example:
1561       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/array_formula.pl>
1562
1563   Example: cgi.pl
1564       Example of how to use the Excel::Writer::XLSX module to send an Excel
1565       file to a browser in a CGI program.
1566
1567       On Windows the hash-bang line should be something like:
1568
1569           #!C:\Perl\bin\perl.exe
1570
1571       The "Content-Disposition" line will cause a prompt to be generated to
1572       save the file. If you want to stream the file to the browser instead,
1573       comment out that line as shown below.
1574
1575           #!/usr/bin/perl
1576
1577           ###############################################################################
1578           #
1579           # Example of how to use the Excel::Writer::XLSX module to send an Excel
1580           # file to a browser in a CGI program.
1581           #
1582           # On Windows the hash-bang line should be something like:
1583           #
1584           #     #!C:\Perl\bin\perl.exe
1585           #
1586           # The "Content-Disposition" line will cause a prompt to be generated to save
1587           # the file. If you want to stream the file to the browser instead, comment out
1588           # that line as shown below.
1589           #
1590           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
1591           #
1592
1593           use strict;
1594           use warnings;
1595           use Excel::Writer::XLSX;
1596
1597           # Set the filename and send the content type
1598           my $filename = "cgitest.xlsx";
1599
1600           print "Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n";
1601
1602           # The Content-Disposition will generate a prompt to save the file. If you want
1603           # to stream the file to the browser, comment out the following line.
1604           print "Content-Disposition: attachment; filename=$filename\n";
1605           print "\n";
1606
1607           # Redirect the output to STDOUT. Binmode the filehandle in case it is needed.
1608           binmode STDOUT;
1609
1610           my $workbook  = Excel::Writer::XLSX->new( \*STDOUT );
1611           my $worksheet = $workbook->add_worksheet();
1612
1613
1614           # Set the column width for column 1
1615           $worksheet->set_column( 0, 0, 20 );
1616
1617
1618           # Create a format
1619           my $format = $workbook->add_format();
1620           $format->set_bold();
1621           $format->set_size( 15 );
1622           $format->set_color( 'blue' );
1623
1624
1625           # Write to the workbook
1626           $worksheet->write( 0, 0, "Hi Excel!", $format );
1627
1628           $workbook->close();
1629
1630           __END__
1631
1632       Download this example:
1633       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/cgi.pl>
1634
1635   Example: chart_area.pl
1636       A demo of an Area chart in Excel::Writer::XLSX.
1637
1638       Source code for this example:
1639
1640           #!/usr/bin/perl
1641
1642           #######################################################################
1643           #
1644           # A demo of an Area chart in Excel::Writer::XLSX.
1645           #
1646           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
1647           #
1648
1649           use strict;
1650           use warnings;
1651           use Excel::Writer::XLSX;
1652
1653           my $workbook  = Excel::Writer::XLSX->new( 'chart_area.xlsx' );
1654           my $worksheet = $workbook->add_worksheet();
1655           my $bold      = $workbook->add_format( bold => 1 );
1656
1657           # Add the worksheet data that the charts will refer to.
1658           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
1659           my $data = [
1660               [ 2,  3,  4,  5,  6,  7 ],
1661               [ 40, 40, 50, 30, 25, 50 ],
1662               [ 30, 25, 30, 10, 5,  10 ],
1663
1664           ];
1665
1666           $worksheet->write( 'A1', $headings, $bold );
1667           $worksheet->write( 'A2', $data );
1668
1669           # Create a new chart object. In this case an embedded chart.
1670           my $chart1 = $workbook->add_chart( type => 'area', embedded => 1 );
1671
1672           # Configure the first series.
1673           $chart1->add_series(
1674               name       => '=Sheet1!$B$1',
1675               categories => '=Sheet1!$A$2:$A$7',
1676               values     => '=Sheet1!$B$2:$B$7',
1677           );
1678
1679           # Configure second series. Note alternative use of array ref to define
1680           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
1681           $chart1->add_series(
1682               name       => '=Sheet1!$C$1',
1683               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1684               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1685           );
1686
1687           # Add a chart title and some axis labels.
1688           $chart1->set_title ( name => 'Results of sample analysis' );
1689           $chart1->set_x_axis( name => 'Test number' );
1690           $chart1->set_y_axis( name => 'Sample length (mm)' );
1691
1692           # Set an Excel chart style. Blue colors with white outline and shadow.
1693           $chart1->set_style( 11 );
1694
1695           # Insert the chart into the worksheet (with an offset).
1696           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
1697
1698
1699           #
1700           # Create a stacked chart sub-type
1701           #
1702           my $chart2 = $workbook->add_chart(
1703               type     => 'area',
1704               embedded => 1,
1705               subtype  => 'stacked'
1706           );
1707
1708           # Configure the first series.
1709           $chart2->add_series(
1710               name       => '=Sheet1!$B$1',
1711               categories => '=Sheet1!$A$2:$A$7',
1712               values     => '=Sheet1!$B$2:$B$7',
1713           );
1714
1715           # Configure second series.
1716           $chart2->add_series(
1717               name       => '=Sheet1!$C$1',
1718               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1719               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1720           );
1721
1722           # Add a chart title and some axis labels.
1723           $chart2->set_title ( name => 'Stacked Chart' );
1724           $chart2->set_x_axis( name => 'Test number' );
1725           $chart2->set_y_axis( name => 'Sample length (mm)' );
1726
1727           # Set an Excel chart style. Blue colors with white outline and shadow.
1728           $chart2->set_style( 12 );
1729
1730           # Insert the chart into the worksheet (with an offset).
1731           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
1732
1733
1734           #
1735           # Create a percent stacked chart sub-type
1736           #
1737           my $chart3 = $workbook->add_chart(
1738               type     => 'area',
1739               embedded => 1,
1740               subtype  => 'percent_stacked'
1741           );
1742
1743           # Configure the first series.
1744           $chart3->add_series(
1745               name       => '=Sheet1!$B$1',
1746               categories => '=Sheet1!$A$2:$A$7',
1747               values     => '=Sheet1!$B$2:$B$7',
1748           );
1749
1750           # Configure second series.
1751           $chart3->add_series(
1752               name       => '=Sheet1!$C$1',
1753               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1754               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1755           );
1756
1757           # Add a chart title and some axis labels.
1758           $chart3->set_title ( name => 'Percent Stacked Chart' );
1759           $chart3->set_x_axis( name => 'Test number' );
1760           $chart3->set_y_axis( name => 'Sample length (mm)' );
1761
1762           # Set an Excel chart style. Blue colors with white outline and shadow.
1763           $chart3->set_style( 13 );
1764
1765           # Insert the chart into the worksheet (with an offset).
1766           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
1767
1768           $workbook->close();
1769
1770           __END__
1771
1772       Download this example:
1773       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_area.pl>
1774
1775   Example: chart_bar.pl
1776       A demo of an Bar chart in Excel::Writer::XLSX.
1777
1778       Source code for this example:
1779
1780           #!/usr/bin/perl
1781
1782           #######################################################################
1783           #
1784           # A demo of an Bar chart in Excel::Writer::XLSX.
1785           #
1786           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
1787           #
1788
1789           use strict;
1790           use warnings;
1791           use Excel::Writer::XLSX;
1792
1793           my $workbook  = Excel::Writer::XLSX->new( 'chart_bar.xlsx' );
1794           my $worksheet = $workbook->add_worksheet();
1795           my $bold      = $workbook->add_format( bold => 1 );
1796
1797           # Add the worksheet data that the charts will refer to.
1798           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
1799           my $data = [
1800               [ 2,  3,  4,  5,  6,  7 ],
1801               [ 10, 40, 50, 20, 10, 50 ],
1802               [ 30, 60, 70, 50, 40, 30 ],
1803
1804           ];
1805
1806           $worksheet->write( 'A1', $headings, $bold );
1807           $worksheet->write( 'A2', $data );
1808
1809           # Create a new chart object. In this case an embedded chart.
1810           my $chart1 = $workbook->add_chart( type => 'bar', embedded => 1 );
1811
1812           # Configure the first series.
1813           $chart1->add_series(
1814               name       => '=Sheet1!$B$1',
1815               categories => '=Sheet1!$A$2:$A$7',
1816               values     => '=Sheet1!$B$2:$B$7',
1817           );
1818
1819           # Configure second series. Note alternative use of array ref to define
1820           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
1821           $chart1->add_series(
1822               name       => '=Sheet1!$C$1',
1823               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1824               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1825           );
1826
1827           # Add a chart title and some axis labels.
1828           $chart1->set_title ( name => 'Results of sample analysis' );
1829           $chart1->set_x_axis( name => 'Test number' );
1830           $chart1->set_y_axis( name => 'Sample length (mm)' );
1831
1832           # Set an Excel chart style. Blue colors with white outline and shadow.
1833           $chart1->set_style( 11 );
1834
1835           # Insert the chart into the worksheet (with an offset).
1836           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
1837
1838
1839           #
1840           # Create a stacked chart sub-type
1841           #
1842           my $chart2 = $workbook->add_chart(
1843               type     => 'bar',
1844               embedded => 1,
1845               subtype  => 'stacked'
1846           );
1847
1848           # Configure the first series.
1849           $chart2->add_series(
1850               name       => '=Sheet1!$B$1',
1851               categories => '=Sheet1!$A$2:$A$7',
1852               values     => '=Sheet1!$B$2:$B$7',
1853           );
1854
1855           # Configure second series.
1856           $chart2->add_series(
1857               name       => '=Sheet1!$C$1',
1858               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1859               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1860           );
1861
1862           # Add a chart title and some axis labels.
1863           $chart2->set_title ( name => 'Stacked Chart' );
1864           $chart2->set_x_axis( name => 'Test number' );
1865           $chart2->set_y_axis( name => 'Sample length (mm)' );
1866
1867           # Set an Excel chart style. Blue colors with white outline and shadow.
1868           $chart2->set_style( 12 );
1869
1870           # Insert the chart into the worksheet (with an offset).
1871           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
1872
1873
1874           #
1875           # Create a percent stacked chart sub-type
1876           #
1877           my $chart3 = $workbook->add_chart(
1878               type     => 'bar',
1879               embedded => 1,
1880               subtype  => 'percent_stacked'
1881           );
1882
1883           # Configure the first series.
1884           $chart3->add_series(
1885               name       => '=Sheet1!$B$1',
1886               categories => '=Sheet1!$A$2:$A$7',
1887               values     => '=Sheet1!$B$2:$B$7',
1888           );
1889
1890           # Configure second series.
1891           $chart3->add_series(
1892               name       => '=Sheet1!$C$1',
1893               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1894               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1895           );
1896
1897           # Add a chart title and some axis labels.
1898           $chart3->set_title ( name => 'Percent Stacked Chart' );
1899           $chart3->set_x_axis( name => 'Test number' );
1900           $chart3->set_y_axis( name => 'Sample length (mm)' );
1901
1902           # Set an Excel chart style. Blue colors with white outline and shadow.
1903           $chart3->set_style( 13 );
1904
1905           # Insert the chart into the worksheet (with an offset).
1906           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
1907
1908           $workbook->close();
1909
1910           __END__
1911
1912       Download this example:
1913       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_bar.pl>
1914
1915   Example: chart_column.pl
1916       A demo of a Column chart in Excel::Writer::XLSX.
1917
1918       Source code for this example:
1919
1920           #!/usr/bin/perl
1921
1922           #######################################################################
1923           #
1924           # A demo of a Column chart in Excel::Writer::XLSX.
1925           #
1926           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
1927           #
1928
1929           use strict;
1930           use warnings;
1931           use Excel::Writer::XLSX;
1932
1933           my $workbook  = Excel::Writer::XLSX->new( 'chart_column.xlsx' );
1934           my $worksheet = $workbook->add_worksheet();
1935           my $bold      = $workbook->add_format( bold => 1 );
1936
1937           # Add the worksheet data that the charts will refer to.
1938           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
1939           my $data = [
1940               [ 2,  3,  4,  5,  6,  7 ],
1941               [ 10, 40, 50, 20, 10, 50 ],
1942               [ 30, 60, 70, 50, 40, 30 ],
1943
1944           ];
1945
1946           $worksheet->write( 'A1', $headings, $bold );
1947           $worksheet->write( 'A2', $data );
1948
1949           # Create a new chart object. In this case an embedded chart.
1950           my $chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
1951
1952           # Configure the first series.
1953           $chart1->add_series(
1954               name       => '=Sheet1!$B$1',
1955               categories => '=Sheet1!$A$2:$A$7',
1956               values     => '=Sheet1!$B$2:$B$7',
1957           );
1958
1959           # Configure second series. Note alternative use of array ref to define
1960           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
1961           $chart1->add_series(
1962               name       => '=Sheet1!$C$1',
1963               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1964               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1965           );
1966
1967           # Add a chart title and some axis labels.
1968           $chart1->set_title ( name => 'Results of sample analysis' );
1969           $chart1->set_x_axis( name => 'Test number' );
1970           $chart1->set_y_axis( name => 'Sample length (mm)' );
1971
1972           # Set an Excel chart style. Blue colors with white outline and shadow.
1973           $chart1->set_style( 11 );
1974
1975           # Insert the chart into the worksheet (with an offset).
1976           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
1977
1978
1979           #
1980           # Create a stacked chart sub-type
1981           #
1982           my $chart2 = $workbook->add_chart(
1983               type     => 'column',
1984               embedded => 1,
1985               subtype  => 'stacked'
1986           );
1987
1988           # Configure the first series.
1989           $chart2->add_series(
1990               name       => '=Sheet1!$B$1',
1991               categories => '=Sheet1!$A$2:$A$7',
1992               values     => '=Sheet1!$B$2:$B$7',
1993           );
1994
1995           # Configure second series.
1996           $chart2->add_series(
1997               name       => '=Sheet1!$C$1',
1998               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1999               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2000           );
2001
2002           # Add a chart title and some axis labels.
2003           $chart2->set_title ( name => 'Stacked Chart' );
2004           $chart2->set_x_axis( name => 'Test number' );
2005           $chart2->set_y_axis( name => 'Sample length (mm)' );
2006
2007           # Set an Excel chart style. Blue colors with white outline and shadow.
2008           $chart2->set_style( 12 );
2009
2010           # Insert the chart into the worksheet (with an offset).
2011           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
2012
2013
2014           #
2015           # Create a percent stacked chart sub-type
2016           #
2017           my $chart3 = $workbook->add_chart(
2018               type     => 'column',
2019               embedded => 1,
2020               subtype  => 'percent_stacked'
2021           );
2022
2023           # Configure the first series.
2024           $chart3->add_series(
2025               name       => '=Sheet1!$B$1',
2026               categories => '=Sheet1!$A$2:$A$7',
2027               values     => '=Sheet1!$B$2:$B$7',
2028           );
2029
2030           # Configure second series.
2031           $chart3->add_series(
2032               name       => '=Sheet1!$C$1',
2033               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2034               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2035           );
2036
2037           # Add a chart title and some axis labels.
2038           $chart3->set_title ( name => 'Percent Stacked Chart' );
2039           $chart3->set_x_axis( name => 'Test number' );
2040           $chart3->set_y_axis( name => 'Sample length (mm)' );
2041
2042           # Set an Excel chart style. Blue colors with white outline and shadow.
2043           $chart3->set_style( 13 );
2044
2045           # Insert the chart into the worksheet (with an offset).
2046           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
2047
2048           $workbook->close();
2049
2050           __END__
2051
2052       Download this example:
2053       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_column.pl>
2054
2055   Example: chart_line.pl
2056       A demo of a Line chart in Excel::Writer::XLSX.
2057
2058       Source code for this example:
2059
2060           #!/usr/bin/perl
2061
2062           #######################################################################
2063           #
2064           # A demo of a Line chart in Excel::Writer::XLSX.
2065           #
2066           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
2067           #
2068
2069           use strict;
2070           use warnings;
2071           use Excel::Writer::XLSX;
2072
2073           my $workbook  = Excel::Writer::XLSX->new( 'chart_line.xlsx' );
2074           my $worksheet = $workbook->add_worksheet();
2075           my $bold      = $workbook->add_format( bold => 1 );
2076
2077           # Add the worksheet data that the charts will refer to.
2078           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2079           my $data = [
2080               [ 2, 3, 4, 5, 6, 7 ],
2081               [ 10, 40, 50, 20, 10, 50 ],
2082               [ 30, 60, 70, 50, 40, 30 ],
2083
2084           ];
2085
2086           $worksheet->write( 'A1', $headings, $bold );
2087           $worksheet->write( 'A2', $data );
2088
2089           # Create a new chart object. In this case an embedded chart.
2090           my $chart = $workbook->add_chart( type => 'line', embedded => 1 );
2091
2092           # Configure the first series.
2093           $chart->add_series(
2094               name       => '=Sheet1!$B$1',
2095               categories => '=Sheet1!$A$2:$A$7',
2096               values     => '=Sheet1!$B$2:$B$7',
2097           );
2098
2099           # Configure second series. Note alternative use of array ref to define
2100           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2101           $chart->add_series(
2102               name       => '=Sheet1!$C$1',
2103               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2104               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2105           );
2106
2107           # Add a chart title and some axis labels.
2108           $chart->set_title ( name => 'Results of sample analysis' );
2109           $chart->set_x_axis( name => 'Test number' );
2110           $chart->set_y_axis( name => 'Sample length (mm)' );
2111
2112           # Set an Excel chart style. Colors with white outline and shadow.
2113           $chart->set_style( 10 );
2114
2115           # Insert the chart into the worksheet (with an offset).
2116           $worksheet->insert_chart( 'D2', $chart, { x_offset => 25, y_offset => 10 } );
2117
2118
2119           #
2120           # Create a stacked chart sub-type
2121           #
2122           my $chart2 = $workbook->add_chart(
2123               type     => 'line',
2124               embedded => 1,
2125               subtype  => 'stacked'
2126           );
2127
2128           # Configure the first series.
2129           $chart2->add_series(
2130               name       => '=Sheet1!$B$1',
2131               categories => '=Sheet1!$A$2:$A$7',
2132               values     => '=Sheet1!$B$2:$B$7',
2133           );
2134
2135           # Configure second series.
2136           $chart2->add_series(
2137               name       => '=Sheet1!$C$1',
2138               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2139               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2140           );
2141
2142           # Add a chart title and some axis labels.
2143           $chart2->set_title ( name => 'Stacked Chart' );
2144           $chart2->set_x_axis( name => 'Test number' );
2145           $chart2->set_y_axis( name => 'Sample length (mm)' );
2146
2147           # Set an Excel chart style. Blue colors with white outline and shadow.
2148           $chart2->set_style( 12 );
2149
2150           # Insert the chart into the worksheet (with an offset).
2151           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
2152
2153
2154           #
2155           # Create a percent stacked chart sub-type
2156           #
2157           my $chart3 = $workbook->add_chart(
2158               type     => 'line',
2159               embedded => 1,
2160               subtype  => 'percent_stacked'
2161           );
2162
2163           # Configure the first series.
2164           $chart3->add_series(
2165               name       => '=Sheet1!$B$1',
2166               categories => '=Sheet1!$A$2:$A$7',
2167               values     => '=Sheet1!$B$2:$B$7',
2168           );
2169
2170           # Configure second series.
2171           $chart3->add_series(
2172               name       => '=Sheet1!$C$1',
2173               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2174               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2175           );
2176
2177           # Add a chart title and some axis labels.
2178           $chart3->set_title ( name => 'Percent Stacked Chart' );
2179           $chart3->set_x_axis( name => 'Test number' );
2180           $chart3->set_y_axis( name => 'Sample length (mm)' );
2181
2182           # Set an Excel chart style. Blue colors with white outline and shadow.
2183           $chart3->set_style( 13 );
2184
2185           # Insert the chart into the worksheet (with an offset).
2186           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
2187
2188           $workbook->close();
2189
2190           __END__
2191
2192       Download this example:
2193       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_line.pl>
2194
2195   Example: chart_pie.pl
2196       A demo of a Pie chart in Excel::Writer::XLSX.
2197
2198       The demo also shows how to set segment colours. It is possible to
2199       define chart colors for most types of Excel::Writer::XLSX charts via
2200       the add_series() method. However, Pie and Doughtnut charts are a
2201       special case since each segment is represented as a point so it is
2202       necessary to assign formatting to each point in the series.
2203
2204       Source code for this example:
2205
2206           #!/usr/bin/perl
2207
2208           #######################################################################
2209           #
2210           # A demo of a Pie chart in Excel::Writer::XLSX.
2211           #
2212           # The demo also shows how to set segment colours. It is possible to define
2213           # chart colors for most types of Excel::Writer::XLSX charts via the
2214           # add_series() method. However, Pie and Doughtnut charts are a special case
2215           # since each segment is represented as a point so it is necessary to assign
2216           # formatting to each point in the series.
2217           #
2218           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
2219           #
2220
2221           use strict;
2222           use warnings;
2223           use Excel::Writer::XLSX;
2224
2225           my $workbook  = Excel::Writer::XLSX->new( 'chart_pie.xlsx' );
2226           my $worksheet = $workbook->add_worksheet();
2227           my $bold      = $workbook->add_format( bold => 1 );
2228
2229           # Add the worksheet data that the charts will refer to.
2230           my $headings = [ 'Category', 'Values' ];
2231           my $data = [
2232               [ 'Apple', 'Cherry', 'Pecan' ],
2233               [ 60,       30,       10     ],
2234           ];
2235
2236           $worksheet->write( 'A1', $headings, $bold );
2237           $worksheet->write( 'A2', $data );
2238
2239           # Create a new chart object. In this case an embedded chart.
2240           my $chart1 = $workbook->add_chart( type => 'pie', embedded => 1 );
2241
2242           # Configure the series. Note the use of the array ref to define ranges:
2243           # [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2244           # See below for an alternative syntax.
2245           $chart1->add_series(
2246               name       => 'Pie sales data',
2247               categories => [ 'Sheet1', 1, 3, 0, 0 ],
2248               values     => [ 'Sheet1', 1, 3, 1, 1 ],
2249           );
2250
2251           # Add a title.
2252           $chart1->set_title( name => 'Popular Pie Types' );
2253
2254           # Set an Excel chart style. Colors with white outline and shadow.
2255           $chart1->set_style( 10 );
2256
2257           # Insert the chart into the worksheet (with an offset).
2258           $worksheet->insert_chart( 'C2', $chart1, { x_offset => 25, y_offset => 10 } );
2259
2260
2261           #
2262           # Create a Pie chart with user defined segment colors.
2263           #
2264
2265           # Create an example Pie chart like above.
2266           my $chart2 = $workbook->add_chart( type => 'pie', embedded => 1 );
2267
2268           # Configure the series and add user defined segment colours.
2269           $chart2->add_series(
2270               name       => 'Pie sales data',
2271               categories => '=Sheet1!$A$2:$A$4',
2272               values     => '=Sheet1!$B$2:$B$4',
2273               points     => [
2274                   { fill => { color => '#5ABA10' } },
2275                   { fill => { color => '#FE110E' } },
2276                   { fill => { color => '#CA5C05' } },
2277               ],
2278           );
2279
2280           # Add a title.
2281           $chart2->set_title( name => 'Pie Chart with user defined colors' );
2282
2283
2284           # Insert the chart into the worksheet (with an offset).
2285           $worksheet->insert_chart( 'C18', $chart2, { x_offset => 25, y_offset => 10 } );
2286
2287
2288           #
2289           # Create a Pie chart with rotation of the segments.
2290           #
2291
2292           # Create an example Pie chart like above.
2293           my $chart3 = $workbook->add_chart( type => 'pie', embedded => 1 );
2294
2295           # Configure the series.
2296           $chart3->add_series(
2297               name       => 'Pie sales data',
2298               categories => '=Sheet1!$A$2:$A$4',
2299               values     => '=Sheet1!$B$2:$B$4',
2300           );
2301
2302           # Add a title.
2303           $chart3->set_title( name => 'Pie Chart with segment rotation' );
2304
2305           # Change the angle/rotation of the first segment.
2306           $chart3->set_rotation(90);
2307
2308           # Insert the chart into the worksheet (with an offset).
2309           $worksheet->insert_chart( 'C34', $chart3, { x_offset => 25, y_offset => 10 } );
2310
2311           $workbook->close();
2312
2313           __END__
2314
2315       Download this example:
2316       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_pie.pl>
2317
2318   Example: chart_doughnut.pl
2319       A demo of a Doughnut chart in Excel::Writer::XLSX.
2320
2321       The demo also shows how to set segment colours. It is possible to
2322       define chart colors for most types of Excel::Writer::XLSX charts via
2323       the add_series() method. However, Pie and Doughtnut charts are a
2324       special case since each segment is represented as a point so it is
2325       necessary to assign formatting to each point in the series.
2326
2327       Source code for this example:
2328
2329           #!/usr/bin/perl
2330
2331           #######################################################################
2332           #
2333           # A demo of a Doughnut chart in Excel::Writer::XLSX.
2334           #
2335           # The demo also shows how to set segment colours. It is possible to define
2336           # chart colors for most types of Excel::Writer::XLSX charts via the
2337           # add_series() method. However, Pie and Doughtnut charts are a special case
2338           # since each segment is represented as a point so it is necessary to assign
2339           # formatting to each point in the series.
2340           #
2341           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
2342           #
2343
2344           use strict;
2345           use warnings;
2346           use Excel::Writer::XLSX;
2347
2348           my $workbook  = Excel::Writer::XLSX->new( 'chart_doughnut.xlsx' );
2349           my $worksheet = $workbook->add_worksheet();
2350           my $bold      = $workbook->add_format( bold => 1 );
2351
2352           # Add the worksheet data that the charts will refer to.
2353           my $headings = [ 'Category', 'Values' ];
2354           my $data = [
2355               [ 'Glazed', 'Chocolate', 'Cream' ],
2356               [ 50,       35,          15      ],
2357           ];
2358
2359           $worksheet->write( 'A1', $headings, $bold );
2360           $worksheet->write( 'A2', $data );
2361
2362           # Create a new chart object. In this case an embedded chart.
2363           my $chart1 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2364
2365           # Configure the series. Note the use of the array ref to define ranges:
2366           # [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2367           # See below for an alternative syntax.
2368           $chart1->add_series(
2369               name       => 'Doughnut sales data',
2370               categories => [ 'Sheet1', 1, 3, 0, 0 ],
2371               values     => [ 'Sheet1', 1, 3, 1, 1 ],
2372           );
2373
2374           # Add a title.
2375           $chart1->set_title( name => 'Popular Doughnut Types' );
2376
2377           # Set an Excel chart style. Colors with white outline and shadow.
2378           $chart1->set_style( 10 );
2379
2380           # Insert the chart into the worksheet (with an offset).
2381           $worksheet->insert_chart( 'C2', $chart1, { x_offset => 25, y_offset => 10 } );
2382
2383
2384           #
2385           # Create a Doughnut chart with user defined segment colors.
2386           #
2387
2388           # Create an example Doughnut chart like above.
2389           my $chart2 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2390
2391           # Configure the series and add user defined segment colours.
2392           $chart2->add_series(
2393               name       => 'Doughnut sales data',
2394               categories => '=Sheet1!$A$2:$A$4',
2395               values     => '=Sheet1!$B$2:$B$4',
2396               points     => [
2397                   { fill => { color => '#FA58D0' } },
2398                   { fill => { color => '#61210B' } },
2399                   { fill => { color => '#F5F6CE' } },
2400               ],
2401           );
2402
2403           # Add a title.
2404           $chart2->set_title( name => 'Doughnut Chart with user defined colors' );
2405
2406
2407           # Insert the chart into the worksheet (with an offset).
2408           $worksheet->insert_chart( 'C18', $chart2, { x_offset => 25, y_offset => 10 } );
2409
2410
2411           #
2412           # Create a Doughnut chart with rotation of the segments.
2413           #
2414
2415           # Create an example Doughnut chart like above.
2416           my $chart3 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2417
2418           # Configure the series.
2419           $chart3->add_series(
2420               name       => 'Doughnut sales data',
2421               categories => '=Sheet1!$A$2:$A$4',
2422               values     => '=Sheet1!$B$2:$B$4',
2423           );
2424
2425           # Add a title.
2426           $chart3->set_title( name => 'Doughnut Chart with segment rotation' );
2427
2428           # Change the angle/rotation of the first segment.
2429           $chart3->set_rotation(90);
2430
2431           # Insert the chart into the worksheet (with an offset).
2432           $worksheet->insert_chart( 'C34', $chart3, { x_offset => 25, y_offset => 10 } );
2433
2434
2435           #
2436           # Create a Doughnut chart with user defined hole size.
2437           #
2438
2439           # Create an example Doughnut chart like above.
2440           my $chart4 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2441
2442           # Configure the series.
2443           $chart4->add_series(
2444               name       => 'Doughnut sales data',
2445               categories => '=Sheet1!$A$2:$A$4',
2446               values     => '=Sheet1!$B$2:$B$4',
2447           );
2448
2449           # Add a title.
2450           $chart4->set_title( name => 'Doughnut Chart with user defined hole size' );
2451
2452           # Change the hole size.
2453           $chart4->set_hole_size(33);
2454
2455           # Insert the chart into the worksheet (with an offset).
2456           $worksheet->insert_chart( 'C50', $chart4, { x_offset => 25, y_offset => 10 } );
2457
2458           $workbook->close();
2459
2460           __END__
2461
2462       Download this example:
2463       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_doughnut.pl>
2464
2465   Example: chart_radar.pl
2466       A demo of an Radar chart in Excel::Writer::XLSX.
2467
2468       Source code for this example:
2469
2470           #!/usr/bin/perl
2471
2472           #######################################################################
2473           #
2474           # A demo of an Radar chart in Excel::Writer::XLSX.
2475           #
2476           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
2477           #
2478
2479           use strict;
2480           use warnings;
2481           use Excel::Writer::XLSX;
2482
2483           my $workbook  = Excel::Writer::XLSX->new( 'chart_radar.xlsx' );
2484           my $worksheet = $workbook->add_worksheet();
2485           my $bold      = $workbook->add_format( bold => 1 );
2486
2487           # Add the worksheet data that the charts will refer to.
2488           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2489           my $data = [
2490               [ 2,  3,  4,  5,  6,  7 ],
2491               [ 30, 60, 70, 50, 40, 30 ],
2492               [ 25, 40, 50, 30, 50, 40 ],
2493
2494           ];
2495
2496           $worksheet->write( 'A1', $headings, $bold );
2497           $worksheet->write( 'A2', $data );
2498
2499           # Create a new chart object. In this case an embedded chart.
2500           my $chart1 = $workbook->add_chart( type => 'radar', embedded => 1 );
2501
2502           # Configure the first series.
2503           $chart1->add_series(
2504               name       => '=Sheet1!$B$1',
2505               categories => '=Sheet1!$A$2:$A$7',
2506               values     => '=Sheet1!$B$2:$B$7',
2507           );
2508
2509           # Configure second series. Note alternative use of array ref to define
2510           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2511           $chart1->add_series(
2512               name       => '=Sheet1!$C$1',
2513               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2514               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2515           );
2516
2517           # Add a chart title and some axis labels.
2518           $chart1->set_title ( name => 'Results of sample analysis' );
2519           $chart1->set_x_axis( name => 'Test number' );
2520           $chart1->set_y_axis( name => 'Sample length (mm)' );
2521
2522           # Set an Excel chart style. Blue colors with white outline and shadow.
2523           $chart1->set_style( 11 );
2524
2525           # Insert the chart into the worksheet (with an offset).
2526           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
2527
2528
2529           #
2530           # Create a with_markers chart sub-type
2531           #
2532           my $chart2 = $workbook->add_chart(
2533               type     => 'radar',
2534               embedded => 1,
2535               subtype  => 'with_markers'
2536           );
2537
2538           # Configure the first series.
2539           $chart2->add_series(
2540               name       => '=Sheet1!$B$1',
2541               categories => '=Sheet1!$A$2:$A$7',
2542               values     => '=Sheet1!$B$2:$B$7',
2543           );
2544
2545           # Configure second series.
2546           $chart2->add_series(
2547               name       => '=Sheet1!$C$1',
2548               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2549               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2550           );
2551
2552           # Add a chart title and some axis labels.
2553           $chart2->set_title ( name => 'Stacked Chart' );
2554           $chart2->set_x_axis( name => 'Test number' );
2555           $chart2->set_y_axis( name => 'Sample length (mm)' );
2556
2557           # Set an Excel chart style. Blue colors with white outline and shadow.
2558           $chart2->set_style( 12 );
2559
2560           # Insert the chart into the worksheet (with an offset).
2561           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
2562
2563
2564           #
2565           # Create a filled chart sub-type
2566           #
2567           my $chart3 = $workbook->add_chart(
2568               type     => 'radar',
2569               embedded => 1,
2570               subtype  => 'filled'
2571           );
2572
2573           # Configure the first series.
2574           $chart3->add_series(
2575               name       => '=Sheet1!$B$1',
2576               categories => '=Sheet1!$A$2:$A$7',
2577               values     => '=Sheet1!$B$2:$B$7',
2578           );
2579
2580           # Configure second series.
2581           $chart3->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           $chart3->set_title ( name => 'Percent Stacked Chart' );
2589           $chart3->set_x_axis( name => 'Test number' );
2590           $chart3->set_y_axis( name => 'Sample length (mm)' );
2591
2592           # Set an Excel chart style. Blue colors with white outline and shadow.
2593           $chart3->set_style( 13 );
2594
2595           # Insert the chart into the worksheet (with an offset).
2596           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
2597
2598           $workbook->close();
2599
2600           __END__
2601
2602       Download this example:
2603       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_radar.pl>
2604
2605   Example: chart_scatter.pl
2606       A demo of a Scatter chart in Excel::Writer::XLSX. Other subtypes are
2607       also supported such as markers_only (the default),
2608       straight_with_markers, straight, smooth_with_markers and smooth. See
2609       the main documentation for more details.
2610
2611       Source code for this example:
2612
2613           #!/usr/bin/perl
2614
2615           #######################################################################
2616           #
2617           # A demo of a Scatter chart in Excel::Writer::XLSX. Other subtypes are
2618           # also supported such as markers_only (the default), straight_with_markers,
2619           # straight, smooth_with_markers and smooth. See the main documentation for
2620           # more details.
2621           #
2622           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
2623           #
2624
2625           use strict;
2626           use warnings;
2627           use Excel::Writer::XLSX;
2628
2629           my $workbook  = Excel::Writer::XLSX->new( 'chart_scatter.xlsx' );
2630           my $worksheet = $workbook->add_worksheet();
2631           my $bold      = $workbook->add_format( bold => 1 );
2632
2633           # Add the worksheet data that the charts will refer to.
2634           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2635           my $data = [
2636               [ 2,  3,  4,  5,  6,  7 ],
2637               [ 10, 40, 50, 20, 10, 50 ],
2638               [ 30, 60, 70, 50, 40, 30 ],
2639
2640           ];
2641
2642           $worksheet->write( 'A1', $headings, $bold );
2643           $worksheet->write( 'A2', $data );
2644
2645           # Create a new chart object. In this case an embedded chart.
2646           my $chart1 = $workbook->add_chart( type => 'scatter', embedded => 1 );
2647
2648           # Configure the first series.
2649           $chart1->add_series(
2650               name       => '=Sheet1!$B$1',
2651               categories => '=Sheet1!$A$2:$A$7',
2652               values     => '=Sheet1!$B$2:$B$7',
2653           );
2654
2655           # Configure second series. Note alternative use of array ref to define
2656           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2657           $chart1->add_series(
2658               name       => '=Sheet1!$C$1',
2659               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2660               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2661           );
2662
2663           # Add a chart title and some axis labels.
2664           $chart1->set_title ( name => 'Results of sample analysis' );
2665           $chart1->set_x_axis( name => 'Test number' );
2666           $chart1->set_y_axis( name => 'Sample length (mm)' );
2667
2668           # Set an Excel chart style. Blue colors with white outline and shadow.
2669           $chart1->set_style( 11 );
2670
2671           # Insert the chart into the worksheet (with an offset).
2672           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
2673
2674
2675           #
2676           # Create a scatter chart sub-type with straight lines and markers.
2677           #
2678           my $chart2 = $workbook->add_chart(
2679               type     => 'scatter',
2680               embedded => 1,
2681               subtype  => 'straight_with_markers'
2682           );
2683
2684           # Configure the first series.
2685           $chart2->add_series(
2686               name       => '=Sheet1!$B$1',
2687               categories => '=Sheet1!$A$2:$A$7',
2688               values     => '=Sheet1!$B$2:$B$7',
2689           );
2690
2691           # Configure second series.
2692           $chart2->add_series(
2693               name       => '=Sheet1!$C$1',
2694               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2695               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2696           );
2697
2698           # Add a chart title and some axis labels.
2699           $chart2->set_title ( name => 'Straight line with markers' );
2700           $chart2->set_x_axis( name => 'Test number' );
2701           $chart2->set_y_axis( name => 'Sample length (mm)' );
2702
2703           # Set an Excel chart style. Blue colors with white outline and shadow.
2704           $chart2->set_style( 12 );
2705
2706           # Insert the chart into the worksheet (with an offset).
2707           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
2708
2709
2710           #
2711           # Create a scatter chart sub-type with straight lines and no markers.
2712           #
2713           my $chart3 = $workbook->add_chart(
2714               type     => 'scatter',
2715               embedded => 1,
2716               subtype  => 'straight'
2717           );
2718
2719           # Configure the first series.
2720           $chart3->add_series(
2721               name       => '=Sheet1!$B$1',
2722               categories => '=Sheet1!$A$2:$A$7',
2723               values     => '=Sheet1!$B$2:$B$7',
2724           );
2725
2726           # Configure second series.
2727           $chart3->add_series(
2728               name       => '=Sheet1!$C$1',
2729               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2730               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2731           );
2732
2733           # Add a chart title and some axis labels.
2734           $chart3->set_title ( name => 'Straight line' );
2735           $chart3->set_x_axis( name => 'Test number' );
2736           $chart3->set_y_axis( name => 'Sample length (mm)' );
2737
2738           # Set an Excel chart style. Blue colors with white outline and shadow.
2739           $chart3->set_style( 13 );
2740
2741           # Insert the chart into the worksheet (with an offset).
2742           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
2743
2744
2745           #
2746           # Create a scatter chart sub-type with smooth lines and markers.
2747           #
2748           my $chart4 = $workbook->add_chart(
2749               type     => 'scatter',
2750               embedded => 1,
2751               subtype  => 'smooth_with_markers'
2752           );
2753
2754           # Configure the first series.
2755           $chart4->add_series(
2756               name       => '=Sheet1!$B$1',
2757               categories => '=Sheet1!$A$2:$A$7',
2758               values     => '=Sheet1!$B$2:$B$7',
2759           );
2760
2761           # Configure second series.
2762           $chart4->add_series(
2763               name       => '=Sheet1!$C$1',
2764               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2765               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2766           );
2767
2768           # Add a chart title and some axis labels.
2769           $chart4->set_title ( name => 'Smooth line with markers' );
2770           $chart4->set_x_axis( name => 'Test number' );
2771           $chart4->set_y_axis( name => 'Sample length (mm)' );
2772
2773           # Set an Excel chart style. Blue colors with white outline and shadow.
2774           $chart4->set_style( 14 );
2775
2776           # Insert the chart into the worksheet (with an offset).
2777           $worksheet->insert_chart( 'D51', $chart4, { x_offset => 25, y_offset => 10 } );
2778
2779
2780           #
2781           # Create a scatter chart sub-type with smooth lines and no markers.
2782           #
2783           my $chart5 = $workbook->add_chart(
2784               type     => 'scatter',
2785               embedded => 1,
2786               subtype  => 'smooth'
2787           );
2788
2789           # Configure the first series.
2790           $chart5->add_series(
2791               name       => '=Sheet1!$B$1',
2792               categories => '=Sheet1!$A$2:$A$7',
2793               values     => '=Sheet1!$B$2:$B$7',
2794           );
2795
2796           # Configure second series.
2797           $chart5->add_series(
2798               name       => '=Sheet1!$C$1',
2799               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2800               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2801           );
2802
2803           # Add a chart title and some axis labels.
2804           $chart5->set_title ( name => 'Smooth line' );
2805           $chart5->set_x_axis( name => 'Test number' );
2806           $chart5->set_y_axis( name => 'Sample length (mm)' );
2807
2808           # Set an Excel chart style. Blue colors with white outline and shadow.
2809           $chart5->set_style( 15 );
2810
2811           # Insert the chart into the worksheet (with an offset).
2812           $worksheet->insert_chart( 'D66', $chart5, { x_offset => 25, y_offset => 10 } );
2813
2814
2815           $workbook->close();
2816
2817           __END__
2818
2819       Download this example:
2820       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_scatter.pl>
2821
2822   Example: chart_secondary_axis.pl
2823       A demo of a Line chart with a secondary axis in Excel::Writer::XLSX.
2824
2825       Source code for this example:
2826
2827           #!/usr/bin/perl
2828
2829           #######################################################################
2830           #
2831           # A demo of a Line chart with a secondary axis in Excel::Writer::XLSX.
2832           #
2833           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
2834           #
2835
2836           use strict;
2837           use warnings;
2838           use Excel::Writer::XLSX;
2839
2840           my $workbook  = Excel::Writer::XLSX->new( 'chart_secondary_axis.xlsx' );
2841           my $worksheet = $workbook->add_worksheet();
2842           my $bold      = $workbook->add_format( bold => 1 );
2843
2844           # Add the worksheet data that the charts will refer to.
2845           my $headings = [ 'Aliens', 'Humans', ];
2846           my $data = [
2847               [ 2,  3,  4,  5,  6,  7 ],
2848               [ 10, 40, 50, 20, 10, 50 ],
2849
2850           ];
2851
2852
2853           $worksheet->write( 'A1', $headings, $bold );
2854           $worksheet->write( 'A2', $data );
2855
2856           # Create a new chart object. In this case an embedded chart.
2857           my $chart = $workbook->add_chart( type => 'line', embedded => 1 );
2858
2859           # Configure a series with a secondary axis
2860           $chart->add_series(
2861               name    => '=Sheet1!$A$1',
2862               values  => '=Sheet1!$A$2:$A$7',
2863               y2_axis => 1,
2864           );
2865
2866           $chart->add_series(
2867               name   => '=Sheet1!$B$1',
2868               values => '=Sheet1!$B$2:$B$7',
2869           );
2870
2871           $chart->set_legend( position => 'right' );
2872
2873           # Add a chart title and some axis labels.
2874           $chart->set_title( name => 'Survey results' );
2875           $chart->set_x_axis( name => 'Days', );
2876           $chart->set_y_axis( name => 'Population', major_gridlines => { visible => 0 } );
2877           $chart->set_y2_axis( name => 'Laser wounds' );
2878
2879           # Insert the chart into the worksheet (with an offset).
2880           $worksheet->insert_chart( 'D2', $chart, { x_offset => 25, y_offset => 10 } );
2881
2882           $workbook->close();
2883
2884           __END__
2885
2886       Download this example:
2887       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_secondary_axis.pl>
2888
2889   Example: chart_combined.pl
2890       An example of a Combined chart in Excel::Writer::XLSX.
2891
2892           #!/usr/bin/perl
2893
2894           #######################################################################
2895           #
2896           # An example of a Combined chart in Excel::Writer::XLSX.
2897           #
2898           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
2899           #
2900
2901           use strict;
2902           use warnings;
2903           use Excel::Writer::XLSX;
2904
2905           my $workbook  = Excel::Writer::XLSX->new( 'chart_combined.xlsx' );
2906           my $worksheet = $workbook->add_worksheet();
2907           my $bold      = $workbook->add_format( bold => 1 );
2908
2909           # Add the worksheet data that the charts will refer to.
2910           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2911           my $data = [
2912               [ 2,  3,  4,  5,  6,  7 ],
2913               [ 10, 40, 50, 20, 10, 50 ],
2914               [ 30, 60, 70, 50, 40, 30 ],
2915
2916           ];
2917
2918           $worksheet->write( 'A1', $headings, $bold );
2919           $worksheet->write( 'A2', $data );
2920
2921           #
2922           # In the first example we will create a combined column and line chart.
2923           # They will share the same X and Y axes.
2924           #
2925
2926           # Create a new column chart. This will use this as the primary chart.
2927           my $column_chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
2928
2929           # Configure the data series for the primary chart.
2930           $column_chart1->add_series(
2931               name       => '=Sheet1!$B$1',
2932               categories => '=Sheet1!$A$2:$A$7',
2933               values     => '=Sheet1!$B$2:$B$7',
2934           );
2935
2936           # Create a new column chart. This will use this as the secondary chart.
2937           my $line_chart1 = $workbook->add_chart( type => 'line', embedded => 1 );
2938
2939           # Configure the data series for the secondary chart.
2940           $line_chart1->add_series(
2941               name       => '=Sheet1!$C$1',
2942               categories => '=Sheet1!$A$2:$A$7',
2943               values     => '=Sheet1!$C$2:$C$7',
2944           );
2945
2946           # Combine the charts.
2947           $column_chart1->combine( $line_chart1 );
2948
2949           # Add a chart title and some axis labels. Note, this is done via the
2950           # primary chart.
2951           $column_chart1->set_title( name => 'Combined chart - same Y axis' );
2952           $column_chart1->set_x_axis( name => 'Test number' );
2953           $column_chart1->set_y_axis( name => 'Sample length (mm)' );
2954
2955
2956           # Insert the chart into the worksheet
2957           $worksheet->insert_chart( 'E2', $column_chart1 );
2958
2959           #
2960           # In the second example we will create a similar combined column and line
2961           # chart except that the secondary chart will have a secondary Y axis.
2962           #
2963
2964           # Create a new column chart. This will use this as the primary chart.
2965           my $column_chart2 = $workbook->add_chart( type => 'column', embedded => 1 );
2966
2967           # Configure the data series for the primary chart.
2968           $column_chart2->add_series(
2969               name       => '=Sheet1!$B$1',
2970               categories => '=Sheet1!$A$2:$A$7',
2971               values     => '=Sheet1!$B$2:$B$7',
2972           );
2973
2974           # Create a new column chart. This will use this as the secondary chart.
2975           my $line_chart2 = $workbook->add_chart( type => 'line', embedded => 1 );
2976
2977           # Configure the data series for the secondary chart. We also set a
2978           # secondary Y axis via (y2_axis). This is the only difference between
2979           # this and the first example, apart from the axis label below.
2980           $line_chart2->add_series(
2981               name       => '=Sheet1!$C$1',
2982               categories => '=Sheet1!$A$2:$A$7',
2983               values     => '=Sheet1!$C$2:$C$7',
2984               y2_axis    => 1,
2985           );
2986
2987           # Combine the charts.
2988           $column_chart2->combine( $line_chart2 );
2989
2990           # Add a chart title and some axis labels.
2991           $column_chart2->set_title(  name => 'Combine chart - secondary Y axis' );
2992           $column_chart2->set_x_axis( name => 'Test number' );
2993           $column_chart2->set_y_axis( name => 'Sample length (mm)' );
2994
2995           # Note: the y2 properites are on the secondary chart.
2996           $line_chart2->set_y2_axis( name => 'Target length (mm)' );
2997
2998
2999           # Insert the chart into the worksheet
3000           $worksheet->insert_chart( 'E18', $column_chart2 );
3001
3002           $workbook->close();
3003
3004           __END__
3005
3006       Download this example:
3007       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_combined.pl>
3008
3009   Example: chart_pareto.pl
3010       A demo of a Pareto chart in Excel::Writer::XLSX.
3011
3012           #!/usr/bin/perl
3013
3014           #######################################################################
3015           #
3016           # A demo of a Pareto chart in Excel::Writer::XLSX.
3017           #
3018           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
3019           #
3020
3021           use strict;
3022           use warnings;
3023           use Excel::Writer::XLSX;
3024
3025           my $workbook  = Excel::Writer::XLSX->new( 'chart_pareto.xlsx' );
3026           my $worksheet = $workbook->add_worksheet();
3027
3028           # Formats used in the workbook.
3029           my $bold           = $workbook->add_format( bold       => 1 );
3030           my $percent_format = $workbook->add_format( num_format => '0.0%' );
3031
3032
3033           # Widen the columns for visibility.
3034           $worksheet->set_column( 'A:A', 15 );
3035           $worksheet->set_column( 'B:C', 10 );
3036
3037           # Add the worksheet data that the charts will refer to.
3038           my $headings = [ 'Reason', 'Number', 'Percentage' ];
3039
3040           my $reasons = [
3041               'Traffic',   'Child care', 'Public Transport', 'Weather',
3042               'Overslept', 'Emergency',
3043           ];
3044
3045           my $numbers  = [ 60,   40,    20,  15,  10,    5 ];
3046           my $percents = [ 0.44, 0.667, 0.8, 0.9, 0.967, 1 ];
3047
3048           $worksheet->write_row( 'A1', $headings, $bold );
3049           $worksheet->write_col( 'A2', $reasons );
3050           $worksheet->write_col( 'B2', $numbers );
3051           $worksheet->write_col( 'C2', $percents, $percent_format );
3052
3053
3054           # Create a new column chart. This will be the primary chart.
3055           my $column_chart = $workbook->add_chart( type => 'column', embedded => 1 );
3056
3057           # Add a series.
3058           $column_chart->add_series(
3059               categories => '=Sheet1!$A$2:$A$7',
3060               values     => '=Sheet1!$B$2:$B$7',
3061           );
3062
3063           # Add a chart title.
3064           $column_chart->set_title( name => 'Reasons for lateness' );
3065
3066           # Turn off the chart legend.
3067           $column_chart->set_legend( position => 'none' );
3068
3069           # Set the title and scale of the Y axes. Note, the secondary axis is set from
3070           # the primary chart.
3071           $column_chart->set_y_axis(
3072               name => 'Respondents (number)',
3073               min  => 0,
3074               max  => 120
3075           );
3076           $column_chart->set_y2_axis( max => 1 );
3077
3078           # Create a new line chart. This will be the secondary chart.
3079           my $line_chart = $workbook->add_chart( type => 'line', embedded => 1 );
3080
3081           # Add a series, on the secondary axis.
3082           $line_chart->add_series(
3083               categories => '=Sheet1!$A$2:$A$7',
3084               values     => '=Sheet1!$C$2:$C$7',
3085               marker     => { type => 'automatic' },
3086               y2_axis    => 1,
3087           );
3088
3089
3090           # Combine the charts.
3091           $column_chart->combine( $line_chart );
3092
3093           # Insert the chart into the worksheet.
3094           $worksheet->insert_chart( 'F2', $column_chart );
3095
3096           $workbook->close();
3097
3098           __END__
3099
3100       Download this example:
3101       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_pareto.pl>
3102
3103   Example: chart_stock.pl
3104       A demo of a Stock chart in Excel::Writer::XLSX.
3105
3106       Source code for this example:
3107
3108           #!/usr/bin/perl
3109
3110           #######################################################################
3111           #
3112           # A demo of a Stock chart in Excel::Writer::XLSX.
3113           #
3114           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
3115           #
3116
3117           use strict;
3118           use warnings;
3119           use Excel::Writer::XLSX;
3120           use Excel::Writer::XLSX;
3121
3122           my $workbook    = Excel::Writer::XLSX->new( 'chart_stock.xlsx' );
3123           my $worksheet   = $workbook->add_worksheet();
3124           my $bold        = $workbook->add_format( bold => 1 );
3125           my $date_format = $workbook->add_format( num_format => 'dd/mm/yyyy' );
3126           my $chart       = $workbook->add_chart( type => 'stock', embedded => 1 );
3127
3128
3129           # Add the worksheet data that the charts will refer to.
3130           my $headings = [ 'Date', 'High', 'Low', 'Close' ];
3131           my $data = [
3132
3133               [ '2007-01-01T', '2007-01-02T', '2007-01-03T', '2007-01-04T', '2007-01-05T' ],
3134               [ 27.2,  25.03, 19.05, 20.34, 18.5 ],
3135               [ 23.49, 19.55, 15.12, 17.84, 16.34 ],
3136               [ 25.45, 23.05, 17.32, 20.45, 17.34 ],
3137
3138           ];
3139
3140           $worksheet->write( 'A1', $headings, $bold );
3141
3142           for my $row ( 0 .. 4 ) {
3143               $worksheet->write_date_time( $row+1, 0, $data->[0]->[$row], $date_format );
3144               $worksheet->write( $row+1, 1, $data->[1]->[$row] );
3145               $worksheet->write( $row+1, 2, $data->[2]->[$row] );
3146               $worksheet->write( $row+1, 3, $data->[3]->[$row] );
3147
3148           }
3149
3150           $worksheet->set_column( 'A:D', 11 );
3151
3152           # Add a series for each of the High-Low-Close columns.
3153           $chart->add_series(
3154               categories => '=Sheet1!$A$2:$A$6',
3155               values     => '=Sheet1!$B$2:$B$6',
3156           );
3157
3158           $chart->add_series(
3159               categories => '=Sheet1!$A$2:$A$6',
3160               values     => '=Sheet1!$C$2:$C$6',
3161           );
3162
3163           $chart->add_series(
3164               categories => '=Sheet1!$A$2:$A$6',
3165               values     => '=Sheet1!$D$2:$D$6',
3166           );
3167
3168           # Add a chart title and some axis labels.
3169           $chart->set_title ( name => 'High-Low-Close', );
3170           $chart->set_x_axis( name => 'Date', );
3171           $chart->set_y_axis( name => 'Share price', );
3172
3173
3174           $worksheet->insert_chart( 'E9', $chart );
3175
3176           $workbook->close();
3177
3178           __END__
3179
3180       Download this example:
3181       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_stock.pl>
3182
3183   Example: chart_data_table.pl
3184       A demo of an Column chart with a data table on the X-axis using
3185       Excel::Writer::XLSX.
3186
3187       Source code for this example:
3188
3189           #!/usr/bin/perl
3190
3191           #######################################################################
3192           #
3193           # A demo of an Column chart with a data table on the X-axis using
3194           # Excel::Writer::XLSX.
3195           #
3196           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
3197           #
3198
3199           use strict;
3200           use warnings;
3201           use Excel::Writer::XLSX;
3202
3203           my $workbook  = Excel::Writer::XLSX->new( 'chart_data_table.xlsx' );
3204           my $worksheet = $workbook->add_worksheet();
3205           my $bold      = $workbook->add_format( bold => 1 );
3206
3207           # Add the worksheet data that the charts will refer to.
3208           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
3209           my $data = [
3210               [ 2,  3,  4,  5,  6,  7 ],
3211               [ 10, 40, 50, 20, 10, 50 ],
3212               [ 30, 60, 70, 50, 40, 30 ],
3213
3214           ];
3215
3216           $worksheet->write( 'A1', $headings, $bold );
3217           $worksheet->write( 'A2', $data );
3218
3219           # Create a column chart with a data table.
3220           my $chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
3221
3222           # Configure the first series.
3223           $chart1->add_series(
3224               name       => '=Sheet1!$B$1',
3225               categories => '=Sheet1!$A$2:$A$7',
3226               values     => '=Sheet1!$B$2:$B$7',
3227           );
3228
3229           # Configure second series. Note alternative use of array ref to define
3230           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
3231           $chart1->add_series(
3232               name       => '=Sheet1!$C$1',
3233               categories => [ 'Sheet1', 1, 6, 0, 0 ],
3234               values     => [ 'Sheet1', 1, 6, 2, 2 ],
3235           );
3236
3237           # Add a chart title and some axis labels.
3238           $chart1->set_title( name => 'Chart with Data Table' );
3239           $chart1->set_x_axis( name => 'Test number' );
3240           $chart1->set_y_axis( name => 'Sample length (mm)' );
3241
3242           # Set a default data table on the X-Axis.
3243           $chart1->set_table();
3244
3245           # Insert the chart into the worksheet (with an offset).
3246           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
3247
3248
3249           #
3250           # Create a second chart.
3251           #
3252           my $chart2 = $workbook->add_chart( type => 'column', embedded => 1 );
3253
3254           # Configure the first series.
3255           $chart2->add_series(
3256               name       => '=Sheet1!$B$1',
3257               categories => '=Sheet1!$A$2:$A$7',
3258               values     => '=Sheet1!$B$2:$B$7',
3259           );
3260
3261           # Configure second series.
3262           $chart2->add_series(
3263               name       => '=Sheet1!$C$1',
3264               categories => [ 'Sheet1', 1, 6, 0, 0 ],
3265               values     => [ 'Sheet1', 1, 6, 2, 2 ],
3266           );
3267
3268           # Add a chart title and some axis labels.
3269           $chart2->set_title( name => 'Data Table with legend keys' );
3270           $chart2->set_x_axis( name => 'Test number' );
3271           $chart2->set_y_axis( name => 'Sample length (mm)' );
3272
3273           # Set a data table on the X-Axis with the legend keys showm.
3274           $chart2->set_table( show_keys => 1 );
3275
3276           # Hide the chart legend since the keys are show on the data table.
3277           $chart2->set_legend( position => 'none' );
3278
3279           # Insert the chart into the worksheet (with an offset).
3280           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
3281
3282           $workbook->close();
3283
3284           __END__
3285
3286       Download this example:
3287       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_data_table.pl>
3288
3289   Example: chart_data_tools.pl
3290       A demo of an various Excel chart data tools that are available via an
3291       Excel::Writer::XLSX chart.
3292
3293       These include, Trendlines, Data Labels, Error Bars, Drop Lines, High-
3294       Low Lines and Up-Down Bars.
3295
3296       Source code for this example:
3297
3298           #!/usr/bin/perl
3299
3300           #######################################################################
3301           #
3302           # A demo of an various Excel chart data tools that are available via
3303           # an Excel::Writer::XLSX chart.
3304           #
3305           # These include, Trendlines, Data Labels, Error Bars, Drop Lines,
3306           # High-Low Lines and Up-Down Bars.
3307           #
3308           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
3309           #
3310
3311           use strict;
3312           use warnings;
3313           use Excel::Writer::XLSX;
3314
3315           my $workbook  = Excel::Writer::XLSX->new( 'chart_data_tools.xlsx' );
3316           my $worksheet = $workbook->add_worksheet();
3317           my $bold      = $workbook->add_format( bold => 1 );
3318
3319           # Add the worksheet data that the charts will refer to.
3320           my $headings = [ 'Number', 'Data 1', 'Data 2' ];
3321           my $data = [
3322               [ 2,  3,  4,  5,  6,  7 ],
3323               [ 10, 40, 50, 20, 10, 50 ],
3324               [ 30, 60, 70, 50, 40, 30 ],
3325
3326           ];
3327
3328           $worksheet->write( 'A1', $headings, $bold );
3329           $worksheet->write( 'A2', $data );
3330
3331
3332           #######################################################################
3333           #
3334           # Trendline example.
3335           #
3336
3337           # Create a Line chart.
3338           my $chart1 = $workbook->add_chart( type => 'line', embedded => 1 );
3339
3340           # Configure the first series with a polynomial trendline.
3341           $chart1->add_series(
3342               categories => '=Sheet1!$A$2:$A$7',
3343               values     => '=Sheet1!$B$2:$B$7',
3344               trendline  => {
3345                   type  => 'polynomial',
3346                   order => 3,
3347               },
3348           );
3349
3350           # Configure the second series with a moving average trendline.
3351           $chart1->add_series(
3352               categories => '=Sheet1!$A$2:$A$7',
3353               values     => '=Sheet1!$C$2:$C$7',
3354               trendline  => { type => 'linear' },
3355           );
3356
3357           # Add a chart title. and some axis labels.
3358           $chart1->set_title( name => 'Chart with Trendlines' );
3359
3360           # Insert the chart into the worksheet (with an offset).
3361           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
3362
3363
3364           #######################################################################
3365           #
3366           # Data Labels and Markers example.
3367           #
3368
3369           # Create a Line chart.
3370           my $chart2 = $workbook->add_chart( type => 'line', embedded => 1 );
3371
3372           # Configure the first series.
3373           $chart2->add_series(
3374               categories  => '=Sheet1!$A$2:$A$7',
3375               values      => '=Sheet1!$B$2:$B$7',
3376               data_labels => { value => 1 },
3377               marker      => { type => 'automatic' },
3378           );
3379
3380           # Configure the second series.
3381           $chart2->add_series(
3382               categories => '=Sheet1!$A$2:$A$7',
3383               values     => '=Sheet1!$C$2:$C$7',
3384           );
3385
3386           # Add a chart title. and some axis labels.
3387           $chart2->set_title( name => 'Chart with Data Labels and Markers' );
3388
3389           # Insert the chart into the worksheet (with an offset).
3390           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
3391
3392
3393           #######################################################################
3394           #
3395           # Error Bars example.
3396           #
3397
3398           # Create a Line chart.
3399           my $chart3 = $workbook->add_chart( type => 'line', embedded => 1 );
3400
3401           # Configure the first series.
3402           $chart3->add_series(
3403               categories   => '=Sheet1!$A$2:$A$7',
3404               values       => '=Sheet1!$B$2:$B$7',
3405               y_error_bars => { type => 'standard_error' },
3406           );
3407
3408           # Configure the second series.
3409           $chart3->add_series(
3410               categories => '=Sheet1!$A$2:$A$7',
3411               values     => '=Sheet1!$C$2:$C$7',
3412           );
3413
3414           # Add a chart title. and some axis labels.
3415           $chart3->set_title( name => 'Chart with Error Bars' );
3416
3417           # Insert the chart into the worksheet (with an offset).
3418           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
3419
3420
3421           #######################################################################
3422           #
3423           # Up-Down Bars example.
3424           #
3425
3426           # Create a Line chart.
3427           my $chart4 = $workbook->add_chart( type => 'line', embedded => 1 );
3428
3429           # Add the Up-Down Bars.
3430           $chart4->set_up_down_bars();
3431
3432           # Configure the first series.
3433           $chart4->add_series(
3434               categories => '=Sheet1!$A$2:$A$7',
3435               values     => '=Sheet1!$B$2:$B$7',
3436           );
3437
3438           # Configure the second series.
3439           $chart4->add_series(
3440               categories => '=Sheet1!$A$2:$A$7',
3441               values     => '=Sheet1!$C$2:$C$7',
3442           );
3443
3444           # Add a chart title. and some axis labels.
3445           $chart4->set_title( name => 'Chart with Up-Down Bars' );
3446
3447           # Insert the chart into the worksheet (with an offset).
3448           $worksheet->insert_chart( 'D50', $chart4, { x_offset => 25, y_offset => 10 } );
3449
3450
3451           #######################################################################
3452           #
3453           # High-Low Lines example.
3454           #
3455
3456           # Create a Line chart.
3457           my $chart5 = $workbook->add_chart( type => 'line', embedded => 1 );
3458
3459           # Add the High-Low lines.
3460           $chart5->set_high_low_lines();
3461
3462           # Configure the first series.
3463           $chart5->add_series(
3464               categories => '=Sheet1!$A$2:$A$7',
3465               values     => '=Sheet1!$B$2:$B$7',
3466           );
3467
3468           # Configure the second series.
3469           $chart5->add_series(
3470               categories => '=Sheet1!$A$2:$A$7',
3471               values     => '=Sheet1!$C$2:$C$7',
3472           );
3473
3474           # Add a chart title. and some axis labels.
3475           $chart5->set_title( name => 'Chart with High-Low Lines' );
3476
3477           # Insert the chart into the worksheet (with an offset).
3478           $worksheet->insert_chart( 'D66', $chart5, { x_offset => 25, y_offset => 10 } );
3479
3480
3481           #######################################################################
3482           #
3483           # Drop Lines example.
3484           #
3485
3486           # Create a Line chart.
3487           my $chart6 = $workbook->add_chart( type => 'line', embedded => 1 );
3488
3489           # Add Drop Lines.
3490           $chart6->set_drop_lines();
3491
3492           # Configure the first series.
3493           $chart6->add_series(
3494               categories => '=Sheet1!$A$2:$A$7',
3495               values     => '=Sheet1!$B$2:$B$7',
3496           );
3497
3498           # Configure the second series.
3499           $chart6->add_series(
3500               categories => '=Sheet1!$A$2:$A$7',
3501               values     => '=Sheet1!$C$2:$C$7',
3502           );
3503
3504           # Add a chart title. and some axis labels.
3505           $chart6->set_title( name => 'Chart with Drop Lines' );
3506
3507           # Insert the chart into the worksheet (with an offset).
3508           $worksheet->insert_chart( 'D82', $chart6, { x_offset => 25, y_offset => 10 } );
3509
3510           $workbook->close();
3511
3512           __END__
3513
3514       Download this example:
3515       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_data_tools.pl>
3516
3517   Example: chart_data_labels.pl
3518       A demo of an various Excel chart data label features that are available
3519       via an Excel::Writer::XLSX chart.
3520
3521           #!/usr/bin/perl
3522
3523           #######################################################################
3524           #
3525           # A demo of an various Excel chart data label features that are available
3526           # via an Excel::Writer::XLSX chart.
3527           #
3528           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
3529           #
3530
3531           use strict;
3532           use warnings;
3533           use Excel::Writer::XLSX;
3534
3535           my $workbook  = Excel::Writer::XLSX->new( 'chart_data_labels.xlsx' );
3536           my $worksheet = $workbook->add_worksheet();
3537           my $bold      = $workbook->add_format( bold => 1 );
3538
3539           # Add the worksheet data that the charts will refer to.
3540           my $headings = [ 'Number', 'Data', 'Text' ];
3541           my $data = [
3542               [ 2,  3,  4,  5,  6,  7 ],
3543               [ 20, 10, 20, 30, 40, 30 ],
3544               [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun' ],
3545           ];
3546
3547           $worksheet->write( 'A1', $headings, $bold );
3548           $worksheet->write( 'A2', $data );
3549
3550
3551           #######################################################################
3552           #
3553           # Example with standard data labels.
3554           #
3555
3556           # Create a Column chart.
3557           my $chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
3558
3559           # Configure the data series and add the data labels.
3560           $chart1->add_series(
3561               categories => '=Sheet1!$A$2:$A$7',
3562               values     => '=Sheet1!$B$2:$B$7',
3563               data_labels => { value => 1 },
3564           );
3565
3566           # Add a chart title. and some axis labels.
3567           $chart1->set_title( name => 'Chart with standard data labels' );
3568
3569           # Turn off the chart legend.
3570           $chart1->set_legend( none => 1 );
3571
3572           # Insert the chart into the worksheet (with an offset).
3573           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
3574
3575
3576           #######################################################################
3577           #
3578           # Example with value and category data labels.
3579           #
3580
3581           # Create a Column chart.
3582           my $chart2 = $workbook->add_chart( type => 'column', embedded => 1 );
3583
3584           # Configure the data series and add the data labels.
3585           $chart2->add_series(
3586               categories => '=Sheet1!$A$2:$A$7',
3587               values     => '=Sheet1!$B$2:$B$7',
3588               data_labels => { value => 1, category => 1 },
3589           );
3590
3591           # Add a chart title. and some axis labels.
3592           $chart2->set_title( name => 'Category and Value data labels' );
3593
3594           # Turn off the chart legend.
3595           $chart2->set_legend( none => 1 );
3596
3597           # Insert the chart into the worksheet (with an offset).
3598           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
3599
3600
3601           #######################################################################
3602           #
3603           # Example with standard data labels with different font.
3604           #
3605
3606           # Create a Column chart.
3607           my $chart3 = $workbook->add_chart( type => 'column', embedded => 1 );
3608
3609           # Configure the data series and add the data labels.
3610           $chart3->add_series(
3611               categories => '=Sheet1!$A$2:$A$7',
3612               values     => '=Sheet1!$B$2:$B$7',
3613               data_labels => { value => 1,
3614                                font => { bold => 1,
3615                                          color => 'red',
3616                                          rotation => -30} },
3617           );
3618
3619           # Add a chart title. and some axis labels.
3620           $chart3->set_title( name => 'Data labels with user defined font' );
3621
3622           # Turn off the chart legend.
3623           $chart3->set_legend( none => 1 );
3624
3625           # Insert the chart into the worksheet (with an offset).
3626           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
3627
3628
3629           #######################################################################
3630           #
3631           # Example with standard data labels and formatting.
3632           #
3633
3634           # Create a Column chart.
3635           my $chart4 = $workbook->add_chart( type => 'column', embedded => 1 );
3636
3637           # Configure the data series and add the data labels.
3638           $chart4->add_series(
3639               categories => '=Sheet1!$A$2:$A$7',
3640               values     => '=Sheet1!$B$2:$B$7',
3641               data_labels => { value  => 1,
3642                                border => {color => 'red'},
3643                                fill   => {color => 'yellow'} },
3644           );
3645
3646           # Add a chart title. and some axis labels.
3647           $chart4->set_title( name => 'Data labels with formatting' );
3648
3649           # Turn off the chart legend.
3650           $chart4->set_legend( none => 1 );
3651
3652           # Insert the chart into the worksheet (with an offset).
3653           $worksheet->insert_chart( 'D50', $chart4, { x_offset => 25, y_offset => 10 } );
3654
3655
3656           #######################################################################
3657           #
3658           # Example with custom string data labels.
3659           #
3660
3661           # Create a Column chart.
3662           my $chart5 = $workbook->add_chart( type => 'column', embedded => 1 );
3663
3664           # Some custom labels.
3665           my $custom_labels = [
3666               { value => 'Amy' },
3667               { value => 'Bea' },
3668               { value => 'Eva' },
3669               { value => 'Fay' },
3670               { value => 'Liv' },
3671               { value => 'Una' },
3672           ];
3673
3674
3675           # Configure the data series and add the data labels.
3676           $chart5->add_series(
3677               categories => '=Sheet1!$A$2:$A$7',
3678               values     => '=Sheet1!$B$2:$B$7',
3679               data_labels => { value => 1, custom => $custom_labels },
3680           );
3681
3682           # Add a chart title. and some axis labels.
3683           $chart5->set_title( name => 'Chart with custom string data labels' );
3684
3685           # Turn off the chart legend.
3686           $chart5->set_legend( none => 1 );
3687
3688           # Insert the chart into the worksheet (with an offset).
3689           $worksheet->insert_chart( 'D66', $chart5, { x_offset => 25, y_offset => 10 } );
3690
3691
3692           #######################################################################
3693           #
3694           # Example with custom data labels from cells.
3695           #
3696
3697           # Create a Column chart.
3698           my $chart6 = $workbook->add_chart( type => 'column', embedded => 1 );
3699
3700           # Some custom labels.
3701           $custom_labels = [
3702               { value => '=Sheet1!$C$2' },
3703               { value => '=Sheet1!$C$3' },
3704               { value => '=Sheet1!$C$4' },
3705               { value => '=Sheet1!$C$5' },
3706               { value => '=Sheet1!$C$6' },
3707               { value => '=Sheet1!$C$7' },
3708           ];
3709
3710
3711           # Configure the data series and add the data labels.
3712           $chart6->add_series(
3713               categories => '=Sheet1!$A$2:$A$7',
3714               values     => '=Sheet1!$B$2:$B$7',
3715               data_labels => { value => 1, custom => $custom_labels },
3716           );
3717
3718           # Add a chart title. and some axis labels.
3719           $chart6->set_title( name => 'Chart with custom data labels from cells' );
3720
3721           # Turn off the chart legend.
3722           $chart6->set_legend( none => 1 );
3723
3724           # Insert the chart into the worksheet (with an offset).
3725           $worksheet->insert_chart( 'D82', $chart6, { x_offset => 25, y_offset => 10 } );
3726
3727
3728           #######################################################################
3729           #
3730           # Example with custom and default data labels.
3731           #
3732
3733           # Create a Column chart.
3734           my $chart7 = $workbook->add_chart( type => 'column', embedded => 1 );
3735
3736           # Some custom labels. The undef items will get the default value.
3737           # We also set a font for the custom items as an extra example.
3738           $custom_labels = [
3739               { value => '=Sheet1!$C$2', font => { color => 'red' } },
3740               undef,
3741               { value => '=Sheet1!$C$4', font => { color => 'red' } },
3742               { value => '=Sheet1!$C$5', font => { color => 'red' } },
3743           ];
3744
3745
3746           # Configure the data series and add the data labels.
3747           $chart7->add_series(
3748               categories => '=Sheet1!$A$2:$A$7',
3749               values     => '=Sheet1!$B$2:$B$7',
3750               data_labels => { value => 1, custom => $custom_labels },
3751           );
3752
3753           # Add a chart title. and some axis labels.
3754           $chart7->set_title( name => 'Mixed custom and default data labels' );
3755
3756           # Turn off the chart legend.
3757           $chart7->set_legend( none => 1 );
3758
3759           # Insert the chart into the worksheet (with an offset).
3760           $worksheet->insert_chart( 'D98', $chart7, { x_offset => 25, y_offset => 10 } );
3761
3762
3763           #######################################################################
3764           #
3765           # Example with deleted custom data labels.
3766           #
3767
3768           # Create a Column chart.
3769           my $chart8 = $workbook->add_chart( type => 'column', embedded => 1 );
3770
3771           # Some deleted custom labels and defaults (undef). This allows us to
3772           # highlight certain values such as the minimum and maximum.
3773           $custom_labels = [
3774               { delete => 1 },
3775               undef,
3776               { delete => 1 },
3777               { delete => 1 },
3778               undef,
3779               { delete => 1 },
3780           ];
3781
3782           # Configure the data series and add the data labels.
3783           $chart8->add_series(
3784               categories => '=Sheet1!$A$2:$A$7',
3785               values     => '=Sheet1!$B$2:$B$7',
3786               data_labels => { value => 1, custom => $custom_labels },
3787           );
3788
3789           # Add a chart title. and some axis labels.
3790           $chart8->set_title( name => 'Chart with deleted data labels' );
3791
3792           # Turn off the chart legend.
3793           $chart8->set_legend( none => 1 );
3794
3795           # Insert the chart into the worksheet (with an offset).
3796           $worksheet->insert_chart( 'D114', $chart8, { x_offset => 25, y_offset => 10 } );
3797
3798
3799           #######################################################################
3800           #
3801           # Example with custom string data labels and formatting.
3802           #
3803
3804           # Create a Column chart.
3805           my $chart9 = $workbook->add_chart( type => 'column', embedded => 1 );
3806
3807           # Some custom labels.
3808           $custom_labels = [
3809               { value => 'Amy', border => {color => 'blue'} },
3810               { value => 'Bea' },
3811               { value => 'Eva' },
3812               { value => 'Fay' },
3813               { value => 'Liv' },
3814               { value => 'Una', fill   => {color => 'green'} },
3815           ];
3816
3817
3818           # Configure the data series and add the data labels.
3819           $chart9->add_series(
3820               categories => '=Sheet1!$A$2:$A$7',
3821               values     => '=Sheet1!$B$2:$B$7',
3822               data_labels => { value => 1,
3823                                custom => $custom_labels,
3824                                border => {color => 'red'},
3825                                fill   => {color => 'yellow'} },
3826           );
3827
3828           # Add a chart title. and some axis labels.
3829           $chart9->set_title( name => 'Chart with custom labels and formatting' );
3830
3831           # Turn off the chart legend.
3832           $chart9->set_legend( none => 1 );
3833
3834           # Insert the chart into the worksheet (with an offset).
3835           $worksheet->insert_chart( 'D130', $chart9, { x_offset => 25, y_offset => 10 } );
3836
3837
3838           $workbook->close();
3839
3840           __END__
3841
3842       Download this example:
3843       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_data_labels.pl>
3844
3845   Example: chart_clustered.pl
3846       A demo of a clustered category chart in Excel::Writer::XLSX.
3847
3848           #!/usr/bin/perl
3849
3850           #######################################################################
3851           #
3852           # A demo of a clustered category chart in Excel::Writer::XLSX.
3853           #
3854           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
3855           #
3856
3857           use strict;
3858           use warnings;
3859           use Excel::Writer::XLSX;
3860
3861           my $workbook  = Excel::Writer::XLSX->new( 'chart_clustered.xlsx' );
3862           my $worksheet = $workbook->add_worksheet();
3863           my $bold      = $workbook->add_format( bold => 1 );
3864
3865           # Add the worksheet data that the charts will refer to.
3866           my $headings = [ 'Types',  'Sub Type',   'Value 1', 'Value 2', 'Value 3' ];
3867           my $data = [
3868               [ 'Type 1', 'Sub Type A', 5000,      8000,      6000 ],
3869               [ '',       'Sub Type B', 2000,      3000,      4000 ],
3870               [ '',       'Sub Type C', 250,       1000,      2000 ],
3871               [ 'Type 2', 'Sub Type D', 6000,      6000,      6500 ],
3872               [ '',       'Sub Type E', 500,       300,       200 ],
3873           ];
3874
3875           $worksheet->write( 'A1', $headings, $bold );
3876           $worksheet->write_col( 'A2', $data );
3877
3878           # Create a new chart object. In this case an embedded chart.
3879           my $chart = $workbook->add_chart( type => 'column', embedded => 1 );
3880
3881           # Configure the series. Note, that the categories are 2D ranges (from column A
3882           # to column B). This creates the clusters. The series are shown as formula
3883           # strings for clarity but you can also use the array syntax. See the docs.
3884           $chart->add_series(
3885               name       => '=Sheet1!$C$1',
3886               categories => '=Sheet1!$A$2:$B$6',
3887               values     => '=Sheet1!$C$2:$C$6',
3888           );
3889
3890           $chart->add_series(
3891               name       => '=Sheet1!$D$1',
3892               categories => '=Sheet1!$A$2:$B$6',
3893               values     => '=Sheet1!$D$2:$D$6',
3894           );
3895
3896           $chart->add_series(
3897               name       => '=Sheet1!$E$1',
3898               categories => '=Sheet1!$A$2:$B$6',
3899               values     => '=Sheet1!$E$2:$E$6',
3900           );
3901
3902           # Set the Excel chart style.
3903           $chart->set_style( 37 );
3904
3905           # Turn off the legend.
3906           $chart->set_legend( position => 'none' );
3907
3908           # Insert the chart into the worksheet.
3909           $worksheet->insert_chart( 'G3', $chart );
3910
3911           $workbook->close();
3912
3913           __END__
3914
3915       Download this example:
3916       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_clustered.pl>
3917
3918   Example: chart_styles.pl
3919       An example showing all 48 default chart styles available in Excel 2007
3920       using Excel::Writer::XLSX.. Note, these styles are not the same as the
3921       styles available in Excel 2013.
3922
3923           #!/usr/bin/perl
3924
3925           #######################################################################
3926           #
3927           # An example showing all 48 default chart styles available in Excel 2007
3928           # using Excel::Writer::XLSX.. Note, these styles are not the same as the
3929           # styles available in Excel 2013.
3930           #
3931           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
3932           #
3933
3934           use strict;
3935           use warnings;
3936           use Excel::Writer::XLSX;
3937
3938           my $workbook = Excel::Writer::XLSX->new( 'chart_styles.xlsx' );
3939
3940           # Show the styles for all of these chart types.
3941           my @chart_types = ( 'column', 'area', 'line', 'pie' );
3942
3943
3944           for my $chart_type ( @chart_types ) {
3945
3946               # Add a worksheet for each chart type.
3947               my $worksheet = $workbook->add_worksheet( ucfirst( $chart_type ) );
3948               $worksheet->set_zoom( 30 );
3949               my $style_number = 1;
3950
3951               # Create 48 charts, each with a different style.
3952               for ( my $row_num = 0 ; $row_num < 90 ; $row_num += 15 ) {
3953                   for ( my $col_num = 0 ; $col_num < 64 ; $col_num += 8 ) {
3954
3955                       my $chart = $workbook->add_chart(
3956                           type     => $chart_type,
3957                           embedded => 1
3958                       );
3959
3960                       $chart->add_series( values => '=Data!$A$1:$A$6' );
3961                       $chart->set_title( name => 'Style ' . $style_number );
3962                       $chart->set_legend( none => 1 );
3963                       $chart->set_style( $style_number );
3964
3965                       $worksheet->insert_chart( $row_num, $col_num, $chart );
3966                       $style_number++;
3967                   }
3968               }
3969           }
3970
3971           # Create a worksheet with data for the charts.
3972           my $data = [ 10, 40, 50, 20, 10, 50 ];
3973           my $data_worksheet = $workbook->add_worksheet( 'Data' );
3974           $data_worksheet->write_col( 'A1', $data );
3975           $data_worksheet->hide();
3976
3977           $workbook->close();
3978
3979           __END__
3980
3981       Download this example:
3982       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_styles.pl>
3983
3984   Example: chart_gauge.pl
3985       A demo of an Gauge Chart in Excel::Writer::XLSX.
3986
3987       A Gauge Chart isn't a native chart type in Excel. It is constructed by
3988       combining a doughnut chart and a pie chart and by using some non-filled
3989       elements. This example follows the following online example of how to
3990       create a Gauge Chart in Excel:
3991       https://www.excel-easy.com/examples/gauge-chart.html
3992
3993           #!/usr/bin/perl
3994
3995           #######################################################################
3996           #
3997           # A demo of an Gauge Chart in Excel::Writer::XLSX.
3998           #
3999           # A Gauge Chart isn't a native chart type in Excel. It is constructed by
4000           # combining a doughnut chart and a pie chart and by using some non-filled
4001           # elements. This example follows the following online example of how to create
4002           # a Gauge Chart in Excel: https://www.excel-easy.com/examples/gauge-chart.html
4003           #
4004           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
4005           #
4006
4007           use strict;
4008           use warnings;
4009           use Excel::Writer::XLSX;
4010
4011           my $workbook  = Excel::Writer::XLSX->new( 'chart_gauge.xlsx' );
4012           my $worksheet = $workbook->add_worksheet();
4013
4014           my $chart_doughnut = $workbook->add_chart( type => 'doughnut', embedded => 1 );
4015           my $chart_pie      = $workbook->add_chart( type => 'pie', embedded => 1 );
4016
4017           # Add some data for the Doughnut and Pie charts. This is set up so the
4018           # gauge goes from 0-100. It is initially set at 75%.
4019           $worksheet->write_col( 'H2', ['Donut', 25, 50, 25, 100] );
4020           $worksheet->write_col( 'I2', ['Pie', 75, 1, '=200-I4-I3'] );
4021
4022           # Configure the doughnut chart as the background for the gauge.
4023           $chart_doughnut->add_series(
4024               name   => '=Sheet1!$H$2',
4025               values => '=Sheet1!$H$3:$H$6',
4026               points => [
4027                   { fill => { color => 'green' } },
4028                   { fill => { color => 'yellow' } },
4029                   { fill => { color => 'red' } },
4030                   { fill => { none  => 1 } },
4031               ],
4032           );
4033
4034           # Rotate chart so the gauge parts are above the horizontal.
4035           $chart_doughnut->set_rotation( 270 );
4036
4037           # Turn off the chart legend.
4038           $chart_doughnut->set_legend( none => 1 );
4039
4040           # Turn off the chart fill and border.
4041           $chart_doughnut->set_chartarea(
4042               border => { none  => 1 },
4043               fill   => { none  => 1 },
4044           );
4045
4046           # Configure the pie chart as the needle for the gauge.
4047           $chart_pie->add_series(
4048               name   => '=Sheet1!$I$2',
4049               values => '=Sheet1!$I$3:$I$6',
4050               points => [
4051                   { fill => { none  => 1 } },
4052                   { fill => { color => 'black' } },
4053                   { fill => { none  => 1 } },
4054               ],
4055           );
4056
4057           # Rotate the pie chart/needle to align with the doughnut/gauge.
4058           $chart_pie->set_rotation( 270 );
4059
4060           # Combine the pie and doughnut charts.
4061           $chart_doughnut->combine($chart_pie);
4062
4063           # Insert the chart into the worksheet.
4064           $worksheet->insert_chart( 'A1', $chart_doughnut );
4065
4066           $workbook->close();
4067
4068       Download this example:
4069       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/chart_gauge.pl>
4070
4071   Example: colors.pl
4072       Demonstrates Excel::Writer::XLSX's named colours and the Excel colour
4073       palette.
4074
4075       The set_custom_color() Worksheet method can be used to override one of
4076       the built-in palette values with a more suitable colour. See the main
4077       docs.
4078
4079       Source code for this example:
4080
4081           #!/usr/bin/perl -w
4082
4083           ################################################################################
4084           #
4085           # Demonstrates Excel::Writer::XLSX's named colours and the Excel colour
4086           # palette.
4087           #
4088           # The set_custom_color() Worksheet method can be used to override one of the
4089           # built-in palette values with a more suitable colour. See the main docs.
4090           #
4091           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
4092           #
4093
4094           use strict;
4095           use Excel::Writer::XLSX;
4096
4097           my $workbook = Excel::Writer::XLSX->new( 'colors.xlsx' );
4098
4099           # Some common formats
4100           my $center = $workbook->add_format( align => 'center' );
4101           my $heading = $workbook->add_format( align => 'center', bold => 1 );
4102
4103
4104           ######################################################################
4105           #
4106           # Demonstrate the named colors.
4107           #
4108
4109           my %colors = (
4110               0x08, 'black',
4111               0x0C, 'blue',
4112               0x10, 'brown',
4113               0x0F, 'cyan',
4114               0x17, 'gray',
4115               0x11, 'green',
4116               0x0B, 'lime',
4117               0x0E, 'magenta',
4118               0x12, 'navy',
4119               0x35, 'orange',
4120               0x21, 'pink',
4121               0x14, 'purple',
4122               0x0A, 'red',
4123               0x16, 'silver',
4124               0x09, 'white',
4125               0x0D, 'yellow',
4126
4127           );
4128
4129           my $worksheet1 = $workbook->add_worksheet( 'Named colors' );
4130
4131           $worksheet1->set_column( 0, 3, 15 );
4132
4133           $worksheet1->write( 0, 0, "Index", $heading );
4134           $worksheet1->write( 0, 1, "Index", $heading );
4135           $worksheet1->write( 0, 2, "Name",  $heading );
4136           $worksheet1->write( 0, 3, "Color", $heading );
4137
4138           my $i = 1;
4139
4140           while ( my ( $index, $color ) = each %colors ) {
4141               my $format = $workbook->add_format(
4142                   fg_color => $color,
4143                   pattern  => 1,
4144                   border   => 1
4145               );
4146
4147               $worksheet1->write( $i + 1, 0, $index, $center );
4148               $worksheet1->write( $i + 1, 1, sprintf( "0x%02X", $index ), $center );
4149               $worksheet1->write( $i + 1, 2, $color, $center );
4150               $worksheet1->write( $i + 1, 3, '',     $format );
4151               $i++;
4152           }
4153
4154
4155           ######################################################################
4156           #
4157           # Demonstrate the standard Excel colors in the range 8..63.
4158           #
4159
4160           my $worksheet2 = $workbook->add_worksheet( 'Standard colors' );
4161
4162           $worksheet2->set_column( 0, 3, 15 );
4163
4164           $worksheet2->write( 0, 0, "Index", $heading );
4165           $worksheet2->write( 0, 1, "Index", $heading );
4166           $worksheet2->write( 0, 2, "Color", $heading );
4167           $worksheet2->write( 0, 3, "Name",  $heading );
4168
4169           for my $i ( 8 .. 63 ) {
4170               my $format = $workbook->add_format(
4171                   fg_color => $i,
4172                   pattern  => 1,
4173                   border   => 1
4174               );
4175
4176               $worksheet2->write( ( $i - 7 ), 0, $i, $center );
4177               $worksheet2->write( ( $i - 7 ), 1, sprintf( "0x%02X", $i ), $center );
4178               $worksheet2->write( ( $i - 7 ), 2, '', $format );
4179
4180               # Add the  color names
4181               if ( exists $colors{$i} ) {
4182                   $worksheet2->write( ( $i - 7 ), 3, $colors{$i}, $center );
4183
4184               }
4185           }
4186
4187
4188           ######################################################################
4189           #
4190           # Demonstrate the Html colors.
4191           #
4192
4193
4194
4195           %colors = (
4196               '#000000',  'black',
4197               '#0000FF',  'blue',
4198               '#800000',  'brown',
4199               '#00FFFF',  'cyan',
4200               '#808080',  'gray',
4201               '#008000',  'green',
4202               '#00FF00',  'lime',
4203               '#FF00FF',  'magenta',
4204               '#000080',  'navy',
4205               '#FF6600',  'orange',
4206               '#FF00FF',  'pink',
4207               '#800080',  'purple',
4208               '#FF0000',  'red',
4209               '#C0C0C0',  'silver',
4210               '#FFFFFF',  'white',
4211               '#FFFF00',  'yellow',
4212           );
4213
4214           my $worksheet3 = $workbook->add_worksheet( 'Html colors' );
4215
4216           $worksheet3->set_column( 0, 3, 15 );
4217
4218           $worksheet3->write( 0, 0, "Html", $heading );
4219           $worksheet3->write( 0, 1, "Name",  $heading );
4220           $worksheet3->write( 0, 2, "Color", $heading );
4221
4222           $i = 1;
4223
4224           while ( my ( $html_color, $color ) = each %colors ) {
4225               my $format = $workbook->add_format(
4226                   fg_color => $html_color,
4227                   pattern  => 1,
4228                   border   => 1
4229               );
4230
4231               $worksheet3->write( $i + 1, 1, $html_color, $center );
4232               $worksheet3->write( $i + 1, 2, $color,      $center );
4233               $worksheet3->write( $i + 1, 3, '',          $format );
4234               $i++;
4235           }
4236
4237           $workbook->close();
4238
4239           __END__
4240
4241       Download this example:
4242       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/colors.pl>
4243
4244   Example: comments1.pl
4245       This example demonstrates writing cell comments.
4246
4247       A cell comment is indicated in Excel by a small red triangle in the
4248       upper right-hand corner of the cell.
4249
4250       For more advanced comment options see comments2.pl.
4251
4252       Source code for this example:
4253
4254           #!/usr/bin/perl
4255
4256           ###############################################################################
4257           #
4258           # This example demonstrates writing cell comments.
4259           #
4260           # A cell comment is indicated in Excel by a small red triangle in the upper
4261           # right-hand corner of the cell.
4262           #
4263           # For more advanced comment options see comments2.pl.
4264           #
4265           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
4266           #
4267
4268           use strict;
4269           use warnings;
4270           use Excel::Writer::XLSX;
4271
4272           my $workbook  = Excel::Writer::XLSX->new( 'comments1.xlsx' );
4273           my $worksheet = $workbook->add_worksheet();
4274
4275
4276           $worksheet->write( 'A1', 'Hello' );
4277           $worksheet->write_comment( 'A1', 'This is a comment' );
4278
4279           $workbook->close();
4280
4281           __END__
4282
4283       Download this example:
4284       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/comments1.pl>
4285
4286   Example: comments2.pl
4287       This example demonstrates writing cell comments.
4288
4289       A cell comment is indicated in Excel by a small red triangle in the
4290       upper right-hand corner of the cell.
4291
4292       Each of the worksheets demonstrates different features of cell
4293       comments.
4294
4295       Source code for this example:
4296
4297           #!/usr/bin/perl
4298
4299           ###############################################################################
4300           #
4301           # This example demonstrates writing cell comments.
4302           #
4303           # A cell comment is indicated in Excel by a small red triangle in the upper
4304           # right-hand corner of the cell.
4305           #
4306           # Each of the worksheets demonstrates different features of cell comments.
4307           #
4308           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
4309           #
4310
4311           use strict;
4312           use warnings;
4313           use Excel::Writer::XLSX;
4314
4315           my $workbook   = Excel::Writer::XLSX->new( 'comments2.xlsx' );
4316           my $text_wrap  = $workbook->add_format( text_wrap => 1, valign => 'top' );
4317           my $worksheet1 = $workbook->add_worksheet();
4318           my $worksheet2 = $workbook->add_worksheet();
4319           my $worksheet3 = $workbook->add_worksheet();
4320           my $worksheet4 = $workbook->add_worksheet();
4321           my $worksheet5 = $workbook->add_worksheet();
4322           my $worksheet6 = $workbook->add_worksheet();
4323           my $worksheet7 = $workbook->add_worksheet();
4324           my $worksheet8 = $workbook->add_worksheet();
4325
4326
4327           # Variables that we will use in each example.
4328           my $cell_text = '';
4329           my $comment   = '';
4330
4331
4332           ###############################################################################
4333           #
4334           # Example 1. Demonstrates a simple cell comments without formatting.
4335           #            comments.
4336           #
4337
4338           # Set up some formatting.
4339           $worksheet1->set_column( 'C:C', 25 );
4340           $worksheet1->set_row( 2, 50 );
4341           $worksheet1->set_row( 5, 50 );
4342
4343
4344           # Simple ascii string.
4345           $cell_text = 'Hold the mouse over this cell to see the comment.';
4346
4347           $comment = 'This is a comment.';
4348
4349           $worksheet1->write( 'C3', $cell_text, $text_wrap );
4350           $worksheet1->write_comment( 'C3', $comment );
4351
4352           $cell_text = 'This is a UTF-8 string.';
4353           $comment   = chr 0x263a;
4354
4355           $worksheet1->write( 'C6', $cell_text, $text_wrap );
4356           $worksheet1->write_comment( 'C6', $comment );
4357
4358
4359
4360           ###############################################################################
4361           #
4362           # Example 2. Demonstrates visible and hidden comments.
4363           #
4364
4365           # Set up some formatting.
4366           $worksheet2->set_column( 'C:C', 25 );
4367           $worksheet2->set_row( 2, 50 );
4368           $worksheet2->set_row( 5, 50 );
4369
4370
4371           $cell_text = 'This cell comment is visible.';
4372
4373           $comment = 'Hello.';
4374
4375           $worksheet2->write( 'C3', $cell_text, $text_wrap );
4376           $worksheet2->write_comment( 'C3', $comment, visible => 1 );
4377
4378
4379           $cell_text = "This cell comment isn't visible (the default).";
4380
4381           $comment = 'Hello.';
4382
4383           $worksheet2->write( 'C6', $cell_text, $text_wrap );
4384           $worksheet2->write_comment( 'C6', $comment );
4385
4386
4387           ###############################################################################
4388           #
4389           # Example 3. Demonstrates visible and hidden comments set at the worksheet
4390           #            level.
4391           #
4392
4393           # Set up some formatting.
4394           $worksheet3->set_column( 'C:C', 25 );
4395           $worksheet3->set_row( 2, 50 );
4396           $worksheet3->set_row( 5, 50 );
4397           $worksheet3->set_row( 8, 50 );
4398
4399           # Make all comments on the worksheet visible.
4400           $worksheet3->show_comments();
4401
4402           $cell_text = 'This cell comment is visible, explicitly.';
4403
4404           $comment = 'Hello.';
4405
4406           $worksheet3->write( 'C3', $cell_text, $text_wrap );
4407           $worksheet3->write_comment( 'C3', $comment, visible => 1 );
4408
4409
4410           $cell_text =
4411             'This cell comment is also visible because ' . 'we used show_comments().';
4412
4413           $comment = 'Hello.';
4414
4415           $worksheet3->write( 'C6', $cell_text, $text_wrap );
4416           $worksheet3->write_comment( 'C6', $comment );
4417
4418
4419           $cell_text = 'However, we can still override it locally.';
4420
4421           $comment = 'Hello.';
4422
4423           $worksheet3->write( 'C9', $cell_text, $text_wrap );
4424           $worksheet3->write_comment( 'C9', $comment, visible => 0 );
4425
4426
4427           ###############################################################################
4428           #
4429           # Example 4. Demonstrates changes to the comment box dimensions.
4430           #
4431
4432           # Set up some formatting.
4433           $worksheet4->set_column( 'C:C', 25 );
4434           $worksheet4->set_row( 2,  50 );
4435           $worksheet4->set_row( 5,  50 );
4436           $worksheet4->set_row( 8,  50 );
4437           $worksheet4->set_row( 15, 50 );
4438
4439           $worksheet4->show_comments();
4440
4441           $cell_text = 'This cell comment is default size.';
4442
4443           $comment = 'Hello.';
4444
4445           $worksheet4->write( 'C3', $cell_text, $text_wrap );
4446           $worksheet4->write_comment( 'C3', $comment );
4447
4448
4449           $cell_text = 'This cell comment is twice as wide.';
4450
4451           $comment = 'Hello.';
4452
4453           $worksheet4->write( 'C6', $cell_text, $text_wrap );
4454           $worksheet4->write_comment( 'C6', $comment, x_scale => 2 );
4455
4456
4457           $cell_text = 'This cell comment is twice as high.';
4458
4459           $comment = 'Hello.';
4460
4461           $worksheet4->write( 'C9', $cell_text, $text_wrap );
4462           $worksheet4->write_comment( 'C9', $comment, y_scale => 2 );
4463
4464
4465           $cell_text = 'This cell comment is scaled in both directions.';
4466
4467           $comment = 'Hello.';
4468
4469           $worksheet4->write( 'C16', $cell_text, $text_wrap );
4470           $worksheet4->write_comment( 'C16', $comment, x_scale => 1.2, y_scale => 0.8 );
4471
4472
4473           $cell_text = 'This cell comment has width and height specified in pixels.';
4474
4475           $comment = 'Hello.';
4476
4477           $worksheet4->write( 'C19', $cell_text, $text_wrap );
4478           $worksheet4->write_comment( 'C19', $comment, width => 200, height => 20 );
4479
4480
4481           ###############################################################################
4482           #
4483           # Example 5. Demonstrates changes to the cell comment position.
4484           #
4485
4486           $worksheet5->set_column( 'C:C', 25 );
4487           $worksheet5->set_row( 2,  50 );
4488           $worksheet5->set_row( 5,  50 );
4489           $worksheet5->set_row( 8,  50 );
4490           $worksheet5->set_row( 11, 50 );
4491
4492           $worksheet5->show_comments();
4493
4494           $cell_text = 'This cell comment is in the default position.';
4495
4496           $comment = 'Hello.';
4497
4498           $worksheet5->write( 'C3', $cell_text, $text_wrap );
4499           $worksheet5->write_comment( 'C3', $comment );
4500
4501
4502           $cell_text = 'This cell comment has been moved to another cell.';
4503
4504           $comment = 'Hello.';
4505
4506           $worksheet5->write( 'C6', $cell_text, $text_wrap );
4507           $worksheet5->write_comment( 'C6', $comment, start_cell => 'E4' );
4508
4509
4510           $cell_text = 'This cell comment has been moved to another cell.';
4511
4512           $comment = 'Hello.';
4513
4514           $worksheet5->write( 'C9', $cell_text, $text_wrap );
4515           $worksheet5->write_comment( 'C9', $comment, start_row => 8, start_col => 4 );
4516
4517
4518           $cell_text = 'This cell comment has been shifted within its default cell.';
4519
4520           $comment = 'Hello.';
4521
4522           $worksheet5->write( 'C12', $cell_text, $text_wrap );
4523           $worksheet5->write_comment( 'C12', $comment, x_offset => 30, y_offset => 12 );
4524
4525
4526           ###############################################################################
4527           #
4528           # Example 6. Demonstrates changes to the comment background colour.
4529           #
4530
4531           $worksheet6->set_column( 'C:C', 25 );
4532           $worksheet6->set_row( 2, 50 );
4533           $worksheet6->set_row( 5, 50 );
4534           $worksheet6->set_row( 8, 50 );
4535
4536           $worksheet6->show_comments();
4537
4538           $cell_text = 'This cell comment has a different colour.';
4539
4540           $comment = 'Hello.';
4541
4542           $worksheet6->write( 'C3', $cell_text, $text_wrap );
4543           $worksheet6->write_comment( 'C3', $comment, color => 'green' );
4544
4545
4546           $cell_text = 'This cell comment has the default colour.';
4547
4548           $comment = 'Hello.';
4549
4550           $worksheet6->write( 'C6', $cell_text, $text_wrap );
4551           $worksheet6->write_comment( 'C6', $comment );
4552
4553
4554           $cell_text = 'This cell comment has a different colour.';
4555
4556           $comment = 'Hello.';
4557
4558           $worksheet6->write( 'C9', $cell_text, $text_wrap );
4559           $worksheet6->write_comment( 'C9', $comment, color => '#FF6600' );
4560
4561
4562           ###############################################################################
4563           #
4564           # Example 7. Demonstrates how to set the cell comment author.
4565           #
4566
4567           $worksheet7->set_column( 'C:C', 30 );
4568           $worksheet7->set_row( 2,  50 );
4569           $worksheet7->set_row( 5,  50 );
4570           $worksheet7->set_row( 8,  50 );
4571
4572           my $author = '';
4573           my $cell   = 'C3';
4574
4575           $cell_text = "Move the mouse over this cell and you will see 'Cell commented "
4576             . "by $author' (blank) in the status bar at the bottom";
4577
4578           $comment = 'Hello.';
4579
4580           $worksheet7->write( $cell, $cell_text, $text_wrap );
4581           $worksheet7->write_comment( $cell, $comment );
4582
4583
4584           $author    = 'Perl';
4585           $cell      = 'C6';
4586           $cell_text = "Move the mouse over this cell and you will see 'Cell commented "
4587             . "by $author' in the status bar at the bottom";
4588
4589           $comment = 'Hello.';
4590
4591           $worksheet7->write( $cell, $cell_text, $text_wrap );
4592           $worksheet7->write_comment( $cell, $comment, author => $author );
4593
4594
4595           $author    = chr 0x20AC;
4596           $cell      = 'C9';
4597           $cell_text = "Move the mouse over this cell and you will see 'Cell commented "
4598             . "by $author' in the status bar at the bottom";
4599           $comment = 'Hello.';
4600
4601           $worksheet7->write( $cell, $cell_text, $text_wrap );
4602           $worksheet7->write_comment( $cell, $comment, author => $author );
4603
4604
4605
4606
4607           ###############################################################################
4608           #
4609           # Example 8. Demonstrates the need to explicitly set the row height.
4610           #
4611
4612           # Set up some formatting.
4613           $worksheet8->set_column( 'C:C', 25 );
4614           $worksheet8->set_row( 2, 80 );
4615
4616           $worksheet8->show_comments();
4617
4618
4619           $cell_text =
4620               'The height of this row has been adjusted explicitly using '
4621             . 'set_row(). The size of the comment box is adjusted '
4622             . 'accordingly by Excel::Writer::XLSX.';
4623
4624           $comment = 'Hello.';
4625
4626           $worksheet8->write( 'C3', $cell_text, $text_wrap );
4627           $worksheet8->write_comment( 'C3', $comment );
4628
4629
4630           $cell_text =
4631               'The height of this row has been adjusted by Excel due to the '
4632             . 'text wrap property being set. Unfortunately this means that '
4633             . 'the height of the row is unknown to Excel::Writer::XLSX at '
4634             . "run time and thus the comment box is stretched as well.\n\n"
4635             . 'Use set_row() to specify the row height explicitly to avoid '
4636             . 'this problem.';
4637
4638           $comment = 'Hello.';
4639
4640           $worksheet8->write( 'C6', $cell_text, $text_wrap );
4641           $worksheet8->write_comment( 'C6', $comment );
4642
4643           $workbook->close();
4644
4645           __END__
4646
4647       Download this example:
4648       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/comments2.pl>
4649
4650   Example: conditional_format.pl
4651       Example of how to add conditional formatting to an Excel::Writer::XLSX
4652       file.
4653
4654       Conditional formatting allows you to apply a format to a cell or a
4655       range of cells based on certain criteria.
4656
4657       Source code for this example:
4658
4659           #!/usr/bin/perl
4660
4661           ###############################################################################
4662           #
4663           # Example of how to add conditional formatting to an Excel::Writer::XLSX file.
4664           #
4665           # Conditional formatting allows you to apply a format to a cell or a range of
4666           # cells based on certain criteria.
4667           #
4668           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
4669           #
4670
4671           use strict;
4672           use warnings;
4673           use Excel::Writer::XLSX;
4674
4675           my $workbook   = Excel::Writer::XLSX->new( 'conditional_format.xlsx' );
4676           my $worksheet1 = $workbook->add_worksheet();
4677           my $worksheet2 = $workbook->add_worksheet();
4678           my $worksheet3 = $workbook->add_worksheet();
4679           my $worksheet4 = $workbook->add_worksheet();
4680           my $worksheet5 = $workbook->add_worksheet();
4681           my $worksheet6 = $workbook->add_worksheet();
4682           my $worksheet7 = $workbook->add_worksheet();
4683           my $worksheet8 = $workbook->add_worksheet();
4684           my $worksheet9 = $workbook->add_worksheet();
4685
4686
4687           # Light red fill with dark red text.
4688           my $format1 = $workbook->add_format(
4689               bg_color => '#FFC7CE',
4690               color    => '#9C0006',
4691
4692           );
4693
4694           # Green fill with dark green text.
4695           my $format2 = $workbook->add_format(
4696               bg_color => '#C6EFCE',
4697               color    => '#006100',
4698
4699           );
4700
4701           # Some sample data to run the conditional formatting against.
4702           my $data = [
4703               [ 34, 72,  38, 30, 75, 48, 75, 66, 84, 86 ],
4704               [ 6,  24,  1,  84, 54, 62, 60, 3,  26, 59 ],
4705               [ 28, 79,  97, 13, 85, 93, 93, 22, 5,  14 ],
4706               [ 27, 71,  40, 17, 18, 79, 90, 93, 29, 47 ],
4707               [ 88, 25,  33, 23, 67, 1,  59, 79, 47, 36 ],
4708               [ 24, 100, 20, 88, 29, 33, 38, 54, 54, 88 ],
4709               [ 6,  57,  88, 28, 10, 26, 37, 7,  41, 48 ],
4710               [ 52, 78,  1,  96, 26, 45, 47, 33, 96, 36 ],
4711               [ 60, 54,  81, 66, 81, 90, 80, 93, 12, 55 ],
4712               [ 70, 5,   46, 14, 71, 19, 66, 36, 41, 21 ],
4713           ];
4714
4715
4716           ###############################################################################
4717           #
4718           # Example 1.
4719           #
4720           my $caption = 'Cells with values >= 50 are in light red. '
4721             . 'Values < 50 are in light green.';
4722
4723           # Write the data.
4724           $worksheet1->write( 'A1', $caption );
4725           $worksheet1->write_col( 'B3', $data );
4726
4727           # Write a conditional format over a range.
4728           $worksheet1->conditional_formatting( 'B3:K12',
4729               {
4730                   type     => 'cell',
4731                   criteria => '>=',
4732                   value    => 50,
4733                   format   => $format1,
4734               }
4735           );
4736
4737           # Write another conditional format over the same range.
4738           $worksheet1->conditional_formatting( 'B3:K12',
4739               {
4740                   type     => 'cell',
4741                   criteria => '<',
4742                   value    => 50,
4743                   format   => $format2,
4744               }
4745           );
4746
4747
4748           ###############################################################################
4749           #
4750           # Example 2.
4751           #
4752           $caption = 'Values between 30 and 70 are in light red. '
4753             . 'Values outside that range are in light green.';
4754
4755           $worksheet2->write( 'A1', $caption );
4756           $worksheet2->write_col( 'B3', $data );
4757
4758           $worksheet2->conditional_formatting( 'B3:K12',
4759               {
4760                   type     => 'cell',
4761                   criteria => 'between',
4762                   minimum  => 30,
4763                   maximum  => 70,
4764                   format   => $format1,
4765               }
4766           );
4767
4768           $worksheet2->conditional_formatting( 'B3:K12',
4769               {
4770                   type     => 'cell',
4771                   criteria => 'not between',
4772                   minimum  => 30,
4773                   maximum  => 70,
4774                   format   => $format2,
4775               }
4776           );
4777
4778
4779           ###############################################################################
4780           #
4781           # Example 3.
4782           #
4783           $caption = 'Duplicate values are in light red. '
4784             . 'Unique values are in light green.';
4785
4786           $worksheet3->write( 'A1', $caption );
4787           $worksheet3->write_col( 'B3', $data );
4788
4789           $worksheet3->conditional_formatting( 'B3:K12',
4790               {
4791                   type     => 'duplicate',
4792                   format   => $format1,
4793               }
4794           );
4795
4796           $worksheet3->conditional_formatting( 'B3:K12',
4797               {
4798                   type     => 'unique',
4799                   format   => $format2,
4800               }
4801           );
4802
4803
4804           ###############################################################################
4805           #
4806           # Example 4.
4807           #
4808           $caption = 'Above average values are in light red. '
4809             . 'Below average values are in light green.';
4810
4811           $worksheet4->write( 'A1', $caption );
4812           $worksheet4->write_col( 'B3', $data );
4813
4814           $worksheet4->conditional_formatting( 'B3:K12',
4815               {
4816                   type     => 'average',
4817                   criteria => 'above',
4818                   format   => $format1,
4819               }
4820           );
4821
4822           $worksheet4->conditional_formatting( 'B3:K12',
4823               {
4824                   type     => 'average',
4825                   criteria => 'below',
4826                   format   => $format2,
4827               }
4828           );
4829
4830
4831           ###############################################################################
4832           #
4833           # Example 5.
4834           #
4835           $caption = 'Top 10 values are in light red. '
4836             . 'Bottom 10 values are in light green.';
4837
4838           $worksheet5->write( 'A1', $caption );
4839           $worksheet5->write_col( 'B3', $data );
4840
4841           $worksheet5->conditional_formatting( 'B3:K12',
4842               {
4843                   type     => 'top',
4844                   value    => '10',
4845                   format   => $format1,
4846               }
4847           );
4848
4849           $worksheet5->conditional_formatting( 'B3:K12',
4850               {
4851                   type     => 'bottom',
4852                   value    => '10',
4853                   format   => $format2,
4854               }
4855           );
4856
4857
4858           ###############################################################################
4859           #
4860           # Example 6.
4861           #
4862           $caption = 'Cells with values >= 50 are in light red. '
4863             . 'Values < 50 are in light green. Non-contiguous ranges.';
4864
4865           # Write the data.
4866           $worksheet6->write( 'A1', $caption );
4867           $worksheet6->write_col( 'B3', $data );
4868
4869           # Write a conditional format over a range.
4870           $worksheet6->conditional_formatting( 'B3:K6,B9:K12',
4871               {
4872                   type     => 'cell',
4873                   criteria => '>=',
4874                   value    => 50,
4875                   format   => $format1,
4876               }
4877           );
4878
4879           # Write another conditional format over the same range.
4880           $worksheet6->conditional_formatting( 'B3:K6,B9:K12',
4881               {
4882                   type     => 'cell',
4883                   criteria => '<',
4884                   value    => 50,
4885                   format   => $format2,
4886               }
4887           );
4888
4889
4890           ###############################################################################
4891           #
4892           # Example 7.
4893           #
4894           $caption = 'Examples of color scales with default and user colors.';
4895
4896           $data = [ 1 .. 12 ];
4897
4898           $worksheet7->write( 'A1', $caption );
4899
4900           $worksheet7->write    ( 'B2', "2 Color Scale" );
4901           $worksheet7->write_col( 'B3', $data );
4902
4903           $worksheet7->write    ( 'D2', "2 Color Scale + user colors" );
4904           $worksheet7->write_col( 'D3', $data );
4905
4906           $worksheet7->write    ( 'G2', "3 Color Scale" );
4907           $worksheet7->write_col( 'G3', $data );
4908
4909           $worksheet7->write    ( 'I2', "3 Color Scale + user colors" );
4910           $worksheet7->write_col( 'I3', $data );
4911
4912
4913           $worksheet7->conditional_formatting( 'B3:B14',
4914               {
4915                   type => '2_color_scale',
4916               }
4917           );
4918
4919           $worksheet7->conditional_formatting( 'D3:D14',
4920               {
4921                   type => '3_color_scale',
4922               }
4923           );
4924
4925           $worksheet7->conditional_formatting( 'G3:G14',
4926               {
4927                   type      => '2_color_scale',
4928                   min_color => "#FF0000",
4929                   max_color => "#00FF00",
4930
4931               }
4932           );
4933
4934           $worksheet7->conditional_formatting( 'I3:I14',
4935               {
4936                   type      => '3_color_scale',
4937                   min_color => "#C5D9F1",
4938                   mid_color => "#8DB4E3",
4939                   max_color => "#538ED5",
4940               }
4941           );
4942
4943
4944           ###############################################################################
4945           #
4946           # Example 8.
4947           #
4948           $caption = 'Examples of data bars.';
4949
4950           $data = [ 1 .. 12 ];
4951
4952           $worksheet8->write( 'A1', $caption );
4953
4954           $worksheet8->write    ( 'B2', "Default data bars" );
4955           $worksheet8->write_col( 'B3', $data );
4956
4957           $worksheet8->write    ( 'D2', "Bars only" );
4958           $worksheet8->write_col( 'D3', $data );
4959
4960           $worksheet8->write    ( 'F2', "With user color" );
4961           $worksheet8->write_col( 'F3', $data );
4962
4963           $worksheet8->write    ( 'H2', "Solid bars" );
4964           $worksheet8->write_col( 'H3', $data );
4965
4966           $worksheet8->write    ( 'J2', "Right to left" );
4967           $worksheet8->write_col( 'J3', $data );
4968
4969           $data = [-1, -2, -3, -2, -1, 0, 1, 2, 3, 2, 1, 0];
4970
4971           $worksheet8->write    ( 'L2', "Excel 2010 style" );
4972           $worksheet8->write_col( 'L3', $data );
4973
4974           $worksheet8->write    ( 'N2', "Negative same as positive" );
4975           $worksheet8->write_col( 'N3', $data );
4976
4977
4978           $worksheet8->conditional_formatting( 'B3:B14',
4979               {
4980                   type      => 'data_bar'
4981               }
4982           );
4983
4984           $worksheet8->conditional_formatting( 'D3:D14',
4985               {
4986                   type     => 'data_bar',
4987                   bar_only => 1
4988               }
4989           );
4990
4991           $worksheet8->conditional_formatting( 'F3:F14',
4992               {
4993                   type      => 'data_bar',
4994                   bar_color => '#63C384'
4995               }
4996           );
4997
4998           $worksheet8->conditional_formatting( 'H3:H14',
4999               {
5000                   type      => 'data_bar',
5001                   bar_solid => 1
5002               }
5003           );
5004
5005           $worksheet8->conditional_formatting( 'J3:J14',
5006               {
5007                   type          => 'data_bar',
5008                   bar_direction => 'right'
5009               }
5010           );
5011
5012           $worksheet8->conditional_formatting( 'L3:L14',
5013               {
5014                   type          => 'data_bar',
5015                   data_bar_2010 => 1
5016               }
5017           );
5018
5019           $worksheet8->conditional_formatting( 'N3:N14',
5020               {
5021                   type                           => 'data_bar',
5022                   bar_negative_color_same        => 1,
5023                   bar_negative_border_color_same => 1
5024               }
5025           );
5026
5027
5028           ###############################################################################
5029           #
5030           # Example 9.
5031           #
5032           $caption = 'Examples of conditional formats with icon sets.';
5033
5034           $data = [
5035               [ 1, 2, 3 ],
5036               [ 1, 2, 3 ],
5037               [ 1, 2, 3 ],
5038               [ 1, 2, 3 ],
5039               [ 1, 2, 3, 4 ],
5040               [ 1, 2, 3, 4, 5 ],
5041               [ 1, 2, 3, 4, 5 ],
5042           ];
5043
5044           $worksheet9->write( 'A1', $caption );
5045           $worksheet9->write_col( 'B3', $data );
5046
5047           $worksheet9->conditional_formatting( 'B3:D3',
5048               {
5049                   type         => 'icon_set',
5050                   icon_style   => '3_traffic_lights',
5051               }
5052           );
5053
5054           $worksheet9->conditional_formatting( 'B4:D4',
5055               {
5056                   type         => 'icon_set',
5057                   icon_style   => '3_traffic_lights',
5058                   reverse_icons => 1,
5059               }
5060           );
5061
5062           $worksheet9->conditional_formatting( 'B5:D5',
5063               {
5064                   type         => 'icon_set',
5065                   icon_style   => '3_traffic_lights',
5066                   icons_only   => 1,
5067               }
5068           );
5069
5070           $worksheet9->conditional_formatting( 'B6:D6',
5071               {
5072                   type         => 'icon_set',
5073                   icon_style   => '3_arrows',
5074               }
5075           );
5076
5077           $worksheet9->conditional_formatting( 'B7:E8',
5078               {
5079                   type         => 'icon_set',
5080                   icon_style   => '4_arrows',
5081               }
5082           );
5083
5084           $worksheet9->conditional_formatting( 'B8:F8',
5085               {
5086                   type         => 'icon_set',
5087                   icon_style   => '5_arrows',
5088               }
5089           );
5090
5091
5092           $worksheet9->conditional_formatting( 'B9:F9',
5093               {
5094                   type         => 'icon_set',
5095                   icon_style   => '5_ratings',
5096               }
5097           );
5098
5099           $workbook->close();
5100
5101           __END__
5102
5103       Download this example:
5104       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/conditional_format.pl>
5105
5106   Example: data_validate.pl
5107       Example of how to add data validation and dropdown lists to an
5108       Excel::Writer::XLSX file.
5109
5110       Data validation is a feature of Excel which allows you to restrict the
5111       data that a user enters in a cell and to display help and warning
5112       messages. It also allows you to restrict input to values in a drop down
5113       list.
5114
5115       Source code for this example:
5116
5117           #!/usr/bin/perl
5118
5119           ###############################################################################
5120           #
5121           # Example of how to add data validation and dropdown lists to an
5122           # Excel::Writer::XLSX file.
5123           #
5124           # Data validation is a feature of Excel which allows you to restrict the data
5125           # that a user enters in a cell and to display help and warning messages. It
5126           # also allows you to restrict input to values in a drop down list.
5127           #
5128           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
5129           #
5130
5131           use strict;
5132           use warnings;
5133           use Excel::Writer::XLSX;
5134
5135           my $workbook  = Excel::Writer::XLSX->new( 'data_validate.xlsx' );
5136           my $worksheet = $workbook->add_worksheet();
5137
5138           # Add a format for the header cells.
5139           my $header_format = $workbook->add_format(
5140               border    => 1,
5141               bg_color  => '#C6EFCE',
5142               bold      => 1,
5143               text_wrap => 1,
5144               valign    => 'vcenter',
5145               indent    => 1,
5146           );
5147
5148           # Set up layout of the worksheet.
5149           $worksheet->set_column( 'A:A', 68 );
5150           $worksheet->set_column( 'B:B', 15 );
5151           $worksheet->set_column( 'D:D', 15 );
5152           $worksheet->set_row( 0, 36 );
5153           $worksheet->set_selection( 'B3' );
5154
5155
5156           # Write the header cells and some data that will be used in the examples.
5157           my $row = 0;
5158           my $txt;
5159           my $heading1 = 'Some examples of data validation in Excel::Writer::XLSX';
5160           my $heading2 = 'Enter values in this column';
5161           my $heading3 = 'Sample Data';
5162
5163           $worksheet->write( 'A1', $heading1, $header_format );
5164           $worksheet->write( 'B1', $heading2, $header_format );
5165           $worksheet->write( 'D1', $heading3, $header_format );
5166
5167           $worksheet->write( 'D3', [ 'Integers', 1, 10 ] );
5168           $worksheet->write( 'D4', [ 'List data', 'open', 'high', 'close' ] );
5169           $worksheet->write( 'D5', [ 'Formula', '=AND(F5=50,G5=60)', 50, 60 ] );
5170
5171
5172           #
5173           # Example 1. Limiting input to an integer in a fixed range.
5174           #
5175           $txt = 'Enter an integer between 1 and 10';
5176           $row += 2;
5177
5178           $worksheet->write( $row, 0, $txt );
5179           $worksheet->data_validation(
5180               $row, 1,
5181               {
5182                   validate => 'integer',
5183                   criteria => 'between',
5184                   minimum  => 1,
5185                   maximum  => 10,
5186               }
5187           );
5188
5189
5190           #
5191           # Example 2. Limiting input to an integer outside a fixed range.
5192           #
5193           $txt = 'Enter an integer that is not between 1 and 10 (using cell references)';
5194           $row += 2;
5195
5196           $worksheet->write( $row, 0, $txt );
5197           $worksheet->data_validation(
5198               $row, 1,
5199               {
5200                   validate => 'integer',
5201                   criteria => 'not between',
5202                   minimum  => '=E3',
5203                   maximum  => '=F3',
5204               }
5205           );
5206
5207
5208           #
5209           # Example 3. Limiting input to an integer greater than a fixed value.
5210           #
5211           $txt = 'Enter an integer greater than 0';
5212           $row += 2;
5213
5214           $worksheet->write( $row, 0, $txt );
5215           $worksheet->data_validation(
5216               $row, 1,
5217               {
5218                   validate => 'integer',
5219                   criteria => '>',
5220                   value    => 0,
5221               }
5222           );
5223
5224
5225           #
5226           # Example 4. Limiting input to an integer less than a fixed value.
5227           #
5228           $txt = 'Enter an integer less than 10';
5229           $row += 2;
5230
5231           $worksheet->write( $row, 0, $txt );
5232           $worksheet->data_validation(
5233               $row, 1,
5234               {
5235                   validate => 'integer',
5236                   criteria => '<',
5237                   value    => 10,
5238               }
5239           );
5240
5241
5242           #
5243           # Example 5. Limiting input to a decimal in a fixed range.
5244           #
5245           $txt = 'Enter a decimal between 0.1 and 0.5';
5246           $row += 2;
5247
5248           $worksheet->write( $row, 0, $txt );
5249           $worksheet->data_validation(
5250               $row, 1,
5251               {
5252                   validate => 'decimal',
5253                   criteria => 'between',
5254                   minimum  => 0.1,
5255                   maximum  => 0.5,
5256               }
5257           );
5258
5259
5260           #
5261           # Example 6. Limiting input to a value in a dropdown list.
5262           #
5263           $txt = 'Select a value from a drop down list';
5264           $row += 2;
5265
5266           $worksheet->write( $row, 0, $txt );
5267           $worksheet->data_validation(
5268               $row, 1,
5269               {
5270                   validate => 'list',
5271                   source   => [ 'open', 'high', 'close' ],
5272               }
5273           );
5274
5275
5276           #
5277           # Example 6. Limiting input to a value in a dropdown list.
5278           #
5279           $txt = 'Select a value from a drop down list (using a cell range)';
5280           $row += 2;
5281
5282           $worksheet->write( $row, 0, $txt );
5283           $worksheet->data_validation(
5284               $row, 1,
5285               {
5286                   validate => 'list',
5287                   source   => '=$E$4:$G$4',
5288               }
5289           );
5290
5291
5292           #
5293           # Example 7. Limiting input to a date in a fixed range.
5294           #
5295           $txt = 'Enter a date between 1/1/2008 and 12/12/2008';
5296           $row += 2;
5297
5298           $worksheet->write( $row, 0, $txt );
5299           $worksheet->data_validation(
5300               $row, 1,
5301               {
5302                   validate => 'date',
5303                   criteria => 'between',
5304                   minimum  => '2008-01-01T',
5305                   maximum  => '2008-12-12T',
5306               }
5307           );
5308
5309
5310           #
5311           # Example 8. Limiting input to a time in a fixed range.
5312           #
5313           $txt = 'Enter a time between 6:00 and 12:00';
5314           $row += 2;
5315
5316           $worksheet->write( $row, 0, $txt );
5317           $worksheet->data_validation(
5318               $row, 1,
5319               {
5320                   validate => 'time',
5321                   criteria => 'between',
5322                   minimum  => 'T06:00',
5323                   maximum  => 'T12:00',
5324               }
5325           );
5326
5327
5328           #
5329           # Example 9. Limiting input to a string greater than a fixed length.
5330           #
5331           $txt = 'Enter a string longer than 3 characters';
5332           $row += 2;
5333
5334           $worksheet->write( $row, 0, $txt );
5335           $worksheet->data_validation(
5336               $row, 1,
5337               {
5338                   validate => 'length',
5339                   criteria => '>',
5340                   value    => 3,
5341               }
5342           );
5343
5344
5345           #
5346           # Example 10. Limiting input based on a formula.
5347           #
5348           $txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"';
5349           $row += 2;
5350
5351           $worksheet->write( $row, 0, $txt );
5352           $worksheet->data_validation(
5353               $row, 1,
5354               {
5355                   validate => 'custom',
5356                   value    => '=AND(F5=50,G5=60)',
5357               }
5358           );
5359
5360
5361           #
5362           # Example 11. Displaying and modify data validation messages.
5363           #
5364           $txt = 'Displays a message when you select the cell';
5365           $row += 2;
5366
5367           $worksheet->write( $row, 0, $txt );
5368           $worksheet->data_validation(
5369               $row, 1,
5370               {
5371                   validate      => 'integer',
5372                   criteria      => 'between',
5373                   minimum       => 1,
5374                   maximum       => 100,
5375                   input_title   => 'Enter an integer:',
5376                   input_message => 'between 1 and 100',
5377               }
5378           );
5379
5380
5381           #
5382           # Example 12. Displaying and modify data validation messages.
5383           #
5384           $txt = 'Display a custom error message when integer isn\'t between 1 and 100';
5385           $row += 2;
5386
5387           $worksheet->write( $row, 0, $txt );
5388           $worksheet->data_validation(
5389               $row, 1,
5390               {
5391                   validate      => 'integer',
5392                   criteria      => 'between',
5393                   minimum       => 1,
5394                   maximum       => 100,
5395                   input_title   => 'Enter an integer:',
5396                   input_message => 'between 1 and 100',
5397                   error_title   => 'Input value is not valid!',
5398                   error_message => 'It should be an integer between 1 and 100',
5399               }
5400           );
5401
5402
5403           #
5404           # Example 13. Displaying and modify data validation messages.
5405           #
5406           $txt =
5407             'Display a custom information message when integer isn\'t between 1 and 100';
5408           $row += 2;
5409
5410           $worksheet->write( $row, 0, $txt );
5411           $worksheet->data_validation(
5412               $row, 1,
5413               {
5414                   validate      => 'integer',
5415                   criteria      => 'between',
5416                   minimum       => 1,
5417                   maximum       => 100,
5418                   input_title   => 'Enter an integer:',
5419                   input_message => 'between 1 and 100',
5420                   error_title   => 'Input value is not valid!',
5421                   error_message => 'It should be an integer between 1 and 100',
5422                   error_type    => 'information',
5423               }
5424           );
5425
5426           $workbook->close();
5427
5428           __END__
5429
5430       Download this example:
5431       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/data_validate.pl>
5432
5433   Example: date_time.pl
5434       Excel::Writer::XLSX example of writing dates and times using the
5435       write_date_time() Worksheet method.
5436
5437       Source code for this example:
5438
5439           #!/usr/bin/perl
5440
5441           ###############################################################################
5442           #
5443           # Excel::Writer::XLSX example of writing dates and times using the
5444           # write_date_time() Worksheet method.
5445           #
5446           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
5447           #
5448
5449           use strict;
5450           use warnings;
5451           use Excel::Writer::XLSX;
5452
5453
5454           # Create a new workbook and add a worksheet
5455           my $workbook  = Excel::Writer::XLSX->new( 'date_time.xlsx' );
5456           my $worksheet = $workbook->add_worksheet();
5457           my $bold      = $workbook->add_format( bold => 1 );
5458
5459
5460           # Expand the first columns so that the date is visible.
5461           $worksheet->set_column( "A:B", 30 );
5462
5463
5464           # Write the column headers
5465           $worksheet->write( 'A1', 'Formatted date', $bold );
5466           $worksheet->write( 'B1', 'Format',         $bold );
5467
5468
5469           # Examples date and time formats. In the output file compare how changing
5470           # the format codes change the appearance of the date.
5471           #
5472           my @date_formats = (
5473               'dd/mm/yy',
5474               'mm/dd/yy',
5475               '',
5476               'd mm yy',
5477               'dd mm yy',
5478               '',
5479               'dd m yy',
5480               'dd mm yy',
5481               'dd mmm yy',
5482               'dd mmmm yy',
5483               '',
5484               'dd mm y',
5485               'dd mm yyy',
5486               'dd mm yyyy',
5487               '',
5488               'd mmmm yyyy',
5489               '',
5490               'dd/mm/yy',
5491               'dd/mm/yy hh:mm',
5492               'dd/mm/yy hh:mm:ss',
5493               'dd/mm/yy hh:mm:ss.000',
5494               '',
5495               'hh:mm',
5496               'hh:mm:ss',
5497               'hh:mm:ss.000',
5498           );
5499
5500
5501           # Write the same date and time using each of the above formats. The empty
5502           # string formats create a blank line to make the example clearer.
5503           #
5504           my $row = 0;
5505           for my $date_format ( @date_formats ) {
5506               $row++;
5507               next if $date_format eq '';
5508
5509               # Create a format for the date or time.
5510               my $format = $workbook->add_format(
5511                   num_format => $date_format,
5512                   align      => 'left'
5513               );
5514
5515               # Write the same date using different formats.
5516               $worksheet->write_date_time( $row, 0, '2004-08-01T12:30:45.123', $format );
5517               $worksheet->write( $row, 1, $date_format );
5518           }
5519
5520
5521           # The following is an example of an invalid date. It is written as a string
5522           # instead of a number. This is also Excel's default behaviour.
5523           #
5524           $row += 2;
5525           $worksheet->write_date_time( $row, 0, '2004-13-01T12:30:45.123' );
5526           $worksheet->write( $row, 1, 'Invalid date. Written as string.', $bold );
5527
5528           $workbook->close();
5529
5530           __END__
5531
5532       Download this example:
5533       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/date_time.pl>
5534
5535   Example: defined_name.pl
5536       Example of how to create defined names in an Excel::Writer::XLSX file.
5537
5538       This method is used to define a user friendly name to represent a
5539       value, a single cell or a range of cells in a workbook.
5540
5541       Source code for this example:
5542
5543           #!/usr/bin/perl
5544
5545           ##############################################################################
5546           #
5547           # Example of how to create defined names in an Excel::Writer::XLSX file.
5548           #
5549           # This method is used to define a user friendly name to represent a value,
5550           # a single cell or a range of cells in a workbook.
5551           #
5552           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
5553           #
5554
5555           use strict;
5556           use warnings;
5557           use Excel::Writer::XLSX;
5558
5559           my $workbook   = Excel::Writer::XLSX->new( 'defined_name.xlsx' );
5560           my $worksheet1 = $workbook->add_worksheet();
5561           my $worksheet2 = $workbook->add_worksheet();
5562
5563           # Define some global/workbook names.
5564           $workbook->define_name( 'Exchange_rate', '=0.96' );
5565           $workbook->define_name( 'Sales',         '=Sheet1!$G$1:$H$10' );
5566
5567           # Define a local/worksheet name.
5568           $workbook->define_name( 'Sheet2!Sales', '=Sheet2!$G$1:$G$10' );
5569
5570           # Write some text in the file and one of the defined names in a formula.
5571           for my $worksheet ( $workbook->sheets() ) {
5572               $worksheet->set_column( 'A:A', 45 );
5573               $worksheet->write( 'A1', 'This worksheet contains some defined names.' );
5574               $worksheet->write( 'A2', 'See Formulas -> Name Manager above.' );
5575               $worksheet->write( 'A3', 'Example formula in cell B3 ->' );
5576
5577               $worksheet->write( 'B3', '=Exchange_rate' );
5578           }
5579
5580           $workbook->close();
5581
5582           __END__
5583
5584       Download this example:
5585       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/defined_name.pl>
5586
5587   Example: diag_border.pl
5588       A simple formatting example that demonstrates how to add a diagonal
5589       cell border with Excel::Writer::XLSX
5590
5591       Source code for this example:
5592
5593           #!/usr/bin/perl -w
5594
5595           ##############################################################################
5596           #
5597           # A simple formatting example that demonstrates how to add a diagonal cell
5598           # border with Excel::Writer::XLSX
5599           #
5600           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
5601           #
5602
5603           use strict;
5604           use Excel::Writer::XLSX;
5605
5606
5607           my $workbook  = Excel::Writer::XLSX->new( 'diag_border.xlsx' );
5608           my $worksheet = $workbook->add_worksheet();
5609
5610
5611           my $format1 = $workbook->add_format( diag_type => 1 );
5612
5613           my $format2 = $workbook->add_format( diag_type => 2 );
5614
5615           my $format3 = $workbook->add_format( diag_type => 3 );
5616
5617           my $format4 = $workbook->add_format(
5618               diag_type   => 3,
5619               diag_border => 7,
5620               diag_color  => 'red',
5621           );
5622
5623
5624           $worksheet->write( 'B3',  'Text', $format1 );
5625           $worksheet->write( 'B6',  'Text', $format2 );
5626           $worksheet->write( 'B9',  'Text', $format3 );
5627           $worksheet->write( 'B12', 'Text', $format4 );
5628
5629           $workbook->close();
5630
5631           __END__
5632
5633       Download this example:
5634       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/diag_border.pl>
5635
5636   Example: filehandle.pl
5637       Example of using Excel::Writer::XLSX to write Excel files to different
5638       filehandles.
5639
5640       Source code for this example:
5641
5642           #!/usr/bin/perl
5643
5644           ###############################################################################
5645           #
5646           # Example of using Excel::Writer::XLSX to write Excel files to different
5647           # filehandles.
5648           #
5649           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
5650           #
5651
5652           use strict;
5653           use warnings;
5654           use Excel::Writer::XLSX;
5655           use IO::Scalar;
5656
5657
5658           ###############################################################################
5659           #
5660           # Example 1. This demonstrates the standard way of creating an Excel file by
5661           # specifying a file name.
5662           #
5663
5664           my $workbook1  = Excel::Writer::XLSX->new( 'fh_01.xlsx' );
5665           my $worksheet1 = $workbook1->add_worksheet();
5666
5667           $worksheet1->write( 0, 0, 'Hi Excel 1' );
5668
5669           $workbook1->close();
5670
5671
5672           ###############################################################################
5673           #
5674           # Example 2. Write an Excel file to an existing filehandle.
5675           #
5676
5677           open TEST, '>', 'fh_02.xlsx' or die "Couldn't open file: $!";
5678           binmode TEST;   # Always do this regardless of whether the platform requires it.
5679
5680           my $workbook2  = Excel::Writer::XLSX->new( \*TEST );
5681           my $worksheet2 = $workbook2->add_worksheet();
5682
5683           $worksheet2->write( 0, 0, 'Hi Excel 2' );
5684
5685           $workbook2->close();
5686
5687           ###############################################################################
5688           #
5689           # Example 3. Write an Excel file to an existing OO style filehandle.
5690           #
5691
5692           my $fh = FileHandle->new( '> fh_03.xlsx' ) or die "Couldn't open file: $!";
5693
5694           binmode( $fh );
5695
5696           my $workbook3  = Excel::Writer::XLSX->new( $fh );
5697           my $worksheet3 = $workbook3->add_worksheet();
5698
5699           $worksheet3->write( 0, 0, 'Hi Excel 3' );
5700
5701           $workbook3->close();
5702
5703
5704           ###############################################################################
5705           #
5706           # Example 4. Write an Excel file to a string via IO::Scalar. Please refer to
5707           # the IO::Scalar documentation for further details.
5708           #
5709
5710           my $xlsx_str;
5711
5712           tie *XLSX, 'IO::Scalar', \$xlsx_str;
5713
5714           my $workbook4  = Excel::Writer::XLSX->new( \*XLSX );
5715           my $worksheet4 = $workbook4->add_worksheet();
5716
5717           $worksheet4->write( 0, 0, 'Hi Excel 4' );
5718           $workbook4->close();    # This is required before we use the scalar
5719
5720
5721           # The Excel file is now in $xlsx_str. As a demonstration, print it to a file.
5722           open TMP, '>', 'fh_04.xlsx' or die "Couldn't open file: $!";
5723           binmode TMP;
5724           print TMP $xlsx_str;
5725           close TMP;
5726
5727
5728           ###############################################################################
5729           #
5730           # Example 5. Write an Excel file to a string via IO::Scalar's newer interface.
5731           # Please refer to the IO::Scalar documentation for further details.
5732           #
5733           my $xlsx_str2;
5734
5735           my $fh5 = IO::Scalar->new( \$xlsx_str2 );
5736
5737           my $workbook5  = Excel::Writer::XLSX->new( $fh5 );
5738           my $worksheet5 = $workbook5->add_worksheet();
5739
5740           $worksheet5->write( 0, 0, 'Hi Excel 5' );
5741           $workbook5->close();    # This is required before we use the scalar
5742
5743           # The Excel file is now in $xlsx_str. As a demonstration, print it to a file.
5744           open TMP, '>', 'fh_05.xlsx' or die "Couldn't open file: $!";
5745           binmode TMP;
5746           print TMP $xlsx_str2;
5747           close TMP;
5748
5749           __END__
5750
5751       Download this example:
5752       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/filehandle.pl>
5753
5754   Example: headers.pl
5755       This program shows several examples of how to set up headers and
5756       footers with Excel::Writer::XLSX.
5757
5758       The control characters used in the header/footer strings are:
5759
5760           Control             Category            Description
5761           =======             ========            ===========
5762           &L                  Justification       Left
5763           &C                                      Center
5764           &R                                      Right
5765
5766           &P                  Information         Page number
5767           &N                                      Total number of pages
5768           &D                                      Date
5769           &T                                      Time
5770           &F                                      File name
5771           &A                                      Worksheet name
5772
5773           &fontsize           Font                Font size
5774           &"font,style"                           Font name and style
5775           &U                                      Single underline
5776           &E                                      Double underline
5777           &S                                      Strikethrough
5778           &X                                      Superscript
5779           &Y                                      Subscript
5780
5781           &[Picture]          Images              Image placeholder
5782           &G                                      Same as &[Picture]
5783
5784           &&                  Miscellaneous       Literal ampersand &
5785
5786       See the main Excel::Writer::XLSX documentation for more information.
5787
5788       Source code for this example:
5789
5790           #!/usr/bin/perl
5791
5792           ######################################################################
5793           #
5794           # This program shows several examples of how to set up headers and
5795           # footers with Excel::Writer::XLSX.
5796           #
5797           # The control characters used in the header/footer strings are:
5798           #
5799           #     Control             Category            Description
5800           #     =======             ========            ===========
5801           #     &L                  Justification       Left
5802           #     &C                                      Center
5803           #     &R                                      Right
5804           #
5805           #     &P                  Information         Page number
5806           #     &N                                      Total number of pages
5807           #     &D                                      Date
5808           #     &T                                      Time
5809           #     &F                                      File name
5810           #     &A                                      Worksheet name
5811           #
5812           #     &fontsize           Font                Font size
5813           #     &"font,style"                           Font name and style
5814           #     &U                                      Single underline
5815           #     &E                                      Double underline
5816           #     &S                                      Strikethrough
5817           #     &X                                      Superscript
5818           #     &Y                                      Subscript
5819           #
5820           #     &[Picture]          Images              Image placeholder
5821           #     &G                                      Same as &[Picture]
5822           #
5823           #     &&                  Miscellaneous       Literal ampersand &
5824           #
5825           # See the main Excel::Writer::XLSX documentation for more information.
5826           #
5827           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
5828           #
5829
5830
5831           use strict;
5832           use warnings;
5833           use Excel::Writer::XLSX;
5834
5835           my $workbook = Excel::Writer::XLSX->new( 'headers.xlsx' );
5836           my $preview  = 'Select Print Preview to see the header and footer';
5837
5838
5839           ######################################################################
5840           #
5841           # A simple example to start
5842           #
5843           my $worksheet1 = $workbook->add_worksheet( 'Simple' );
5844           my $header1    = '&CHere is some centred text.';
5845           my $footer1    = '&LHere is some left aligned text.';
5846
5847           $worksheet1->set_header( $header1 );
5848           $worksheet1->set_footer( $footer1 );
5849
5850           $worksheet1->set_column( 'A:A', 50 );
5851           $worksheet1->write( 'A1', $preview );
5852
5853
5854           ######################################################################
5855           #
5856           # A simple example to start
5857           #
5858           my $worksheet2 = $workbook->add_worksheet( 'Image' );
5859           my $header2    = '&L&[Picture]';
5860
5861           # Adjust the page top margin to allow space for the header image.
5862           $worksheet2->set_margin_top(1.75);
5863
5864           $worksheet2->set_header( $header2, 0.3, {image_left => 'republic.png'});
5865
5866           $worksheet2->set_column( 'A:A', 50 );
5867           $worksheet2->write( 'A1', $preview );
5868
5869
5870           ######################################################################
5871           #
5872           # This is an example of some of the header/footer variables.
5873           #
5874           my $worksheet3 = $workbook->add_worksheet( 'Variables' );
5875           my $header3    = '&LPage &P of &N' . '&CFilename: &F' . '&RSheetname: &A';
5876           my $footer3    = '&LCurrent date: &D' . '&RCurrent time: &T';
5877
5878           $worksheet3->set_header( $header3 );
5879           $worksheet3->set_footer( $footer3 );
5880
5881           $worksheet3->set_column( 'A:A', 50 );
5882           $worksheet3->write( 'A1',  $preview );
5883           $worksheet3->write( 'A21', 'Next sheet' );
5884           $worksheet3->set_h_pagebreaks( 20 );
5885
5886
5887           ######################################################################
5888           #
5889           # This example shows how to use more than one font
5890           #
5891           my $worksheet4 = $workbook->add_worksheet( 'Mixed fonts' );
5892           my $header4    = q(&C&"Courier New,Bold"Hello &"Arial,Italic"World);
5893           my $footer4    = q(&C&"Symbol"e&"Arial" = mc&X2);
5894
5895           $worksheet4->set_header( $header4 );
5896           $worksheet4->set_footer( $footer4 );
5897
5898           $worksheet4->set_column( 'A:A', 50 );
5899           $worksheet4->write( 'A1', $preview );
5900
5901
5902           ######################################################################
5903           #
5904           # Example of line wrapping
5905           #
5906           my $worksheet5 = $workbook->add_worksheet( 'Word wrap' );
5907           my $header5    = "&CHeading 1\nHeading 2";
5908
5909           $worksheet5->set_header( $header5 );
5910
5911           $worksheet5->set_column( 'A:A', 50 );
5912           $worksheet5->write( 'A1', $preview );
5913
5914
5915           ######################################################################
5916           #
5917           # Example of inserting a literal ampersand &
5918           #
5919           my $worksheet6 = $workbook->add_worksheet( 'Ampersand' );
5920           my $header6    = '&CCuriouser && Curiouser - Attorneys at Law';
5921
5922           $worksheet6->set_header( $header6 );
5923
5924           $worksheet6->set_column( 'A:A', 50 );
5925           $worksheet6->write( 'A1', $preview );
5926
5927           $workbook->close();
5928
5929           __END__
5930
5931       Download this example:
5932       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/headers.pl>
5933
5934   Example: hide_row_col.pl
5935       Example of how to hide rows and columns in Excel::Writer::XLSX. In
5936       order to hide rows without setting each one, (of approximately 1
5937       million rows), Excel uses an optimisation to hide all rows that don't
5938       have data.
5939
5940       Source code for this example:
5941
5942           #!/usr/bin/perl
5943
5944           ###############################################################################
5945           #
5946           # Example of how to hide rows and columns in Excel::Writer::XLSX. In order to
5947           # hide rows without setting each one, (of approximately 1 million rows),
5948           # Excel uses an optimisation to hide all rows that don't have data.
5949           #
5950           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
5951           #
5952
5953           use strict;
5954           use warnings;
5955           use Excel::Writer::XLSX;
5956
5957           my $workbook  = Excel::Writer::XLSX->new( 'hide_row_col.xlsx' );
5958           my $worksheet = $workbook->add_worksheet();
5959
5960
5961           # Write some data.
5962           $worksheet->write( 'D1', 'Some hidden columns.' );
5963           $worksheet->write( 'A8', 'Some hidden rows.' );
5964
5965           # Hide all rows without data.
5966           $worksheet->set_default_row( undef, 1 );
5967
5968           # Set emptys row that we do want to display. All other will be hidden.
5969           for my $row (1 .. 6) {
5970               $worksheet->set_row( $row, 15 );
5971           }
5972
5973           # Hide a range of columns.
5974           $worksheet->set_column( 'G:XFD', undef, undef, 1);
5975
5976           $workbook->close();
5977
5978           __END__
5979
5980       Download this example:
5981       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/hide_row_col.pl>
5982
5983   Example: hide_sheet.pl
5984       Example of how to hide a worksheet with Excel::Writer::XLSX.
5985
5986       Source code for this example:
5987
5988           #!/usr/bin/perl
5989
5990           #######################################################################
5991           #
5992           # Example of how to hide a worksheet with Excel::Writer::XLSX.
5993           #
5994           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
5995           #
5996
5997           use strict;
5998           use warnings;
5999           use Excel::Writer::XLSX;
6000
6001           my $workbook   = Excel::Writer::XLSX->new( 'hide_sheet.xlsx' );
6002           my $worksheet1 = $workbook->add_worksheet();
6003           my $worksheet2 = $workbook->add_worksheet();
6004           my $worksheet3 = $workbook->add_worksheet();
6005
6006           $worksheet1->set_column( 'A:A', 30 );
6007           $worksheet2->set_column( 'A:A', 30 );
6008           $worksheet3->set_column( 'A:A', 30 );
6009
6010           # Sheet2 won't be visible until it is unhidden in Excel.
6011           $worksheet2->hide();
6012
6013           $worksheet1->write( 0, 0, 'Sheet2 is hidden' );
6014           $worksheet2->write( 0, 0, "Now it's my turn to find you." );
6015           $worksheet3->write( 0, 0, 'Sheet2 is hidden' );
6016
6017           $workbook->close();
6018
6019           __END__
6020
6021       Download this example:
6022       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/hide_sheet.pl>
6023
6024   Example: hyperlink1.pl
6025       Example of how to use the Excel::Writer::XLSX module to write
6026       hyperlinks
6027
6028       See also hyperlink2.pl for worksheet URL examples.
6029
6030       Source code for this example:
6031
6032           #!/usr/bin/perl
6033
6034           ###############################################################################
6035           #
6036           # Example of how to use the Excel::Writer::XLSX module to write hyperlinks
6037           #
6038           # See also hyperlink2.pl for worksheet URL examples.
6039           #
6040           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6041           #
6042
6043           use strict;
6044           use warnings;
6045           use Excel::Writer::XLSX;
6046
6047           # Create a new workbook and add a worksheet
6048           my $workbook = Excel::Writer::XLSX->new( 'hyperlink.xlsx' );
6049
6050
6051           my $worksheet = $workbook->add_worksheet( 'Hyperlinks' );
6052
6053           # Format the first column
6054           $worksheet->set_column( 'A:A', 30 );
6055           $worksheet->set_selection( 'B1' );
6056
6057           # Add a user defined hyperlink format.
6058           my $red_format = $workbook->add_format(
6059               color     => 'red',
6060               bold      => 1,
6061               underline => 1,
6062               size      => 12,
6063           );
6064
6065           # Add an alternate description string to the URL.
6066           my $str = 'Perl home.';
6067
6068           # Add a "tool tip" to the URL.
6069           my $tip = 'Get the latest Perl news here.';
6070
6071
6072           # Write some hyperlinks. Unspecified or undefined format paraamters will be
6073           # replace with the defuault Excel hyperlink style.
6074           $worksheet->write( 'A1', 'http://www.perl.com/' );
6075           $worksheet->write( 'A3', 'http://www.perl.com/', undef, $str );
6076           $worksheet->write( 'A5', 'http://www.perl.com/', undef, $str, $tip );
6077           $worksheet->write( 'A7', 'http://www.perl.com/', $red_format );
6078           $worksheet->write( 'A9', 'mailto:jmcnamara@cpan.org', undef, 'Mail me' );
6079
6080           # Write a URL that isn't a hyperlink
6081           $worksheet->write_string( 'A11', 'http://www.perl.com/' );
6082
6083           $workbook->close();
6084
6085           __END__
6086
6087       Download this example:
6088       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/hyperlink1.pl>
6089
6090   Example: hyperlink2.pl
6091       Example of how to use the Excel::Writer::XLSX module to write internal
6092       and external hyperlinks.
6093
6094       If you wish to run this program and follow the hyperlinks you should
6095       create the following directory structure:
6096
6097       C:\ -- Temp --+-- Europe
6098                     |
6099                     \-- Asia
6100
6101       See also hyperlink1.pl for web URL examples.
6102
6103           #!/usr/bin/perl
6104
6105           ###############################################################################
6106           #
6107           # Example of how to use the Excel::Writer::XLSX module to write internal and
6108           # external hyperlinks.
6109           #
6110           # If you wish to run this program and follow the hyperlinks you should create
6111           # the following directory structure:
6112           #
6113           # C:\ -- Temp --+-- Europe
6114           #               |
6115           #               \-- Asia
6116           #
6117           #
6118           # See also hyperlink1.pl for web URL examples.
6119           #
6120           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6121           #
6122
6123
6124           use strict;
6125           use warnings;
6126           use Excel::Writer::XLSX;
6127
6128           # Create three workbooks:
6129           #   C:\Temp\Europe\Ireland.xlsx
6130           #   C:\Temp\Europe\Italy.xlsx
6131           #   C:\Temp\Asia\China.xlsx
6132           #
6133
6134           my $ireland = Excel::Writer::XLSX->new( 'C:\Temp\Europe\Ireland.xlsx' );
6135
6136           my $ire_links      = $ireland->add_worksheet( 'Links' );
6137           my $ire_sales      = $ireland->add_worksheet( 'Sales' );
6138           my $ire_data       = $ireland->add_worksheet( 'Product Data' );
6139           my $ire_url_format = $ireland->get_default_url_format();
6140
6141
6142           my $italy = Excel::Writer::XLSX->new( 'C:\Temp\Europe\Italy.xlsx' );
6143
6144           my $ita_links      = $italy->add_worksheet( 'Links' );
6145           my $ita_sales      = $italy->add_worksheet( 'Sales' );
6146           my $ita_data       = $italy->add_worksheet( 'Product Data' );
6147           my $ita_url_format = $italy->get_default_url_format();
6148
6149
6150           my $china = Excel::Writer::XLSX->new( 'C:\Temp\Asia\China.xlsx' );
6151
6152           my $cha_links      = $china->add_worksheet( 'Links' );
6153           my $cha_sales      = $china->add_worksheet( 'Sales' );
6154           my $cha_data       = $china->add_worksheet( 'Product Data' );
6155           my $cha_url_format = $china->get_default_url_format();
6156
6157
6158           # Add an alternative format
6159           my $format = $ireland->add_format( color => 'green', bold => 1 );
6160           $ire_links->set_column( 'A:B', 25 );
6161
6162
6163           ###############################################################################
6164           #
6165           # Examples of internal links
6166           #
6167           $ire_links->write( 'A1', 'Internal links', $format );
6168
6169           # Internal link
6170           $ire_links->write_url( 'A2', 'internal:Sales!A2', $ire_url_format );
6171
6172           # Internal link to a range
6173           $ire_links->write_url( 'A3', 'internal:Sales!A3:D3', $ire_url_format );
6174
6175           # Internal link with an alternative string
6176           $ire_links->write_url( 'A4', 'internal:Sales!A4', $ire_url_format, 'Link' );
6177
6178           # Internal link with an alternative format
6179           $ire_links->write_url( 'A5', 'internal:Sales!A5', $format );
6180
6181           # Internal link with an alternative string and format
6182           $ire_links->write_url( 'A6', 'internal:Sales!A6', $ire_url_format, 'Link' );
6183
6184           # Internal link (spaces in worksheet name)
6185           $ire_links->write_url( 'A7', q{internal:'Product Data'!A7}, $ire_url_format );
6186
6187
6188           ###############################################################################
6189           #
6190           # Examples of external links
6191           #
6192           $ire_links->write( 'B1', 'External links', $format );
6193
6194           # External link to a local file
6195           $ire_links->write_url( 'B2', 'external:Italy.xlsx', $ire_url_format );
6196
6197           # External link to a local file with worksheet
6198           $ire_links->write_url( 'B3', 'external:Italy.xlsx#Sales!B3', $ire_url_format );
6199
6200           # External link to a local file with worksheet and alternative string
6201           $ire_links->write_url( 'B4', 'external:Italy.xlsx#Sales!B4', $ire_url_format, 'Link' );
6202
6203           # External link to a local file with worksheet and format
6204           $ire_links->write_url( 'B5', 'external:Italy.xlsx#Sales!B5', $format );
6205
6206           # External link to a remote file, absolute path
6207           $ire_links->write_url( 'B6', 'external:C:/Temp/Asia/China.xlsx', $ire_url_format );
6208
6209           # External link to a remote file, relative path
6210           $ire_links->write_url( 'B7', 'external:../Asia/China.xlsx', $ire_url_format );
6211
6212           # External link to a remote file with worksheet
6213           $ire_links->write_url( 'B8', 'external:C:/Temp/Asia/China.xlsx#Sales!B8', $ire_url_format );
6214
6215           # External link to a remote file with worksheet (with spaces in the name)
6216           $ire_links->write_url( 'B9', q{external:C:/Temp/Asia/China.xlsx#'Product Data'!B9}, $ire_url_format );
6217
6218
6219           ###############################################################################
6220           #
6221           # Some utility links to return to the main sheet
6222           #
6223           $ire_sales->write_url( 'A2', 'internal:Links!A2', $ire_url_format, 'Back' );
6224           $ire_sales->write_url( 'A3', 'internal:Links!A3', $ire_url_format, 'Back' );
6225           $ire_sales->write_url( 'A4', 'internal:Links!A4', $ire_url_format, 'Back' );
6226           $ire_sales->write_url( 'A5', 'internal:Links!A5', $ire_url_format, 'Back' );
6227           $ire_sales->write_url( 'A6', 'internal:Links!A6', $ire_url_format, 'Back' );
6228           $ire_data->write_url ( 'A7', 'internal:Links!A7', $ire_url_format, 'Back' );
6229
6230           $ita_links->write_url( 'A1', 'external:Ireland.xlsx#Links!B2', $ita_url_format, 'Back' );
6231           $ita_sales->write_url( 'B3', 'external:Ireland.xlsx#Links!B3', $ita_url_format, 'Back' );
6232           $ita_sales->write_url( 'B4', 'external:Ireland.xlsx#Links!B4', $ita_url_format, 'Back' );
6233           $ita_sales->write_url( 'B5', 'external:Ireland.xlsx#Links!B5', $ita_url_format, 'Back' );
6234           $cha_links->write_url( 'A1', 'external:C:/Temp/Europe/Ireland.xlsx#Links!B6', $cha_url_format, 'Back' );
6235           $cha_sales->write_url( 'B8', 'external:C:/Temp/Europe/Ireland.xlsx#Links!B8', $cha_url_format, 'Back' );
6236           $cha_data->write_url ( 'B9', 'external:C:/Temp/Europe/Ireland.xlsx#Links!B9', $cha_url_format, 'Back' );
6237
6238           $ireland->close();
6239           $italy->close();
6240           $china->close();
6241
6242           __END__
6243
6244       Download this example:
6245       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/hyperlink2.pl>
6246
6247   Example: indent.pl
6248       A simple formatting example using Excel::Writer::XLSX.
6249
6250       This program demonstrates the indentation cell format.
6251
6252       Source code for this example:
6253
6254           #!/usr/bin/perl -w
6255
6256           ##############################################################################
6257           #
6258           # A simple formatting example using Excel::Writer::XLSX.
6259           #
6260           # This program demonstrates the indentation cell format.
6261           #
6262           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6263           #
6264
6265
6266           use strict;
6267           use Excel::Writer::XLSX;
6268
6269           my $workbook = Excel::Writer::XLSX->new( 'indent.xlsx' );
6270
6271           my $worksheet = $workbook->add_worksheet();
6272           my $indent1   = $workbook->add_format( indent => 1 );
6273           my $indent2   = $workbook->add_format( indent => 2 );
6274
6275           $worksheet->set_column( 'A:A', 40 );
6276
6277
6278           $worksheet->write( 'A1', "This text is indented 1 level",  $indent1 );
6279           $worksheet->write( 'A2', "This text is indented 2 levels", $indent2 );
6280
6281           $workbook->close();
6282
6283           __END__
6284
6285       Download this example:
6286       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/indent.pl>
6287
6288   Example: macros.pl
6289       An example of adding macros to an Excel::Writer::XLSX file using a VBA
6290       project file extracted from an existing Excel xlsm file.
6291
6292       The "extract_vba" utility supplied with Excel::Writer::XLSX can be used
6293       to extract the vbaProject.bin file.
6294
6295       An embedded macro is connected to a form button on the worksheet.
6296
6297       Source code for this example:
6298
6299           #!/usr/bin/perl
6300
6301           #######################################################################
6302           #
6303           # An example of adding macros to an Excel::Writer::XLSX file using
6304           # a VBA project file extracted from an existing Excel xlsm file.
6305           #
6306           # The C<extract_vba> utility supplied with Excel::Writer::XLSX can be
6307           # used to extract the vbaProject.bin file.
6308           #
6309           # An embedded macro is connected to a form button on the worksheet.
6310           #
6311           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6312           #
6313
6314           use strict;
6315           use warnings;
6316           use Excel::Writer::XLSX;
6317
6318           # Note the file extension should be .xlsm.
6319           my $workbook  = Excel::Writer::XLSX->new( 'macros.xlsm' );
6320           my $worksheet = $workbook->add_worksheet();
6321
6322           $worksheet->set_column( 'A:A', 30 );
6323
6324           # Add the VBA project binary.
6325           $workbook->add_vba_project( './vbaProject.bin' );
6326
6327           # Show text for the end user.
6328           $worksheet->write( 'A3', 'Press the button to say hello.' );
6329
6330           # Add a button tied to a macro in the VBA project.
6331           $worksheet->insert_button(
6332               'B3',
6333               {
6334                   macro   => 'say_hello',
6335                   caption => 'Press Me',
6336                   width   => 80,
6337                   height  => 30
6338               }
6339           );
6340
6341           $workbook->close();
6342
6343           __END__
6344
6345       Download this example:
6346       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/macros.pl>
6347
6348   Example: merge1.pl
6349       Simple example of merging cells using the Excel::Writer::XLSX module.
6350
6351       This example merges three cells using the "Centre Across Selection"
6352       alignment which was the Excel 5 method of achieving a merge. For a more
6353       modern approach use the merge_range() worksheet method instead.  See
6354       the merge3.pl - merge6.pl programs.
6355
6356       Source code for this example:
6357
6358           #!/usr/bin/perl
6359
6360           ###############################################################################
6361           #
6362           # Simple example of merging cells using the Excel::Writer::XLSX module.
6363           #
6364           # This example merges three cells using the "Centre Across Selection"
6365           # alignment which was the Excel 5 method of achieving a merge. For a more
6366           # modern approach use the merge_range() worksheet method instead.
6367           # See the merge3.pl - merge6.pl programs.
6368           #
6369           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6370           #
6371
6372           use strict;
6373           use warnings;
6374           use Excel::Writer::XLSX;
6375
6376           # Create a new workbook and add a worksheet
6377           my $workbook  = Excel::Writer::XLSX->new( 'merge1.xlsx' );
6378           my $worksheet = $workbook->add_worksheet();
6379
6380
6381           # Increase the cell size of the merged cells to highlight the formatting.
6382           $worksheet->set_column( 'B:D', 20 );
6383           $worksheet->set_row( 2, 30 );
6384
6385
6386           # Create a merge format
6387           my $format = $workbook->add_format( center_across => 1 );
6388
6389
6390           # Only one cell should contain text, the others should be blank.
6391           $worksheet->write( 2, 1, "Center across selection", $format );
6392           $worksheet->write_blank( 2, 2, $format );
6393           $worksheet->write_blank( 2, 3, $format );
6394
6395           $workbook->close();
6396
6397           __END__
6398
6399       Download this example:
6400       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/merge1.pl>
6401
6402   Example: merge2.pl
6403       Simple example of merging cells using the Excel::Writer::XLSX module
6404
6405       This example merges three cells using the "Centre Across Selection"
6406       alignment which was the Excel 5 method of achieving a merge. For a more
6407       modern approach use the merge_range() worksheet method instead.  See
6408       the merge3.pl - merge6.pl programs.
6409
6410       Source code for this example:
6411
6412           #!/usr/bin/perl
6413
6414           ###############################################################################
6415           #
6416           # Simple example of merging cells using the Excel::Writer::XLSX module
6417           #
6418           # This example merges three cells using the "Centre Across Selection"
6419           # alignment which was the Excel 5 method of achieving a merge. For a more
6420           # modern approach use the merge_range() worksheet method instead.
6421           # See the merge3.pl - merge6.pl programs.
6422           #
6423           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6424           #
6425
6426           use strict;
6427           use warnings;
6428           use Excel::Writer::XLSX;
6429
6430           # Create a new workbook and add a worksheet
6431           my $workbook  = Excel::Writer::XLSX->new( 'merge2.xlsx' );
6432           my $worksheet = $workbook->add_worksheet();
6433
6434
6435           # Increase the cell size of the merged cells to highlight the formatting.
6436           $worksheet->set_column( 1, 2, 30 );
6437           $worksheet->set_row( 2, 40 );
6438
6439
6440           # Create a merged format
6441           my $format = $workbook->add_format(
6442               center_across => 1,
6443               bold          => 1,
6444               size          => 15,
6445               pattern       => 1,
6446               border        => 6,
6447               color         => 'white',
6448               fg_color      => 'green',
6449               border_color  => 'yellow',
6450               align         => 'vcenter',
6451           );
6452
6453
6454           # Only one cell should contain text, the others should be blank.
6455           $worksheet->write( 2, 1, "Center across selection", $format );
6456           $worksheet->write_blank( 2, 2, $format );
6457
6458           $workbook->close();
6459
6460           __END__
6461
6462       Download this example:
6463       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/merge2.pl>
6464
6465   Example: merge3.pl
6466       Example of how to use Excel::Writer::XLSX to write a hyperlink in a
6467       merged cell.
6468
6469       Source code for this example:
6470
6471           #!/usr/bin/perl
6472
6473           ###############################################################################
6474           #
6475           # Example of how to use Excel::Writer::XLSX to write a hyperlink in a
6476           # merged cell.
6477           #
6478           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6479           #
6480
6481           use strict;
6482           use warnings;
6483           use Excel::Writer::XLSX;
6484
6485           # Create a new workbook and add a worksheet
6486           my $workbook  = Excel::Writer::XLSX->new( 'merge3.xlsx' );
6487           my $worksheet = $workbook->add_worksheet();
6488
6489
6490           # Increase the cell size of the merged cells to highlight the formatting.
6491           $worksheet->set_row( $_, 30 ) for ( 3, 6, 7 );
6492           $worksheet->set_column( 'B:D', 20 );
6493
6494
6495           ###############################################################################
6496           #
6497           # Example: Merge cells containing a hyperlink using merge_range().
6498           #
6499           my $format = $workbook->add_format(
6500               border    => 1,
6501               underline => 1,
6502               color     => 'blue',
6503               align     => 'center',
6504               valign    => 'vcenter',
6505           );
6506
6507           # Merge 3 cells
6508           $worksheet->merge_range( 'B4:D4', 'http://www.perl.com', $format );
6509
6510
6511           # Merge 3 cells over two rows
6512           $worksheet->merge_range( 'B7:D8', 'http://www.perl.com', $format );
6513
6514
6515           $workbook->close();
6516
6517           __END__
6518
6519       Download this example:
6520       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/merge3.pl>
6521
6522   Example: merge4.pl
6523       Example of how to use the Excel::Writer::XLSX merge_range() workbook
6524       method with complex formatting.
6525
6526       Source code for this example:
6527
6528           #!/usr/bin/perl
6529
6530           ###############################################################################
6531           #
6532           # Example of how to use the Excel::Writer::XLSX merge_range() workbook
6533           # method with complex formatting.
6534           #
6535           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6536           #
6537
6538           use strict;
6539           use warnings;
6540           use Excel::Writer::XLSX;
6541
6542           # Create a new workbook and add a worksheet
6543           my $workbook  = Excel::Writer::XLSX->new( 'merge4.xlsx' );
6544           my $worksheet = $workbook->add_worksheet();
6545
6546
6547           # Increase the cell size of the merged cells to highlight the formatting.
6548           $worksheet->set_row( $_, 30 ) for ( 1 .. 11 );
6549           $worksheet->set_column( 'B:D', 20 );
6550
6551
6552           ###############################################################################
6553           #
6554           # Example 1: Text centered vertically and horizontally
6555           #
6556           my $format1 = $workbook->add_format(
6557               border => 6,
6558               bold   => 1,
6559               color  => 'red',
6560               valign => 'vcenter',
6561               align  => 'center',
6562           );
6563
6564
6565           $worksheet->merge_range( 'B2:D3', 'Vertical and horizontal', $format1 );
6566
6567
6568           ###############################################################################
6569           #
6570           # Example 2: Text aligned to the top and left
6571           #
6572           my $format2 = $workbook->add_format(
6573               border => 6,
6574               bold   => 1,
6575               color  => 'red',
6576               valign => 'top',
6577               align  => 'left',
6578           );
6579
6580
6581           $worksheet->merge_range( 'B5:D6', 'Aligned to the top and left', $format2 );
6582
6583
6584           ###############################################################################
6585           #
6586           # Example 3:  Text aligned to the bottom and right
6587           #
6588           my $format3 = $workbook->add_format(
6589               border => 6,
6590               bold   => 1,
6591               color  => 'red',
6592               valign => 'bottom',
6593               align  => 'right',
6594           );
6595
6596
6597           $worksheet->merge_range( 'B8:D9', 'Aligned to the bottom and right', $format3 );
6598
6599
6600           ###############################################################################
6601           #
6602           # Example 4:  Text justified (i.e. wrapped) in the cell
6603           #
6604           my $format4 = $workbook->add_format(
6605               border => 6,
6606               bold   => 1,
6607               color  => 'red',
6608               valign => 'top',
6609               align  => 'justify',
6610           );
6611
6612
6613           $worksheet->merge_range( 'B11:D12', 'Justified: ' . 'so on and ' x 18,
6614               $format4 );
6615
6616           $workbook->close();
6617
6618           __END__
6619
6620       Download this example:
6621       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/merge4.pl>
6622
6623   Example: merge5.pl
6624       Example of how to use the Excel::Writer::XLSX merge_cells() workbook
6625       method with complex formatting and rotation.
6626
6627       Source code for this example:
6628
6629           #!/usr/bin/perl
6630
6631           ###############################################################################
6632           #
6633           # Example of how to use the Excel::Writer::XLSX merge_cells() workbook
6634           # method with complex formatting and rotation.
6635           #
6636           #
6637           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6638           #
6639
6640           use strict;
6641           use warnings;
6642           use Excel::Writer::XLSX;
6643
6644           # Create a new workbook and add a worksheet
6645           my $workbook  = Excel::Writer::XLSX->new( 'merge5.xlsx' );
6646           my $worksheet = $workbook->add_worksheet();
6647
6648
6649           # Increase the cell size of the merged cells to highlight the formatting.
6650           $worksheet->set_row( $_, 36 ) for ( 3 .. 8 );
6651           $worksheet->set_column( $_, $_, 15 ) for ( 1, 3, 5 );
6652
6653
6654           ###############################################################################
6655           #
6656           # Rotation 1, letters run from top to bottom
6657           #
6658           my $format1 = $workbook->add_format(
6659               border   => 6,
6660               bold     => 1,
6661               color    => 'red',
6662               valign   => 'vcentre',
6663               align    => 'centre',
6664               rotation => 270,
6665           );
6666
6667
6668           $worksheet->merge_range( 'B4:B9', 'Rotation 270', $format1 );
6669
6670
6671           ###############################################################################
6672           #
6673           # Rotation 2, 90° anticlockwise
6674           #
6675           my $format2 = $workbook->add_format(
6676               border   => 6,
6677               bold     => 1,
6678               color    => 'red',
6679               valign   => 'vcentre',
6680               align    => 'centre',
6681               rotation => 90,
6682           );
6683
6684
6685           $worksheet->merge_range( 'D4:D9', 'Rotation 90°', $format2 );
6686
6687
6688           ###############################################################################
6689           #
6690           # Rotation 3, 90° clockwise
6691           #
6692           my $format3 = $workbook->add_format(
6693               border   => 6,
6694               bold     => 1,
6695               color    => 'red',
6696               valign   => 'vcentre',
6697               align    => 'centre',
6698               rotation => -90,
6699           );
6700
6701
6702           $worksheet->merge_range( 'F4:F9', 'Rotation -90°', $format3 );
6703
6704           $workbook->close();
6705
6706           __END__
6707
6708       Download this example:
6709       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/merge5.pl>
6710
6711   Example: merge6.pl
6712       Example of how to use the Excel::Writer::XLSX merge_cells() workbook
6713       method with Unicode strings.
6714
6715       Source code for this example:
6716
6717           #!/usr/bin/perl
6718
6719           ###############################################################################
6720           #
6721           # Example of how to use the Excel::Writer::XLSX merge_cells() workbook
6722           # method with Unicode strings.
6723           #
6724           #
6725           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
6726           #
6727
6728           use strict;
6729           use warnings;
6730           use Excel::Writer::XLSX;
6731
6732           # Create a new workbook and add a worksheet
6733           my $workbook  = Excel::Writer::XLSX->new( 'merge6.xlsx' );
6734           my $worksheet = $workbook->add_worksheet();
6735
6736
6737           # Increase the cell size of the merged cells to highlight the formatting.
6738           $worksheet->set_row( $_, 36 ) for 2 .. 9;
6739           $worksheet->set_column( 'B:D', 25 );
6740
6741
6742           # Format for the merged cells.
6743           my $format = $workbook->add_format(
6744               border => 6,
6745               bold   => 1,
6746               color  => 'red',
6747               size   => 20,
6748               valign => 'vcentre',
6749               align  => 'left',
6750               indent => 1,
6751           );
6752
6753
6754           ###############################################################################
6755           #
6756           # Write an Ascii string.
6757           #
6758           $worksheet->merge_range( 'B3:D4', 'ASCII: A simple string', $format );
6759
6760
6761           ###############################################################################
6762           #
6763           # Write a UTF-8 Unicode string.
6764           #
6765           my $smiley = chr 0x263a;
6766           $worksheet->merge_range( 'B6:D7', "UTF-8: A Unicode smiley $smiley", $format );
6767
6768           $workbook->close();
6769
6770           __END__
6771
6772       Download this example:
6773       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/merge6.pl>
6774
6775   Example: mod_perl1.pl
6776       Example of how to use the Excel::Writer::XLSX module to send an Excel
6777       file to a browser using mod_perl 1 and Apache
6778
6779       This module ties *XLSX directly to Apache, and with the correct
6780       content-disposition/types it will prompt the user to save the file, or
6781       open it at this location.
6782
6783       This script is a modification of the Excel::Writer::XLSX cgi.pl
6784       example.
6785
6786       Change the name of this file to Cgi.pm.  Change the package location to
6787       wherever you locate this package.  In the example below it is located
6788       in the Excel::Writer::XLSX directory.
6789
6790       Your httpd.conf entry for this module, should you choose to use it as a
6791       stand alone app, should look similar to the following:
6792
6793           <Location /spreadsheet-test>
6794             SetHandler perl-script
6795             PerlHandler Excel::Writer::XLSX::Cgi
6796             PerlSendHeader On
6797           </Location>
6798
6799       The PerlHandler name above and the package name below *have* to match.
6800
6801           ###############################################################################
6802           #
6803           # Example of how to use the Excel::Writer::XLSX module to send an Excel
6804           # file to a browser using mod_perl 1 and Apache
6805           #
6806           # This module ties *XLSX directly to Apache, and with the correct
6807           # content-disposition/types it will prompt the user to save
6808           # the file, or open it at this location.
6809           #
6810           # This script is a modification of the Excel::Writer::XLSX cgi.pl example.
6811           #
6812           # Change the name of this file to Cgi.pm.
6813           # Change the package location to wherever you locate this package.
6814           # In the example below it is located in the Excel::Writer::XLSX directory.
6815           #
6816           # Your httpd.conf entry for this module, should you choose to use it
6817           # as a stand alone app, should look similar to the following:
6818           #
6819           #     <Location /spreadsheet-test>
6820           #       SetHandler perl-script
6821           #       PerlHandler Excel::Writer::XLSX::Cgi
6822           #       PerlSendHeader On
6823           #     </Location>
6824           #
6825           # The PerlHandler name above and the package name below *have* to match.
6826
6827           # Apr 2001, Thomas Sullivan, webmaster@860.org
6828           # Feb 2001, John McNamara, jmcnamara@cpan.org
6829
6830           package Excel::Writer::XLSX::Cgi;
6831
6832           ##########################################
6833           # Pragma Definitions
6834           ##########################################
6835           use strict;
6836
6837           ##########################################
6838           # Required Modules
6839           ##########################################
6840           use Apache::Constants qw(:common);
6841           use Apache::Request;
6842           use Apache::URI;    # This may not be needed
6843           use Excel::Writer::XLSX;
6844
6845           ##########################################
6846           # Main App Body
6847           ##########################################
6848           sub handler {
6849
6850               # New apache object
6851               # Should you decide to use it.
6852               my $r = Apache::Request->new( shift );
6853
6854               # Set the filename and send the content type
6855               # This will appear when they save the spreadsheet
6856               my $filename = "cgitest.xlsx";
6857
6858               ####################################################
6859               ## Send the content type headers
6860               ####################################################
6861               print "Content-disposition: attachment;filename=$filename\n";
6862               print "Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n\n";
6863
6864               ####################################################
6865               # Tie a filehandle to Apache's STDOUT.
6866               # Create a new workbook and add a worksheet.
6867               ####################################################
6868               tie *XLSX => 'Apache';
6869               binmode( *XLSX );
6870
6871               my $workbook  = Excel::Writer::XLSX->new( \*XLSX );
6872               my $worksheet = $workbook->add_worksheet();
6873
6874
6875               # Set the column width for column 1
6876               $worksheet->set_column( 0, 0, 20 );
6877
6878
6879               # Create a format
6880               my $format = $workbook->add_format();
6881               $format->set_bold();
6882               $format->set_size( 15 );
6883               $format->set_color( 'blue' );
6884
6885
6886               # Write to the workbook
6887               $worksheet->write( 0, 0, "Hi Excel!", $format );
6888
6889               # You must close the workbook for Content-disposition
6890               $workbook->close();
6891           }
6892
6893           1;
6894
6895       Download this example:
6896       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/mod_perl1.pl>
6897
6898   Example: mod_perl2.pl
6899       Example of how to use the Excel::Writer::XLSX module to send an Excel
6900       file to a browser using mod_perl 2 and Apache.
6901
6902       This module ties *XLSX directly to Apache, and with the correct
6903       content-disposition/types it will prompt the user to save the file, or
6904       open it at this location.
6905
6906       This script is a modification of the Excel::Writer::XLSX cgi.pl
6907       example.
6908
6909       Change the name of this file to MP2Test.pm.  Change the package
6910       location to wherever you locate this package.  In the example below it
6911       is located in the Excel::Writer::XLSX directory.
6912
6913       Your httpd.conf entry for this module, should you choose to use it as a
6914       stand alone app, should look similar to the following:
6915
6916           PerlModule Apache2::RequestRec
6917           PerlModule APR::Table
6918           PerlModule Apache2::RequestIO
6919
6920           <Location /spreadsheet-test>
6921              SetHandler perl-script
6922              PerlResponseHandler Excel::Writer::XLSX::MP2Test
6923           </Location>
6924
6925       The PerlResponseHandler must match the package name below.
6926
6927           ###############################################################################
6928           #
6929           # Example of how to use the Excel::Writer::XLSX module to send an Excel
6930           # file to a browser using mod_perl 2 and Apache.
6931           #
6932           # This module ties *XLSX directly to Apache, and with the correct
6933           # content-disposition/types it will prompt the user to save
6934           # the file, or open it at this location.
6935           #
6936           # This script is a modification of the Excel::Writer::XLSX cgi.pl example.
6937           #
6938           # Change the name of this file to MP2Test.pm.
6939           # Change the package location to wherever you locate this package.
6940           # In the example below it is located in the Excel::Writer::XLSX directory.
6941           #
6942           # Your httpd.conf entry for this module, should you choose to use it
6943           # as a stand alone app, should look similar to the following:
6944           #
6945           #     PerlModule Apache2::RequestRec
6946           #     PerlModule APR::Table
6947           #     PerlModule Apache2::RequestIO
6948           #
6949           #     <Location /spreadsheet-test>
6950           #        SetHandler perl-script
6951           #        PerlResponseHandler Excel::Writer::XLSX::MP2Test
6952           #     </Location>
6953           #
6954           # The PerlResponseHandler must match the package name below.
6955
6956           # Jun 2004, Matisse Enzer, matisse@matisse.net  (mod_perl 2 version)
6957           # Apr 2001, Thomas Sullivan, webmaster@860.org
6958           # Feb 2001, John McNamara, jmcnamara@cpan.org
6959
6960           package Excel::Writer::XLSX::MP2Test;
6961
6962           ##########################################
6963           # Pragma Definitions
6964           ##########################################
6965           use strict;
6966
6967           ##########################################
6968           # Required Modules
6969           ##########################################
6970           use Apache2::Const -compile => qw( :common );
6971           use Excel::Writer::XLSX;
6972
6973           ##########################################
6974           # Main App Body
6975           ##########################################
6976           sub handler {
6977               my ( $r ) = @_;   # Apache request object is passed to handler in mod_perl 2
6978
6979               # Set the filename and send the content type
6980               # This will appear when they save the spreadsheet
6981               my $filename = "mod_perl2_test.xlsx";
6982
6983               ####################################################
6984               ## Send the content type headers the mod_perl 2 way
6985               ####################################################
6986               $r->headers_out->{'Content-Disposition'} = "attachment;filename=$filename";
6987               $r->content_type( 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
6988
6989               ####################################################
6990               # Tie a filehandle to Apache's STDOUT.
6991               # Create a new workbook and add a worksheet.
6992               ####################################################
6993               tie *XLSX => $r;  # The mod_perl 2 way. Tie to the Apache::RequestRec object
6994               binmode( *XLSX );
6995
6996               my $workbook  = Excel::Writer::XLSX->new( \*XLSX );
6997               my $worksheet = $workbook->add_worksheet();
6998
6999
7000               # Set the column width for column 1
7001               $worksheet->set_column( 0, 0, 20 );
7002
7003
7004               # Create a format
7005               my $format = $workbook->add_format();
7006               $format->set_bold();
7007               $format->set_size( 15 );
7008               $format->set_color( 'blue' );
7009
7010
7011               # Write to the workbook
7012               $worksheet->write( 0, 0, 'Hi Excel! from ' . $r->hostname, $format );
7013
7014               # You must close the workbook for Content-disposition
7015               $workbook->close();
7016               return Apache2::Const::OK;
7017           }
7018
7019           1;
7020
7021       Download this example:
7022       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/mod_perl2.pl>
7023
7024   Example: outline.pl
7025       Example of how use Excel::Writer::XLSX to generate Excel outlines and
7026       grouping.
7027
7028       Excel allows you to group rows or columns so that they can be hidden or
7029       displayed with a single mouse click. This feature is referred to as
7030       outlines.
7031
7032       Outlines can reduce complex data down to a few salient sub-totals or
7033       summaries.
7034
7035       This feature is best viewed in Excel but the following is an ASCII
7036       representation of what a worksheet with three outlines might look like.
7037       Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
7038       level 1. The lines at the left hand side are called outline level bars.
7039
7040                   ------------------------------------------
7041            1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7042                   ------------------------------------------
7043             _    | 1 |   A   |       |       |       |  ...
7044            |  _  | 2 |   B   |       |       |       |  ...
7045            | |   | 3 |  (C)  |       |       |       |  ...
7046            | |   | 4 |  (D)  |       |       |       |  ...
7047            | -   | 5 |   E   |       |       |       |  ...
7048            |  _  | 6 |   F   |       |       |       |  ...
7049            | |   | 7 |  (G)  |       |       |       |  ...
7050            | |   | 8 |  (H)  |       |       |       |  ...
7051            | -   | 9 |   I   |       |       |       |  ...
7052            -     | . |  ...  |  ...  |  ...  |  ...  |  ...
7053
7054       Clicking the minus sign on each of the level 2 outlines will collapse
7055       and hide the data as shown in the next figure. The minus sign changes
7056       to a plus sign to indicate that the data in the outline is hidden.
7057
7058                   ------------------------------------------
7059            1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7060                   ------------------------------------------
7061             _    | 1 |   A   |       |       |       |  ...
7062            |     | 2 |   B   |       |       |       |  ...
7063            | +   | 5 |   E   |       |       |       |  ...
7064            |     | 6 |   F   |       |       |       |  ...
7065            | +   | 9 |   I   |       |       |       |  ...
7066            -     | . |  ...  |  ...  |  ...  |  ...  |  ...
7067
7068       Clicking on the minus sign on the level 1 outline will collapse the
7069       remaining rows as follows:
7070
7071                   ------------------------------------------
7072            1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7073                   ------------------------------------------
7074                  | 1 |   A   |       |       |       |  ...
7075            +     | . |  ...  |  ...  |  ...  |  ...  |  ...
7076
7077       See the main Excel::Writer::XLSX documentation for more information.
7078
7079       Source code for this example:
7080
7081           #!/usr/bin/perl
7082
7083           ###############################################################################
7084           #
7085           # Example of how use Excel::Writer::XLSX to generate Excel outlines and
7086           # grouping.
7087           #
7088           #
7089           # Excel allows you to group rows or columns so that they can be hidden or
7090           # displayed with a single mouse click. This feature is referred to as outlines.
7091           #
7092           # Outlines can reduce complex data down to a few salient sub-totals or
7093           # summaries.
7094           #
7095           # This feature is best viewed in Excel but the following is an ASCII
7096           # representation of what a worksheet with three outlines might look like.
7097           # Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
7098           # level 1. The lines at the left hand side are called outline level bars.
7099           #
7100           #
7101           #             ------------------------------------------
7102           #      1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7103           #             ------------------------------------------
7104           #       _    | 1 |   A   |       |       |       |  ...
7105           #      |  _  | 2 |   B   |       |       |       |  ...
7106           #      | |   | 3 |  (C)  |       |       |       |  ...
7107           #      | |   | 4 |  (D)  |       |       |       |  ...
7108           #      | -   | 5 |   E   |       |       |       |  ...
7109           #      |  _  | 6 |   F   |       |       |       |  ...
7110           #      | |   | 7 |  (G)  |       |       |       |  ...
7111           #      | |   | 8 |  (H)  |       |       |       |  ...
7112           #      | -   | 9 |   I   |       |       |       |  ...
7113           #      -     | . |  ...  |  ...  |  ...  |  ...  |  ...
7114           #
7115           #
7116           # Clicking the minus sign on each of the level 2 outlines will collapse and
7117           # hide the data as shown in the next figure. The minus sign changes to a plus
7118           # sign to indicate that the data in the outline is hidden.
7119           #
7120           #             ------------------------------------------
7121           #      1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7122           #             ------------------------------------------
7123           #       _    | 1 |   A   |       |       |       |  ...
7124           #      |     | 2 |   B   |       |       |       |  ...
7125           #      | +   | 5 |   E   |       |       |       |  ...
7126           #      |     | 6 |   F   |       |       |       |  ...
7127           #      | +   | 9 |   I   |       |       |       |  ...
7128           #      -     | . |  ...  |  ...  |  ...  |  ...  |  ...
7129           #
7130           #
7131           # Clicking on the minus sign on the level 1 outline will collapse the remaining
7132           # rows as follows:
7133           #
7134           #             ------------------------------------------
7135           #      1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7136           #             ------------------------------------------
7137           #            | 1 |   A   |       |       |       |  ...
7138           #      +     | . |  ...  |  ...  |  ...  |  ...  |  ...
7139           #
7140           # See the main Excel::Writer::XLSX documentation for more information.
7141           #
7142           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
7143           #
7144
7145
7146           use strict;
7147           use warnings;
7148           use Excel::Writer::XLSX;
7149
7150           # Create a new workbook and add some worksheets
7151           my $workbook   = Excel::Writer::XLSX->new( 'outline.xlsx' );
7152           my $worksheet1 = $workbook->add_worksheet( 'Outlined Rows' );
7153           my $worksheet2 = $workbook->add_worksheet( 'Collapsed Rows' );
7154           my $worksheet3 = $workbook->add_worksheet( 'Outline Columns' );
7155           my $worksheet4 = $workbook->add_worksheet( 'Outline levels' );
7156
7157           # Add a general format
7158           my $bold = $workbook->add_format( bold => 1 );
7159
7160
7161           ###############################################################################
7162           #
7163           # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
7164           # functions so that it looks like the type of automatic outlines that are
7165           # generated when you use the Excel Data->SubTotals menu item.
7166           #
7167
7168
7169           # For outlines the important parameters are $hidden and $level. Rows with the
7170           # same $level are grouped together. The group will be collapsed if $hidden is
7171           # non-zero. $height and $XF are assigned default values if they are undef.
7172           #
7173           # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
7174           #
7175           $worksheet1->set_row( 1, undef, undef, 0, 2 );
7176           $worksheet1->set_row( 2, undef, undef, 0, 2 );
7177           $worksheet1->set_row( 3, undef, undef, 0, 2 );
7178           $worksheet1->set_row( 4, undef, undef, 0, 2 );
7179           $worksheet1->set_row( 5, undef, undef, 0, 1 );
7180
7181           $worksheet1->set_row( 6,  undef, undef, 0, 2 );
7182           $worksheet1->set_row( 7,  undef, undef, 0, 2 );
7183           $worksheet1->set_row( 8,  undef, undef, 0, 2 );
7184           $worksheet1->set_row( 9,  undef, undef, 0, 2 );
7185           $worksheet1->set_row( 10, undef, undef, 0, 1 );
7186
7187
7188           # Add a column format for clarity
7189           $worksheet1->set_column( 'A:A', 20 );
7190
7191           # Add the data, labels and formulas
7192           $worksheet1->write( 'A1', 'Region', $bold );
7193           $worksheet1->write( 'A2', 'North' );
7194           $worksheet1->write( 'A3', 'North' );
7195           $worksheet1->write( 'A4', 'North' );
7196           $worksheet1->write( 'A5', 'North' );
7197           $worksheet1->write( 'A6', 'North Total', $bold );
7198
7199           $worksheet1->write( 'B1', 'Sales', $bold );
7200           $worksheet1->write( 'B2', 1000 );
7201           $worksheet1->write( 'B3', 1200 );
7202           $worksheet1->write( 'B4', 900 );
7203           $worksheet1->write( 'B5', 1200 );
7204           $worksheet1->write( 'B6', '=SUBTOTAL(9,B2:B5)', $bold );
7205
7206           $worksheet1->write( 'A7',  'South' );
7207           $worksheet1->write( 'A8',  'South' );
7208           $worksheet1->write( 'A9',  'South' );
7209           $worksheet1->write( 'A10', 'South' );
7210           $worksheet1->write( 'A11', 'South Total', $bold );
7211
7212           $worksheet1->write( 'B7',  400 );
7213           $worksheet1->write( 'B8',  600 );
7214           $worksheet1->write( 'B9',  500 );
7215           $worksheet1->write( 'B10', 600 );
7216           $worksheet1->write( 'B11', '=SUBTOTAL(9,B7:B10)', $bold );
7217
7218           $worksheet1->write( 'A12', 'Grand Total',         $bold );
7219           $worksheet1->write( 'B12', '=SUBTOTAL(9,B2:B10)', $bold );
7220
7221
7222           ###############################################################################
7223           #
7224           # Example 2: Create a worksheet with outlined rows. This is the same as the
7225           # previous example except that the rows are collapsed.
7226           # Note: We need to indicate the row that contains the collapsed symbol '+'
7227           # with the optional parameter, $collapsed.
7228
7229           # The group will be collapsed if $hidden is non-zero.
7230           # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
7231           #
7232           $worksheet2->set_row( 1, undef, undef, 1, 2 );
7233           $worksheet2->set_row( 2, undef, undef, 1, 2 );
7234           $worksheet2->set_row( 3, undef, undef, 1, 2 );
7235           $worksheet2->set_row( 4, undef, undef, 1, 2 );
7236           $worksheet2->set_row( 5, undef, undef, 1, 1 );
7237
7238           $worksheet2->set_row( 6,  undef, undef, 1, 2 );
7239           $worksheet2->set_row( 7,  undef, undef, 1, 2 );
7240           $worksheet2->set_row( 8,  undef, undef, 1, 2 );
7241           $worksheet2->set_row( 9,  undef, undef, 1, 2 );
7242           $worksheet2->set_row( 10, undef, undef, 1, 1 );
7243           $worksheet2->set_row( 11, undef, undef, 0, 0, 1 );
7244
7245
7246           # Add a column format for clarity
7247           $worksheet2->set_column( 'A:A', 20 );
7248
7249           # Add the data, labels and formulas
7250           $worksheet2->write( 'A1', 'Region', $bold );
7251           $worksheet2->write( 'A2', 'North' );
7252           $worksheet2->write( 'A3', 'North' );
7253           $worksheet2->write( 'A4', 'North' );
7254           $worksheet2->write( 'A5', 'North' );
7255           $worksheet2->write( 'A6', 'North Total', $bold );
7256
7257           $worksheet2->write( 'B1', 'Sales', $bold );
7258           $worksheet2->write( 'B2', 1000 );
7259           $worksheet2->write( 'B3', 1200 );
7260           $worksheet2->write( 'B4', 900 );
7261           $worksheet2->write( 'B5', 1200 );
7262           $worksheet2->write( 'B6', '=SUBTOTAL(9,B2:B5)', $bold );
7263
7264           $worksheet2->write( 'A7',  'South' );
7265           $worksheet2->write( 'A8',  'South' );
7266           $worksheet2->write( 'A9',  'South' );
7267           $worksheet2->write( 'A10', 'South' );
7268           $worksheet2->write( 'A11', 'South Total', $bold );
7269
7270           $worksheet2->write( 'B7',  400 );
7271           $worksheet2->write( 'B8',  600 );
7272           $worksheet2->write( 'B9',  500 );
7273           $worksheet2->write( 'B10', 600 );
7274           $worksheet2->write( 'B11', '=SUBTOTAL(9,B7:B10)', $bold );
7275
7276           $worksheet2->write( 'A12', 'Grand Total',         $bold );
7277           $worksheet2->write( 'B12', '=SUBTOTAL(9,B2:B10)', $bold );
7278
7279
7280           ###############################################################################
7281           #
7282           # Example 3: Create a worksheet with outlined columns.
7283           #
7284           my $data = [
7285               [ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ' Total' ],
7286               [ 'North', 50,    20,    15,    25,    65,    80,    '=SUM(B2:G2)' ],
7287               [ 'South', 10,    20,    30,    50,    50,    50,    '=SUM(B3:G3)' ],
7288               [ 'East',  45,    75,    50,    15,    75,    100,   '=SUM(B4:G4)' ],
7289               [ 'West',  15,    15,    55,    35,    20,    50,    '=SUM(B5:G5)' ],
7290           ];
7291
7292           # Add bold format to the first row
7293           $worksheet3->set_row( 0, undef, $bold );
7294
7295           # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
7296           $worksheet3->set_column( 'A:A', 10, $bold );
7297           $worksheet3->set_column( 'B:G', 5, undef, 0, 1 );
7298           $worksheet3->set_column( 'H:H', 10 );
7299
7300           # Write the data and a formula
7301           $worksheet3->write_col( 'A1', $data );
7302           $worksheet3->write( 'H6', '=SUM(H2:H5)', $bold );
7303
7304
7305           ###############################################################################
7306           #
7307           # Example 4: Show all possible outline levels.
7308           #
7309           my $levels = [
7310               "Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6",
7311               "Level 7", "Level 6", "Level 5", "Level 4", "Level 3", "Level 2",
7312               "Level 1"
7313           ];
7314
7315
7316           $worksheet4->write_col( 'A1', $levels );
7317
7318           $worksheet4->set_row( 0,  undef, undef, undef, 1 );
7319           $worksheet4->set_row( 1,  undef, undef, undef, 2 );
7320           $worksheet4->set_row( 2,  undef, undef, undef, 3 );
7321           $worksheet4->set_row( 3,  undef, undef, undef, 4 );
7322           $worksheet4->set_row( 4,  undef, undef, undef, 5 );
7323           $worksheet4->set_row( 5,  undef, undef, undef, 6 );
7324           $worksheet4->set_row( 6,  undef, undef, undef, 7 );
7325           $worksheet4->set_row( 7,  undef, undef, undef, 6 );
7326           $worksheet4->set_row( 8,  undef, undef, undef, 5 );
7327           $worksheet4->set_row( 9,  undef, undef, undef, 4 );
7328           $worksheet4->set_row( 10, undef, undef, undef, 3 );
7329           $worksheet4->set_row( 11, undef, undef, undef, 2 );
7330           $worksheet4->set_row( 12, undef, undef, undef, 1 );
7331
7332           $workbook->close();
7333
7334           __END__
7335
7336       Download this example:
7337       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/outline.pl>
7338
7339   Example: outline_collapsed.pl
7340       Example of how to use Excel::Writer::XLSX to generate Excel outlines
7341       and grouping.
7342
7343       These examples focus mainly on collapsed outlines. See also the
7344       outlines.pl example program for more general examples.
7345
7346       Source code for this example:
7347
7348           #!/usr/bin/perl
7349
7350           ###############################################################################
7351           #
7352           # Example of how to use Excel::Writer::XLSX to generate Excel outlines and
7353           # grouping.
7354           #
7355           # These examples focus mainly on collapsed outlines. See also the
7356           # outlines.pl example program for more general examples.
7357           #
7358           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
7359           #
7360
7361           use strict;
7362           use warnings;
7363           use Excel::Writer::XLSX;
7364
7365           # Create a new workbook and add some worksheets
7366           my $workbook   = Excel::Writer::XLSX->new( 'outline_collapsed.xlsx' );
7367           my $worksheet1 = $workbook->add_worksheet( 'Outlined Rows' );
7368           my $worksheet2 = $workbook->add_worksheet( 'Collapsed Rows 1' );
7369           my $worksheet3 = $workbook->add_worksheet( 'Collapsed Rows 2' );
7370           my $worksheet4 = $workbook->add_worksheet( 'Collapsed Rows 3' );
7371           my $worksheet5 = $workbook->add_worksheet( 'Outline Columns' );
7372           my $worksheet6 = $workbook->add_worksheet( 'Collapsed Columns' );
7373
7374
7375           # Add a general format
7376           my $bold = $workbook->add_format( bold => 1 );
7377
7378
7379           #
7380           # This function will generate the same data and sub-totals on each worksheet.
7381           #
7382           sub create_sub_totals {
7383
7384               my $worksheet = $_[0];
7385
7386               # Add a column format for clarity
7387               $worksheet->set_column( 'A:A', 20 );
7388
7389               # Add the data, labels and formulas
7390               $worksheet->write( 'A1', 'Region', $bold );
7391               $worksheet->write( 'A2', 'North' );
7392               $worksheet->write( 'A3', 'North' );
7393               $worksheet->write( 'A4', 'North' );
7394               $worksheet->write( 'A5', 'North' );
7395               $worksheet->write( 'A6', 'North Total', $bold );
7396
7397               $worksheet->write( 'B1', 'Sales', $bold );
7398               $worksheet->write( 'B2', 1000 );
7399               $worksheet->write( 'B3', 1200 );
7400               $worksheet->write( 'B4', 900 );
7401               $worksheet->write( 'B5', 1200 );
7402               $worksheet->write( 'B6', '=SUBTOTAL(9,B2:B5)', $bold );
7403
7404               $worksheet->write( 'A7',  'South' );
7405               $worksheet->write( 'A8',  'South' );
7406               $worksheet->write( 'A9',  'South' );
7407               $worksheet->write( 'A10', 'South' );
7408               $worksheet->write( 'A11', 'South Total', $bold );
7409
7410               $worksheet->write( 'B7',  400 );
7411               $worksheet->write( 'B8',  600 );
7412               $worksheet->write( 'B9',  500 );
7413               $worksheet->write( 'B10', 600 );
7414               $worksheet->write( 'B11', '=SUBTOTAL(9,B7:B10)', $bold );
7415
7416               $worksheet->write( 'A12', 'Grand Total',         $bold );
7417               $worksheet->write( 'B12', '=SUBTOTAL(9,B2:B10)', $bold );
7418
7419           }
7420
7421
7422           ###############################################################################
7423           #
7424           # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
7425           # functions so that it looks like the type of automatic outlines that are
7426           # generated when you use the Excel Data->SubTotals menu item.
7427           #
7428
7429           # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
7430           $worksheet1->set_row( 1, undef, undef, 0, 2 );
7431           $worksheet1->set_row( 2, undef, undef, 0, 2 );
7432           $worksheet1->set_row( 3, undef, undef, 0, 2 );
7433           $worksheet1->set_row( 4, undef, undef, 0, 2 );
7434           $worksheet1->set_row( 5, undef, undef, 0, 1 );
7435
7436           $worksheet1->set_row( 6,  undef, undef, 0, 2 );
7437           $worksheet1->set_row( 7,  undef, undef, 0, 2 );
7438           $worksheet1->set_row( 8,  undef, undef, 0, 2 );
7439           $worksheet1->set_row( 9,  undef, undef, 0, 2 );
7440           $worksheet1->set_row( 10, undef, undef, 0, 1 );
7441
7442           # Write the sub-total data that is common to the row examples.
7443           create_sub_totals( $worksheet1 );
7444
7445
7446           ###############################################################################
7447           #
7448           # Example 2: Create a worksheet with collapsed outlined rows.
7449           # This is the same as the example 1  except that the all rows are collapsed.
7450           # Note: We need to indicate the row that contains the collapsed symbol '+' with
7451           # the optional parameter, $collapsed.
7452
7453           $worksheet2->set_row( 1, undef, undef, 1, 2 );
7454           $worksheet2->set_row( 2, undef, undef, 1, 2 );
7455           $worksheet2->set_row( 3, undef, undef, 1, 2 );
7456           $worksheet2->set_row( 4, undef, undef, 1, 2 );
7457           $worksheet2->set_row( 5, undef, undef, 1, 1 );
7458
7459           $worksheet2->set_row( 6,  undef, undef, 1, 2 );
7460           $worksheet2->set_row( 7,  undef, undef, 1, 2 );
7461           $worksheet2->set_row( 8,  undef, undef, 1, 2 );
7462           $worksheet2->set_row( 9,  undef, undef, 1, 2 );
7463           $worksheet2->set_row( 10, undef, undef, 1, 1 );
7464
7465           $worksheet2->set_row( 11, undef, undef, 0, 0, 1 );
7466
7467           # Write the sub-total data that is common to the row examples.
7468           create_sub_totals( $worksheet2 );
7469
7470
7471           ###############################################################################
7472           #
7473           # Example 3: Create a worksheet with collapsed outlined rows.
7474           # Same as the example 1  except that the two sub-totals are collapsed.
7475
7476           $worksheet3->set_row( 1, undef, undef, 1, 2 );
7477           $worksheet3->set_row( 2, undef, undef, 1, 2 );
7478           $worksheet3->set_row( 3, undef, undef, 1, 2 );
7479           $worksheet3->set_row( 4, undef, undef, 1, 2 );
7480           $worksheet3->set_row( 5, undef, undef, 0, 1, 1 );
7481
7482           $worksheet3->set_row( 6,  undef, undef, 1, 2 );
7483           $worksheet3->set_row( 7,  undef, undef, 1, 2 );
7484           $worksheet3->set_row( 8,  undef, undef, 1, 2 );
7485           $worksheet3->set_row( 9,  undef, undef, 1, 2 );
7486           $worksheet3->set_row( 10, undef, undef, 0, 1, 1 );
7487
7488
7489           # Write the sub-total data that is common to the row examples.
7490           create_sub_totals( $worksheet3 );
7491
7492
7493           ###############################################################################
7494           #
7495           # Example 4: Create a worksheet with outlined rows.
7496           # Same as the example 1  except that the two sub-totals are collapsed.
7497
7498           $worksheet4->set_row( 1, undef, undef, 1, 2 );
7499           $worksheet4->set_row( 2, undef, undef, 1, 2 );
7500           $worksheet4->set_row( 3, undef, undef, 1, 2 );
7501           $worksheet4->set_row( 4, undef, undef, 1, 2 );
7502           $worksheet4->set_row( 5, undef, undef, 1, 1, 1 );
7503
7504           $worksheet4->set_row( 6,  undef, undef, 1, 2 );
7505           $worksheet4->set_row( 7,  undef, undef, 1, 2 );
7506           $worksheet4->set_row( 8,  undef, undef, 1, 2 );
7507           $worksheet4->set_row( 9,  undef, undef, 1, 2 );
7508           $worksheet4->set_row( 10, undef, undef, 1, 1, 1 );
7509
7510           $worksheet4->set_row( 11, undef, undef, 0, 0, 1 );
7511
7512           # Write the sub-total data that is common to the row examples.
7513           create_sub_totals( $worksheet4 );
7514
7515
7516           ###############################################################################
7517           #
7518           # Example 5: Create a worksheet with outlined columns.
7519           #
7520           my $data = [
7521               [ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Total' ],
7522               [ 'North', 50,    20,    15,    25,    65,    80,,   '=SUM(B2:G2)' ],
7523               [ 'South', 10,    20,    30,    50,    50,    50,,   '=SUM(B3:G3)' ],
7524               [ 'East',  45,    75,    50,    15,    75,    100,,  '=SUM(B4:G4)' ],
7525               [ 'West',  15,    15,    55,    35,    20,    50,,   '=SUM(B5:G6)' ],
7526           ];
7527
7528           # Add bold format to the first row
7529           $worksheet5->set_row( 0, undef, $bold );
7530
7531           # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
7532           $worksheet5->set_column( 'A:A', 10, $bold );
7533           $worksheet5->set_column( 'B:G', 5, undef, 0, 1 );
7534           $worksheet5->set_column( 'H:H', 10 );
7535
7536           # Write the data and a formula
7537           $worksheet5->write_col( 'A1', $data );
7538           $worksheet5->write( 'H6', '=SUM(H2:H5)', $bold );
7539
7540
7541           ###############################################################################
7542           #
7543           # Example 6: Create a worksheet with collapsed outlined columns.
7544           # This is the same as the previous example except collapsed columns.
7545
7546           # Add bold format to the first row
7547           $worksheet6->set_row( 0, undef, $bold );
7548
7549           # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
7550           $worksheet6->set_column( 'A:A', 10, $bold );
7551           $worksheet6->set_column( 'B:G', 5,  undef, 1, 1 );
7552           $worksheet6->set_column( 'H:H', 10, undef, 0, 0, 1 );
7553
7554           # Write the data and a formula
7555           $worksheet6->write_col( 'A1', $data );
7556           $worksheet6->write( 'H6', '=SUM(H2:H5)', $bold );
7557
7558           $workbook->close();
7559
7560           __END__
7561
7562       Download this example:
7563       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/outline_collapsed.pl>
7564
7565   Example: panes.pl
7566       Example of using the Excel::Writer::XLSX module to create worksheet
7567       panes.
7568
7569       Source code for this example:
7570
7571           #!/usr/bin/perl
7572
7573           #######################################################################
7574           #
7575           # Example of using the Excel::Writer::XLSX module to create worksheet panes.
7576           #
7577           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
7578           #
7579
7580           use strict;
7581           use warnings;
7582           use Excel::Writer::XLSX;
7583
7584           my $workbook = Excel::Writer::XLSX->new( 'panes.xlsx' );
7585
7586           my $worksheet1 = $workbook->add_worksheet( 'Panes 1' );
7587           my $worksheet2 = $workbook->add_worksheet( 'Panes 2' );
7588           my $worksheet3 = $workbook->add_worksheet( 'Panes 3' );
7589           my $worksheet4 = $workbook->add_worksheet( 'Panes 4' );
7590
7591           # Freeze panes
7592           $worksheet1->freeze_panes( 1, 0 );    # 1 row
7593
7594           $worksheet2->freeze_panes( 0, 1 );    # 1 column
7595           $worksheet3->freeze_panes( 1, 1 );    # 1 row and column
7596
7597           # Split panes.
7598           # The divisions must be specified in terms of row and column dimensions.
7599           # The default row height is 15 and the default column width is 8.43
7600           #
7601           $worksheet4->split_panes( 15, 8.43 );    # 1 row and column
7602
7603
7604           #######################################################################
7605           #
7606           # Set up some formatting and text to highlight the panes
7607           #
7608
7609           my $header = $workbook->add_format(
7610               align    => 'center',
7611               valign   => 'vcenter',
7612               fg_color => '#C3FFC0',
7613           );
7614
7615           my $center = $workbook->add_format( align => 'center' );
7616
7617
7618           #######################################################################
7619           #
7620           # Sheet 1
7621           #
7622
7623           $worksheet1->set_column( 'A:I', 16 );
7624           $worksheet1->set_row( 0, 20 );
7625           $worksheet1->set_selection( 'C3' );
7626
7627           for my $i ( 0 .. 8 ) {
7628               $worksheet1->write( 0, $i, 'Scroll down', $header );
7629           }
7630
7631           for my $i ( 1 .. 100 ) {
7632               for my $j ( 0 .. 8 ) {
7633                   $worksheet1->write( $i, $j, $i + 1, $center );
7634               }
7635           }
7636
7637
7638           #######################################################################
7639           #
7640           # Sheet 2
7641           #
7642
7643           $worksheet2->set_column( 'A:A', 16 );
7644           $worksheet2->set_selection( 'C3' );
7645
7646           for my $i ( 0 .. 49 ) {
7647               $worksheet2->set_row( $i, 15 );
7648               $worksheet2->write( $i, 0, 'Scroll right', $header );
7649           }
7650
7651           for my $i ( 0 .. 49 ) {
7652               for my $j ( 1 .. 25 ) {
7653                   $worksheet2->write( $i, $j, $j, $center );
7654               }
7655           }
7656
7657
7658           #######################################################################
7659           #
7660           # Sheet 3
7661           #
7662
7663           $worksheet3->set_column( 'A:Z', 16 );
7664           $worksheet3->set_selection( 'C3' );
7665
7666           $worksheet3->write( 0, 0, '', $header );
7667
7668           for my $i ( 1 .. 25 ) {
7669               $worksheet3->write( 0, $i, 'Scroll down', $header );
7670           }
7671
7672           for my $i ( 1 .. 49 ) {
7673               $worksheet3->write( $i, 0, 'Scroll right', $header );
7674           }
7675
7676           for my $i ( 1 .. 49 ) {
7677               for my $j ( 1 .. 25 ) {
7678                   $worksheet3->write( $i, $j, $j, $center );
7679               }
7680           }
7681
7682
7683           #######################################################################
7684           #
7685           # Sheet 4
7686           #
7687
7688           $worksheet4->set_selection( 'C3' );
7689
7690           for my $i ( 1 .. 25 ) {
7691               $worksheet4->write( 0, $i, 'Scroll', $center );
7692           }
7693
7694           for my $i ( 1 .. 49 ) {
7695               $worksheet4->write( $i, 0, 'Scroll', $center );
7696           }
7697
7698           for my $i ( 1 .. 49 ) {
7699               for my $j ( 1 .. 25 ) {
7700                   $worksheet4->write( $i, $j, $j, $center );
7701               }
7702           }
7703
7704           $workbook->close();
7705
7706           __END__
7707
7708       Download this example:
7709       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/panes.pl>
7710
7711   Example: properties.pl
7712       An example of adding document properties to a Excel::Writer::XLSX file.
7713
7714       Source code for this example:
7715
7716           #!/usr/bin/perl
7717
7718           ##############################################################################
7719           #
7720           # An example of adding document properties to a Excel::Writer::XLSX file.
7721           #
7722           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
7723           #
7724
7725           use strict;
7726           use warnings;
7727           use Excel::Writer::XLSX;
7728
7729           my $workbook  = Excel::Writer::XLSX->new( 'properties.xlsx' );
7730           my $worksheet = $workbook->add_worksheet();
7731
7732
7733           $workbook->set_properties(
7734               title    => 'This is an example spreadsheet',
7735               subject  => 'With document properties',
7736               author   => 'John McNamara',
7737               manager  => 'Dr. Heinz Doofenshmirtz',
7738               company  => 'of Wolves',
7739               category => 'Example spreadsheets',
7740               keywords => 'Sample, Example, Properties',
7741               comments => 'Created with Perl and Excel::Writer::XLSX',
7742               status   => 'Quo',
7743           );
7744
7745
7746           $worksheet->set_column( 'A:A', 70 );
7747           $worksheet->write( 'A1', qq{Select 'Office Button -> Prepare -> Properties' to see the file properties.} );
7748
7749           $workbook->close();
7750
7751           __END__
7752
7753       Download this example:
7754       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/properties.pl>
7755
7756   Example: protection.pl
7757       Example of cell locking and formula hiding in an Excel worksheet via
7758       the Excel::Writer::XLSX module.
7759
7760       Source code for this example:
7761
7762           #!/usr/bin/perl
7763
7764           ########################################################################
7765           #
7766           # Example of cell locking and formula hiding in an Excel worksheet via
7767           # the Excel::Writer::XLSX module.
7768           #
7769           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
7770           #
7771
7772           use strict;
7773           use warnings;
7774           use Excel::Writer::XLSX;
7775
7776           my $workbook  = Excel::Writer::XLSX->new( 'protection.xlsx' );
7777           my $worksheet = $workbook->add_worksheet();
7778
7779           # Create some format objects
7780           my $unlocked = $workbook->add_format( locked => 0 );
7781           my $hidden   = $workbook->add_format( hidden => 1 );
7782
7783           # Format the columns
7784           $worksheet->set_column( 'A:A', 45 );
7785           $worksheet->set_selection( 'B3' );
7786
7787           # Protect the worksheet
7788           $worksheet->protect();
7789
7790           # Examples of cell locking and hiding.
7791           $worksheet->write( 'A1', 'Cell B1 is locked. It cannot be edited.' );
7792           $worksheet->write_formula( 'B1', '=1+2', undef, 3 );    # Locked by default.
7793
7794           $worksheet->write( 'A2', 'Cell B2 is unlocked. It can be edited.' );
7795           $worksheet->write_formula( 'B2', '=1+2', $unlocked, 3 );
7796
7797           $worksheet->write( 'A3', "Cell B3 is hidden. The formula isn't visible." );
7798           $worksheet->write_formula( 'B3', '=1+2', $hidden, 3 );
7799
7800           $worksheet->write( 'A5', 'Use Menu->Tools->Protection->Unprotect Sheet' );
7801           $worksheet->write( 'A6', 'to remove the worksheet protection.' );
7802
7803           $workbook->close();
7804
7805           __END__
7806
7807       Download this example:
7808       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/protection.pl>
7809
7810   Example: rich_strings.pl
7811       An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
7812       strings with multiple formatting.
7813
7814       Source code for this example:
7815
7816           #!/usr/bin/perl
7817
7818           #######################################################################
7819           #
7820           # An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
7821           # strings with multiple formatting.
7822           #
7823           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
7824           #
7825
7826           use strict;
7827           use warnings;
7828           use Excel::Writer::XLSX;
7829
7830           my $workbook  = Excel::Writer::XLSX->new( 'rich_strings.xlsx' );
7831           my $worksheet = $workbook->add_worksheet();
7832
7833           $worksheet->set_column( 'A:A', 30 );
7834
7835           # Set some formats to use.
7836           my $bold   = $workbook->add_format( bold        => 1 );
7837           my $italic = $workbook->add_format( italic      => 1 );
7838           my $red    = $workbook->add_format( color       => 'red' );
7839           my $blue   = $workbook->add_format( color       => 'blue' );
7840           my $center = $workbook->add_format( align       => 'center' );
7841           my $super  = $workbook->add_format( font_script => 1 );
7842
7843
7844           # Write some strings with multiple formats.
7845           $worksheet->write_rich_string( 'A1',
7846               'This is ', $bold, 'bold', ' and this is ', $italic, 'italic' );
7847
7848           $worksheet->write_rich_string( 'A3',
7849               'This is ', $red, 'red', ' and this is ', $blue, 'blue' );
7850
7851           $worksheet->write_rich_string( 'A5',
7852               'Some ', $bold, 'bold text', ' centered', $center );
7853
7854           $worksheet->write_rich_string( 'A7',
7855               $italic, 'j = k', $super, '(n-1)', $center );
7856
7857           $workbook->close();
7858
7859           __END__
7860
7861       Download this example:
7862       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/rich_strings.pl>
7863
7864   Example: right_to_left.pl
7865       Example of how to change the default worksheet direction from left-to-
7866       right to right-to-left as required by some eastern verions of Excel.
7867
7868       Source code for this example:
7869
7870           #!/usr/bin/perl
7871
7872           #######################################################################
7873           #
7874           # Example of how to change the default worksheet direction from
7875           # left-to-right to right-to-left as required by some eastern verions
7876           # of Excel.
7877           #
7878           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
7879           #
7880
7881           use strict;
7882           use warnings;
7883           use Excel::Writer::XLSX;
7884
7885           my $workbook   = Excel::Writer::XLSX->new( 'right_to_left.xlsx' );
7886           my $worksheet1 = $workbook->add_worksheet();
7887           my $worksheet2 = $workbook->add_worksheet();
7888
7889           $worksheet2->right_to_left();
7890
7891           $worksheet1->write( 0, 0, 'Hello' );    #  A1, B1, C1, ...
7892           $worksheet2->write( 0, 0, 'Hello' );    # ..., C1, B1, A1
7893
7894           $workbook->close();
7895
7896           __END__
7897
7898       Download this example:
7899       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/right_to_left.pl>
7900
7901   Example: sales.pl
7902       Example of a sales worksheet to demonstrate several different features.
7903       Also uses functions from the Excel::Writer::XLSX::Utility module.
7904
7905       Source code for this example:
7906
7907           #!/usr/bin/perl -w
7908
7909           ###############################################################################
7910           #
7911           # Example of a sales worksheet to demonstrate several different features.
7912           # Also uses functions from the L<Excel::Writer::XLSX::Utility> module.
7913           #
7914           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
7915           #
7916
7917           use strict;
7918           use Excel::Writer::XLSX;
7919           use Excel::Writer::XLSX::Utility;
7920
7921           # Create a new workbook and add a worksheet
7922           my $workbook  = Excel::Writer::XLSX->new( 'sales.xlsx' );
7923           my $worksheet = $workbook->add_worksheet( 'May Sales' );
7924
7925
7926           # Set up some formats
7927           my %heading = (
7928               bold     => 1,
7929               pattern  => 1,
7930               fg_color => '#C3FFC0',
7931               border   => 1,
7932               align    => 'center',
7933           );
7934
7935           my %total = (
7936               bold       => 1,
7937               top        => 1,
7938               num_format => '$#,##0.00'
7939           );
7940
7941           my $heading      = $workbook->add_format( %heading );
7942           my $total_format = $workbook->add_format( %total );
7943           my $price_format = $workbook->add_format( num_format => '$#,##0.00' );
7944           my $date_format  = $workbook->add_format( num_format => 'mmm d yyy' );
7945
7946
7947           # Write the main headings
7948           $worksheet->freeze_panes( 1 );    # Freeze the first row
7949           $worksheet->write( 'A1', 'Item',     $heading );
7950           $worksheet->write( 'B1', 'Quantity', $heading );
7951           $worksheet->write( 'C1', 'Price',    $heading );
7952           $worksheet->write( 'D1', 'Total',    $heading );
7953           $worksheet->write( 'E1', 'Date',     $heading );
7954
7955           # Set the column widths
7956           $worksheet->set_column( 'A:A', 25 );
7957           $worksheet->set_column( 'B:B', 10 );
7958           $worksheet->set_column( 'C:E', 16 );
7959
7960
7961           # Extract the sales data from the __DATA__ section at the end of the file.
7962           # In reality this information would probably come from a database
7963           my @sales;
7964
7965           foreach my $line ( <DATA> ) {
7966               chomp $line;
7967               next if $line eq '';
7968
7969               # Simple-minded processing of CSV data. Refer to the Text::CSV_XS
7970               # and Text::xSV modules for a more complete CSV handling.
7971               my @items = split /,/, $line;
7972               push @sales, \@items;
7973           }
7974
7975
7976           # Write out the items from each row
7977           my $row = 1;
7978           foreach my $sale ( @sales ) {
7979
7980               $worksheet->write( $row, 0, @$sale[0] );
7981               $worksheet->write( $row, 1, @$sale[1] );
7982               $worksheet->write( $row, 2, @$sale[2], $price_format );
7983
7984               # Create a formula like '=B2*C2'
7985               my $formula =
7986                 '=' . xl_rowcol_to_cell( $row, 1 ) . "*" . xl_rowcol_to_cell( $row, 2 );
7987
7988               $worksheet->write( $row, 3, $formula, $price_format );
7989
7990               # Parse the date
7991               my $date = xl_decode_date_US( @$sale[3] );
7992               $worksheet->write( $row, 4, $date, $date_format );
7993               $row++;
7994           }
7995
7996           # Create a formula to sum the totals, like '=SUM(D2:D6)'
7997           my $total = '=SUM(D2:' . xl_rowcol_to_cell( $row - 1, 3 ) . ")";
7998
7999           $worksheet->write( $row, 3, $total, $total_format );
8000
8001           $workbook->close();
8002
8003           __DATA__
8004           586 card,20,125.50,5/12/01
8005           Flat Screen Monitor,1,1300.00,5/12/01
8006           64 MB dimms,45,49.99,5/13/01
8007           15 GB HD,12,300.00,5/13/01
8008           Speakers (pair),5,15.50,5/14/01
8009
8010       Download this example:
8011       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/sales.pl>
8012
8013   Example: shape1.pl
8014       A simple example of how to use the Excel::Writer::XLSX module to add
8015       shapes to an Excel xlsx file.
8016
8017       Source code for this example:
8018
8019           #!/usr/bin/perl
8020
8021           #######################################################################
8022           #
8023           # A simple example of how to use the Excel::Writer::XLSX module to
8024           # add shapes to an Excel xlsx file.
8025           #
8026           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8027           #
8028
8029           use strict;
8030           use warnings;
8031           use Excel::Writer::XLSX;
8032
8033           my $workbook  = Excel::Writer::XLSX->new( 'shape1.xlsx' );
8034           my $worksheet = $workbook->add_worksheet();
8035
8036           # Add a circle, with centered text.
8037           my $ellipse = $workbook->add_shape(
8038               type   => 'ellipse',
8039               text   => "Hello\nWorld",
8040               width  => 60,
8041               height => 60
8042           );
8043
8044           $worksheet->insert_shape( 'A1', $ellipse, 50, 50 );
8045
8046           # Add a plus sign.
8047           my $plus = $workbook->add_shape( type => 'plus', width => 20, height => 20 );
8048           $worksheet->insert_shape( 'D8', $plus );
8049
8050           $workbook->close();
8051
8052           __END__
8053
8054       Download this example:
8055       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/shape1.pl>
8056
8057   Example: shape2.pl
8058       A simple example of how to use the Excel::Writer::XLSX module to modify
8059       shape properties in an Excel xlsx file.
8060
8061       Source code for this example:
8062
8063           #!/usr/bin/perl
8064
8065           #######################################################################
8066           #
8067           # A simple example of how to use the Excel::Writer::XLSX module to
8068           # modify shape properties in an Excel xlsx file.
8069           #
8070           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8071           #
8072
8073           use strict;
8074           use warnings;
8075           use Excel::Writer::XLSX;
8076
8077           my $workbook  = Excel::Writer::XLSX->new( 'shape2.xlsx' );
8078           my $worksheet = $workbook->add_worksheet();
8079
8080           $worksheet->hide_gridlines( 2 );
8081
8082           my $plain = $workbook->add_shape(
8083               type   => 'smileyFace',
8084               text   => "Plain",
8085               width  => 100,
8086               height => 100,
8087           );
8088
8089           my $bbformat = $workbook->add_format(
8090               color => 'red',
8091               font  => 'Lucida Calligraphy',
8092           );
8093
8094           $bbformat->set_bold();
8095           $bbformat->set_underline();
8096           $bbformat->set_italic();
8097
8098           my $decor = $workbook->add_shape(
8099               type        => 'smileyFace',
8100               text        => "Decorated",
8101               rotation    => 45,
8102               width       => 200,
8103               height      => 100,
8104               format      => $bbformat,
8105               line_type   => 'sysDot',
8106               line_weight => 3,
8107               fill        => 'FFFF00',
8108               line        => '3366FF',
8109           );
8110
8111           $worksheet->insert_shape( 'A1', $plain, 50,  50 );
8112           $worksheet->insert_shape( 'A1', $decor, 250, 50 );
8113
8114           $workbook->close();
8115
8116           __END__
8117
8118       Download this example:
8119       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/shape2.pl>
8120
8121   Example: shape3.pl
8122       A simple example of how to use the Excel::Writer::XLSX module to scale
8123       shapes in an Excel xlsx file.
8124
8125       Source code for this example:
8126
8127           #!/usr/bin/perl
8128
8129           #######################################################################
8130           #
8131           # A simple example of how to use the Excel::Writer::XLSX module to
8132           # scale shapes in an Excel xlsx file.
8133           #
8134           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8135           #
8136
8137           use strict;
8138           use warnings;
8139           use Excel::Writer::XLSX;
8140
8141           my $workbook  = Excel::Writer::XLSX->new( 'shape3.xlsx' );
8142           my $worksheet = $workbook->add_worksheet();
8143
8144           my $normal = $workbook->add_shape(
8145               name   => 'chip',
8146               type   => 'diamond',
8147               text   => "Normal",
8148               width  => 100,
8149               height => 100,
8150           );
8151
8152           $worksheet->insert_shape( 'A1', $normal, 50, 50 );
8153           $normal->set_text( 'Scaled 3w x 2h' );
8154           $normal->set_name( 'Hope' );
8155           $worksheet->insert_shape( 'A1', $normal, 250, 50, 3, 2 );
8156
8157           $workbook->close();
8158
8159           __END__
8160
8161       Download this example:
8162       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/shape3.pl>
8163
8164   Example: shape4.pl
8165       A simple example of how to use the Excel::Writer::XLSX module to
8166       demonstrate stenciling in an Excel xlsx file.
8167
8168       Source code for this example:
8169
8170           #!/usr/bin/perl
8171
8172           #######################################################################
8173           #
8174           # A simple example of how to use the Excel::Writer::XLSX module to
8175           # demonstrate stenciling in an Excel xlsx file.
8176           #
8177           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8178           #
8179
8180           use strict;
8181           use warnings;
8182           use Excel::Writer::XLSX;
8183
8184           my $workbook  = Excel::Writer::XLSX->new( 'shape4.xlsx' );
8185           my $worksheet = $workbook->add_worksheet();
8186
8187           $worksheet->hide_gridlines( 2 );
8188
8189           my $type  = 'rect';
8190           my $shape = $workbook->add_shape(
8191               type   => $type,
8192               width  => 90,
8193               height => 90,
8194           );
8195
8196           for my $n ( 1 .. 10 ) {
8197
8198               # Change the last 5 rectangles to stars. Previously inserted shapes stay
8199               # as rectangles.
8200               $type = 'star5' if $n == 6;
8201               $shape->set_type( $type );
8202               $shape->set_text( "$type $n" );
8203               $worksheet->insert_shape( 'A1', $shape, $n * 100, 50 );
8204           }
8205
8206
8207           my $stencil = $workbook->add_shape(
8208               stencil => 1,                    # The default.
8209               width   => 90,
8210               height  => 90,
8211               text    => 'started as a box',
8212           );
8213           $worksheet->insert_shape( 'A1', $stencil, 100, 150 );
8214
8215           $stencil->set_stencil( 0 );
8216           $worksheet->insert_shape( 'A1', $stencil, 200, 150 );
8217           $worksheet->insert_shape( 'A1', $stencil, 300, 150 );
8218
8219           # Ooops!  Changed my mind.  Change the rectangle to an ellipse (circle),
8220           # for the last two shapes.
8221           $stencil->set_type( 'ellipse' );
8222           $stencil->set_text( 'Now its a circle' );
8223
8224           $workbook->close();
8225
8226           __END__
8227
8228       Download this example:
8229       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/shape4.pl>
8230
8231   Example: shape5.pl
8232       A simple example of how to use the Excel::Writer::XLSX module to add
8233       shapes (objects and top/bottom connectors) to an Excel xlsx file.
8234
8235       Source code for this example:
8236
8237           #!/usr/bin/perl
8238
8239           #######################################################################
8240           #
8241           # A simple example of how to use the Excel::Writer::XLSX module to
8242           # add shapes (objects and top/bottom connectors) to an Excel xlsx file.
8243           #
8244           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8245           #
8246
8247           use strict;
8248           use warnings;
8249           use Excel::Writer::XLSX;
8250
8251           my $workbook  = Excel::Writer::XLSX->new( 'shape5.xlsx' );
8252           my $worksheet = $workbook->add_worksheet();
8253
8254           my $s1 = $workbook->add_shape( type => 'ellipse', width => 60, height => 60 );
8255           $worksheet->insert_shape( 'A1', $s1, 50, 50 );
8256
8257           my $s2 = $workbook->add_shape( type => 'plus', width => 20, height => 20 );
8258           $worksheet->insert_shape( 'A1', $s2, 250, 200 );
8259
8260           # Create a connector to link the two shapes.
8261           my $cxn_shape = $workbook->add_shape( type => 'bentConnector3' );
8262
8263           # Link the start of the connector to the right side.
8264           $cxn_shape->set_start( $s1->get_id() );
8265           $cxn_shape->set_start_index( 4 );  # 4th connection pt, clockwise from top(0).
8266           $cxn_shape->set_start_side( 'b' ); # r)ight or b)ottom.
8267
8268           # Link the end of the connector to the left side.
8269           $cxn_shape->set_end( $s2->get_id() );
8270           $cxn_shape->set_end_index( 0 );     # clockwise from top(0).
8271           $cxn_shape->set_end_side( 't' );    # t)top.
8272
8273           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8274
8275           $workbook->close();
8276
8277           __END__
8278
8279       Download this example:
8280       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/shape5.pl>
8281
8282   Example: shape6.pl
8283       A simple example of how to use the Excel::Writer::XLSX module to add
8284       shapes (objects and right/left connectors) to an Excel xlsx file.
8285
8286       Source code for this example:
8287
8288           #!/usr/bin/perl
8289
8290           #######################################################################
8291           #
8292           # A simple example of how to use the Excel::Writer::XLSX module to
8293           # add shapes (objects and right/left connectors) to an Excel xlsx file.
8294           #
8295           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8296           #
8297
8298           use strict;
8299           use warnings;
8300           use Excel::Writer::XLSX;
8301
8302           my $workbook  = Excel::Writer::XLSX->new( 'shape6.xlsx' );
8303           my $worksheet = $workbook->add_worksheet();
8304
8305           my $s1 = $workbook->add_shape( type => 'chevron', width => 60, height => 60 );
8306           $worksheet->insert_shape( 'A1', $s1, 50, 50 );
8307
8308           my $s2 = $workbook->add_shape( type => 'pentagon', width => 20, height => 20 );
8309           $worksheet->insert_shape( 'A1', $s2, 250, 200 );
8310
8311           # Create a connector to link the two shapes.
8312           my $cxn_shape = $workbook->add_shape( type => 'curvedConnector3' );
8313
8314           # Link the start of the connector to the right side.
8315           $cxn_shape->set_start( $s1->get_id() );
8316           $cxn_shape->set_start_index( 2 );    # 2nd connection pt, clockwise from top(0).
8317           $cxn_shape->set_start_side( 'r' );   # r)ight or b)ottom.
8318
8319           # Link the end of the connector to the left side.
8320           $cxn_shape->set_end( $s2->get_id() );
8321           $cxn_shape->set_end_index( 4 );      # 4th connection pt, clockwise from top(0).
8322           $cxn_shape->set_end_side( 'l' );     # l)eft or t)op.
8323
8324           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8325
8326           $workbook->close();
8327
8328           __END__
8329
8330       Download this example:
8331       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/shape6.pl>
8332
8333   Example: shape7.pl
8334       A simple example of how to use the Excel::Writer::XLSX module to add
8335       shapes and one-to-many connectors to an Excel xlsx file.
8336
8337       Source code for this example:
8338
8339           #!/usr/bin/perl
8340
8341           #######################################################################
8342           #
8343           # A simple example of how to use the Excel::Writer::XLSX module to
8344           # add shapes and one-to-many connectors to an Excel xlsx file.
8345           #
8346           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8347           #
8348
8349           use strict;
8350           use warnings;
8351           use Excel::Writer::XLSX;
8352
8353           my $workbook  = Excel::Writer::XLSX->new( 'shape7.xlsx' );
8354           my $worksheet = $workbook->add_worksheet();
8355
8356           # Add a circle, with centered text. c is for circle, not center.
8357           my $cw = 60;
8358           my $ch = 60;
8359           my $cx = 210;
8360           my $cy = 190;
8361
8362           my $ellipse = $workbook->add_shape(
8363               type   => 'ellipse',
8364               id     => 2,
8365               text   => "Hello\nWorld",
8366               width  => $cw,
8367               height => $ch
8368           );
8369           $worksheet->insert_shape( 'A1', $ellipse, $cx, $cy );
8370
8371           # Add a plus sign at 4 different positions around the circle.
8372           my $pw = 20;
8373           my $ph = 20;
8374           my $px = 120;
8375           my $py = 250;
8376           my $plus =
8377             $workbook->add_shape( type => 'plus', id => 3, width => $pw, height => $ph );
8378           my $p1 = $worksheet->insert_shape( 'A1', $plus, 350, 350 );
8379           my $p2 = $worksheet->insert_shape( 'A1', $plus, 150, 350 );
8380           my $p3 = $worksheet->insert_shape( 'A1', $plus, 350, 150 );
8381           $plus->set_adjustments( 35 );    # change shape of plus symbol.
8382           my $p4 = $worksheet->insert_shape( 'A1', $plus, 150, 150 );
8383
8384           my $cxn_shape = $workbook->add_shape( type => 'bentConnector3', fill => 0 );
8385
8386           $cxn_shape->set_start( $ellipse->get_id() );
8387           $cxn_shape->set_start_index( 4 );    # 4nd connection pt, clockwise from top(0).
8388           $cxn_shape->set_start_side( 'b' );   # r)ight or b)ottom.
8389
8390           $cxn_shape->set_end( $p1->get_id() );
8391           $cxn_shape->set_end_index( 0 );
8392           $cxn_shape->set_end_side( 't' );
8393           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8394
8395           $cxn_shape->set_end( $p2->get_id() );
8396           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8397
8398           $cxn_shape->set_end( $p3->get_id() );
8399           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8400
8401           $cxn_shape->set_end( $p4->get_id() );
8402           $cxn_shape->set_adjustments( -50, 45, 120 );
8403           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8404
8405           $workbook->close();
8406
8407           __END__
8408
8409       Download this example:
8410       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/shape7.pl>
8411
8412   Example: shape8.pl
8413       A simple example of how to use the Excel::Writer::XLSX module to add
8414       shapes and one-to-many connectors to an Excel xlsx file.
8415
8416       Source code for this example:
8417
8418           #!/usr/bin/perl
8419
8420           #######################################################################
8421           #
8422           # A simple example of how to use the Excel::Writer::XLSX module to
8423           # add shapes and one-to-many connectors to an Excel xlsx file.
8424           #
8425           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8426           #
8427
8428           use strict;
8429           use warnings;
8430           use Excel::Writer::XLSX;
8431
8432           my $workbook  = Excel::Writer::XLSX->new( 'shape8.xlsx' );
8433           my $worksheet = $workbook->add_worksheet();
8434
8435           # Add a circle, with centered text. c is for circle, not center.
8436           my $cw = 60;
8437           my $ch = 60;
8438           my $cx = 210;
8439           my $cy = 190;
8440
8441           my $ellipse = $workbook->add_shape(
8442               type   => 'ellipse',
8443               id     => 2,
8444               text   => "Hello\nWorld",
8445               width  => $cw,
8446               height => $ch
8447           );
8448           $worksheet->insert_shape( 'A1', $ellipse, $cx, $cy );
8449
8450           # Add a plus sign at 4 different positions around the circle.
8451           my $pw = 20;
8452           my $ph = 20;
8453           my $px = 120;
8454           my $py = 250;
8455           my $plus =
8456             $workbook->add_shape( type => 'plus', id => 3, width => $pw, height => $ph );
8457           my $p1 = $worksheet->insert_shape( 'A1', $plus, 350, 150 );    #  2:00
8458           my $p2 = $worksheet->insert_shape( 'A1', $plus, 350, 350 );    #  4:00
8459           my $p3 = $worksheet->insert_shape( 'A1', $plus, 150, 350 );    #  8:00
8460           my $p4 = $worksheet->insert_shape( 'A1', $plus, 150, 150 );    # 10:00
8461
8462           my $cxn_shape = $workbook->add_shape( type => 'bentConnector3', fill => 0 );
8463
8464           $cxn_shape->set_start( $ellipse->get_id() );
8465           $cxn_shape->set_start_index( 2 );    # 2nd connection pt, clockwise from top(0).
8466           $cxn_shape->set_start_side( 'r' );   # r)ight or b)ottom.
8467
8468           $cxn_shape->set_end( $p1->get_id() );
8469           $cxn_shape->set_end_index( 3 );      # 3rd connection point on plus, right side
8470           $cxn_shape->set_end_side( 'l' );
8471           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8472
8473           $cxn_shape->set_end( $p2->get_id() );
8474           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8475
8476           $cxn_shape->set_end( $p3->get_id() );
8477           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8478
8479           $cxn_shape->set_end( $p4->get_id() );
8480           $cxn_shape->set_adjustments( -50, 45, 120 );
8481           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8482
8483           $workbook->close();
8484
8485           __END__
8486
8487       Download this example:
8488       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/shape8.pl>
8489
8490   Example: shape_all.pl
8491       A simple example of how to use the Excel::Writer::XLSX module to add
8492       all shapes (as currently implemented) to an Excel xlsx file.
8493
8494       The list at the end consists of all the shape types defined as
8495       ST_ShapeType in ECMA-376, Office Open XML File Formats Part 4.
8496
8497       The grouping by worksheet name is for illustration only. It isn't part
8498       of the ECMA-376 standard.
8499
8500       Source code for this example:
8501
8502           #!/usr/bin/perl
8503
8504           #######################################################################
8505           #
8506           # A simple example of how to use the Excel::Writer::XLSX module to
8507           # add all shapes (as currently implemented) to an Excel xlsx file.
8508           #
8509           # The list at the end consists of all the shape types defined as
8510           # ST_ShapeType in ECMA-376, Office Open XML File Formats Part 4.
8511           #
8512           # The grouping by worksheet name is for illustration only. It isn't
8513           # part of the ECMA-376 standard.
8514           #
8515           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8516           #
8517
8518           use strict;
8519           use warnings;
8520           use Excel::Writer::XLSX;
8521
8522           my $workbook = Excel::Writer::XLSX->new( 'shape_all.xlsx' );
8523
8524           my ( $worksheet, $last_sheet, $shape, $r ) = ( 0, '', '', undef, 0 );
8525
8526           while ( <DATA> ) {
8527               chomp;
8528               next unless m/^\w/;    # Skip blank lines and comments.
8529
8530               my ( $sheet, $name ) = split( /\t/, $_ );
8531               if ( $last_sheet ne $sheet ) {
8532                   $worksheet = $workbook->add_worksheet( $sheet );
8533                   $r         = 2;
8534               }
8535               $last_sheet = $sheet;
8536               $shape      = $workbook->add_shape(
8537                   type   => $name,
8538                   text   => $name,
8539                   width  => 90,
8540                   height => 90
8541               );
8542
8543               # Connectors can not have labels, so write the connector name in the cell
8544               # to the left.
8545               $worksheet->write( $r, 0, $name ) if $sheet eq 'Connector';
8546               $worksheet->insert_shape( $r, 2, $shape, 0, 0 );
8547               $r += 5;
8548           }
8549
8550           $workbook->close();
8551
8552           __END__
8553           Action      actionButtonBackPrevious
8554           Action      actionButtonBeginning
8555           Action      actionButtonBlank
8556           Action      actionButtonDocument
8557           Action      actionButtonEnd
8558           Action      actionButtonForwardNext
8559           Action      actionButtonHelp
8560           Action      actionButtonHome
8561           Action      actionButtonInformation
8562           Action      actionButtonMovie
8563           Action      actionButtonReturn
8564           Action      actionButtonSound
8565           Arrow       bentArrow
8566           Arrow       bentUpArrow
8567           Arrow       circularArrow
8568           Arrow       curvedDownArrow
8569           Arrow       curvedLeftArrow
8570           Arrow       curvedRightArrow
8571           Arrow       curvedUpArrow
8572           Arrow       downArrow
8573           Arrow       leftArrow
8574           Arrow       leftCircularArrow
8575           Arrow       leftRightArrow
8576           Arrow       leftRightCircularArrow
8577           Arrow       leftRightUpArrow
8578           Arrow       leftUpArrow
8579           Arrow       notchedRightArrow
8580           Arrow       quadArrow
8581           Arrow       rightArrow
8582           Arrow       stripedRightArrow
8583           Arrow       swooshArrow
8584           Arrow       upArrow
8585           Arrow       upDownArrow
8586           Arrow       uturnArrow
8587           Basic       blockArc
8588           Basic       can
8589           Basic       chevron
8590           Basic       cube
8591           Basic       decagon
8592           Basic       diamond
8593           Basic       dodecagon
8594           Basic       donut
8595           Basic       ellipse
8596           Basic       funnel
8597           Basic       gear6
8598           Basic       gear9
8599           Basic       heart
8600           Basic       heptagon
8601           Basic       hexagon
8602           Basic       homePlate
8603           Basic       lightningBolt
8604           Basic       line
8605           Basic       lineInv
8606           Basic       moon
8607           Basic       nonIsoscelesTrapezoid
8608           Basic       noSmoking
8609           Basic       octagon
8610           Basic       parallelogram
8611           Basic       pentagon
8612           Basic       pie
8613           Basic       pieWedge
8614           Basic       plaque
8615           Basic       rect
8616           Basic       round1Rect
8617           Basic       round2DiagRect
8618           Basic       round2SameRect
8619           Basic       roundRect
8620           Basic       rtTriangle
8621           Basic       smileyFace
8622           Basic       snip1Rect
8623           Basic       snip2DiagRect
8624           Basic       snip2SameRect
8625           Basic       snipRoundRect
8626           Basic       star10
8627           Basic       star12
8628           Basic       star16
8629           Basic       star24
8630           Basic       star32
8631           Basic       star4
8632           Basic       star5
8633           Basic       star6
8634           Basic       star7
8635           Basic       star8
8636           Basic       sun
8637           Basic       teardrop
8638           Basic       trapezoid
8639           Basic       triangle
8640           Callout     accentBorderCallout1
8641           Callout     accentBorderCallout2
8642           Callout     accentBorderCallout3
8643           Callout     accentCallout1
8644           Callout     accentCallout2
8645           Callout     accentCallout3
8646           Callout     borderCallout1
8647           Callout     borderCallout2
8648           Callout     borderCallout3
8649           Callout     callout1
8650           Callout     callout2
8651           Callout     callout3
8652           Callout     cloudCallout
8653           Callout     downArrowCallout
8654           Callout     leftArrowCallout
8655           Callout     leftRightArrowCallout
8656           Callout     quadArrowCallout
8657           Callout     rightArrowCallout
8658           Callout     upArrowCallout
8659           Callout     upDownArrowCallout
8660           Callout     wedgeEllipseCallout
8661           Callout     wedgeRectCallout
8662           Callout     wedgeRoundRectCallout
8663           Chart       chartPlus
8664           Chart       chartStar
8665           Chart       chartX
8666           Connector   bentConnector2
8667           Connector   bentConnector3
8668           Connector   bentConnector4
8669           Connector   bentConnector5
8670           Connector   curvedConnector2
8671           Connector   curvedConnector3
8672           Connector   curvedConnector4
8673           Connector   curvedConnector5
8674           Connector   straightConnector1
8675           FlowChart   flowChartAlternateProcess
8676           FlowChart   flowChartCollate
8677           FlowChart   flowChartConnector
8678           FlowChart   flowChartDecision
8679           FlowChart   flowChartDelay
8680           FlowChart   flowChartDisplay
8681           FlowChart   flowChartDocument
8682           FlowChart   flowChartExtract
8683           FlowChart   flowChartInputOutput
8684           FlowChart   flowChartInternalStorage
8685           FlowChart   flowChartMagneticDisk
8686           FlowChart   flowChartMagneticDrum
8687           FlowChart   flowChartMagneticTape
8688           FlowChart   flowChartManualInput
8689           FlowChart   flowChartManualOperation
8690           FlowChart   flowChartMerge
8691           FlowChart   flowChartMultidocument
8692           FlowChart   flowChartOfflineStorage
8693           FlowChart   flowChartOffpageConnector
8694           FlowChart   flowChartOnlineStorage
8695           FlowChart   flowChartOr
8696           FlowChart   flowChartPredefinedProcess
8697           FlowChart   flowChartPreparation
8698           FlowChart   flowChartProcess
8699           FlowChart   flowChartPunchedCard
8700           FlowChart   flowChartPunchedTape
8701           FlowChart   flowChartSort
8702           FlowChart   flowChartSummingJunction
8703           FlowChart   flowChartTerminator
8704           Math        mathDivide
8705           Math        mathEqual
8706           Math        mathMinus
8707           Math        mathMultiply
8708           Math        mathNotEqual
8709           Math        mathPlus
8710           Star_Banner arc
8711           Star_Banner bevel
8712           Star_Banner bracePair
8713           Star_Banner bracketPair
8714           Star_Banner chord
8715           Star_Banner cloud
8716           Star_Banner corner
8717           Star_Banner diagStripe
8718           Star_Banner doubleWave
8719           Star_Banner ellipseRibbon
8720           Star_Banner ellipseRibbon2
8721           Star_Banner foldedCorner
8722           Star_Banner frame
8723           Star_Banner halfFrame
8724           Star_Banner horizontalScroll
8725           Star_Banner irregularSeal1
8726           Star_Banner irregularSeal2
8727           Star_Banner leftBrace
8728           Star_Banner leftBracket
8729           Star_Banner leftRightRibbon
8730           Star_Banner plus
8731           Star_Banner ribbon
8732           Star_Banner ribbon2
8733           Star_Banner rightBrace
8734           Star_Banner rightBracket
8735           Star_Banner verticalScroll
8736           Star_Banner wave
8737           Tabs        cornerTabs
8738           Tabs        plaqueTabs
8739           Tabs        squareTabs
8740
8741       Download this example:
8742       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/shape_all.pl>
8743
8744   Example: sparklines1.pl
8745       Example of how to add sparklines to an Excel::Writer::XLSX file.
8746
8747       Sparklines are small charts that fit in a single cell and are used to
8748       show trends in data. See sparklines2.pl for examples of more complex
8749       sparkline formatting.
8750
8751       Source code for this example:
8752
8753           #!/usr/bin/perl
8754
8755           ###############################################################################
8756           #
8757           # Example of how to add sparklines to an Excel::Writer::XLSX file.
8758           #
8759           # Sparklines are small charts that fit in a single cell and are
8760           # used to show trends in data. See sparklines2.pl for examples
8761           # of more complex sparkline formatting.
8762           #
8763           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8764           #
8765
8766           use strict;
8767           use warnings;
8768           use Excel::Writer::XLSX;
8769
8770           my $workbook  = Excel::Writer::XLSX->new( 'sparklines1.xlsx' );
8771           my $worksheet = $workbook->add_worksheet();
8772
8773           # Some sample data to plot.
8774           my $data = [
8775
8776               [ -2, 2,  3,  -1, 0 ],
8777               [ 30, 20, 33, 20, 15 ],
8778               [ 1,  -1, -1, 1,  -1 ],
8779
8780           ];
8781
8782           # Write the sample data to the worksheet.
8783           $worksheet->write_col( 'A1', $data );
8784
8785
8786           # Add a line sparkline (the default) with markers.
8787           $worksheet->add_sparkline(
8788               {
8789                   location => 'F1',
8790                   range    => 'Sheet1!A1:E1',
8791                   markers  => 1,
8792               }
8793           );
8794
8795           # Add a column sparkline with non-default style.
8796           $worksheet->add_sparkline(
8797               {
8798                   location => 'F2',
8799                   range    => 'Sheet1!A2:E2',
8800                   type     => 'column',
8801                   style    => 12,
8802               }
8803           );
8804
8805           # Add a win/loss sparkline with negative values highlighted.
8806           $worksheet->add_sparkline(
8807               {
8808                   location        => 'F3',
8809                   range           => 'Sheet1!A3:E3',
8810                   type            => 'win_loss',
8811                   negative_points => 1,
8812               }
8813           );
8814
8815           $workbook->close();
8816
8817           __END__
8818
8819       Download this example:
8820       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/sparklines1.pl>
8821
8822   Example: sparklines2.pl
8823       Example of how to add sparklines to an Excel::Writer::XLSX file.
8824
8825       Sparklines are small charts that fit in a single cell and are used to
8826       show trends in data. This example shows the majority of options that
8827       can be applied to sparklines.
8828
8829       Source code for this example:
8830
8831           #!/usr/bin/perl
8832
8833           ###############################################################################
8834           #
8835           # Example of how to add sparklines to an Excel::Writer::XLSX file.
8836           #
8837           # Sparklines are small charts that fit in a single cell and are
8838           # used to show trends in data. This example shows the majority of
8839           # options that can be applied to sparklines.
8840           #
8841           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
8842           #
8843
8844           use strict;
8845           use warnings;
8846           use Excel::Writer::XLSX;
8847
8848           my $workbook    = Excel::Writer::XLSX->new( 'sparklines2.xlsx' );
8849           my $worksheet1  = $workbook->add_worksheet();
8850           my $worksheet2  = $workbook->add_worksheet();
8851           my $bold        = $workbook->add_format( bold => 1 );
8852           my $str;
8853           my $row = 1;
8854
8855           # Set the columns widths to make the output clearer.
8856           $worksheet1->set_column( 'A:A', 14 );
8857           $worksheet1->set_column( 'B:B', 50 );
8858           $worksheet1->set_zoom( 150 );
8859
8860           # Headings.
8861           $worksheet1->write( 'A1', 'Sparkline',   $bold );
8862           $worksheet1->write( 'B1', 'Description', $bold );
8863
8864
8865           ###############################################################################
8866           #
8867           $str = 'A default "line" sparkline.';
8868
8869           $worksheet1->add_sparkline(
8870               {
8871                   location => 'A2',
8872                   range    => 'Sheet2!A1:J1',
8873               }
8874           );
8875
8876           $worksheet1->write( $row++, 1, $str );
8877
8878
8879           ###############################################################################
8880           #
8881           $str = 'A default "column" sparkline.';
8882
8883           $worksheet1->add_sparkline(
8884               {
8885                   location => 'A3',
8886                   range    => 'Sheet2!A2:J2',
8887                   type     => 'column',
8888               }
8889           );
8890
8891           $worksheet1->write( $row++, 1, $str );
8892
8893
8894           ###############################################################################
8895           #
8896           $str = 'A default "win/loss" sparkline.';
8897
8898           $worksheet1->add_sparkline(
8899               {
8900                   location => 'A4',
8901                   range    => 'Sheet2!A3:J3',
8902                   type     => 'win_loss',
8903               }
8904           );
8905
8906           $worksheet1->write( $row++, 1, $str );
8907           $row++;
8908
8909
8910           ###############################################################################
8911           #
8912           $str = 'Line with markers.';
8913
8914           $worksheet1->add_sparkline(
8915               {
8916                   location => 'A6',
8917                   range    => 'Sheet2!A1:J1',
8918                   markers  => 1,
8919               }
8920           );
8921
8922           $worksheet1->write( $row++, 1, $str );
8923
8924
8925           ###############################################################################
8926           #
8927           $str = 'Line with high and low points.';
8928
8929           $worksheet1->add_sparkline(
8930               {
8931                   location   => 'A7',
8932                   range      => 'Sheet2!A1:J1',
8933                   high_point => 1,
8934                   low_point  => 1,
8935               }
8936           );
8937
8938           $worksheet1->write( $row++, 1, $str );
8939
8940
8941           ###############################################################################
8942           #
8943           $str = 'Line with first and last point markers.';
8944
8945           $worksheet1->add_sparkline(
8946               {
8947                   location    => 'A8',
8948                   range       => 'Sheet2!A1:J1',
8949                   first_point => 1,
8950                   last_point  => 1,
8951               }
8952           );
8953
8954           $worksheet1->write( $row++, 1, $str );
8955
8956
8957           ###############################################################################
8958           #
8959           $str = 'Line with negative point markers.';
8960
8961           $worksheet1->add_sparkline(
8962               {
8963                   location        => 'A9',
8964                   range           => 'Sheet2!A1:J1',
8965                   negative_points => 1,
8966               }
8967           );
8968
8969           $worksheet1->write( $row++, 1, $str );
8970
8971
8972           ###############################################################################
8973           #
8974           $str = 'Line with axis.';
8975
8976           $worksheet1->add_sparkline(
8977               {
8978                   location => 'A10',
8979                   range    => 'Sheet2!A1:J1',
8980                   axis     => 1,
8981               }
8982           );
8983
8984           $worksheet1->write( $row++, 1, $str );
8985           $row++;
8986
8987
8988           ###############################################################################
8989           #
8990           $str = 'Column with default style (1).';
8991
8992           $worksheet1->add_sparkline(
8993               {
8994                   location => 'A12',
8995                   range    => 'Sheet2!A2:J2',
8996                   type     => 'column',
8997               }
8998           );
8999
9000           $worksheet1->write( $row++, 1, $str );
9001
9002
9003           ###############################################################################
9004           #
9005           $str = 'Column with style 2.';
9006
9007           $worksheet1->add_sparkline(
9008               {
9009                   location => 'A13',
9010                   range    => 'Sheet2!A2:J2',
9011                   type     => 'column',
9012                   style    => 2,
9013               }
9014           );
9015
9016           $worksheet1->write( $row++, 1, $str );
9017
9018
9019           ###############################################################################
9020           #
9021           $str = 'Column with style 3.';
9022
9023           $worksheet1->add_sparkline(
9024               {
9025                   location => 'A14',
9026                   range    => 'Sheet2!A2:J2',
9027                   type     => 'column',
9028                   style    => 3,
9029               }
9030           );
9031
9032           $worksheet1->write( $row++, 1, $str );
9033
9034
9035           ###############################################################################
9036           #
9037           $str = 'Column with style 4.';
9038
9039           $worksheet1->add_sparkline(
9040               {
9041                   location => 'A15',
9042                   range    => 'Sheet2!A2:J2',
9043                   type     => 'column',
9044                   style    => 4,
9045               }
9046           );
9047
9048           $worksheet1->write( $row++, 1, $str );
9049
9050
9051           ###############################################################################
9052           #
9053           $str = 'Column with style 5.';
9054
9055           $worksheet1->add_sparkline(
9056               {
9057                   location => 'A16',
9058                   range    => 'Sheet2!A2:J2',
9059                   type     => 'column',
9060                   style    => 5,
9061               }
9062           );
9063
9064           $worksheet1->write( $row++, 1, $str );
9065
9066
9067           ###############################################################################
9068           #
9069           $str = 'Column with style 6.';
9070
9071           $worksheet1->add_sparkline(
9072               {
9073                   location => 'A17',
9074                   range    => 'Sheet2!A2:J2',
9075                   type     => 'column',
9076                   style    => 6,
9077               }
9078           );
9079
9080           $worksheet1->write( $row++, 1, $str );
9081
9082
9083           ###############################################################################
9084           #
9085           $str = 'Column with a user defined colour.';
9086
9087           $worksheet1->add_sparkline(
9088               {
9089                   location     => 'A18',
9090                   range        => 'Sheet2!A2:J2',
9091                   type         => 'column',
9092                   series_color => '#E965E0',
9093               }
9094           );
9095
9096           $worksheet1->write( $row++, 1, $str );
9097           $row++;
9098
9099
9100           ###############################################################################
9101           #
9102           $str = 'A win/loss sparkline.';
9103
9104           $worksheet1->add_sparkline(
9105               {
9106                   location => 'A20',
9107                   range    => 'Sheet2!A3:J3',
9108                   type     => 'win_loss',
9109               }
9110           );
9111
9112           $worksheet1->write( $row++, 1, $str );
9113
9114
9115           ###############################################################################
9116           #
9117           $str = 'A win/loss sparkline with negative points highlighted.';
9118
9119           $worksheet1->add_sparkline(
9120               {
9121                   location        => 'A21',
9122                   range           => 'Sheet2!A3:J3',
9123                   type            => 'win_loss',
9124                   negative_points => 1,
9125               }
9126           );
9127
9128           $worksheet1->write( $row++, 1, $str );
9129           $row++;
9130
9131
9132           ###############################################################################
9133           #
9134           $str = 'A left to right column (the default).';
9135
9136           $worksheet1->add_sparkline(
9137               {
9138                   location => 'A23',
9139                   range    => 'Sheet2!A4:J4',
9140                   type     => 'column',
9141                   style    => 20,
9142               }
9143           );
9144
9145           $worksheet1->write( $row++, 1, $str );
9146
9147
9148           ###############################################################################
9149           #
9150           $str = 'A right to left column.';
9151
9152           $worksheet1->add_sparkline(
9153               {
9154                   location => 'A24',
9155                   range    => 'Sheet2!A4:J4',
9156                   type     => 'column',
9157                   style    => 20,
9158                   reverse  => 1,
9159               }
9160           );
9161
9162           $worksheet1->write( $row++, 1, $str );
9163
9164
9165           ###############################################################################
9166           #
9167           $str = 'Sparkline and text in one cell.';
9168
9169           $worksheet1->add_sparkline(
9170               {
9171                   location => 'A25',
9172                   range    => 'Sheet2!A4:J4',
9173                   type     => 'column',
9174                   style    => 20,
9175               }
9176           );
9177
9178           $worksheet1->write( $row,   0, 'Growth' );
9179           $worksheet1->write( $row++, 1, $str );
9180           $row++;
9181
9182
9183           ###############################################################################
9184           #
9185           $str = 'A grouped sparkline. Changes are applied to all three.';
9186
9187           $worksheet1->add_sparkline(
9188               {
9189                   location => [ 'A27',          'A28',          'A29' ],
9190                   range    => [ 'Sheet2!A5:J5', 'Sheet2!A6:J6', 'Sheet2!A7:J7' ],
9191                   markers  => 1,
9192               }
9193           );
9194
9195           $worksheet1->write( $row++, 1, $str );
9196
9197
9198
9199
9200           ###############################################################################
9201           #
9202           # Create a second worksheet with data to plot.
9203           #
9204
9205           $worksheet2->set_column( 'A:J', 11 );
9206
9207           my $data = [
9208
9209               # Simple line data.
9210               [ -2, 2, 3, -1, 0, -2, 3, 2, 1, 0 ],
9211
9212               # Simple column data.
9213               [ 30, 20, 33, 20, 15, 5, 5, 15, 10, 15 ],
9214
9215               # Simple win/loss data.
9216               [ 1, 1, -1, -1, 1, -1, 1, 1, 1, -1 ],
9217
9218               # Unbalanced histogram.
9219               [ 5, 6, 7, 10, 15, 20, 30, 50, 70, 100 ],
9220
9221               # Data for the grouped sparkline example.
9222               [ -2, 2,  3, -1, 0, -2, 3, 2, 1, 0 ],
9223               [ 3,  -1, 0, -2, 3, 2,  1, 0, 2, 1 ],
9224               [ 0,  -2, 3, 2,  1, 0,  1, 2, 3, 1 ],
9225
9226
9227           ];
9228
9229           # Write the sample data to the worksheet.
9230           $worksheet2->write_col( 'A1', $data );
9231
9232           $workbook->close();
9233
9234           __END__
9235
9236       Download this example:
9237       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/sparklines2.pl>
9238
9239   Example: stats_ext.pl
9240       Example of formatting using the Excel::Writer::XLSX module
9241
9242       This is a simple example of how to use functions that reference cells
9243       in other worksheets within the same workbook.
9244
9245       Source code for this example:
9246
9247           #!/usr/bin/perl -w
9248
9249           ###############################################################################
9250           #
9251           # Example of formatting using the Excel::Writer::XLSX module
9252           #
9253           # This is a simple example of how to use functions that reference cells in
9254           # other worksheets within the same workbook.
9255           #
9256           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
9257           #
9258
9259           use strict;
9260           use Excel::Writer::XLSX;
9261
9262           # Create a new workbook and add a worksheet
9263           my $workbook   = Excel::Writer::XLSX->new( 'stats_ext.xlsx' );
9264           my $worksheet1 = $workbook->add_worksheet( 'Test results' );
9265           my $worksheet2 = $workbook->add_worksheet( 'Data' );
9266
9267           # Set the column width for columns 1
9268           $worksheet1->set_column( 'A:A', 20 );
9269
9270
9271           # Create a format for the headings
9272           my $heading = $workbook->add_format();
9273           $heading->set_bold();
9274
9275           # Create a numerical format
9276           my $numformat = $workbook->add_format();
9277           $numformat->set_num_format( '0.00' );
9278
9279
9280           # Write some statistical functions
9281           $worksheet1->write( 'A1', 'Count', $heading );
9282           $worksheet1->write( 'B1', '=COUNT(Data!B2:B9)' );
9283
9284           $worksheet1->write( 'A2', 'Sum', $heading );
9285           $worksheet1->write( 'B2', '=SUM(Data!B2:B9)' );
9286
9287           $worksheet1->write( 'A3', 'Average', $heading );
9288           $worksheet1->write( 'B3', '=AVERAGE(Data!B2:B9)' );
9289
9290           $worksheet1->write( 'A4', 'Min', $heading );
9291           $worksheet1->write( 'B4', '=MIN(Data!B2:B9)' );
9292
9293           $worksheet1->write( 'A5', 'Max', $heading );
9294           $worksheet1->write( 'B5', '=MAX(Data!B2:B9)' );
9295
9296           $worksheet1->write( 'A6', 'Standard Deviation', $heading );
9297           $worksheet1->write( 'B6', '=STDEV(Data!B2:B9)' );
9298
9299           $worksheet1->write( 'A7', 'Kurtosis', $heading );
9300           $worksheet1->write( 'B7', '=KURT(Data!B2:B9)' );
9301
9302
9303           # Write the sample data
9304           $worksheet2->write( 'A1', 'Sample', $heading );
9305           $worksheet2->write( 'A2', 1 );
9306           $worksheet2->write( 'A3', 2 );
9307           $worksheet2->write( 'A4', 3 );
9308           $worksheet2->write( 'A5', 4 );
9309           $worksheet2->write( 'A6', 5 );
9310           $worksheet2->write( 'A7', 6 );
9311           $worksheet2->write( 'A8', 7 );
9312           $worksheet2->write( 'A9', 8 );
9313
9314           $worksheet2->write( 'B1', 'Length', $heading );
9315           $worksheet2->write( 'B2', 25.4,     $numformat );
9316           $worksheet2->write( 'B3', 25.4,     $numformat );
9317           $worksheet2->write( 'B4', 24.8,     $numformat );
9318           $worksheet2->write( 'B5', 25.0,     $numformat );
9319           $worksheet2->write( 'B6', 25.3,     $numformat );
9320           $worksheet2->write( 'B7', 24.9,     $numformat );
9321           $worksheet2->write( 'B8', 25.2,     $numformat );
9322           $worksheet2->write( 'B9', 24.8,     $numformat );
9323
9324           $workbook->close();
9325
9326           __END__
9327
9328       Download this example:
9329       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/stats_ext.pl>
9330
9331   Example: stocks.pl
9332       Example of formatting using the Excel::Writer::XLSX module
9333
9334       This example shows how to use a conditional numerical format with
9335       colours to indicate if a share price has gone up or down.
9336
9337       Source code for this example:
9338
9339           #!/usr/bin/perl -w
9340
9341           ###############################################################################
9342           #
9343           # Example of formatting using the Excel::Writer::XLSX module
9344           #
9345           # This example shows how to use a conditional numerical format
9346           # with colours to indicate if a share price has gone up or down.
9347           #
9348           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
9349           #
9350
9351           use strict;
9352           use Excel::Writer::XLSX;
9353
9354           # Create a new workbook and add a worksheet
9355           my $workbook  = Excel::Writer::XLSX->new( 'stocks.xlsx' );
9356           my $worksheet = $workbook->add_worksheet();
9357
9358           # Set the column width for columns 1, 2, 3 and 4
9359           $worksheet->set_column( 0, 3, 15 );
9360
9361
9362           # Create a format for the column headings
9363           my $header = $workbook->add_format();
9364           $header->set_bold();
9365           $header->set_size( 12 );
9366           $header->set_color( 'blue' );
9367
9368
9369           # Create a format for the stock price
9370           my $f_price = $workbook->add_format();
9371           $f_price->set_align( 'left' );
9372           $f_price->set_num_format( '$0.00' );
9373
9374
9375           # Create a format for the stock volume
9376           my $f_volume = $workbook->add_format();
9377           $f_volume->set_align( 'left' );
9378           $f_volume->set_num_format( '#,##0' );
9379
9380
9381           # Create a format for the price change. This is an example of a conditional
9382           # format. The number is formatted as a percentage. If it is positive it is
9383           # formatted in green, if it is negative it is formatted in red and if it is
9384           # zero it is formatted as the default font colour (in this case black).
9385           # Note: the [Green] format produces an unappealing lime green. Try
9386           # [Color 10] instead for a dark green.
9387           #
9388           my $f_change = $workbook->add_format();
9389           $f_change->set_align( 'left' );
9390           $f_change->set_num_format( '[Green]0.0%;[Red]-0.0%;0.0%' );
9391
9392
9393           # Write out the data
9394           $worksheet->write( 0, 0, 'Company', $header );
9395           $worksheet->write( 0, 1, 'Price',   $header );
9396           $worksheet->write( 0, 2, 'Volume',  $header );
9397           $worksheet->write( 0, 3, 'Change',  $header );
9398
9399           $worksheet->write( 1, 0, 'Damage Inc.' );
9400           $worksheet->write( 1, 1, 30.25, $f_price );       # $30.25
9401           $worksheet->write( 1, 2, 1234567, $f_volume );    # 1,234,567
9402           $worksheet->write( 1, 3, 0.085, $f_change );      # 8.5% in green
9403
9404           $worksheet->write( 2, 0, 'Dump Corp.' );
9405           $worksheet->write( 2, 1, 1.56, $f_price );        # $1.56
9406           $worksheet->write( 2, 2, 7564, $f_volume );       # 7,564
9407           $worksheet->write( 2, 3, -0.015, $f_change );     # -1.5% in red
9408
9409           $worksheet->write( 3, 0, 'Rev Ltd.' );
9410           $worksheet->write( 3, 1, 0.13, $f_price );        # $0.13
9411           $worksheet->write( 3, 2, 321, $f_volume );        # 321
9412           $worksheet->write( 3, 3, 0, $f_change );          # 0 in the font color (black)
9413
9414
9415           $workbook->close();
9416
9417           __END__
9418
9419       Download this example:
9420       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/stocks.pl>
9421
9422   Example: tab_colors.pl
9423       Example of how to set Excel worksheet tab colours.
9424
9425       Source code for this example:
9426
9427           #!/usr/bin/perl
9428
9429           #######################################################################
9430           #
9431           # Example of how to set Excel worksheet tab colours.
9432           #
9433           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
9434           #
9435
9436           use strict;
9437           use warnings;
9438           use Excel::Writer::XLSX;
9439
9440
9441           my $workbook = Excel::Writer::XLSX->new( 'tab_colors.xlsx' );
9442
9443           my $worksheet1 = $workbook->add_worksheet();
9444           my $worksheet2 = $workbook->add_worksheet();
9445           my $worksheet3 = $workbook->add_worksheet();
9446           my $worksheet4 = $workbook->add_worksheet();
9447
9448           # Worksheet1 will have the default tab colour.
9449           $worksheet2->set_tab_color( 'red' );
9450           $worksheet3->set_tab_color( 'green' );
9451           $worksheet4->set_tab_color( '#FF6600'); # Orange
9452
9453           $workbook->close();
9454
9455           __END__
9456
9457       Download this example:
9458       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/tab_colors.pl>
9459
9460   Example: tables.pl
9461       Example of how to add tables to an Excel::Writer::XLSX worksheet.
9462
9463       Tables in Excel are used to group rows and columns of data into a
9464       single structure that can be referenced in a formula or formatted
9465       collectively.
9466
9467       Source code for this example:
9468
9469           #!/usr/bin/perl
9470
9471           ###############################################################################
9472           #
9473           # Example of how to add tables to an Excel::Writer::XLSX worksheet.
9474           #
9475           # Tables in Excel are used to group rows and columns of data into a single
9476           # structure that can be referenced in a formula or formatted collectively.
9477           #
9478           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
9479           #
9480
9481           use strict;
9482           use warnings;
9483           use Excel::Writer::XLSX;
9484
9485           my $workbook    = Excel::Writer::XLSX->new( 'tables.xlsx' );
9486           my $worksheet1  = $workbook->add_worksheet();
9487           my $worksheet2  = $workbook->add_worksheet();
9488           my $worksheet3  = $workbook->add_worksheet();
9489           my $worksheet4  = $workbook->add_worksheet();
9490           my $worksheet5  = $workbook->add_worksheet();
9491           my $worksheet6  = $workbook->add_worksheet();
9492           my $worksheet7  = $workbook->add_worksheet();
9493           my $worksheet8  = $workbook->add_worksheet();
9494           my $worksheet9  = $workbook->add_worksheet();
9495           my $worksheet10 = $workbook->add_worksheet();
9496           my $worksheet11 = $workbook->add_worksheet();
9497           my $worksheet12 = $workbook->add_worksheet();
9498           my $worksheet13 = $workbook->add_worksheet();
9499
9500           my $currency_format = $workbook->add_format( num_format => '$#,##0' );
9501
9502
9503           # Some sample data for the table.
9504           my $data = [
9505               [ 'Apples',  10000, 5000, 8000, 6000 ],
9506               [ 'Pears',   2000,  3000, 4000, 5000 ],
9507               [ 'Bananas', 6000,  6000, 6500, 6000 ],
9508               [ 'Oranges', 500,   300,  200,  700 ],
9509
9510           ];
9511
9512
9513           ###############################################################################
9514           #
9515           # Example 1.
9516           #
9517           my $caption = 'Default table with no data.';
9518
9519           # Set the columns widths.
9520           $worksheet1->set_column( 'B:G', 12 );
9521
9522           # Write the caption.
9523           $worksheet1->write( 'B1', $caption );
9524
9525           # Add a table to the worksheet.
9526           $worksheet1->add_table( 'B3:F7' );
9527
9528
9529           ###############################################################################
9530           #
9531           # Example 2.
9532           #
9533           $caption = 'Default table with data.';
9534
9535           # Set the columns widths.
9536           $worksheet2->set_column( 'B:G', 12 );
9537
9538           # Write the caption.
9539           $worksheet2->write( 'B1', $caption );
9540
9541           # Add a table to the worksheet.
9542           $worksheet2->add_table( 'B3:F7', { data => $data } );
9543
9544
9545           ###############################################################################
9546           #
9547           # Example 3.
9548           #
9549           $caption = 'Table without default autofilter.';
9550
9551           # Set the columns widths.
9552           $worksheet3->set_column( 'B:G', 12 );
9553
9554           # Write the caption.
9555           $worksheet3->write( 'B1', $caption );
9556
9557           # Add a table to the worksheet.
9558           $worksheet3->add_table( 'B3:F7', { autofilter => 0 } );
9559
9560           # Table data can also be written separately, as an array or individual cells.
9561           $worksheet3->write_col( 'B4', $data );
9562
9563
9564           ###############################################################################
9565           #
9566           # Example 4.
9567           #
9568           $caption = 'Table without default header row.';
9569
9570           # Set the columns widths.
9571           $worksheet4->set_column( 'B:G', 12 );
9572
9573           # Write the caption.
9574           $worksheet4->write( 'B1', $caption );
9575
9576           # Add a table to the worksheet.
9577           $worksheet4->add_table( 'B4:F7', { header_row => 0 } );
9578
9579           # Table data can also be written separately, as an array or individual cells.
9580           $worksheet4->write_col( 'B4', $data );
9581
9582
9583           ###############################################################################
9584           #
9585           # Example 5.
9586           #
9587           $caption = 'Default table with "First Column" and "Last Column" options.';
9588
9589           # Set the columns widths.
9590           $worksheet5->set_column( 'B:G', 12 );
9591
9592           # Write the caption.
9593           $worksheet5->write( 'B1', $caption );
9594
9595           # Add a table to the worksheet.
9596           $worksheet5->add_table( 'B3:F7', { first_column => 1, last_column => 1 } );
9597
9598           # Table data can also be written separately, as an array or individual cells.
9599           $worksheet5->write_col( 'B4', $data );
9600
9601
9602           ###############################################################################
9603           #
9604           # Example 6.
9605           #
9606           $caption = 'Table with banded columns but without default banded rows.';
9607
9608           # Set the columns widths.
9609           $worksheet6->set_column( 'B:G', 12 );
9610
9611           # Write the caption.
9612           $worksheet6->write( 'B1', $caption );
9613
9614           # Add a table to the worksheet.
9615           $worksheet6->add_table( 'B3:F7', { banded_rows => 0, banded_columns => 1 } );
9616
9617           # Table data can also be written separately, as an array or individual cells.
9618           $worksheet6->write_col( 'B4', $data );
9619
9620
9621           ###############################################################################
9622           #
9623           # Example 7.
9624           #
9625           $caption = 'Table with user defined column headers';
9626
9627           # Set the columns widths.
9628           $worksheet7->set_column( 'B:G', 12 );
9629
9630           # Write the caption.
9631           $worksheet7->write( 'B1', $caption );
9632
9633           # Add a table to the worksheet.
9634           $worksheet7->add_table(
9635               'B3:F7',
9636               {
9637                   data    => $data,
9638                   columns => [
9639                       { header => 'Product' },
9640                       { header => 'Quarter 1' },
9641                       { header => 'Quarter 2' },
9642                       { header => 'Quarter 3' },
9643                       { header => 'Quarter 4' },
9644                   ]
9645               }
9646           );
9647
9648
9649           ###############################################################################
9650           #
9651           # Example 8.
9652           #
9653           $caption = 'Table with user defined column headers';
9654
9655           # Set the columns widths.
9656           $worksheet8->set_column( 'B:G', 12 );
9657
9658           # Write the caption.
9659           $worksheet8->write( 'B1', $caption );
9660
9661           # Add a table to the worksheet.
9662           $worksheet8->add_table(
9663               'B3:G7',
9664               {
9665                   data    => $data,
9666                   columns => [
9667                       { header => 'Product' },
9668                       { header => 'Quarter 1' },
9669                       { header => 'Quarter 2' },
9670                       { header => 'Quarter 3' },
9671                       { header => 'Quarter 4' },
9672                       {
9673                           header  => 'Year',
9674                           formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])'
9675                       },
9676                   ]
9677               }
9678           );
9679
9680
9681           ###############################################################################
9682           #
9683           # Example 9.
9684           #
9685           $caption = 'Table with totals row (but no caption or totals).';
9686
9687           # Set the columns widths.
9688           $worksheet9->set_column( 'B:G', 12 );
9689
9690           # Write the caption.
9691           $worksheet9->write( 'B1', $caption );
9692
9693           # Add a table to the worksheet.
9694           $worksheet9->add_table(
9695               'B3:G8',
9696               {
9697                   data      => $data,
9698                   total_row => 1,
9699                   columns   => [
9700                       { header => 'Product' },
9701                       { header => 'Quarter 1' },
9702                       { header => 'Quarter 2' },
9703                       { header => 'Quarter 3' },
9704                       { header => 'Quarter 4' },
9705                       {
9706                           header  => 'Year',
9707                           formula => '=SUM(Table9[@[Quarter 1]:[Quarter 4]])'
9708                       },
9709                   ]
9710               }
9711           );
9712
9713
9714           ###############################################################################
9715           #
9716           # Example 10.
9717           #
9718           $caption = 'Table with totals row with user captions and functions.';
9719
9720           # Set the columns widths.
9721           $worksheet10->set_column( 'B:G', 12 );
9722
9723           # Write the caption.
9724           $worksheet10->write( 'B1', $caption );
9725
9726           # Add a table to the worksheet.
9727           $worksheet10->add_table(
9728               'B3:G8',
9729               {
9730                   data      => $data,
9731                   total_row => 1,
9732                   columns   => [
9733                       { header => 'Product',   total_string   => 'Totals' },
9734                       { header => 'Quarter 1', total_function => 'sum' },
9735                       { header => 'Quarter 2', total_function => 'sum' },
9736                       { header => 'Quarter 3', total_function => 'sum' },
9737                       { header => 'Quarter 4', total_function => 'sum' },
9738                       {
9739                           header         => 'Year',
9740                           formula        => '=SUM(Table10[@[Quarter 1]:[Quarter 4]])',
9741                           total_function => 'sum'
9742                       },
9743                   ]
9744               }
9745           );
9746
9747
9748           ###############################################################################
9749           #
9750           # Example 11.
9751           #
9752           $caption = 'Table with alternative Excel style.';
9753
9754           # Set the columns widths.
9755           $worksheet11->set_column( 'B:G', 12 );
9756
9757           # Write the caption.
9758           $worksheet11->write( 'B1', $caption );
9759
9760           # Add a table to the worksheet.
9761           $worksheet11->add_table(
9762               'B3:G8',
9763               {
9764                   data      => $data,
9765                   style     => 'Table Style Light 11',
9766                   total_row => 1,
9767                   columns   => [
9768                       { header => 'Product',   total_string   => 'Totals' },
9769                       { header => 'Quarter 1', total_function => 'sum' },
9770                       { header => 'Quarter 2', total_function => 'sum' },
9771                       { header => 'Quarter 3', total_function => 'sum' },
9772                       { header => 'Quarter 4', total_function => 'sum' },
9773                       {
9774                           header         => 'Year',
9775                           formula        => '=SUM(Table11[@[Quarter 1]:[Quarter 4]])',
9776                           total_function => 'sum'
9777                       },
9778                   ]
9779               }
9780           );
9781
9782
9783           ###############################################################################
9784           #
9785           # Example 12.
9786           #
9787           $caption = 'Table with no Excel style.';
9788
9789           # Set the columns widths.
9790           $worksheet12->set_column( 'B:G', 12 );
9791
9792           # Write the caption.
9793           $worksheet12->write( 'B1', $caption );
9794
9795           # Add a table to the worksheet.
9796           $worksheet12->add_table(
9797               'B3:G8',
9798               {
9799                   data      => $data,
9800                   style     => 'None',
9801                   total_row => 1,
9802                   columns   => [
9803                       { header => 'Product',   total_string   => 'Totals' },
9804                       { header => 'Quarter 1', total_function => 'sum' },
9805                       { header => 'Quarter 2', total_function => 'sum' },
9806                       { header => 'Quarter 3', total_function => 'sum' },
9807                       { header => 'Quarter 4', total_function => 'sum' },
9808                       {
9809                           header         => 'Year',
9810                           formula        => '=SUM(Table12[@[Quarter 1]:[Quarter 4]])',
9811                           total_function => 'sum'
9812                       },
9813                   ]
9814               }
9815           );
9816
9817
9818           ###############################################################################
9819           #
9820           # Example 13.
9821           #
9822           $caption = 'Table with column formats.';
9823
9824           # Set the columns widths.
9825           $worksheet13->set_column( 'B:G', 12 );
9826
9827           # Write the caption.
9828           $worksheet13->write( 'B1', $caption );
9829
9830           # Add a table to the worksheet.
9831           $worksheet13->add_table(
9832               'B3:G8',
9833               {
9834                   data      => $data,
9835                   total_row => 1,
9836                   columns   => [
9837                       { header => 'Product', total_string => 'Totals' },
9838                       {
9839                           header         => 'Quarter 1',
9840                           total_function => 'sum',
9841                           format         => $currency_format,
9842                       },
9843                       {
9844                           header         => 'Quarter 2',
9845                           total_function => 'sum',
9846                           format         => $currency_format,
9847                       },
9848                       {
9849                           header         => 'Quarter 3',
9850                           total_function => 'sum',
9851                           format         => $currency_format,
9852                       },
9853                       {
9854                           header         => 'Quarter 4',
9855                           total_function => 'sum',
9856                           format         => $currency_format,
9857                       },
9858                       {
9859                           header         => 'Year',
9860                           formula        => '=SUM(Table13[@[Quarter 1]:[Quarter 4]])',
9861                           total_function => 'sum',
9862                           format         => $currency_format,
9863                       },
9864                   ]
9865               }
9866           );
9867
9868
9869           $workbook->close();
9870
9871           __END__
9872
9873       Download this example:
9874       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/tables.pl>
9875
9876   Example: write_handler1.pl
9877       Example of how to add a user defined data handler to the
9878       Excel::Writer::XLSX write() method.
9879
9880       The following example shows how to add a handler for a 7 digit ID
9881       number.
9882
9883       Source code for this example:
9884
9885           #!/usr/bin/perl -w
9886
9887           ###############################################################################
9888           #
9889           # Example of how to add a user defined data handler to the
9890           # Excel::Writer::XLSX write() method.
9891           #
9892           # The following example shows how to add a handler for a 7 digit ID number.
9893           #
9894           #
9895           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
9896           #
9897
9898           use strict;
9899           use Excel::Writer::XLSX;
9900
9901
9902           my $workbook  = Excel::Writer::XLSX->new( 'write_handler1.xlsx' );
9903           my $worksheet = $workbook->add_worksheet();
9904
9905
9906           ###############################################################################
9907           #
9908           # Add a handler for 7 digit id numbers. This is useful when you want a string
9909           # such as 0000001 written as a string instead of a number and thus preserve
9910           # the leading zeroes.
9911           #
9912           # Note: you can get the same effect using the keep_leading_zeros() method but
9913           # this serves as a simple example.
9914           #
9915           $worksheet->add_write_handler( qr[^\d{7}$], \&write_my_id );
9916
9917
9918           ###############################################################################
9919           #
9920           # The following function processes the data when a match is found.
9921           #
9922           sub write_my_id {
9923
9924               my $worksheet = shift;
9925
9926               return $worksheet->write_string( @_ );
9927           }
9928
9929
9930           # This format maintains the cell as text even if it is edited.
9931           my $id_format = $workbook->add_format( num_format => '@' );
9932
9933
9934           # Write some numbers in the user defined format
9935           $worksheet->write( 'A1', '0000000', $id_format );
9936           $worksheet->write( 'A2', '0000001', $id_format );
9937           $worksheet->write( 'A3', '0004000', $id_format );
9938           $worksheet->write( 'A4', '1234567', $id_format );
9939
9940           # Write some numbers that don't match the defined format
9941           $worksheet->write( 'A6', '000000', $id_format );
9942           $worksheet->write( 'A7', '000001', $id_format );
9943           $worksheet->write( 'A8', '004000', $id_format );
9944           $worksheet->write( 'A9', '123456', $id_format );
9945
9946           $workbook->close();
9947
9948           __END__
9949
9950       Download this example:
9951       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/write_handler1.pl>
9952
9953   Example: write_handler2.pl
9954       Example of how to add a user defined data handler to the
9955       Excel::Writer::XLSX write() method.
9956
9957       The following example shows how to add a handler for a 7 digit ID
9958       number.  It adds an additional constraint to the write_handler1.pl in
9959       that it only filters data that isn't in the third column.
9960
9961       Source code for this example:
9962
9963           #!/usr/bin/perl -w
9964
9965           ###############################################################################
9966           #
9967           # Example of how to add a user defined data handler to the
9968           # Excel::Writer::XLSX write() method.
9969           #
9970           # The following example shows how to add a handler for a 7 digit ID number.
9971           # It adds an additional constraint to the write_handler1.pl in that it only
9972           # filters data that isn't in the third column.
9973           #
9974           #
9975           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
9976           #
9977
9978           use strict;
9979           use Excel::Writer::XLSX;
9980
9981
9982           my $workbook  = Excel::Writer::XLSX->new( 'write_handler2.xlsx' );
9983           my $worksheet = $workbook->add_worksheet();
9984
9985
9986           ###############################################################################
9987           #
9988           # Add a handler for 7 digit id numbers. This is useful when you want a string
9989           # such as 0000001 written as a string instead of a number and thus preserve
9990           # the leading zeroes.
9991           #
9992           # Note: you can get the same effect using the keep_leading_zeros() method but
9993           # this serves as a simple example.
9994           #
9995           $worksheet->add_write_handler( qr[^\d{7}$], \&write_my_id );
9996
9997
9998           ###############################################################################
9999           #
10000           # The following function processes the data when a match is found. The handler
10001           # is set up so that it only filters data if it is in the third column.
10002           #
10003           sub write_my_id {
10004
10005               my $worksheet = shift;
10006               my $col       = $_[1];
10007
10008               # col is zero based
10009               if ( $col != 2 ) {
10010                   return $worksheet->write_string( @_ );
10011               }
10012               else {
10013
10014                   # Reject the match and return control to write()
10015                   return undef;
10016               }
10017
10018           }
10019
10020
10021           # This format maintains the cell as text even if it is edited.
10022           my $id_format = $workbook->add_format( num_format => '@' );
10023
10024
10025           # Write some numbers in the user defined format
10026           $worksheet->write( 'A1', '0000000', $id_format );
10027           $worksheet->write( 'B1', '0000001', $id_format );
10028           $worksheet->write( 'C1', '0000002', $id_format );
10029           $worksheet->write( 'D1', '0000003', $id_format );
10030
10031           $workbook->close();
10032
10033           __END__
10034
10035       Download this example:
10036       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/write_handler2.pl>
10037
10038   Example: write_handler3.pl
10039       Example of how to add a user defined data handler to the
10040       Excel::Writer::XLSX write() method.
10041
10042       The following example shows how to add a handler for dates in a
10043       specific format.
10044
10045       See write_handler4.pl for a more rigorous example with error handling.
10046
10047       Source code for this example:
10048
10049           #!/usr/bin/perl -w
10050
10051           ###############################################################################
10052           #
10053           # Example of how to add a user defined data handler to the
10054           # Excel::Writer::XLSX write() method.
10055           #
10056           # The following example shows how to add a handler for dates in a specific
10057           # format.
10058           #
10059           # See write_handler4.pl for a more rigorous example with error handling.
10060           #
10061           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10062           #
10063
10064           use strict;
10065           use Excel::Writer::XLSX;
10066
10067
10068           my $workbook    = Excel::Writer::XLSX->new( 'write_handler3.xlsx' );
10069           my $worksheet   = $workbook->add_worksheet();
10070           my $date_format = $workbook->add_format( num_format => 'dd/mm/yy' );
10071
10072
10073           ###############################################################################
10074           #
10075           # Add a handler to match dates in the following format: d/m/yyyy
10076           #
10077           # The day and month can be single or double digits.
10078           #
10079           $worksheet->add_write_handler( qr[^\d{1,2}/\d{1,2}/\d{4}$], \&write_my_date );
10080
10081
10082           ###############################################################################
10083           #
10084           # The following function processes the data when a match is found.
10085           # See write_handler4.pl for a more rigorous example with error handling.
10086           #
10087           sub write_my_date {
10088
10089               my $worksheet = shift;
10090               my @args      = @_;
10091
10092               my $token = $args[2];
10093               $token =~ qr[^(\d{1,2})/(\d{1,2})/(\d{4})$];
10094
10095               # Change to the date format required by write_date_time().
10096               my $date = sprintf "%4d-%02d-%02dT", $3, $2, $1;
10097
10098               $args[2] = $date;
10099
10100               return $worksheet->write_date_time( @args );
10101           }
10102
10103
10104           # Write some dates in the user defined format
10105           $worksheet->write( 'A1', '22/12/2004', $date_format );
10106           $worksheet->write( 'A2', '1/1/1995',   $date_format );
10107           $worksheet->write( 'A3', '01/01/1995', $date_format );
10108
10109           $workbook->close();
10110
10111           __END__
10112
10113       Download this example:
10114       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/write_handler3.pl>
10115
10116   Example: write_handler4.pl
10117       Example of how to add a user defined data handler to the
10118       Excel::Writer::XLSX write() method.
10119
10120       The following example shows how to add a handler for dates in a
10121       specific format.
10122
10123       This is a more rigorous version of write_handler3.pl.
10124
10125       Source code for this example:
10126
10127           #!/usr/bin/perl -w
10128
10129           ###############################################################################
10130           #
10131           # Example of how to add a user defined data handler to the
10132           # Excel::Writer::XLSX write() method.
10133           #
10134           # The following example shows how to add a handler for dates in a specific
10135           # format.
10136           #
10137           # This is a more rigorous version of write_handler3.pl.
10138           #
10139           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10140           #
10141
10142           use strict;
10143           use Excel::Writer::XLSX;
10144
10145
10146           my $workbook    = Excel::Writer::XLSX->new( 'write_handler4.xlsx' );
10147           my $worksheet   = $workbook->add_worksheet();
10148           my $date_format = $workbook->add_format( num_format => 'dd/mm/yy' );
10149
10150
10151           ###############################################################################
10152           #
10153           # Add a handler to match dates in the following formats: d/m/yy, d/m/yyyy
10154           #
10155           # The day and month can be single or double digits and the year can be  2 or 4
10156           # digits.
10157           #
10158           $worksheet->add_write_handler( qr[^\d{1,2}/\d{1,2}/\d{2,4}$], \&write_my_date );
10159
10160
10161           ###############################################################################
10162           #
10163           # The following function processes the data when a match is found.
10164           #
10165           sub write_my_date {
10166
10167               my $worksheet = shift;
10168               my @args      = @_;
10169
10170               my $token = $args[2];
10171
10172               if ( $token =~ qr[^(\d{1,2})/(\d{1,2})/(\d{2,4})$] ) {
10173
10174                   my $day  = $1;
10175                   my $mon  = $2;
10176                   my $year = $3;
10177
10178                   # Use a window for 2 digit dates. This will keep some ragged Perl
10179                   # programmer employed in thirty years time. :-)
10180                   if ( length $year == 2 ) {
10181                       if ( $year < 50 ) {
10182                           $year += 2000;
10183                       }
10184                       else {
10185                           $year += 1900;
10186                       }
10187                   }
10188
10189                   my $date = sprintf "%4d-%02d-%02dT", $year, $mon, $day;
10190
10191                   # Convert the ISO ISO8601 style string to an Excel date
10192                   $date = $worksheet->convert_date_time( $date );
10193
10194                   if ( defined $date ) {
10195
10196                       # Date was valid
10197                       $args[2] = $date;
10198                       return $worksheet->write_number( @args );
10199                   }
10200                   else {
10201
10202                       # Not a valid date therefore write as a string
10203                       return $worksheet->write_string( @args );
10204                   }
10205               }
10206               else {
10207
10208                   # Shouldn't happen if the same match is used in the re and sub.
10209                   return undef;
10210               }
10211           }
10212
10213
10214           # Write some dates in the user defined format
10215           $worksheet->write( 'A1', '22/12/2004', $date_format );
10216           $worksheet->write( 'A2', '22/12/04',   $date_format );
10217           $worksheet->write( 'A3', '2/12/04',    $date_format );
10218           $worksheet->write( 'A4', '2/5/04',     $date_format );
10219           $worksheet->write( 'A5', '2/5/95',     $date_format );
10220           $worksheet->write( 'A6', '2/5/1995',   $date_format );
10221
10222           # Some erroneous dates
10223           $worksheet->write( 'A8', '2/5/1895',  $date_format ); # Date out of Excel range
10224           $worksheet->write( 'A9', '29/2/2003', $date_format ); # Invalid leap day
10225           $worksheet->write( 'A10', '50/50/50', $date_format ); # Matches but isn't a date
10226
10227           $workbook->close();
10228
10229           __END__
10230
10231       Download this example:
10232       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/write_handler4.pl>
10233
10234   Example: write_to_scalar.pl
10235       An example of writing an Excel::Writer::XLSX file to a perl scalar.
10236
10237           #!/usr/bin/perl
10238
10239           ##############################################################################
10240           #
10241           # An example of writing an Excel::Writer::XLSX file to a perl scalar.
10242           #
10243           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10244           #
10245
10246           use strict;
10247           use warnings;
10248           use Excel::Writer::XLSX;
10249
10250           # Use a scalar as a filehandle.
10251           open my $fh, '>', \my $str or die "Failed to open filehandle: $!";
10252
10253
10254           # Spreadsheet::WriteExce accepts filehandle as well as file names.
10255           my $workbook  = Excel::Writer::XLSX->new( $fh );
10256           my $worksheet = $workbook->add_worksheet();
10257
10258           $worksheet->write( 0, 0, 'Hi Excel!' );
10259
10260           $workbook->close();
10261
10262
10263           # The Excel file in now in $str. Remember to binmode() the output
10264           # filehandle before printing it.
10265           open my $out_fh, '>', 'write_to_scalar.xlsx'
10266             or die "Failed to open out filehandle: $!";
10267
10268           binmode $out_fh;
10269           print   $out_fh $str;
10270           close   $out_fh;
10271
10272           __END__
10273
10274       Download this example:
10275       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/write_to_scalar.pl>
10276
10277   Example: unicode_2022_jp.pl
10278       A simple example of converting some Unicode text to an Excel file using
10279       Excel::Writer::XLSX.
10280
10281       This example generates some Japanese from a file with ISO-2022-JP
10282       encoded text.
10283
10284       Source code for this example:
10285
10286           #!/usr/bin/perl
10287
10288           ##############################################################################
10289           #
10290           # A simple example of converting some Unicode text to an Excel file using
10291           # Excel::Writer::XLSX.
10292           #
10293           # This example generates some Japanese from a file with ISO-2022-JP
10294           # encoded text.
10295           #
10296           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10297           #
10298
10299           use strict;
10300           use warnings;
10301           use Excel::Writer::XLSX;
10302
10303
10304           my $workbook = Excel::Writer::XLSX->new( 'unicode_2022_jp.xlsx' );
10305
10306           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10307
10308           my $worksheet = $workbook->add_worksheet();
10309           $worksheet->set_column( 'A:A', 50 );
10310
10311
10312           my $file = 'unicode_2022_jp.txt';
10313
10314           open FH, '<:encoding(iso-2022-jp)', $file or die "Couldn't open $file: $!\n";
10315
10316           my $row = 0;
10317
10318           while ( <FH> ) {
10319               next if /^#/;    # Ignore the comments in the sample file.
10320               chomp;
10321               $worksheet->write( $row++, 0, $_ );
10322           }
10323
10324           $workbook->close();
10325
10326           __END__
10327
10328       Download this example:
10329       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_2022_jp.pl>
10330
10331   Example: unicode_8859_11.pl
10332       A simple example of converting some Unicode text to an Excel file using
10333       Excel::Writer::XLSX.
10334
10335       This example generates some Thai from a file with ISO-8859-11 encoded
10336       text.
10337
10338       Source code for this example:
10339
10340           #!/usr/bin/perl
10341
10342           ##############################################################################
10343           #
10344           # A simple example of converting some Unicode text to an Excel file using
10345           # Excel::Writer::XLSX.
10346           #
10347           # This example generates some Thai from a file with ISO-8859-11 encoded text.
10348           #
10349           #
10350           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10351           #
10352
10353           use strict;
10354           use warnings;
10355           use Excel::Writer::XLSX;
10356
10357
10358           my $workbook = Excel::Writer::XLSX->new( 'unicode_8859_11.xlsx' );
10359
10360           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10361
10362           my $worksheet = $workbook->add_worksheet();
10363           $worksheet->set_column( 'A:A', 50 );
10364
10365
10366           my $file = 'unicode_8859_11.txt';
10367
10368           open FH, '<:encoding(iso-8859-11)', $file or die "Couldn't open $file: $!\n";
10369
10370           my $row = 0;
10371
10372           while ( <FH> ) {
10373               next if /^#/;    # Ignore the comments in the sample file.
10374               chomp;
10375               $worksheet->write( $row++, 0, $_ );
10376           }
10377
10378           $workbook->close();
10379
10380           __END__
10381
10382       Download this example:
10383       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_8859_11.pl>
10384
10385   Example: unicode_8859_7.pl
10386       A simple example of converting some Unicode text to an Excel file using
10387       Excel::Writer::XLSX.
10388
10389       This example generates some Greek from a file with ISO-8859-7 encoded
10390       text.
10391
10392       Source code for this example:
10393
10394           #!/usr/bin/perl
10395
10396           ##############################################################################
10397           #
10398           # A simple example of converting some Unicode text to an Excel file using
10399           # Excel::Writer::XLSX.
10400           #
10401           # This example generates some Greek from a file with ISO-8859-7 encoded text.
10402           #
10403           #
10404           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10405           #
10406
10407           use strict;
10408           use warnings;
10409           use Excel::Writer::XLSX;
10410
10411
10412           my $workbook = Excel::Writer::XLSX->new( 'unicode_8859_7.xlsx' );
10413
10414           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10415
10416           my $worksheet = $workbook->add_worksheet();
10417           $worksheet->set_column( 'A:A', 50 );
10418
10419
10420           my $file = 'unicode_8859_7.txt';
10421
10422           open FH, '<:encoding(iso-8859-7)', $file or die "Couldn't open $file: $!\n";
10423
10424           my $row = 0;
10425
10426           while ( <FH> ) {
10427               next if /^#/;    # Ignore the comments in the sample file.
10428               chomp;
10429               $worksheet->write( $row++, 0, $_ );
10430           }
10431
10432           $workbook->close();
10433
10434           __END__
10435
10436       Download this example:
10437       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_8859_7.pl>
10438
10439   Example: unicode_big5.pl
10440       A simple example of converting some Unicode text to an Excel file using
10441       Excel::Writer::XLSX.
10442
10443       This example generates some Chinese from a file with BIG5 encoded text.
10444
10445       Source code for this example:
10446
10447           #!/usr/bin/perl
10448
10449           ##############################################################################
10450           #
10451           # A simple example of converting some Unicode text to an Excel file using
10452           # Excel::Writer::XLSX.
10453           #
10454           # This example generates some Chinese from a file with BIG5 encoded text.
10455           #
10456           #
10457           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10458           #
10459
10460           use strict;
10461           use warnings;
10462           use Excel::Writer::XLSX;
10463
10464
10465           my $workbook = Excel::Writer::XLSX->new( 'unicode_big5.xlsx' );
10466
10467           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10468
10469           my $worksheet = $workbook->add_worksheet();
10470           $worksheet->set_column( 'A:A', 80 );
10471
10472
10473           my $file = 'unicode_big5.txt';
10474
10475           open FH, '<:encoding(big5)', $file or die "Couldn't open $file: $!\n";
10476
10477           my $row = 0;
10478
10479           while ( <FH> ) {
10480               next if /^#/;    # Ignore the comments in the sample file.
10481               chomp;
10482               $worksheet->write( $row++, 0, $_ );
10483           }
10484
10485           $workbook->close();
10486
10487           __END__
10488
10489       Download this example:
10490       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_big5.pl>
10491
10492   Example: unicode_cp1251.pl
10493       A simple example of converting some Unicode text to an Excel file using
10494       Excel::Writer::XLSX.
10495
10496       This example generates some Russian from a file with CP1251 encoded
10497       text.
10498
10499       Source code for this example:
10500
10501           #!/usr/bin/perl
10502
10503           ##############################################################################
10504           #
10505           # A simple example of converting some Unicode text to an Excel file using
10506           # Excel::Writer::XLSX.
10507           #
10508           # This example generates some Russian from a file with CP1251 encoded text.
10509           #
10510           #
10511           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10512           #
10513
10514           use strict;
10515           use warnings;
10516           use Excel::Writer::XLSX;
10517
10518
10519           my $workbook = Excel::Writer::XLSX->new( 'unicode_cp1251.xlsx' );
10520
10521           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10522
10523           my $worksheet = $workbook->add_worksheet();
10524           $worksheet->set_column( 'A:A', 50 );
10525
10526
10527           my $file = 'unicode_cp1251.txt';
10528
10529           open FH, '<:encoding(cp1251)', $file or die "Couldn't open $file: $!\n";
10530
10531           my $row = 0;
10532
10533           while ( <FH> ) {
10534               next if /^#/;    # Ignore the comments in the sample file.
10535               chomp;
10536               $worksheet->write( $row++, 0, $_ );
10537           }
10538
10539           $workbook->close();
10540
10541           __END__
10542
10543       Download this example:
10544       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_cp1251.pl>
10545
10546   Example: unicode_cp1256.pl
10547       A simple example of converting some Unicode text to an Excel file using
10548       Excel::Writer::XLSX.
10549
10550       This example generates some Arabic text from a CP-1256 encoded file.
10551
10552       Source code for this example:
10553
10554           #!/usr/bin/perl
10555
10556           ##############################################################################
10557           #
10558           # A simple example of converting some Unicode text to an Excel file using
10559           # Excel::Writer::XLSX.
10560           #
10561           # This example generates some Arabic text from a CP-1256 encoded file.
10562           #
10563           #
10564           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10565           #
10566
10567           use strict;
10568           use warnings;
10569           use Excel::Writer::XLSX;
10570
10571
10572           my $workbook = Excel::Writer::XLSX->new( 'unicode_cp1256.xlsx' );
10573
10574           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10575
10576           my $worksheet = $workbook->add_worksheet();
10577           $worksheet->set_column( 'A:A', 50 );
10578
10579
10580           my $file = 'unicode_cp1256.txt';
10581
10582           open FH, '<:encoding(cp1256)', $file or die "Couldn't open $file: $!\n";
10583
10584           my $row = 0;
10585
10586           while ( <FH> ) {
10587               next if /^#/;    # Ignore the comments in the sample file.
10588               chomp;
10589               $worksheet->write( $row++, 0, $_ );
10590           }
10591
10592           $workbook->close();
10593
10594           __END__
10595
10596       Download this example:
10597       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_cp1256.pl>
10598
10599   Example: unicode_cyrillic.pl
10600       A simple example of writing some Russian cyrillic text using
10601       Excel::Writer::XLSX.
10602
10603       Source code for this example:
10604
10605           #!/usr/bin/perl
10606
10607           ##############################################################################
10608           #
10609           # A simple example of writing some Russian cyrillic text using
10610           # Excel::Writer::XLSX.
10611           #
10612           #
10613           #
10614           #
10615           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10616           #
10617
10618           use strict;
10619           use warnings;
10620           use Excel::Writer::XLSX;
10621
10622
10623           # In this example we generate utf8 strings from character data but in a
10624           # real application we would expect them to come from an external source.
10625           #
10626
10627
10628           # Create a Russian worksheet name in utf8.
10629           my $sheet = pack "U*", 0x0421, 0x0442, 0x0440, 0x0430, 0x043D, 0x0438,
10630             0x0446, 0x0430;
10631
10632
10633           # Create a Russian string.
10634           my $str = pack "U*", 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441,
10635             0x0442, 0x0432, 0x0443, 0x0439, 0x0020, 0x041C,
10636             0x0438, 0x0440, 0x0021;
10637
10638
10639           my $workbook = Excel::Writer::XLSX->new( 'unicode_cyrillic.xlsx' );
10640
10641           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10642
10643           my $worksheet = $workbook->add_worksheet( $sheet . '1' );
10644
10645           $worksheet->set_column( 'A:A', 18 );
10646           $worksheet->write( 'A1', $str );
10647
10648           $workbook->close();
10649
10650           __END__
10651
10652       Download this example:
10653       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_cyrillic.pl>
10654
10655   Example: unicode_koi8r.pl
10656       A simple example of converting some Unicode text to an Excel file using
10657       Excel::Writer::XLSX.
10658
10659       This example generates some Russian from a file with KOI8-R encoded
10660       text.
10661
10662       Source code for this example:
10663
10664           #!/usr/bin/perl
10665
10666           ##############################################################################
10667           #
10668           # A simple example of converting some Unicode text to an Excel file using
10669           # Excel::Writer::XLSX.
10670           #
10671           # This example generates some Russian from a file with KOI8-R encoded text.
10672           #
10673           #
10674           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10675           #
10676
10677           use strict;
10678           use warnings;
10679           use Excel::Writer::XLSX;
10680
10681
10682           my $workbook = Excel::Writer::XLSX->new( 'unicode_koi8r.xlsx' );
10683
10684           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10685
10686           my $worksheet = $workbook->add_worksheet();
10687           $worksheet->set_column( 'A:A', 50 );
10688
10689
10690           my $file = 'unicode_koi8r.txt';
10691
10692           open FH, '<:encoding(koi8-r)', $file or die "Couldn't open $file: $!\n";
10693
10694           my $row = 0;
10695
10696           while ( <FH> ) {
10697               next if /^#/;    # Ignore the comments in the sample file.
10698               chomp;
10699               $worksheet->write( $row++, 0, $_ );
10700           }
10701
10702           $workbook->close();
10703
10704           __END__
10705
10706       Download this example:
10707       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_koi8r.pl>
10708
10709   Example: unicode_polish_utf8.pl
10710       A simple example of converting some Unicode text to an Excel file using
10711       Excel::Writer::XLSX.
10712
10713       This example generates some Polish from a file with UTF8 encoded text.
10714
10715       Source code for this example:
10716
10717           #!/usr/bin/perl
10718
10719           ##############################################################################
10720           #
10721           # A simple example of converting some Unicode text to an Excel file using
10722           # Excel::Writer::XLSX.
10723           #
10724           # This example generates some Polish from a file with UTF8 encoded text.
10725           #
10726           #
10727           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10728           #
10729
10730           use strict;
10731           use warnings;
10732           use Excel::Writer::XLSX;
10733
10734
10735           my $workbook = Excel::Writer::XLSX->new( 'unicode_polish_utf8.xlsx' );
10736
10737           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10738
10739           my $worksheet = $workbook->add_worksheet();
10740           $worksheet->set_column( 'A:A', 50 );
10741
10742
10743           my $file = 'unicode_polish_utf8.txt';
10744
10745           open FH, '<:encoding(utf8)', $file or die "Couldn't open $file: $!\n";
10746
10747           my $row = 0;
10748
10749           while ( <FH> ) {
10750               next if /^#/;    # Ignore the comments in the sample file.
10751               chomp;
10752               $worksheet->write( $row++, 0, $_ );
10753           }
10754
10755           $workbook->close();
10756
10757           __END__
10758
10759       Download this example:
10760       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_polish_utf8.pl>
10761
10762   Example: unicode_shift_jis.pl
10763       A simple example of converting some Unicode text to an Excel file using
10764       Excel::Writer::XLSX.
10765
10766       This example generates some Japenese text from a file with Shift-JIS
10767       encoded text.
10768
10769       Source code for this example:
10770
10771           #!/usr/bin/perl
10772
10773           ##############################################################################
10774           #
10775           # A simple example of converting some Unicode text to an Excel file using
10776           # Excel::Writer::XLSX.
10777           #
10778           # This example generates some Japenese text from a file with Shift-JIS
10779           # encoded text.
10780           #
10781           # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
10782           #
10783
10784           use strict;
10785           use warnings;
10786           use Excel::Writer::XLSX;
10787
10788
10789           my $workbook = Excel::Writer::XLSX->new( 'unicode_shift_jis.xlsx' );
10790
10791           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10792
10793           my $worksheet = $workbook->add_worksheet();
10794           $worksheet->set_column( 'A:A', 50 );
10795
10796
10797           my $file = 'unicode_shift_jis.txt';
10798
10799           open FH, '<:encoding(shiftjis)', $file or die "Couldn't open $file: $!\n";
10800
10801           my $row = 0;
10802
10803           while ( <FH> ) {
10804               next if /^#/;    # Ignore the comments in the sample file.
10805               chomp;
10806               $worksheet->write( $row++, 0, $_ );
10807           }
10808
10809           $workbook->close();
10810
10811           __END__
10812
10813       Download this example:
10814       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.07/examples/unicode_shift_jis.pl>
10815

AUTHOR

10817       John McNamara jmcnamara@cpan.org
10818
10819       Contributed examples contain the original author's name.
10820
10822       Copyright MM-MMXVI, John McNamara.
10823
10824       All Rights Reserved. This module is free software. It may be used,
10825       redistributed and/or modified under the same terms as Perl itself.
10826
10827
10828
10829perl v5.32.0                      2020-08-24  Excel::Writer::XLSX::Examples(3)
Impressum