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 95 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: autofit.pl" Examples of simulated worksheet autofit.
33
34       •   "Example: autofilter.pl" Examples of worksheet autofilters.
35
36       •   "Example: array_formula.pl" Examples of how to write array
37           formulas.
38
39       •   "Example: cgi.pl" A simple CGI program.
40
41       •   "Example: chart_area.pl" A demo of area style charts.
42
43       •   "Example: chart_bar.pl" A demo of bar (vertical histogram) style
44           charts.
45
46       •   "Example: chart_column.pl" A demo of column (histogram) style
47           charts.
48
49       •   "Example: chart_line.pl" A demo of line style charts.
50
51       •   "Example: chart_pie.pl" A demo of pie style charts.
52
53       •   "Example: chart_doughnut.pl" A demo of doughnut style charts.
54
55       •   "Example: chart_radar.pl" A demo of radar style charts.
56
57       •   "Example: chart_scatter.pl" A demo of scatter style charts.
58
59       •   "Example: chart_secondary_axis.pl" A demo of a line chart with a
60           secondary axis.
61
62       •   "Example: chart_combined.pl" A demo of a combined column and line
63           chart.
64
65       •   "Example: chart_pareto.pl" A demo of a combined Pareto chart.
66
67       •   "Example: chart_stock.pl" A demo of stock style charts.
68
69       •   "Example: chart_data_table.pl" A demo of a chart with a data table
70           on the axis.
71
72       •   "Example: chart_data_tools.pl" A demo of charts with data
73           highlighting options.
74
75       •   "Example: chart_data_labels.pl" A demo of standard and custom chart
76           data labels.
77
78       •   "Example: chart_clustered.pl" A demo of a chart with a clustered
79           axis.
80
81       •   "Example: chart_styles.pl" A demo of the available chart styles.
82
83       •   "Example: chart_gauge.pl" A demo of a gauge style chart.
84
85       •   "Example: colors.pl" A demo of the colour palette and named
86           colours.
87
88       •   "Example: comments1.pl" Add comments to worksheet cells.
89
90       •   "Example: comments2.pl" Add comments with advanced options.
91
92       •   "Example: conditional_format.pl" Add conditional formats to a range
93           of cells.
94
95       •   "Example: data_validate.pl" An example of data validation and
96           dropdown lists.
97
98       •   "Example: date_time.pl" Write dates and times with
99           write_date_time().
100
101       •   "Example: defined_name.pl" Example of how to create defined names.
102
103       •   "Example: diag_border.pl" A simple example of diagonal cell
104           borders.
105
106       •   "Example: dynamic_arrays.pl" Example of using new Excel 365 dynamic
107           functions.
108
109       •   "Example: filehandle.pl" Examples of working with filehandles.
110
111       •   "Example: headers.pl" Examples of worksheet headers and footers.
112
113       •   "Example: hide_row_col.pl" Example of hiding rows and columns.
114
115       •   "Example: hide_sheet.pl" Simple example of hiding a worksheet.
116
117       •   "Example: hyperlink1.pl" Shows how to create web hyperlinks.
118
119       •   "Example: hyperlink2.pl" Examples of internal and external
120           hyperlinks.
121
122       •   "Example: indent.pl" An example of cell indentation.
123
124       •   "Example: ignore_errors.pl" An example of turning off worksheet
125           cells errors/warnings.
126
127       •   "Example: lambda.pl" Example of using the Excel 365 LAMBDA()
128           function.
129
130       •   "Example: macros.pl" An example of adding macros from an existing
131           file.
132
133       •   "Example: merge1.pl" A simple example of cell merging.
134
135       •   "Example: merge2.pl" A simple example of cell merging with
136           formatting.
137
138       •   "Example: merge3.pl" Add hyperlinks to merged cells.
139
140       •   "Example: merge4.pl" An advanced example of merging with
141           formatting.
142
143       •   "Example: merge5.pl" An advanced example of merging with
144           formatting.
145
146       •   "Example: merge6.pl" An example of merging with Unicode strings.
147
148       •   "Example: mod_perl1.pl" A simple mod_perl 1 program.
149
150       •   "Example: mod_perl2.pl" A simple mod_perl 2 program.
151
152       •   "Example: outline.pl" An example of outlines and grouping.
153
154       •   "Example: outline_collapsed.pl" An example of collapsed outlines.
155
156       •   "Example: panes.pl" An example of how to create panes.
157
158       •   "Example: properties.pl" Add document properties to a workbook.
159
160       •   "Example: protection.pl" Example of cell locking and formula
161           hiding.
162
163       •   "Example: rich_strings.pl" Example of strings with multiple
164           formats.
165
166       •   "Example: right_to_left.pl" Change default sheet direction to right
167           to left.
168
169       •   "Example: sales.pl" An example of a simple sales spreadsheet.
170
171       •   "Example: shape1.pl" Insert shapes in worksheet.
172
173       •   "Example: shape2.pl" Insert shapes in worksheet. With properties.
174
175       •   "Example: shape3.pl" Insert shapes in worksheet. Scaled.
176
177       •   "Example: shape4.pl" Insert shapes in worksheet. With modification.
178
179       •   "Example: shape5.pl" Insert shapes in worksheet. With connections.
180
181       •   "Example: shape6.pl" Insert shapes in worksheet. With connections.
182
183       •   "Example: shape7.pl" Insert shapes in worksheet. One to many
184           connections.
185
186       •   "Example: shape8.pl" Insert shapes in worksheet. One to many
187           connections.
188
189       •   "Example: shape_all.pl" Demo of all the available shape and
190           connector types.
191
192       •   "Example: sparklines1.pl" Simple sparklines demo.
193
194       •   "Example: sparklines2.pl" Sparklines demo showing formatting
195           options.
196
197       •   "Example: stats_ext.pl" Same as stats.pl with external references.
198
199       •   "Example: stocks.pl" Demonstrates conditional formatting.
200
201       •   "Example: watermark.pl" Example of how to set a watermark image for
202           a worksheet.
203
204       •   "Example: background.pl" Example of how to set the background image
205           for a worksheet.
206
207       •   "Example: tab_colors.pl" Example of how to set worksheet tab
208           colours.
209
210       •   "Example: tables.pl" Add Excel tables to a worksheet.
211
212       •   "Example: write_handler1.pl" Example of extending the write()
213           method. Step 1.
214
215       •   "Example: write_handler2.pl" Example of extending the write()
216           method. Step 2.
217
218       •   "Example: write_handler3.pl" Example of extending the write()
219           method. Step 3.
220
221       •   "Example: write_handler4.pl" Example of extending the write()
222           method. Step 4.
223
224       •   "Example: write_to_scalar.pl" Example of writing an Excel file to a
225           Perl scalar.
226
227       •   "Example: unicode_2022_jp.pl" Japanese: ISO-2022-JP.
228
229       •   "Example: unicode_8859_11.pl" Thai:     ISO-8859_11.
230
231       •   "Example: unicode_8859_7.pl" Greek:    ISO-8859_7.
232
233       •   "Example: unicode_big5.pl" Chinese:  BIG5.
234
235       •   "Example: unicode_cp1251.pl" Russian:  CP1251.
236
237       •   "Example: unicode_cp1256.pl" Arabic:   CP1256.
238
239       •   "Example: unicode_cyrillic.pl" Russian:  Cyrillic.
240
241       •   "Example: unicode_koi8r.pl" Russian:  KOI8-R.
242
243       •   "Example: unicode_polish_utf8.pl" Polish :  UTF8.
244
245       •   "Example: unicode_shift_jis.pl" Japanese: Shift JIS.
246
247   Example: a_simple.pl
248       A simple example of how to use the Excel::Writer::XLSX module to write
249       text and numbers to an Excel xlsx file.
250
251       Source code for this example:
252
253           #!/usr/bin/perl -w
254
255           #######################################################################
256           #
257           # A simple example of how to use the Excel::Writer::XLSX module to
258           # write text and numbers to an Excel xlsx file.
259           #
260           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
261           #
262
263           use strict;
264           use Excel::Writer::XLSX;
265
266           # Create a new workbook called simple.xls and add a worksheet
267           my $workbook  = Excel::Writer::XLSX->new( 'a_simple.xlsx' );
268           my $worksheet = $workbook->add_worksheet();
269
270           # The general syntax is write($row, $column, $token). Note that row and
271           # column are zero indexed
272           #
273
274           # Write some text
275           $worksheet->write( 0, 0, "Hi Excel!" );
276
277
278           # Write some numbers
279           $worksheet->write( 2, 0, 3 );          # Writes 3
280           $worksheet->write( 3, 0, 3.00000 );    # Writes 3
281           $worksheet->write( 4, 0, 3.00001 );    # Writes 3.00001
282           $worksheet->write( 5, 0, 3.14159 );    # TeX revision no.?
283
284
285           # Write some formulas
286           $worksheet->write( 7, 0, '=A3 + A6' );
287           $worksheet->write( 8, 0, '=IF(A5>3,"Yes", "No")' );
288
289
290           # Write a hyperlink
291           $worksheet->write( 10, 0, 'http://www.perl.com/' );
292
293           $workbook->close();
294
295           __END__
296
297       Download this example:
298       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/a_simple.pl>
299
300   Example: bug_report.pl
301       A template for submitting a bug report.
302
303       Run this program and read the output from the command line.
304
305           #!/usr/bin/perl -w
306
307           ###############################################################################
308           #
309           # A template for submitting a bug report.
310           #
311           # Run this program and read the output from the command line.
312           #
313           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
314           #
315
316
317           use strict;
318
319           print << 'HINTS_1';
320
321           REPORTING A BUG OR ASKING A QUESTION
322
323               Feel free to report bugs or ask questions. However, to save time
324               consider the following steps first:
325
326               Read the documentation:
327
328                   The Excel::Writer::XLSX documentation has been refined in
329                   response to user questions. Therefore, if you have a question it is
330                   possible that someone else has asked it before you and that it is
331                   already addressed in the documentation. Since there is a lot of
332                   documentation to get through you should at least read the table of
333                   contents and search for keywords that you are interested in.
334
335               Look at the example programs:
336
337                   There are over 80 example programs shipped with the standard
338                   Excel::Writer::XLSX distribution. Many of these were created
339                   in response to user questions. Try to identify an example program
340                   that corresponds to your query and adapt it to your needs.
341
342           HINTS_1
343           print "Press enter ..."; <STDIN>;
344
345           print << 'HINTS_2';
346
347               If you submit a bug report here are some pointers.
348
349               1.  Put "Excel::Writer::XLSX:" at the beginning of the subject line.
350                   This helps to filter genuine messages from spam.
351
352               2.  Describe the problems as clearly and as concisely as possible.
353
354               3.  Send a sample program. It is often easier to describe a problem in
355                   code than in written prose.
356
357               4.  The sample program should be as small as possible to demonstrate the
358                   problem. Don't copy and past large sections of your program. The
359                   program should also be self contained and working.
360
361               A sample bug report is generated below. If you use this format then it
362               will help to analyse your question and respond to it more quickly.
363
364               Please don't send patches without contacting the author first.
365
366
367           HINTS_2
368           print "Press enter ..."; <STDIN>;
369
370
371           print << 'EMAIL';
372
373           =======================================================================
374
375           To:      John McNamara <jmcnamara@cpan.org>
376           Subject: Excel::Writer::XLSX: Problem with something.
377
378           Hi John,
379
380           I am using Excel::Writer::XLSX and I have encountered a problem. I
381           want it to do SOMETHING but the module appears to do SOMETHING_ELSE.
382
383           Here is some code that demonstrates the problem.
384
385               #!/usr/bin/perl -w
386
387               use strict;
388               use Excel::Writer::XLSX;
389
390               my $workbook  = Excel::Writer::XLSX->new("reload.xls");
391               my $worksheet = $workbook->add_worksheet();
392
393               $worksheet->write(0, 0, "Hi Excel!");
394
395               $workbook->close();
396
397               __END__
398
399           My automatically generated system details are as follows:
400           EMAIL
401
402
403           print "\n    Perl version   : $]";
404           print "\n    OS name        : $^O";
405           print "\n    Module versions: (not all are required)\n";
406
407
408           my @modules = qw(
409                             Excel::Writer::XLSX
410                             Spreadsheet::WriteExcel
411                             Archive::Zip
412                             XML::Writer
413                             IO::File
414                             File::Temp
415                           );
416
417
418           for my $module (@modules) {
419               my $version;
420               eval "require $module";
421
422               if (not $@) {
423                   $version = $module->VERSION;
424                   $version = '(unknown)' if not defined $version;
425               }
426               else {
427                   $version = '(not installed)';
428               }
429
430               printf "%21s%-24s\t%s\n", "", $module, $version;
431           }
432
433
434           print << "BYE";
435           Yours etc.,
436
437           A. Person
438           --
439
440           BYE
441
442           __END__
443
444       Download this example:
445       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/bug_report.pl>
446
447   Example: demo.pl
448       A simple demo of some of the features of Excel::Writer::XLSX.
449
450       This program is used to create the project screenshot for Freshmeat:
451       <http://freshmeat.net/projects/writeexcel/>
452
453       Source code for this example:
454
455           #!/usr/bin/perl -w
456
457           #######################################################################
458           #
459           # A simple demo of some of the features of Excel::Writer::XLSX.
460           #
461           # This program is used to create the project screenshot for Freshmeat:
462           # L<http://freshmeat.net/projects/writeexcel/>
463           #
464           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
465           #
466
467           use strict;
468           use Excel::Writer::XLSX;
469
470           my $workbook   = Excel::Writer::XLSX->new( 'demo.xlsx' );
471           my $worksheet  = $workbook->add_worksheet( 'Demo' );
472           my $worksheet2 = $workbook->add_worksheet( 'Another sheet' );
473           my $worksheet3 = $workbook->add_worksheet( 'And another' );
474
475           my $bold = $workbook->add_format( bold => 1 );
476
477
478           #######################################################################
479           #
480           # Write a general heading
481           #
482           $worksheet->set_column( 'A:A', 36, $bold );
483           $worksheet->set_column( 'B:B', 20 );
484           $worksheet->set_row( 0, 40 );
485
486           my $heading = $workbook->add_format(
487               bold  => 1,
488               color => 'blue',
489               size  => 16,
490               merge => 1,
491               align => 'vcenter',
492           );
493
494           my @headings = ( 'Features of Excel::Writer::XLSX', '' );
495           $worksheet->write_row( 'A1', \@headings, $heading );
496
497
498           #######################################################################
499           #
500           # Some text examples
501           #
502           my $text_format = $workbook->add_format(
503               bold   => 1,
504               italic => 1,
505               color  => 'red',
506               size   => 18,
507               font   => 'Lucida Calligraphy'
508           );
509
510
511           $worksheet->write( 'A2', "Text" );
512           $worksheet->write( 'B2', "Hello Excel" );
513           $worksheet->write( 'A3', "Formatted text" );
514           $worksheet->write( 'B3', "Hello Excel", $text_format );
515           $worksheet->write( 'A4', "Unicode text" );
516           $worksheet->write( 'B4', "\x{0410} \x{0411} \x{0412} \x{0413} \x{0414}" );
517
518           #######################################################################
519           #
520           # Some numeric examples
521           #
522           my $num1_format = $workbook->add_format( num_format => '$#,##0.00' );
523           my $num2_format = $workbook->add_format( num_format => ' d mmmm yyy' );
524
525
526           $worksheet->write( 'A5', "Numbers" );
527           $worksheet->write( 'B5', 1234.56 );
528           $worksheet->write( 'A6', "Formatted numbers" );
529           $worksheet->write( 'B6', 1234.56, $num1_format );
530           $worksheet->write( 'A7', "Formatted numbers" );
531           $worksheet->write( 'B7', 37257, $num2_format );
532
533
534           #######################################################################
535           #
536           # Formulae
537           #
538           $worksheet->set_selection( 'B8' );
539           $worksheet->write( 'A8', 'Formulas and functions, "=SIN(PI()/4)"' );
540           $worksheet->write( 'B8', '=SIN(PI()/4)' );
541
542
543           #######################################################################
544           #
545           # Hyperlinks
546           #
547           $worksheet->write( 'A9', "Hyperlinks" );
548           $worksheet->write( 'B9', 'http://www.perl.com/' );
549
550
551           #######################################################################
552           #
553           # Images
554           #
555           $worksheet->write( 'A10', "Images" );
556           $worksheet->insert_image( 'B10', 'republic.png',
557                                            { x_offset => 16, y_offset => 8 } );
558
559
560           #######################################################################
561           #
562           # Misc
563           #
564           $worksheet->write( 'A18', "Page/printer setup" );
565           $worksheet->write( 'A19', "Multiple worksheets" );
566
567           $workbook->close();
568
569           __END__
570
571       Download this example:
572       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/demo.pl>
573
574   Example: formats.pl
575       Examples of formatting using the Excel::Writer::XLSX module.
576
577       This program demonstrates almost all possible formatting options. It is
578       worth running this program and viewing the output Excel file if you are
579       interested in the various formatting possibilities.
580
581       Source code for this example:
582
583           #!/usr/bin/perl -w
584
585           ###############################################################################
586           #
587           # Examples of formatting using the Excel::Writer::XLSX module.
588           #
589           # This program demonstrates almost all possible formatting options. It is worth
590           # running this program and viewing the output Excel file if you are interested
591           # in the various formatting possibilities.
592           #
593           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
594           #
595
596           use strict;
597           use Excel::Writer::XLSX;
598
599           my $workbook = Excel::Writer::XLSX->new( 'formats.xlsx' );
600
601           # Some common formats
602           my $center = $workbook->add_format( align => 'center' );
603           my $heading = $workbook->add_format( align => 'center', bold => 1 );
604
605           # The named colors
606           my %colors = (
607               0x08, 'black',
608               0x0C, 'blue',
609               0x10, 'brown',
610               0x0F, 'cyan',
611               0x17, 'gray',
612               0x11, 'green',
613               0x0B, 'lime',
614               0x0E, 'magenta',
615               0x12, 'navy',
616               0x35, 'orange',
617               0x21, 'pink',
618               0x14, 'purple',
619               0x0A, 'red',
620               0x16, 'silver',
621               0x09, 'white',
622               0x0D, 'yellow',
623
624           );
625
626           # Call these subroutines to demonstrate different formatting options
627           intro();
628           fonts();
629           named_colors();
630           standard_colors();
631           numeric_formats();
632           borders();
633           patterns();
634           alignment();
635           misc();
636
637           # Note: this is required
638           $workbook->close();
639
640
641           ######################################################################
642           #
643           # Intro.
644           #
645           sub intro {
646
647               my $worksheet = $workbook->add_worksheet( 'Introduction' );
648
649               $worksheet->set_column( 0, 0, 60 );
650
651               my $format = $workbook->add_format();
652               $format->set_bold();
653               $format->set_size( 14 );
654               $format->set_color( 'blue' );
655               $format->set_align( 'center' );
656
657               my $format2 = $workbook->add_format();
658               $format2->set_bold();
659               $format2->set_color( 'blue' );
660
661               my $format3 = $workbook->add_format(
662                   color     => 'blue',
663                   underline => 1,
664               );
665
666               $worksheet->write( 2, 0, 'This workbook demonstrates some of', $format );
667               $worksheet->write( 3, 0, 'the formatting options provided by', $format );
668               $worksheet->write( 4, 0, 'the Excel::Writer::XLSX module.',    $format );
669               $worksheet->write( 'A7', 'Sections:', $format2 );
670
671               $worksheet->write( 'A8', "internal:Fonts!A1", 'Fonts', $format3 );
672
673               $worksheet->write( 'A9', "internal:'Named colors'!A1",
674                   'Named colors', $format3 );
675
676               $worksheet->write(
677                   'A10',
678                   "internal:'Standard colors'!A1",
679                   'Standard colors', $format3
680               );
681
682               $worksheet->write(
683                   'A11',
684                   "internal:'Numeric formats'!A1",
685                   'Numeric formats', $format3
686               );
687
688               $worksheet->write( 'A12', "internal:Borders!A1", 'Borders', $format3 );
689               $worksheet->write( 'A13', "internal:Patterns!A1", 'Patterns', $format3 );
690               $worksheet->write( 'A14', "internal:Alignment!A1", 'Alignment', $format3 );
691               $worksheet->write( 'A15', "internal:Miscellaneous!A1", 'Miscellaneous',
692                   $format3 );
693
694           }
695
696
697           ######################################################################
698           #
699           # Demonstrate the named colors.
700           #
701           sub named_colors {
702
703               my $worksheet = $workbook->add_worksheet( 'Named colors' );
704
705               $worksheet->set_column( 0, 3, 15 );
706
707               $worksheet->write( 0, 0, "Index", $heading );
708               $worksheet->write( 0, 1, "Index", $heading );
709               $worksheet->write( 0, 2, "Name",  $heading );
710               $worksheet->write( 0, 3, "Color", $heading );
711
712               my $i = 1;
713
714               while ( my ( $index, $color ) = each %colors ) {
715                   my $format = $workbook->add_format(
716                       bg_color => $color,
717                       pattern  => 1,
718                       border   => 1
719                   );
720
721                   $worksheet->write( $i + 1, 0, $index, $center );
722                   $worksheet->write( $i + 1, 1, sprintf( "0x%02X", $index ), $center );
723                   $worksheet->write( $i + 1, 2, $color, $center );
724                   $worksheet->write( $i + 1, 3, '',     $format );
725                   $i++;
726               }
727           }
728
729
730           ######################################################################
731           #
732           # Demonstrate the standard Excel colors in the range 8..63.
733           #
734           sub standard_colors {
735
736               my $worksheet = $workbook->add_worksheet( 'Standard colors' );
737
738               $worksheet->set_column( 0, 3, 15 );
739
740               $worksheet->write( 0, 0, "Index", $heading );
741               $worksheet->write( 0, 1, "Index", $heading );
742               $worksheet->write( 0, 2, "Color", $heading );
743               $worksheet->write( 0, 3, "Name",  $heading );
744
745               for my $i ( 8 .. 63 ) {
746                   my $format = $workbook->add_format(
747                       bg_color => $i,
748                       pattern  => 1,
749                       border   => 1
750                   );
751
752                   $worksheet->write( ( $i - 7 ), 0, $i, $center );
753                   $worksheet->write( ( $i - 7 ), 1, sprintf( "0x%02X", $i ), $center );
754                   $worksheet->write( ( $i - 7 ), 2, '', $format );
755
756                   # Add the  color names
757                   if ( exists $colors{$i} ) {
758                       $worksheet->write( ( $i - 7 ), 3, $colors{$i}, $center );
759
760                   }
761               }
762           }
763
764
765           ######################################################################
766           #
767           # Demonstrate the standard numeric formats.
768           #
769           sub numeric_formats {
770
771               my $worksheet = $workbook->add_worksheet( 'Numeric formats' );
772
773               $worksheet->set_column( 0, 4, 15 );
774               $worksheet->set_column( 5, 5, 45 );
775
776               $worksheet->write( 0, 0, "Index",       $heading );
777               $worksheet->write( 0, 1, "Index",       $heading );
778               $worksheet->write( 0, 2, "Unformatted", $heading );
779               $worksheet->write( 0, 3, "Formatted",   $heading );
780               $worksheet->write( 0, 4, "Negative",    $heading );
781               $worksheet->write( 0, 5, "Format",      $heading );
782
783               #<<<
784               my @formats;
785               push @formats, [ 0x00, 1234.567,   0,         'General' ];
786               push @formats, [ 0x01, 1234.567,   0,         '0' ];
787               push @formats, [ 0x02, 1234.567,   0,         '0.00' ];
788               push @formats, [ 0x03, 1234.567,   0,         '#,##0' ];
789               push @formats, [ 0x04, 1234.567,   0,         '#,##0.00' ];
790               push @formats, [ 0x05, 1234.567,   -1234.567, '($#,##0_);($#,##0)' ];
791               push @formats, [ 0x06, 1234.567,   -1234.567, '($#,##0_);[Red]($#,##0)' ];
792               push @formats, [ 0x07, 1234.567,   -1234.567, '($#,##0.00_);($#,##0.00)' ];
793               push @formats, [ 0x08, 1234.567,   -1234.567, '($#,##0.00_);[Red]($#,##0.00)' ];
794               push @formats, [ 0x09, 0.567,      0,         '0%' ];
795               push @formats, [ 0x0a, 0.567,      0,         '0.00%' ];
796               push @formats, [ 0x0b, 1234.567,   0,         '0.00E+00' ];
797               push @formats, [ 0x0c, 0.75,       0,         '# ?/?' ];
798               push @formats, [ 0x0d, 0.3125,     0,         '# ??/??' ];
799               push @formats, [ 0x0e, 36892.521,  0,         'm/d/yy' ];
800               push @formats, [ 0x0f, 36892.521,  0,         'd-mmm-yy' ];
801               push @formats, [ 0x10, 36892.521,  0,         'd-mmm' ];
802               push @formats, [ 0x11, 36892.521,  0,         'mmm-yy' ];
803               push @formats, [ 0x12, 36892.521,  0,         'h:mm AM/PM' ];
804               push @formats, [ 0x13, 36892.521,  0,         'h:mm:ss AM/PM' ];
805               push @formats, [ 0x14, 36892.521,  0,         'h:mm' ];
806               push @formats, [ 0x15, 36892.521,  0,         'h:mm:ss' ];
807               push @formats, [ 0x16, 36892.521,  0,         'm/d/yy h:mm' ];
808               push @formats, [ 0x25, 1234.567,   -1234.567, '(#,##0_);(#,##0)' ];
809               push @formats, [ 0x26, 1234.567,   -1234.567, '(#,##0_);[Red](#,##0)' ];
810               push @formats, [ 0x27, 1234.567,   -1234.567, '(#,##0.00_);(#,##0.00)' ];
811               push @formats, [ 0x28, 1234.567,   -1234.567, '(#,##0.00_);[Red](#,##0.00)' ];
812               push @formats, [ 0x29, 1234.567,   -1234.567, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' ];
813               push @formats, [ 0x2a, 1234.567,   -1234.567, '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' ];
814               push @formats, [ 0x2b, 1234.567,   -1234.567, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' ];
815               push @formats, [ 0x2c, 1234.567,   -1234.567, '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' ];
816               push @formats, [ 0x2d, 36892.521,  0,         'mm:ss' ];
817               push @formats, [ 0x2e, 3.0153,     0,         '[h]:mm:ss' ];
818               push @formats, [ 0x2f, 36892.521,  0,         'mm:ss.0' ];
819               push @formats, [ 0x30, 1234.567,   0,         '##0.0E+0' ];
820               push @formats, [ 0x31, 1234.567,   0,         '@' ];
821               #>>>
822
823               my $i;
824               foreach my $format ( @formats ) {
825                   my $style = $workbook->add_format();
826                   $style->set_num_format( $format->[0] );
827
828                   $i++;
829                   $worksheet->write( $i, 0, $format->[0], $center );
830                   $worksheet->write( $i, 1, sprintf( "0x%02X", $format->[0] ), $center );
831                   $worksheet->write( $i, 2, $format->[1], $center );
832                   $worksheet->write( $i, 3, $format->[1], $style );
833
834                   if ( $format->[2] ) {
835                       $worksheet->write( $i, 4, $format->[2], $style );
836                   }
837
838                   $worksheet->write_string( $i, 5, $format->[3] );
839               }
840           }
841
842
843           ######################################################################
844           #
845           # Demonstrate the font options.
846           #
847           sub fonts {
848
849               my $worksheet = $workbook->add_worksheet( 'Fonts' );
850
851               $worksheet->set_column( 0, 0, 30 );
852               $worksheet->set_column( 1, 1, 10 );
853
854               $worksheet->write( 0, 0, "Font name", $heading );
855               $worksheet->write( 0, 1, "Font size", $heading );
856
857               my @fonts;
858               push @fonts, [ 10, 'Arial' ];
859               push @fonts, [ 12, 'Arial' ];
860               push @fonts, [ 14, 'Arial' ];
861               push @fonts, [ 12, 'Arial Black' ];
862               push @fonts, [ 12, 'Arial Narrow' ];
863               push @fonts, [ 12, 'Century Schoolbook' ];
864               push @fonts, [ 12, 'Courier' ];
865               push @fonts, [ 12, 'Courier New' ];
866               push @fonts, [ 12, 'Garamond' ];
867               push @fonts, [ 12, 'Impact' ];
868               push @fonts, [ 12, 'Lucida Handwriting' ];
869               push @fonts, [ 12, 'Times New Roman' ];
870               push @fonts, [ 12, 'Symbol' ];
871               push @fonts, [ 12, 'Wingdings' ];
872               push @fonts, [ 12, 'A font that doesn\'t exist' ];
873
874               my $i;
875               foreach my $font ( @fonts ) {
876                   my $format = $workbook->add_format();
877
878                   $format->set_size( $font->[0] );
879                   $format->set_font( $font->[1] );
880
881                   $i++;
882                   $worksheet->write( $i, 0, $font->[1], $format );
883                   $worksheet->write( $i, 1, $font->[0], $format );
884               }
885
886           }
887
888
889           ######################################################################
890           #
891           # Demonstrate the standard Excel border styles.
892           #
893           sub borders {
894
895               my $worksheet = $workbook->add_worksheet( 'Borders' );
896
897               $worksheet->set_column( 0, 4, 10 );
898               $worksheet->set_column( 5, 5, 40 );
899
900               $worksheet->write( 0, 0, "Index",                                $heading );
901               $worksheet->write( 0, 1, "Index",                                $heading );
902               $worksheet->write( 0, 3, "Style",                                $heading );
903               $worksheet->write( 0, 5, "The style is highlighted in red for ", $heading );
904               $worksheet->write( 1, 5, "emphasis, the default color is black.",
905                   $heading );
906
907               for my $i ( 0 .. 13 ) {
908                   my $format = $workbook->add_format();
909                   $format->set_border( $i );
910                   $format->set_border_color( 'red' );
911                   $format->set_align( 'center' );
912
913                   $worksheet->write( ( 2 * ( $i + 1 ) ), 0, $i, $center );
914                   $worksheet->write( ( 2 * ( $i + 1 ) ),
915                       1, sprintf( "0x%02X", $i ), $center );
916
917                   $worksheet->write( ( 2 * ( $i + 1 ) ), 3, "Border", $format );
918               }
919
920               $worksheet->write( 30, 0, "Diag type",              $heading );
921               $worksheet->write( 30, 1, "Index",                  $heading );
922               $worksheet->write( 30, 3, "Style",                  $heading );
923               $worksheet->write( 30, 5, "Diagonal Border styles", $heading );
924
925               for my $i ( 1 .. 3 ) {
926                   my $format = $workbook->add_format();
927                   $format->set_diag_type( $i );
928                   $format->set_diag_border( 1 );
929                   $format->set_diag_color( 'red' );
930                   $format->set_align( 'center' );
931
932                   $worksheet->write( ( 2 * ( $i + 15 ) ), 0, $i, $center );
933                   $worksheet->write( ( 2 * ( $i + 15 ) ),
934                       1, sprintf( "0x%02X", $i ), $center );
935
936                   $worksheet->write( ( 2 * ( $i + 15 ) ), 3, "Border", $format );
937               }
938           }
939
940
941           ######################################################################
942           #
943           # Demonstrate the standard Excel cell patterns.
944           #
945           sub patterns {
946
947               my $worksheet = $workbook->add_worksheet( 'Patterns' );
948
949               $worksheet->set_column( 0, 4, 10 );
950               $worksheet->set_column( 5, 5, 50 );
951
952               $worksheet->write( 0, 0, "Index",   $heading );
953               $worksheet->write( 0, 1, "Index",   $heading );
954               $worksheet->write( 0, 3, "Pattern", $heading );
955
956               $worksheet->write( 0, 5, "The background colour has been set to silver.",
957                   $heading );
958               $worksheet->write( 1, 5, "The foreground colour has been set to green.",
959                   $heading );
960
961               for my $i ( 0 .. 18 ) {
962                   my $format = $workbook->add_format();
963
964                   $format->set_pattern( $i );
965                   $format->set_bg_color( 'silver' );
966                   $format->set_fg_color( 'green' );
967                   $format->set_align( 'center' );
968
969                   $worksheet->write( ( 2 * ( $i + 1 ) ), 0, $i, $center );
970                   $worksheet->write( ( 2 * ( $i + 1 ) ),
971                       1, sprintf( "0x%02X", $i ), $center );
972
973                   $worksheet->write( ( 2 * ( $i + 1 ) ), 3, "Pattern", $format );
974
975                   if ( $i == 1 ) {
976                       $worksheet->write( ( 2 * ( $i + 1 ) ),
977                           5, "This is solid colour, the most useful pattern.", $heading );
978                   }
979               }
980           }
981
982
983           ######################################################################
984           #
985           # Demonstrate the standard Excel cell alignments.
986           #
987           sub alignment {
988
989               my $worksheet = $workbook->add_worksheet( 'Alignment' );
990
991               $worksheet->set_column( 0, 7, 12 );
992               $worksheet->set_row( 0, 40 );
993               $worksheet->set_selection( 7, 0 );
994
995               my $format01 = $workbook->add_format();
996               my $format02 = $workbook->add_format();
997               my $format03 = $workbook->add_format();
998               my $format04 = $workbook->add_format();
999               my $format05 = $workbook->add_format();
1000               my $format06 = $workbook->add_format();
1001               my $format07 = $workbook->add_format();
1002               my $format08 = $workbook->add_format();
1003               my $format09 = $workbook->add_format();
1004               my $format10 = $workbook->add_format();
1005               my $format11 = $workbook->add_format();
1006               my $format12 = $workbook->add_format();
1007               my $format13 = $workbook->add_format();
1008               my $format14 = $workbook->add_format();
1009               my $format15 = $workbook->add_format();
1010               my $format16 = $workbook->add_format();
1011               my $format17 = $workbook->add_format();
1012
1013               $format02->set_align( 'top' );
1014               $format03->set_align( 'bottom' );
1015               $format04->set_align( 'vcenter' );
1016               $format05->set_align( 'vjustify' );
1017               $format06->set_text_wrap();
1018
1019               $format07->set_align( 'left' );
1020               $format08->set_align( 'right' );
1021               $format09->set_align( 'center' );
1022               $format10->set_align( 'fill' );
1023               $format11->set_align( 'justify' );
1024               $format12->set_merge();
1025
1026               $format13->set_rotation( 45 );
1027               $format14->set_rotation( -45 );
1028               $format15->set_rotation( 270 );
1029
1030               $format16->set_shrink();
1031               $format17->set_indent( 1 );
1032
1033               $worksheet->write( 0, 0, 'Vertical',   $heading );
1034               $worksheet->write( 0, 1, 'top',        $format02 );
1035               $worksheet->write( 0, 2, 'bottom',     $format03 );
1036               $worksheet->write( 0, 3, 'vcenter',    $format04 );
1037               $worksheet->write( 0, 4, 'vjustify',   $format05 );
1038               $worksheet->write( 0, 5, "text\nwrap", $format06 );
1039
1040               $worksheet->write( 2, 0, 'Horizontal', $heading );
1041               $worksheet->write( 2, 1, 'left',       $format07 );
1042               $worksheet->write( 2, 2, 'right',      $format08 );
1043               $worksheet->write( 2, 3, 'center',     $format09 );
1044               $worksheet->write( 2, 4, 'fill',       $format10 );
1045               $worksheet->write( 2, 5, 'justify',    $format11 );
1046
1047               $worksheet->write( 3, 1, 'merge', $format12 );
1048               $worksheet->write( 3, 2, '',      $format12 );
1049
1050               $worksheet->write( 3, 3, 'Shrink ' x 3, $format16 );
1051               $worksheet->write( 3, 4, 'Indent',      $format17 );
1052
1053
1054               $worksheet->write( 5, 0, 'Rotation',   $heading );
1055               $worksheet->write( 5, 1, 'Rotate 45',  $format13 );
1056               $worksheet->write( 6, 1, 'Rotate -45', $format14 );
1057               $worksheet->write( 7, 1, 'Rotate 270', $format15 );
1058           }
1059
1060
1061           ######################################################################
1062           #
1063           # Demonstrate other miscellaneous features.
1064           #
1065           sub misc {
1066
1067               my $worksheet = $workbook->add_worksheet( 'Miscellaneous' );
1068
1069               $worksheet->set_column( 2, 2, 25 );
1070
1071               my $format01 = $workbook->add_format();
1072               my $format02 = $workbook->add_format();
1073               my $format03 = $workbook->add_format();
1074               my $format04 = $workbook->add_format();
1075               my $format05 = $workbook->add_format();
1076               my $format06 = $workbook->add_format();
1077               my $format07 = $workbook->add_format();
1078
1079               $format01->set_underline( 0x01 );
1080               $format02->set_underline( 0x02 );
1081               $format03->set_underline( 0x21 );
1082               $format04->set_underline( 0x22 );
1083               $format05->set_font_strikeout();
1084               $format06->set_font_outline();
1085               $format07->set_font_shadow();
1086
1087               $worksheet->write( 1,  2, 'Underline  0x01',          $format01 );
1088               $worksheet->write( 3,  2, 'Underline  0x02',          $format02 );
1089               $worksheet->write( 5,  2, 'Underline  0x21',          $format03 );
1090               $worksheet->write( 7,  2, 'Underline  0x22',          $format04 );
1091               $worksheet->write( 9,  2, 'Strikeout',                $format05 );
1092               $worksheet->write( 11, 2, 'Outline (Macintosh only)', $format06 );
1093               $worksheet->write( 13, 2, 'Shadow (Macintosh only)',  $format07 );
1094           }
1095
1096
1097           $workbook->close();
1098
1099           __END__
1100
1101       Download this example:
1102       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/formats.pl>
1103
1104   Example: regions.pl
1105       An example of how to use the Excel::Writer::XLSX module to write a
1106       basic Excel workbook with multiple worksheets.
1107
1108       Source code for this example:
1109
1110           #!/usr/bin/perl -w
1111
1112           ###############################################################################
1113           #
1114           # An example of how to use the Excel::Writer::XLSX module to write a basic
1115           # Excel workbook with multiple worksheets.
1116           #
1117           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
1118           #
1119
1120           use strict;
1121           use Excel::Writer::XLSX;
1122
1123           # Create a new Excel workbook
1124           my $workbook = Excel::Writer::XLSX->new( 'regions.xlsx' );
1125
1126           # Add some worksheets
1127           my $north = $workbook->add_worksheet( "North" );
1128           my $south = $workbook->add_worksheet( "South" );
1129           my $east  = $workbook->add_worksheet( "East" );
1130           my $west  = $workbook->add_worksheet( "West" );
1131
1132           # Add a Format
1133           my $format = $workbook->add_format();
1134           $format->set_bold();
1135           $format->set_color( 'blue' );
1136
1137           # Add a caption to each worksheet
1138           foreach my $worksheet ( $workbook->sheets() ) {
1139               $worksheet->write( 0, 0, "Sales", $format );
1140           }
1141
1142           # Write some data
1143           $north->write( 0, 1, 200000 );
1144           $south->write( 0, 1, 100000 );
1145           $east->write( 0, 1, 150000 );
1146           $west->write( 0, 1, 100000 );
1147
1148           # Set the active worksheet
1149           $south->activate();
1150
1151           # Set the width of the first column
1152           $south->set_column( 0, 0, 20 );
1153
1154           # Set the active cell
1155           $south->set_selection( 0, 1 );
1156
1157           $workbook->close();
1158
1159           __END__
1160
1161       Download this example:
1162       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/regions.pl>
1163
1164   Example: stats.pl
1165       A simple example of how to use functions with the Excel::Writer::XLSX
1166       module.
1167
1168       Source code for this example:
1169
1170           #!/usr/bin/perl -w
1171
1172           ###############################################################################
1173           #
1174           # A simple example of how to use functions with the Excel::Writer::XLSX
1175           # module.
1176           #
1177           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
1178           #
1179
1180           use strict;
1181           use Excel::Writer::XLSX;
1182
1183           # Create a new workbook and add a worksheet
1184           my $workbook  = Excel::Writer::XLSX->new( 'stats.xlsx' );
1185           my $worksheet = $workbook->add_worksheet( 'Test data' );
1186
1187           # Set the column width for columns 1
1188           $worksheet->set_column( 0, 0, 20 );
1189
1190
1191           # Create a format for the headings
1192           my $format = $workbook->add_format();
1193           $format->set_bold();
1194
1195
1196           # Write the sample data
1197           $worksheet->write( 0, 0, 'Sample', $format );
1198           $worksheet->write( 0, 1, 1 );
1199           $worksheet->write( 0, 2, 2 );
1200           $worksheet->write( 0, 3, 3 );
1201           $worksheet->write( 0, 4, 4 );
1202           $worksheet->write( 0, 5, 5 );
1203           $worksheet->write( 0, 6, 6 );
1204           $worksheet->write( 0, 7, 7 );
1205           $worksheet->write( 0, 8, 8 );
1206
1207           $worksheet->write( 1, 0, 'Length', $format );
1208           $worksheet->write( 1, 1, 25.4 );
1209           $worksheet->write( 1, 2, 25.4 );
1210           $worksheet->write( 1, 3, 24.8 );
1211           $worksheet->write( 1, 4, 25.0 );
1212           $worksheet->write( 1, 5, 25.3 );
1213           $worksheet->write( 1, 6, 24.9 );
1214           $worksheet->write( 1, 7, 25.2 );
1215           $worksheet->write( 1, 8, 24.8 );
1216
1217           # Write some statistical functions
1218           $worksheet->write( 4, 0, 'Count', $format );
1219           $worksheet->write( 4, 1, '=COUNT(B1:I1)' );
1220
1221           $worksheet->write( 5, 0, 'Sum', $format );
1222           $worksheet->write( 5, 1, '=SUM(B2:I2)' );
1223
1224           $worksheet->write( 6, 0, 'Average', $format );
1225           $worksheet->write( 6, 1, '=AVERAGE(B2:I2)' );
1226
1227           $worksheet->write( 7, 0, 'Min', $format );
1228           $worksheet->write( 7, 1, '=MIN(B2:I2)' );
1229
1230           $worksheet->write( 8, 0, 'Max', $format );
1231           $worksheet->write( 8, 1, '=MAX(B2:I2)' );
1232
1233           $worksheet->write( 9, 0, 'Standard Deviation', $format );
1234           $worksheet->write( 9, 1, '=STDEV(B2:I2)' );
1235
1236           $worksheet->write( 10, 0, 'Kurtosis', $format );
1237           $worksheet->write( 10, 1, '=KURT(B2:I2)' );
1238
1239           $workbook->close();
1240
1241           __END__
1242
1243       Download this example:
1244       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/stats.pl>
1245
1246   Example: autofit.pl
1247       An example of using simulated autofit to automatically adjust the width
1248       of worksheet columns based on the data in the cells.
1249
1250       Source code for this example:
1251
1252           #!/usr/bin/perl -w
1253
1254           #######################################################################
1255           #
1256           # An example of using simulated autofit to automatically adjust the width of
1257           # worksheet columns based on the data in the cells.
1258           #
1259           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
1260           #
1261
1262           use strict;
1263           use Excel::Writer::XLSX;
1264
1265           my $workbook  = Excel::Writer::XLSX->new( 'autofit.xlsx' );
1266           my $worksheet = $workbook->add_worksheet();
1267
1268           # Write some worksheet data to demonstrate autofitting.
1269           $worksheet->write( 0, 0, "Foo" );
1270           $worksheet->write( 1, 0, "Food" );
1271           $worksheet->write( 2, 0, "Foody" );
1272           $worksheet->write( 3, 0, "Froody" );
1273
1274           $worksheet->write( 0, 1, 12345 );
1275           $worksheet->write( 1, 1, 12345678 );
1276           $worksheet->write( 2, 1, 12345 );
1277
1278           $worksheet->write( 0, 2, "Some longer text" );
1279
1280           $worksheet->write( 0, 3, "http://ww.google.com" );
1281           $worksheet->write( 1, 3, "https://github.com" );
1282
1283           # Autofit the worksheet.
1284           $worksheet->autofit();
1285
1286           $workbook->close();
1287
1288           __END__
1289
1290       Download this example:
1291       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/autofit.pl>
1292
1293   Example: autofilter.pl
1294       An example of how to create autofilters with Excel::Writer::XLSX.
1295
1296       An autofilter is a way of adding drop down lists to the headers of a 2D
1297       range of worksheet data. This allows users to filter the data based on
1298       simple criteria so that some data is shown and some is hidden.
1299
1300       Source code for this example:
1301
1302           #!/usr/bin/perl
1303
1304           ###############################################################################
1305           #
1306           # An example of how to create autofilters with Excel::Writer::XLSX.
1307           #
1308           # An autofilter is a way of adding drop down lists to the headers of a 2D range
1309           # of worksheet data. This allows users to filter the data based on
1310           # simple criteria so that some data is shown and some is hidden.
1311           #
1312           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
1313           #
1314
1315           use strict;
1316           use warnings;
1317           use Excel::Writer::XLSX;
1318
1319           my $workbook = Excel::Writer::XLSX->new( 'autofilter.xlsx' );
1320
1321           my $worksheet1 = $workbook->add_worksheet();
1322           my $worksheet2 = $workbook->add_worksheet();
1323           my $worksheet3 = $workbook->add_worksheet();
1324           my $worksheet4 = $workbook->add_worksheet();
1325           my $worksheet5 = $workbook->add_worksheet();
1326           my $worksheet6 = $workbook->add_worksheet();
1327           my $worksheet7 = $workbook->add_worksheet();
1328
1329           my $bold = $workbook->add_format( bold => 1 );
1330
1331
1332           # Extract the data embedded at the end of this file.
1333           my @headings = split ' ', <DATA>;
1334           my @data;
1335           push @data, [split] while <DATA>;
1336
1337
1338           # Set up several sheets with the same data.
1339           for my $worksheet ( $workbook->sheets() ) {
1340               $worksheet->set_column( 'A:D', 12 );
1341               $worksheet->set_row( 0, 20, $bold );
1342               $worksheet->write( 'A1', \@headings );
1343           }
1344
1345
1346           ###############################################################################
1347           #
1348           # Example 1. Autofilter without conditions.
1349           #
1350
1351           $worksheet1->autofilter( 'A1:D51' );
1352           $worksheet1->write( 'A2', [ [@data] ] );
1353
1354
1355           ###############################################################################
1356           #
1357           #
1358           # Example 2. Autofilter with a filter condition in the first column.
1359           #
1360
1361           # The range in this example is the same as above but in row-column notation.
1362           $worksheet2->autofilter( 0, 0, 50, 3 );
1363
1364           # The placeholder "Region" in the filter is ignored and can be any string
1365           # that adds clarity to the expression.
1366           #
1367           $worksheet2->filter_column( 0, 'Region eq East' );
1368
1369           #
1370           # Hide the rows that don't match the filter criteria.
1371           #
1372           my $row = 1;
1373
1374           for my $row_data ( @data ) {
1375               my $region = $row_data->[0];
1376
1377               if ( $region eq 'East' ) {
1378
1379                   # Row is visible.
1380               }
1381               else {
1382
1383                   # Hide row.
1384                   $worksheet2->set_row( $row, undef, undef, 1 );
1385               }
1386
1387               $worksheet2->write( $row++, 0, $row_data );
1388           }
1389
1390
1391           ###############################################################################
1392           #
1393           #
1394           # Example 3. Autofilter with a dual filter condition in one of the columns.
1395           #
1396
1397           $worksheet3->autofilter( 'A1:D51' );
1398
1399           $worksheet3->filter_column( 'A', 'x eq East or x eq South' );
1400
1401           #
1402           # Hide the rows that don't match the filter criteria.
1403           #
1404           $row = 1;
1405
1406           for my $row_data ( @data ) {
1407               my $region = $row_data->[0];
1408
1409               if ( $region eq 'East' or $region eq 'South' ) {
1410
1411                   # Row is visible.
1412               }
1413               else {
1414
1415                   # Hide row.
1416                   $worksheet3->set_row( $row, undef, undef, 1 );
1417               }
1418
1419               $worksheet3->write( $row++, 0, $row_data );
1420           }
1421
1422
1423           ###############################################################################
1424           #
1425           #
1426           # Example 4. Autofilter with filter conditions in two columns.
1427           #
1428
1429           $worksheet4->autofilter( 'A1:D51' );
1430
1431           $worksheet4->filter_column( 'A', 'x eq East' );
1432           $worksheet4->filter_column( 'C', 'x > 3000 and x < 8000' );
1433
1434           #
1435           # Hide the rows that don't match the filter criteria.
1436           #
1437           $row = 1;
1438
1439           for my $row_data ( @data ) {
1440               my $region = $row_data->[0];
1441               my $volume = $row_data->[2];
1442
1443               if (    $region eq 'East'
1444                   and $volume > 3000
1445                   and $volume < 8000 )
1446               {
1447
1448                   # Row is visible.
1449               }
1450               else {
1451
1452                   # Hide row.
1453                   $worksheet4->set_row( $row, undef, undef, 1 );
1454               }
1455
1456               $worksheet4->write( $row++, 0, $row_data );
1457           }
1458
1459
1460           ###############################################################################
1461           #
1462           #
1463           # Example 5. Autofilter with filter list condition in one of the columns.
1464           #
1465
1466           $worksheet5->autofilter( 'A1:D51' );
1467
1468           $worksheet5->filter_column_list( 'A', ('East', 'North', 'South') );
1469
1470           #
1471           # Hide the rows that don't match the filter criteria.
1472           #
1473           $row = 1;
1474
1475           for my $row_data ( @data ) {
1476               my $region = $row_data->[0];
1477
1478               if ( $region eq 'East' or $region eq 'North'  or $region eq 'South' ) {
1479
1480                   # Row is visible.
1481               }
1482               else {
1483
1484                   # Hide row.
1485                   $worksheet5->set_row( $row, undef, undef, 1 );
1486               }
1487
1488               $worksheet5->write( $row++, 0, $row_data );
1489           }
1490
1491
1492           ###############################################################################
1493           #
1494           #
1495           # Example 6. Autofilter with filter for blanks.
1496           #
1497
1498           # Create a blank cell in our test data.
1499           $data[5]->[0] = '';
1500
1501
1502           $worksheet6->autofilter( 'A1:D51' );
1503           $worksheet6->filter_column( 'A', 'x == Blanks' );
1504
1505           #
1506           # Hide the rows that don't match the filter criteria.
1507           #
1508           $row = 1;
1509
1510           for my $row_data ( @data ) {
1511               my $region = $row_data->[0];
1512
1513               if ( $region eq '' ) {
1514
1515                   # Row is visible.
1516               }
1517               else {
1518
1519                   # Hide row.
1520                   $worksheet6->set_row( $row, undef, undef, 1 );
1521               }
1522
1523               $worksheet6->write( $row++, 0, $row_data );
1524           }
1525
1526
1527           ###############################################################################
1528           #
1529           #
1530           # Example 7. Autofilter with filter for non-blanks.
1531           #
1532
1533
1534           $worksheet7->autofilter( 'A1:D51' );
1535           $worksheet7->filter_column( 'A', 'x == NonBlanks' );
1536
1537           #
1538           # Hide the rows that don't match the filter criteria.
1539           #
1540           $row = 1;
1541
1542           for my $row_data ( @data ) {
1543               my $region = $row_data->[0];
1544
1545               if ( $region ne '' ) {
1546
1547                   # Row is visible.
1548               }
1549               else {
1550
1551                   # Hide row.
1552                   $worksheet7->set_row( $row, undef, undef, 1 );
1553               }
1554
1555               $worksheet7->write( $row++, 0, $row_data );
1556           }
1557
1558           $workbook->close();
1559
1560           __DATA__
1561           Region    Item      Volume    Month
1562           East      Apple     9000      July
1563           East      Apple     5000      July
1564           South     Orange    9000      September
1565           North     Apple     2000      November
1566           West      Apple     9000      November
1567           South     Pear      7000      October
1568           North     Pear      9000      August
1569           West      Orange    1000      December
1570           West      Grape     1000      November
1571           South     Pear      10000     April
1572           West      Grape     6000      January
1573           South     Orange    3000      May
1574           North     Apple     3000      December
1575           South     Apple     7000      February
1576           West      Grape     1000      December
1577           East      Grape     8000      February
1578           South     Grape     10000     June
1579           West      Pear      7000      December
1580           South     Apple     2000      October
1581           East      Grape     7000      December
1582           North     Grape     6000      April
1583           East      Pear      8000      February
1584           North     Apple     7000      August
1585           North     Orange    7000      July
1586           North     Apple     6000      June
1587           South     Grape     8000      September
1588           West      Apple     3000      October
1589           South     Orange    10000     November
1590           West      Grape     4000      July
1591           North     Orange    5000      August
1592           East      Orange    1000      November
1593           East      Orange    4000      October
1594           North     Grape     5000      August
1595           East      Apple     1000      December
1596           South     Apple     10000     March
1597           East      Grape     7000      October
1598           West      Grape     1000      September
1599           East      Grape     10000     October
1600           South     Orange    8000      March
1601           North     Apple     4000      July
1602           South     Orange    5000      July
1603           West      Apple     4000      June
1604           East      Apple     5000      April
1605           North     Pear      3000      August
1606           East      Grape     9000      November
1607           North     Orange    8000      October
1608           East      Apple     10000     June
1609           South     Pear      1000      December
1610           North     Grape     10000     July
1611           East      Grape     6000      February
1612
1613       Download this example:
1614       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/autofilter.pl>
1615
1616   Example: array_formula.pl
1617       Example of how to use the Excel::Writer::XLSX module to write simple
1618       array formulas.
1619
1620       Source code for this example:
1621
1622           #!/usr/bin/perl
1623
1624           #######################################################################
1625           #
1626           # Example of how to use the Excel::Writer::XLSX module to write simple
1627           # array formulas.
1628           #
1629           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
1630           #
1631
1632           use strict;
1633           use warnings;
1634           use Excel::Writer::XLSX;
1635
1636           # Create a new workbook and add a worksheet
1637           my $workbook  = Excel::Writer::XLSX->new( 'array_formula.xlsx' );
1638           my $worksheet = $workbook->add_worksheet();
1639
1640           # Write some test data.
1641           $worksheet->write( 'B1', [ [ 500, 10 ], [ 300, 15 ] ] );
1642           $worksheet->write( 'B5', [ [ 1, 2, 3 ], [ 20234, 21003, 10000 ] ] );
1643
1644           # Write an array formula that returns a single value
1645           $worksheet->write( 'A1', '{=SUM(B1:C1*B2:C2)}' );
1646
1647           # Same as above but more verbose.
1648           $worksheet->write_array_formula( 'A2:A2', '{=SUM(B1:C1*B2:C2)}' );
1649
1650           # Write an array formula that returns a range of values
1651           $worksheet->write_array_formula( 'A5:A7', '{=TREND(C5:C7,B5:B7)}' );
1652
1653           $workbook->close();
1654
1655           __END__
1656
1657       Download this example:
1658       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/array_formula.pl>
1659
1660   Example: cgi.pl
1661       Example of how to use the Excel::Writer::XLSX module to send an Excel
1662       file to a browser in a CGI program.
1663
1664       On Windows the hash-bang line should be something like:
1665
1666           #!C:\Perl\bin\perl.exe
1667
1668       The "Content-Disposition" line will cause a prompt to be generated to
1669       save the file. If you want to stream the file to the browser instead,
1670       comment out that line as shown below.
1671
1672           #!/usr/bin/perl
1673
1674           ###############################################################################
1675           #
1676           # Example of how to use the Excel::Writer::XLSX module to send an Excel
1677           # file to a browser in a CGI program.
1678           #
1679           # On Windows the hash-bang line should be something like:
1680           #
1681           #     #!C:\Perl\bin\perl.exe
1682           #
1683           # The "Content-Disposition" line will cause a prompt to be generated to save
1684           # the file. If you want to stream the file to the browser instead, comment out
1685           # that line as shown below.
1686           #
1687           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
1688           #
1689
1690           use strict;
1691           use warnings;
1692           use Excel::Writer::XLSX;
1693
1694           # Set the filename and send the content type
1695           my $filename = "cgitest.xlsx";
1696
1697           print "Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n";
1698
1699           # The Content-Disposition will generate a prompt to save the file. If you want
1700           # to stream the file to the browser, comment out the following line.
1701           print "Content-Disposition: attachment; filename=$filename\n";
1702           print "\n";
1703
1704           # Redirect the output to STDOUT. Binmode the filehandle in case it is needed.
1705           binmode STDOUT;
1706
1707           my $workbook  = Excel::Writer::XLSX->new( \*STDOUT );
1708           my $worksheet = $workbook->add_worksheet();
1709
1710
1711           # Set the column width for column 1
1712           $worksheet->set_column( 0, 0, 20 );
1713
1714
1715           # Create a format
1716           my $format = $workbook->add_format();
1717           $format->set_bold();
1718           $format->set_size( 15 );
1719           $format->set_color( 'blue' );
1720
1721
1722           # Write to the workbook
1723           $worksheet->write( 0, 0, "Hi Excel!", $format );
1724
1725           $workbook->close();
1726
1727           __END__
1728
1729       Download this example:
1730       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/cgi.pl>
1731
1732   Example: chart_area.pl
1733       A demo of an Area chart in Excel::Writer::XLSX.
1734
1735       Source code for this example:
1736
1737           #!/usr/bin/perl
1738
1739           #######################################################################
1740           #
1741           # A demo of an Area chart in Excel::Writer::XLSX.
1742           #
1743           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
1744           #
1745
1746           use strict;
1747           use warnings;
1748           use Excel::Writer::XLSX;
1749
1750           my $workbook  = Excel::Writer::XLSX->new( 'chart_area.xlsx' );
1751           my $worksheet = $workbook->add_worksheet();
1752           my $bold      = $workbook->add_format( bold => 1 );
1753
1754           # Add the worksheet data that the charts will refer to.
1755           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
1756           my $data = [
1757               [ 2,  3,  4,  5,  6,  7 ],
1758               [ 40, 40, 50, 30, 25, 50 ],
1759               [ 30, 25, 30, 10, 5,  10 ],
1760
1761           ];
1762
1763           $worksheet->write( 'A1', $headings, $bold );
1764           $worksheet->write( 'A2', $data );
1765
1766           # Create a new chart object. In this case an embedded chart.
1767           my $chart1 = $workbook->add_chart( type => 'area', embedded => 1 );
1768
1769           # Configure the first series.
1770           $chart1->add_series(
1771               name       => '=Sheet1!$B$1',
1772               categories => '=Sheet1!$A$2:$A$7',
1773               values     => '=Sheet1!$B$2:$B$7',
1774           );
1775
1776           # Configure second series. Note alternative use of array ref to define
1777           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
1778           $chart1->add_series(
1779               name       => '=Sheet1!$C$1',
1780               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1781               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1782           );
1783
1784           # Add a chart title and some axis labels.
1785           $chart1->set_title ( name => 'Results of sample analysis' );
1786           $chart1->set_x_axis( name => 'Test number' );
1787           $chart1->set_y_axis( name => 'Sample length (mm)' );
1788
1789           # Set an Excel chart style. Blue colors with white outline and shadow.
1790           $chart1->set_style( 11 );
1791
1792           # Insert the chart into the worksheet (with an offset).
1793           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
1794
1795
1796           #
1797           # Create a stacked chart sub-type
1798           #
1799           my $chart2 = $workbook->add_chart(
1800               type     => 'area',
1801               embedded => 1,
1802               subtype  => 'stacked'
1803           );
1804
1805           # Configure the first series.
1806           $chart2->add_series(
1807               name       => '=Sheet1!$B$1',
1808               categories => '=Sheet1!$A$2:$A$7',
1809               values     => '=Sheet1!$B$2:$B$7',
1810           );
1811
1812           # Configure second series.
1813           $chart2->add_series(
1814               name       => '=Sheet1!$C$1',
1815               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1816               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1817           );
1818
1819           # Add a chart title and some axis labels.
1820           $chart2->set_title ( name => 'Stacked Chart' );
1821           $chart2->set_x_axis( name => 'Test number' );
1822           $chart2->set_y_axis( name => 'Sample length (mm)' );
1823
1824           # Set an Excel chart style. Blue colors with white outline and shadow.
1825           $chart2->set_style( 12 );
1826
1827           # Insert the chart into the worksheet (with an offset).
1828           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
1829
1830
1831           #
1832           # Create a percent stacked chart sub-type
1833           #
1834           my $chart3 = $workbook->add_chart(
1835               type     => 'area',
1836               embedded => 1,
1837               subtype  => 'percent_stacked'
1838           );
1839
1840           # Configure the first series.
1841           $chart3->add_series(
1842               name       => '=Sheet1!$B$1',
1843               categories => '=Sheet1!$A$2:$A$7',
1844               values     => '=Sheet1!$B$2:$B$7',
1845           );
1846
1847           # Configure second series.
1848           $chart3->add_series(
1849               name       => '=Sheet1!$C$1',
1850               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1851               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1852           );
1853
1854           # Add a chart title and some axis labels.
1855           $chart3->set_title ( name => 'Percent Stacked Chart' );
1856           $chart3->set_x_axis( name => 'Test number' );
1857           $chart3->set_y_axis( name => 'Sample length (mm)' );
1858
1859           # Set an Excel chart style. Blue colors with white outline and shadow.
1860           $chart3->set_style( 13 );
1861
1862           # Insert the chart into the worksheet (with an offset).
1863           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
1864
1865           $workbook->close();
1866
1867           __END__
1868
1869       Download this example:
1870       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_area.pl>
1871
1872   Example: chart_bar.pl
1873       A demo of an Bar chart in Excel::Writer::XLSX.
1874
1875       Source code for this example:
1876
1877           #!/usr/bin/perl
1878
1879           #######################################################################
1880           #
1881           # A demo of an Bar chart in Excel::Writer::XLSX.
1882           #
1883           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
1884           #
1885
1886           use strict;
1887           use warnings;
1888           use Excel::Writer::XLSX;
1889
1890           my $workbook  = Excel::Writer::XLSX->new( 'chart_bar.xlsx' );
1891           my $worksheet = $workbook->add_worksheet();
1892           my $bold      = $workbook->add_format( bold => 1 );
1893
1894           # Add the worksheet data that the charts will refer to.
1895           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
1896           my $data = [
1897               [ 2,  3,  4,  5,  6,  7 ],
1898               [ 10, 40, 50, 20, 10, 50 ],
1899               [ 30, 60, 70, 50, 40, 30 ],
1900
1901           ];
1902
1903           $worksheet->write( 'A1', $headings, $bold );
1904           $worksheet->write( 'A2', $data );
1905
1906           # Create a new chart object. In this case an embedded chart.
1907           my $chart1 = $workbook->add_chart( type => 'bar', embedded => 1 );
1908
1909           # Configure the first series.
1910           $chart1->add_series(
1911               name       => '=Sheet1!$B$1',
1912               categories => '=Sheet1!$A$2:$A$7',
1913               values     => '=Sheet1!$B$2:$B$7',
1914           );
1915
1916           # Configure second series. Note alternative use of array ref to define
1917           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
1918           $chart1->add_series(
1919               name       => '=Sheet1!$C$1',
1920               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1921               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1922           );
1923
1924           # Add a chart title and some axis labels.
1925           $chart1->set_title ( name => 'Results of sample analysis' );
1926           $chart1->set_x_axis( name => 'Test number' );
1927           $chart1->set_y_axis( name => 'Sample length (mm)' );
1928
1929           # Set an Excel chart style. Blue colors with white outline and shadow.
1930           $chart1->set_style( 11 );
1931
1932           # Insert the chart into the worksheet (with an offset).
1933           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
1934
1935
1936           #
1937           # Create a stacked chart sub-type
1938           #
1939           my $chart2 = $workbook->add_chart(
1940               type     => 'bar',
1941               embedded => 1,
1942               subtype  => 'stacked'
1943           );
1944
1945           # Configure the first series.
1946           $chart2->add_series(
1947               name       => '=Sheet1!$B$1',
1948               categories => '=Sheet1!$A$2:$A$7',
1949               values     => '=Sheet1!$B$2:$B$7',
1950           );
1951
1952           # Configure second series.
1953           $chart2->add_series(
1954               name       => '=Sheet1!$C$1',
1955               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1956               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1957           );
1958
1959           # Add a chart title and some axis labels.
1960           $chart2->set_title ( name => 'Stacked Chart' );
1961           $chart2->set_x_axis( name => 'Test number' );
1962           $chart2->set_y_axis( name => 'Sample length (mm)' );
1963
1964           # Set an Excel chart style. Blue colors with white outline and shadow.
1965           $chart2->set_style( 12 );
1966
1967           # Insert the chart into the worksheet (with an offset).
1968           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
1969
1970
1971           #
1972           # Create a percent stacked chart sub-type
1973           #
1974           my $chart3 = $workbook->add_chart(
1975               type     => 'bar',
1976               embedded => 1,
1977               subtype  => 'percent_stacked'
1978           );
1979
1980           # Configure the first series.
1981           $chart3->add_series(
1982               name       => '=Sheet1!$B$1',
1983               categories => '=Sheet1!$A$2:$A$7',
1984               values     => '=Sheet1!$B$2:$B$7',
1985           );
1986
1987           # Configure second series.
1988           $chart3->add_series(
1989               name       => '=Sheet1!$C$1',
1990               categories => [ 'Sheet1', 1, 6, 0, 0 ],
1991               values     => [ 'Sheet1', 1, 6, 2, 2 ],
1992           );
1993
1994           # Add a chart title and some axis labels.
1995           $chart3->set_title ( name => 'Percent Stacked Chart' );
1996           $chart3->set_x_axis( name => 'Test number' );
1997           $chart3->set_y_axis( name => 'Sample length (mm)' );
1998
1999           # Set an Excel chart style. Blue colors with white outline and shadow.
2000           $chart3->set_style( 13 );
2001
2002           # Insert the chart into the worksheet (with an offset).
2003           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
2004
2005           $workbook->close();
2006
2007           __END__
2008
2009       Download this example:
2010       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_bar.pl>
2011
2012   Example: chart_column.pl
2013       A demo of a Column chart in Excel::Writer::XLSX.
2014
2015       Source code for this example:
2016
2017           #!/usr/bin/perl
2018
2019           #######################################################################
2020           #
2021           # A demo of a Column chart in Excel::Writer::XLSX.
2022           #
2023           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
2024           #
2025
2026           use strict;
2027           use warnings;
2028           use Excel::Writer::XLSX;
2029
2030           my $workbook  = Excel::Writer::XLSX->new( 'chart_column.xlsx' );
2031           my $worksheet = $workbook->add_worksheet();
2032           my $bold      = $workbook->add_format( bold => 1 );
2033
2034           # Add the worksheet data that the charts will refer to.
2035           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2036           my $data = [
2037               [ 2,  3,  4,  5,  6,  7 ],
2038               [ 10, 40, 50, 20, 10, 50 ],
2039               [ 30, 60, 70, 50, 40, 30 ],
2040
2041           ];
2042
2043           $worksheet->write( 'A1', $headings, $bold );
2044           $worksheet->write( 'A2', $data );
2045
2046           # Create a new chart object. In this case an embedded chart.
2047           my $chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
2048
2049           # Configure the first series.
2050           $chart1->add_series(
2051               name       => '=Sheet1!$B$1',
2052               categories => '=Sheet1!$A$2:$A$7',
2053               values     => '=Sheet1!$B$2:$B$7',
2054           );
2055
2056           # Configure second series. Note alternative use of array ref to define
2057           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2058           $chart1->add_series(
2059               name       => '=Sheet1!$C$1',
2060               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2061               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2062           );
2063
2064           # Add a chart title and some axis labels.
2065           $chart1->set_title ( name => 'Results of sample analysis' );
2066           $chart1->set_x_axis( name => 'Test number' );
2067           $chart1->set_y_axis( name => 'Sample length (mm)' );
2068
2069           # Set an Excel chart style. Blue colors with white outline and shadow.
2070           $chart1->set_style( 11 );
2071
2072           # Insert the chart into the worksheet (with an offset).
2073           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
2074
2075
2076           #
2077           # Create a stacked chart sub-type
2078           #
2079           my $chart2 = $workbook->add_chart(
2080               type     => 'column',
2081               embedded => 1,
2082               subtype  => 'stacked'
2083           );
2084
2085           # Configure the first series.
2086           $chart2->add_series(
2087               name       => '=Sheet1!$B$1',
2088               categories => '=Sheet1!$A$2:$A$7',
2089               values     => '=Sheet1!$B$2:$B$7',
2090           );
2091
2092           # Configure second series.
2093           $chart2->add_series(
2094               name       => '=Sheet1!$C$1',
2095               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2096               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2097           );
2098
2099           # Add a chart title and some axis labels.
2100           $chart2->set_title ( name => 'Stacked Chart' );
2101           $chart2->set_x_axis( name => 'Test number' );
2102           $chart2->set_y_axis( name => 'Sample length (mm)' );
2103
2104           # Set an Excel chart style. Blue colors with white outline and shadow.
2105           $chart2->set_style( 12 );
2106
2107           # Insert the chart into the worksheet (with an offset).
2108           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
2109
2110
2111           #
2112           # Create a percent stacked chart sub-type
2113           #
2114           my $chart3 = $workbook->add_chart(
2115               type     => 'column',
2116               embedded => 1,
2117               subtype  => 'percent_stacked'
2118           );
2119
2120           # Configure the first series.
2121           $chart3->add_series(
2122               name       => '=Sheet1!$B$1',
2123               categories => '=Sheet1!$A$2:$A$7',
2124               values     => '=Sheet1!$B$2:$B$7',
2125           );
2126
2127           # Configure second series.
2128           $chart3->add_series(
2129               name       => '=Sheet1!$C$1',
2130               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2131               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2132           );
2133
2134           # Add a chart title and some axis labels.
2135           $chart3->set_title ( name => 'Percent Stacked Chart' );
2136           $chart3->set_x_axis( name => 'Test number' );
2137           $chart3->set_y_axis( name => 'Sample length (mm)' );
2138
2139           # Set an Excel chart style. Blue colors with white outline and shadow.
2140           $chart3->set_style( 13 );
2141
2142           # Insert the chart into the worksheet (with an offset).
2143           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
2144
2145           $workbook->close();
2146
2147           __END__
2148
2149       Download this example:
2150       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_column.pl>
2151
2152   Example: chart_line.pl
2153       A demo of a Line chart in Excel::Writer::XLSX.
2154
2155       Source code for this example:
2156
2157           #!/usr/bin/perl
2158
2159           #######################################################################
2160           #
2161           # A demo of a Line chart in Excel::Writer::XLSX.
2162           #
2163           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
2164           #
2165
2166           use strict;
2167           use warnings;
2168           use Excel::Writer::XLSX;
2169
2170           my $workbook  = Excel::Writer::XLSX->new( 'chart_line.xlsx' );
2171           my $worksheet = $workbook->add_worksheet();
2172           my $bold      = $workbook->add_format( bold => 1 );
2173
2174           # Add the worksheet data that the charts will refer to.
2175           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2176           my $data = [
2177               [ 2, 3, 4, 5, 6, 7 ],
2178               [ 10, 40, 50, 20, 10, 50 ],
2179               [ 30, 60, 70, 50, 40, 30 ],
2180
2181           ];
2182
2183           $worksheet->write( 'A1', $headings, $bold );
2184           $worksheet->write( 'A2', $data );
2185
2186           # Create a new chart object. In this case an embedded chart.
2187           my $chart = $workbook->add_chart( type => 'line', embedded => 1 );
2188
2189           # Configure the first series.
2190           $chart->add_series(
2191               name       => '=Sheet1!$B$1',
2192               categories => '=Sheet1!$A$2:$A$7',
2193               values     => '=Sheet1!$B$2:$B$7',
2194           );
2195
2196           # Configure second series. Note alternative use of array ref to define
2197           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2198           $chart->add_series(
2199               name       => '=Sheet1!$C$1',
2200               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2201               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2202           );
2203
2204           # Add a chart title and some axis labels.
2205           $chart->set_title ( name => 'Results of sample analysis' );
2206           $chart->set_x_axis( name => 'Test number' );
2207           $chart->set_y_axis( name => 'Sample length (mm)' );
2208
2209           # Set an Excel chart style. Colors with white outline and shadow.
2210           $chart->set_style( 10 );
2211
2212           # Insert the chart into the worksheet (with an offset).
2213           $worksheet->insert_chart( 'D2', $chart, { x_offset => 25, y_offset => 10 } );
2214
2215
2216           #
2217           # Create a stacked chart sub-type
2218           #
2219           my $chart2 = $workbook->add_chart(
2220               type     => 'line',
2221               embedded => 1,
2222               subtype  => 'stacked'
2223           );
2224
2225           # Configure the first series.
2226           $chart2->add_series(
2227               name       => '=Sheet1!$B$1',
2228               categories => '=Sheet1!$A$2:$A$7',
2229               values     => '=Sheet1!$B$2:$B$7',
2230           );
2231
2232           # Configure second series.
2233           $chart2->add_series(
2234               name       => '=Sheet1!$C$1',
2235               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2236               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2237           );
2238
2239           # Add a chart title and some axis labels.
2240           $chart2->set_title ( name => 'Stacked Chart' );
2241           $chart2->set_x_axis( name => 'Test number' );
2242           $chart2->set_y_axis( name => 'Sample length (mm)' );
2243
2244           # Set an Excel chart style. Blue colors with white outline and shadow.
2245           $chart2->set_style( 12 );
2246
2247           # Insert the chart into the worksheet (with an offset).
2248           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
2249
2250
2251           #
2252           # Create a percent stacked chart sub-type
2253           #
2254           my $chart3 = $workbook->add_chart(
2255               type     => 'line',
2256               embedded => 1,
2257               subtype  => 'percent_stacked'
2258           );
2259
2260           # Configure the first series.
2261           $chart3->add_series(
2262               name       => '=Sheet1!$B$1',
2263               categories => '=Sheet1!$A$2:$A$7',
2264               values     => '=Sheet1!$B$2:$B$7',
2265           );
2266
2267           # Configure second series.
2268           $chart3->add_series(
2269               name       => '=Sheet1!$C$1',
2270               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2271               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2272           );
2273
2274           # Add a chart title and some axis labels.
2275           $chart3->set_title ( name => 'Percent Stacked Chart' );
2276           $chart3->set_x_axis( name => 'Test number' );
2277           $chart3->set_y_axis( name => 'Sample length (mm)' );
2278
2279           # Set an Excel chart style. Blue colors with white outline and shadow.
2280           $chart3->set_style( 13 );
2281
2282           # Insert the chart into the worksheet (with an offset).
2283           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
2284
2285           $workbook->close();
2286
2287           __END__
2288
2289       Download this example:
2290       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_line.pl>
2291
2292   Example: chart_pie.pl
2293       A demo of a Pie chart in Excel::Writer::XLSX.
2294
2295       The demo also shows how to set segment colours. It is possible to
2296       define chart colors for most types of Excel::Writer::XLSX charts via
2297       the add_series() method. However, Pie and Doughtnut charts are a
2298       special case since each segment is represented as a point so it is
2299       necessary to assign formatting to each point in the series.
2300
2301       Source code for this example:
2302
2303           #!/usr/bin/perl
2304
2305           #######################################################################
2306           #
2307           # A demo of a Pie chart in Excel::Writer::XLSX.
2308           #
2309           # The demo also shows how to set segment colours. It is possible to define
2310           # chart colors for most types of Excel::Writer::XLSX charts via the
2311           # add_series() method. However, Pie and Doughtnut charts are a special case
2312           # since each segment is represented as a point so it is necessary to assign
2313           # formatting to each point in the series.
2314           #
2315           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
2316           #
2317
2318           use strict;
2319           use warnings;
2320           use Excel::Writer::XLSX;
2321
2322           my $workbook  = Excel::Writer::XLSX->new( 'chart_pie.xlsx' );
2323           my $worksheet = $workbook->add_worksheet();
2324           my $bold      = $workbook->add_format( bold => 1 );
2325
2326           # Add the worksheet data that the charts will refer to.
2327           my $headings = [ 'Category', 'Values' ];
2328           my $data = [
2329               [ 'Apple', 'Cherry', 'Pecan' ],
2330               [ 60,       30,       10     ],
2331           ];
2332
2333           $worksheet->write( 'A1', $headings, $bold );
2334           $worksheet->write( 'A2', $data );
2335
2336           # Create a new chart object. In this case an embedded chart.
2337           my $chart1 = $workbook->add_chart( type => 'pie', embedded => 1 );
2338
2339           # Configure the series. Note the use of the array ref to define ranges:
2340           # [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2341           # See below for an alternative syntax.
2342           $chart1->add_series(
2343               name       => 'Pie sales data',
2344               categories => [ 'Sheet1', 1, 3, 0, 0 ],
2345               values     => [ 'Sheet1', 1, 3, 1, 1 ],
2346           );
2347
2348           # Add a title.
2349           $chart1->set_title( name => 'Popular Pie Types' );
2350
2351           # Set an Excel chart style. Colors with white outline and shadow.
2352           $chart1->set_style( 10 );
2353
2354           # Insert the chart into the worksheet (with an offset).
2355           $worksheet->insert_chart( 'C2', $chart1, { x_offset => 25, y_offset => 10 } );
2356
2357
2358           #
2359           # Create a Pie chart with user defined segment colors.
2360           #
2361
2362           # Create an example Pie chart like above.
2363           my $chart2 = $workbook->add_chart( type => 'pie', embedded => 1 );
2364
2365           # Configure the series and add user defined segment colours.
2366           $chart2->add_series(
2367               name       => 'Pie sales data',
2368               categories => '=Sheet1!$A$2:$A$4',
2369               values     => '=Sheet1!$B$2:$B$4',
2370               points     => [
2371                   { fill => { color => '#5ABA10' } },
2372                   { fill => { color => '#FE110E' } },
2373                   { fill => { color => '#CA5C05' } },
2374               ],
2375           );
2376
2377           # Add a title.
2378           $chart2->set_title( name => 'Pie Chart with user defined colors' );
2379
2380
2381           # Insert the chart into the worksheet (with an offset).
2382           $worksheet->insert_chart( 'C18', $chart2, { x_offset => 25, y_offset => 10 } );
2383
2384
2385           #
2386           # Create a Pie chart with rotation of the segments.
2387           #
2388
2389           # Create an example Pie chart like above.
2390           my $chart3 = $workbook->add_chart( type => 'pie', embedded => 1 );
2391
2392           # Configure the series.
2393           $chart3->add_series(
2394               name       => 'Pie sales data',
2395               categories => '=Sheet1!$A$2:$A$4',
2396               values     => '=Sheet1!$B$2:$B$4',
2397           );
2398
2399           # Add a title.
2400           $chart3->set_title( name => 'Pie Chart with segment rotation' );
2401
2402           # Change the angle/rotation of the first segment.
2403           $chart3->set_rotation(90);
2404
2405           # Insert the chart into the worksheet (with an offset).
2406           $worksheet->insert_chart( 'C34', $chart3, { x_offset => 25, y_offset => 10 } );
2407
2408           $workbook->close();
2409
2410           __END__
2411
2412       Download this example:
2413       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_pie.pl>
2414
2415   Example: chart_doughnut.pl
2416       A demo of a Doughnut chart in Excel::Writer::XLSX.
2417
2418       The demo also shows how to set segment colours. It is possible to
2419       define chart colors for most types of Excel::Writer::XLSX charts via
2420       the add_series() method. However, Pie and Doughtnut charts are a
2421       special case since each segment is represented as a point so it is
2422       necessary to assign formatting to each point in the series.
2423
2424       Source code for this example:
2425
2426           #!/usr/bin/perl
2427
2428           #######################################################################
2429           #
2430           # A demo of a Doughnut chart in Excel::Writer::XLSX.
2431           #
2432           # The demo also shows how to set segment colours. It is possible to define
2433           # chart colors for most types of Excel::Writer::XLSX charts via the
2434           # add_series() method. However, Pie and Doughtnut charts are a special case
2435           # since each segment is represented as a point so it is necessary to assign
2436           # formatting to each point in the series.
2437           #
2438           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
2439           #
2440
2441           use strict;
2442           use warnings;
2443           use Excel::Writer::XLSX;
2444
2445           my $workbook  = Excel::Writer::XLSX->new( 'chart_doughnut.xlsx' );
2446           my $worksheet = $workbook->add_worksheet();
2447           my $bold      = $workbook->add_format( bold => 1 );
2448
2449           # Add the worksheet data that the charts will refer to.
2450           my $headings = [ 'Category', 'Values' ];
2451           my $data = [
2452               [ 'Glazed', 'Chocolate', 'Cream' ],
2453               [ 50,       35,          15      ],
2454           ];
2455
2456           $worksheet->write( 'A1', $headings, $bold );
2457           $worksheet->write( 'A2', $data );
2458
2459           # Create a new chart object. In this case an embedded chart.
2460           my $chart1 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2461
2462           # Configure the series. Note the use of the array ref to define ranges:
2463           # [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2464           # See below for an alternative syntax.
2465           $chart1->add_series(
2466               name       => 'Doughnut sales data',
2467               categories => [ 'Sheet1', 1, 3, 0, 0 ],
2468               values     => [ 'Sheet1', 1, 3, 1, 1 ],
2469           );
2470
2471           # Add a title.
2472           $chart1->set_title( name => 'Popular Doughnut Types' );
2473
2474           # Set an Excel chart style. Colors with white outline and shadow.
2475           $chart1->set_style( 10 );
2476
2477           # Insert the chart into the worksheet (with an offset).
2478           $worksheet->insert_chart( 'C2', $chart1, { x_offset => 25, y_offset => 10 } );
2479
2480
2481           #
2482           # Create a Doughnut chart with user defined segment colors.
2483           #
2484
2485           # Create an example Doughnut chart like above.
2486           my $chart2 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2487
2488           # Configure the series and add user defined segment colours.
2489           $chart2->add_series(
2490               name       => 'Doughnut sales data',
2491               categories => '=Sheet1!$A$2:$A$4',
2492               values     => '=Sheet1!$B$2:$B$4',
2493               points     => [
2494                   { fill => { color => '#FA58D0' } },
2495                   { fill => { color => '#61210B' } },
2496                   { fill => { color => '#F5F6CE' } },
2497               ],
2498           );
2499
2500           # Add a title.
2501           $chart2->set_title( name => 'Doughnut Chart with user defined colors' );
2502
2503
2504           # Insert the chart into the worksheet (with an offset).
2505           $worksheet->insert_chart( 'C18', $chart2, { x_offset => 25, y_offset => 10 } );
2506
2507
2508           #
2509           # Create a Doughnut chart with rotation of the segments.
2510           #
2511
2512           # Create an example Doughnut chart like above.
2513           my $chart3 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2514
2515           # Configure the series.
2516           $chart3->add_series(
2517               name       => 'Doughnut sales data',
2518               categories => '=Sheet1!$A$2:$A$4',
2519               values     => '=Sheet1!$B$2:$B$4',
2520           );
2521
2522           # Add a title.
2523           $chart3->set_title( name => 'Doughnut Chart with segment rotation' );
2524
2525           # Change the angle/rotation of the first segment.
2526           $chart3->set_rotation(90);
2527
2528           # Insert the chart into the worksheet (with an offset).
2529           $worksheet->insert_chart( 'C34', $chart3, { x_offset => 25, y_offset => 10 } );
2530
2531
2532           #
2533           # Create a Doughnut chart with user defined hole size.
2534           #
2535
2536           # Create an example Doughnut chart like above.
2537           my $chart4 = $workbook->add_chart( type => 'doughnut', embedded => 1 );
2538
2539           # Configure the series.
2540           $chart4->add_series(
2541               name       => 'Doughnut sales data',
2542               categories => '=Sheet1!$A$2:$A$4',
2543               values     => '=Sheet1!$B$2:$B$4',
2544           );
2545
2546           # Add a title.
2547           $chart4->set_title( name => 'Doughnut Chart with user defined hole size' );
2548
2549           # Change the hole size.
2550           $chart4->set_hole_size(33);
2551
2552           # Insert the chart into the worksheet (with an offset).
2553           $worksheet->insert_chart( 'C50', $chart4, { x_offset => 25, y_offset => 10 } );
2554
2555           $workbook->close();
2556
2557           __END__
2558
2559       Download this example:
2560       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_doughnut.pl>
2561
2562   Example: chart_radar.pl
2563       A demo of an Radar chart in Excel::Writer::XLSX.
2564
2565       Source code for this example:
2566
2567           #!/usr/bin/perl
2568
2569           #######################################################################
2570           #
2571           # A demo of an Radar chart in Excel::Writer::XLSX.
2572           #
2573           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
2574           #
2575
2576           use strict;
2577           use warnings;
2578           use Excel::Writer::XLSX;
2579
2580           my $workbook  = Excel::Writer::XLSX->new( 'chart_radar.xlsx' );
2581           my $worksheet = $workbook->add_worksheet();
2582           my $bold      = $workbook->add_format( bold => 1 );
2583
2584           # Add the worksheet data that the charts will refer to.
2585           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2586           my $data = [
2587               [ 2,  3,  4,  5,  6,  7 ],
2588               [ 30, 60, 70, 50, 40, 30 ],
2589               [ 25, 40, 50, 30, 50, 40 ],
2590
2591           ];
2592
2593           $worksheet->write( 'A1', $headings, $bold );
2594           $worksheet->write( 'A2', $data );
2595
2596           # Create a new chart object. In this case an embedded chart.
2597           my $chart1 = $workbook->add_chart( type => 'radar', embedded => 1 );
2598
2599           # Configure the first series.
2600           $chart1->add_series(
2601               name       => '=Sheet1!$B$1',
2602               categories => '=Sheet1!$A$2:$A$7',
2603               values     => '=Sheet1!$B$2:$B$7',
2604           );
2605
2606           # Configure second series. Note alternative use of array ref to define
2607           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2608           $chart1->add_series(
2609               name       => '=Sheet1!$C$1',
2610               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2611               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2612           );
2613
2614           # Add a chart title.
2615           $chart1->set_title ( name => 'Results of sample analysis' );
2616
2617           # Set an Excel chart style. Blue colors with white outline and shadow.
2618           $chart1->set_style( 11 );
2619
2620           # Insert the chart into the worksheet (with an offset).
2621           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
2622
2623
2624           #
2625           # Create a with_markers chart sub-type
2626           #
2627           my $chart2 = $workbook->add_chart(
2628               type     => 'radar',
2629               embedded => 1,
2630               subtype  => 'with_markers'
2631           );
2632
2633           # Configure the first series.
2634           $chart2->add_series(
2635               name       => '=Sheet1!$B$1',
2636               categories => '=Sheet1!$A$2:$A$7',
2637               values     => '=Sheet1!$B$2:$B$7',
2638           );
2639
2640           # Configure second series.
2641           $chart2->add_series(
2642               name       => '=Sheet1!$C$1',
2643               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2644               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2645           );
2646
2647           # Add a chart title.
2648           $chart2->set_title ( name => 'Stacked Chart' );
2649
2650           # Set an Excel chart style. Blue colors with white outline and shadow.
2651           $chart2->set_style( 12 );
2652
2653           # Insert the chart into the worksheet (with an offset).
2654           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
2655
2656
2657           #
2658           # Create a filled chart sub-type
2659           #
2660           my $chart3 = $workbook->add_chart(
2661               type     => 'radar',
2662               embedded => 1,
2663               subtype  => 'filled'
2664           );
2665
2666           # Configure the first series.
2667           $chart3->add_series(
2668               name       => '=Sheet1!$B$1',
2669               categories => '=Sheet1!$A$2:$A$7',
2670               values     => '=Sheet1!$B$2:$B$7',
2671           );
2672
2673           # Configure second series.
2674           $chart3->add_series(
2675               name       => '=Sheet1!$C$1',
2676               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2677               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2678           );
2679
2680           # Add a chart title.
2681           $chart3->set_title ( name => 'Percent Stacked Chart' );
2682
2683           # Set an Excel chart style. Blue colors with white outline and shadow.
2684           $chart3->set_style( 13 );
2685
2686           # Insert the chart into the worksheet (with an offset).
2687           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
2688
2689           $workbook->close();
2690
2691           __END__
2692
2693       Download this example:
2694       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_radar.pl>
2695
2696   Example: chart_scatter.pl
2697       A demo of a Scatter chart in Excel::Writer::XLSX. Other subtypes are
2698       also supported such as markers_only (the default),
2699       straight_with_markers, straight, smooth_with_markers and smooth. See
2700       the main documentation for more details.
2701
2702       Source code for this example:
2703
2704           #!/usr/bin/perl
2705
2706           #######################################################################
2707           #
2708           # A demo of a Scatter chart in Excel::Writer::XLSX. Other subtypes are
2709           # also supported such as markers_only (the default), straight_with_markers,
2710           # straight, smooth_with_markers and smooth. See the main documentation for
2711           # more details.
2712           #
2713           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
2714           #
2715
2716           use strict;
2717           use warnings;
2718           use Excel::Writer::XLSX;
2719
2720           my $workbook  = Excel::Writer::XLSX->new( 'chart_scatter.xlsx' );
2721           my $worksheet = $workbook->add_worksheet();
2722           my $bold      = $workbook->add_format( bold => 1 );
2723
2724           # Add the worksheet data that the charts will refer to.
2725           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
2726           my $data = [
2727               [ 2,  3,  4,  5,  6,  7 ],
2728               [ 10, 40, 50, 20, 10, 50 ],
2729               [ 30, 60, 70, 50, 40, 30 ],
2730
2731           ];
2732
2733           $worksheet->write( 'A1', $headings, $bold );
2734           $worksheet->write( 'A2', $data );
2735
2736           # Create a new chart object. In this case an embedded chart.
2737           my $chart1 = $workbook->add_chart( type => 'scatter', embedded => 1 );
2738
2739           # Configure the first series.
2740           $chart1->add_series(
2741               name       => '=Sheet1!$B$1',
2742               categories => '=Sheet1!$A$2:$A$7',
2743               values     => '=Sheet1!$B$2:$B$7',
2744           );
2745
2746           # Configure second series. Note alternative use of array ref to define
2747           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
2748           $chart1->add_series(
2749               name       => '=Sheet1!$C$1',
2750               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2751               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2752           );
2753
2754           # Add a chart title and some axis labels.
2755           $chart1->set_title ( name => 'Results of sample analysis' );
2756           $chart1->set_x_axis( name => 'Test number' );
2757           $chart1->set_y_axis( name => 'Sample length (mm)' );
2758
2759           # Set an Excel chart style. Blue colors with white outline and shadow.
2760           $chart1->set_style( 11 );
2761
2762           # Insert the chart into the worksheet (with an offset).
2763           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
2764
2765
2766           #
2767           # Create a scatter chart sub-type with straight lines and markers.
2768           #
2769           my $chart2 = $workbook->add_chart(
2770               type     => 'scatter',
2771               embedded => 1,
2772               subtype  => 'straight_with_markers'
2773           );
2774
2775           # Configure the first series.
2776           $chart2->add_series(
2777               name       => '=Sheet1!$B$1',
2778               categories => '=Sheet1!$A$2:$A$7',
2779               values     => '=Sheet1!$B$2:$B$7',
2780           );
2781
2782           # Configure second series.
2783           $chart2->add_series(
2784               name       => '=Sheet1!$C$1',
2785               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2786               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2787           );
2788
2789           # Add a chart title and some axis labels.
2790           $chart2->set_title ( name => 'Straight line with markers' );
2791           $chart2->set_x_axis( name => 'Test number' );
2792           $chart2->set_y_axis( name => 'Sample length (mm)' );
2793
2794           # Set an Excel chart style. Blue colors with white outline and shadow.
2795           $chart2->set_style( 12 );
2796
2797           # Insert the chart into the worksheet (with an offset).
2798           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
2799
2800
2801           #
2802           # Create a scatter chart sub-type with straight lines and no markers.
2803           #
2804           my $chart3 = $workbook->add_chart(
2805               type     => 'scatter',
2806               embedded => 1,
2807               subtype  => 'straight'
2808           );
2809
2810           # Configure the first series.
2811           $chart3->add_series(
2812               name       => '=Sheet1!$B$1',
2813               categories => '=Sheet1!$A$2:$A$7',
2814               values     => '=Sheet1!$B$2:$B$7',
2815           );
2816
2817           # Configure second series.
2818           $chart3->add_series(
2819               name       => '=Sheet1!$C$1',
2820               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2821               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2822           );
2823
2824           # Add a chart title and some axis labels.
2825           $chart3->set_title ( name => 'Straight line' );
2826           $chart3->set_x_axis( name => 'Test number' );
2827           $chart3->set_y_axis( name => 'Sample length (mm)' );
2828
2829           # Set an Excel chart style. Blue colors with white outline and shadow.
2830           $chart3->set_style( 13 );
2831
2832           # Insert the chart into the worksheet (with an offset).
2833           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
2834
2835
2836           #
2837           # Create a scatter chart sub-type with smooth lines and markers.
2838           #
2839           my $chart4 = $workbook->add_chart(
2840               type     => 'scatter',
2841               embedded => 1,
2842               subtype  => 'smooth_with_markers'
2843           );
2844
2845           # Configure the first series.
2846           $chart4->add_series(
2847               name       => '=Sheet1!$B$1',
2848               categories => '=Sheet1!$A$2:$A$7',
2849               values     => '=Sheet1!$B$2:$B$7',
2850           );
2851
2852           # Configure second series.
2853           $chart4->add_series(
2854               name       => '=Sheet1!$C$1',
2855               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2856               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2857           );
2858
2859           # Add a chart title and some axis labels.
2860           $chart4->set_title ( name => 'Smooth line with markers' );
2861           $chart4->set_x_axis( name => 'Test number' );
2862           $chart4->set_y_axis( name => 'Sample length (mm)' );
2863
2864           # Set an Excel chart style. Blue colors with white outline and shadow.
2865           $chart4->set_style( 14 );
2866
2867           # Insert the chart into the worksheet (with an offset).
2868           $worksheet->insert_chart( 'D51', $chart4, { x_offset => 25, y_offset => 10 } );
2869
2870
2871           #
2872           # Create a scatter chart sub-type with smooth lines and no markers.
2873           #
2874           my $chart5 = $workbook->add_chart(
2875               type     => 'scatter',
2876               embedded => 1,
2877               subtype  => 'smooth'
2878           );
2879
2880           # Configure the first series.
2881           $chart5->add_series(
2882               name       => '=Sheet1!$B$1',
2883               categories => '=Sheet1!$A$2:$A$7',
2884               values     => '=Sheet1!$B$2:$B$7',
2885           );
2886
2887           # Configure second series.
2888           $chart5->add_series(
2889               name       => '=Sheet1!$C$1',
2890               categories => [ 'Sheet1', 1, 6, 0, 0 ],
2891               values     => [ 'Sheet1', 1, 6, 2, 2 ],
2892           );
2893
2894           # Add a chart title and some axis labels.
2895           $chart5->set_title ( name => 'Smooth line' );
2896           $chart5->set_x_axis( name => 'Test number' );
2897           $chart5->set_y_axis( name => 'Sample length (mm)' );
2898
2899           # Set an Excel chart style. Blue colors with white outline and shadow.
2900           $chart5->set_style( 15 );
2901
2902           # Insert the chart into the worksheet (with an offset).
2903           $worksheet->insert_chart( 'D66', $chart5, { x_offset => 25, y_offset => 10 } );
2904
2905
2906           $workbook->close();
2907
2908           __END__
2909
2910       Download this example:
2911       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_scatter.pl>
2912
2913   Example: chart_secondary_axis.pl
2914       A demo of a Line chart with a secondary axis in Excel::Writer::XLSX.
2915
2916       Source code for this example:
2917
2918           #!/usr/bin/perl
2919
2920           #######################################################################
2921           #
2922           # A demo of a Line chart with a secondary axis in Excel::Writer::XLSX.
2923           #
2924           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
2925           #
2926
2927           use strict;
2928           use warnings;
2929           use Excel::Writer::XLSX;
2930
2931           my $workbook  = Excel::Writer::XLSX->new( 'chart_secondary_axis.xlsx' );
2932           my $worksheet = $workbook->add_worksheet();
2933           my $bold      = $workbook->add_format( bold => 1 );
2934
2935           # Add the worksheet data that the charts will refer to.
2936           my $headings = [ 'Aliens', 'Humans', ];
2937           my $data = [
2938               [ 2,  3,  4,  5,  6,  7 ],
2939               [ 10, 40, 50, 20, 10, 50 ],
2940
2941           ];
2942
2943
2944           $worksheet->write( 'A1', $headings, $bold );
2945           $worksheet->write( 'A2', $data );
2946
2947           # Create a new chart object. In this case an embedded chart.
2948           my $chart = $workbook->add_chart( type => 'line', embedded => 1 );
2949
2950           # Configure a series with a secondary axis
2951           $chart->add_series(
2952               name    => '=Sheet1!$A$1',
2953               values  => '=Sheet1!$A$2:$A$7',
2954               y2_axis => 1,
2955           );
2956
2957           $chart->add_series(
2958               name   => '=Sheet1!$B$1',
2959               values => '=Sheet1!$B$2:$B$7',
2960           );
2961
2962           $chart->set_legend( position => 'right' );
2963
2964           # Add a chart title and some axis labels.
2965           $chart->set_title( name => 'Survey results' );
2966           $chart->set_x_axis( name => 'Days', );
2967           $chart->set_y_axis( name => 'Population', major_gridlines => { visible => 0 } );
2968           $chart->set_y2_axis( name => 'Laser wounds' );
2969
2970           # Insert the chart into the worksheet (with an offset).
2971           $worksheet->insert_chart( 'D2', $chart, { x_offset => 25, y_offset => 10 } );
2972
2973           $workbook->close();
2974
2975           __END__
2976
2977       Download this example:
2978       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_secondary_axis.pl>
2979
2980   Example: chart_combined.pl
2981       An example of a Combined chart in Excel::Writer::XLSX.
2982
2983           #!/usr/bin/perl
2984
2985           #######################################################################
2986           #
2987           # An example of a Combined chart in Excel::Writer::XLSX.
2988           #
2989           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
2990           #
2991
2992           use strict;
2993           use warnings;
2994           use Excel::Writer::XLSX;
2995
2996           my $workbook  = Excel::Writer::XLSX->new( 'chart_combined.xlsx' );
2997           my $worksheet = $workbook->add_worksheet();
2998           my $bold      = $workbook->add_format( bold => 1 );
2999
3000           # Add the worksheet data that the charts will refer to.
3001           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
3002           my $data = [
3003               [ 2,  3,  4,  5,  6,  7 ],
3004               [ 10, 40, 50, 20, 10, 50 ],
3005               [ 30, 60, 70, 50, 40, 30 ],
3006
3007           ];
3008
3009           $worksheet->write( 'A1', $headings, $bold );
3010           $worksheet->write( 'A2', $data );
3011
3012           #
3013           # In the first example we will create a combined column and line chart.
3014           # They will share the same X and Y axes.
3015           #
3016
3017           # Create a new column chart. This will use this as the primary chart.
3018           my $column_chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
3019
3020           # Configure the data series for the primary chart.
3021           $column_chart1->add_series(
3022               name       => '=Sheet1!$B$1',
3023               categories => '=Sheet1!$A$2:$A$7',
3024               values     => '=Sheet1!$B$2:$B$7',
3025           );
3026
3027           # Create a new column chart. This will use this as the secondary chart.
3028           my $line_chart1 = $workbook->add_chart( type => 'line', embedded => 1 );
3029
3030           # Configure the data series for the secondary chart.
3031           $line_chart1->add_series(
3032               name       => '=Sheet1!$C$1',
3033               categories => '=Sheet1!$A$2:$A$7',
3034               values     => '=Sheet1!$C$2:$C$7',
3035           );
3036
3037           # Combine the charts.
3038           $column_chart1->combine( $line_chart1 );
3039
3040           # Add a chart title and some axis labels. Note, this is done via the
3041           # primary chart.
3042           $column_chart1->set_title( name => 'Combined chart - same Y axis' );
3043           $column_chart1->set_x_axis( name => 'Test number' );
3044           $column_chart1->set_y_axis( name => 'Sample length (mm)' );
3045
3046
3047           # Insert the chart into the worksheet
3048           $worksheet->insert_chart( 'E2', $column_chart1 );
3049
3050           #
3051           # In the second example we will create a similar combined column and line
3052           # chart except that the secondary chart will have a secondary Y axis.
3053           #
3054
3055           # Create a new column chart. This will use this as the primary chart.
3056           my $column_chart2 = $workbook->add_chart( type => 'column', embedded => 1 );
3057
3058           # Configure the data series for the primary chart.
3059           $column_chart2->add_series(
3060               name       => '=Sheet1!$B$1',
3061               categories => '=Sheet1!$A$2:$A$7',
3062               values     => '=Sheet1!$B$2:$B$7',
3063           );
3064
3065           # Create a new column chart. This will use this as the secondary chart.
3066           my $line_chart2 = $workbook->add_chart( type => 'line', embedded => 1 );
3067
3068           # Configure the data series for the secondary chart. We also set a
3069           # secondary Y axis via (y2_axis). This is the only difference between
3070           # this and the first example, apart from the axis label below.
3071           $line_chart2->add_series(
3072               name       => '=Sheet1!$C$1',
3073               categories => '=Sheet1!$A$2:$A$7',
3074               values     => '=Sheet1!$C$2:$C$7',
3075               y2_axis    => 1,
3076           );
3077
3078           # Combine the charts.
3079           $column_chart2->combine( $line_chart2 );
3080
3081           # Add a chart title and some axis labels.
3082           $column_chart2->set_title(  name => 'Combine chart - secondary Y axis' );
3083           $column_chart2->set_x_axis( name => 'Test number' );
3084           $column_chart2->set_y_axis( name => 'Sample length (mm)' );
3085
3086           # Note: the y2 properites are on the secondary chart.
3087           $line_chart2->set_y2_axis( name => 'Target length (mm)' );
3088
3089
3090           # Insert the chart into the worksheet
3091           $worksheet->insert_chart( 'E18', $column_chart2 );
3092
3093           $workbook->close();
3094
3095           __END__
3096
3097       Download this example:
3098       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_combined.pl>
3099
3100   Example: chart_pareto.pl
3101       A demo of a Pareto chart in Excel::Writer::XLSX.
3102
3103           #!/usr/bin/perl
3104
3105           #######################################################################
3106           #
3107           # A demo of a Pareto chart in Excel::Writer::XLSX.
3108           #
3109           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
3110           #
3111
3112           use strict;
3113           use warnings;
3114           use Excel::Writer::XLSX;
3115
3116           my $workbook  = Excel::Writer::XLSX->new( 'chart_pareto.xlsx' );
3117           my $worksheet = $workbook->add_worksheet();
3118
3119           # Formats used in the workbook.
3120           my $bold           = $workbook->add_format( bold       => 1 );
3121           my $percent_format = $workbook->add_format( num_format => '0.0%' );
3122
3123
3124           # Widen the columns for visibility.
3125           $worksheet->set_column( 'A:A', 15 );
3126           $worksheet->set_column( 'B:C', 10 );
3127
3128           # Add the worksheet data that the charts will refer to.
3129           my $headings = [ 'Reason', 'Number', 'Percentage' ];
3130
3131           my $reasons = [
3132               'Traffic',   'Child care', 'Public Transport', 'Weather',
3133               'Overslept', 'Emergency',
3134           ];
3135
3136           my $numbers  = [ 60,   40,    20,  15,  10,    5 ];
3137           my $percents = [ 0.44, 0.667, 0.8, 0.9, 0.967, 1 ];
3138
3139           $worksheet->write_row( 'A1', $headings, $bold );
3140           $worksheet->write_col( 'A2', $reasons );
3141           $worksheet->write_col( 'B2', $numbers );
3142           $worksheet->write_col( 'C2', $percents, $percent_format );
3143
3144
3145           # Create a new column chart. This will be the primary chart.
3146           my $column_chart = $workbook->add_chart( type => 'column', embedded => 1 );
3147
3148           # Add a series.
3149           $column_chart->add_series(
3150               categories => '=Sheet1!$A$2:$A$7',
3151               values     => '=Sheet1!$B$2:$B$7',
3152           );
3153
3154           # Add a chart title.
3155           $column_chart->set_title( name => 'Reasons for lateness' );
3156
3157           # Turn off the chart legend.
3158           $column_chart->set_legend( position => 'none' );
3159
3160           # Set the title and scale of the Y axes. Note, the secondary axis is set from
3161           # the primary chart.
3162           $column_chart->set_y_axis(
3163               name => 'Respondents (number)',
3164               min  => 0,
3165               max  => 120
3166           );
3167           $column_chart->set_y2_axis( max => 1 );
3168
3169           # Create a new line chart. This will be the secondary chart.
3170           my $line_chart = $workbook->add_chart( type => 'line', embedded => 1 );
3171
3172           # Add a series, on the secondary axis.
3173           $line_chart->add_series(
3174               categories => '=Sheet1!$A$2:$A$7',
3175               values     => '=Sheet1!$C$2:$C$7',
3176               marker     => { type => 'automatic' },
3177               y2_axis    => 1,
3178           );
3179
3180
3181           # Combine the charts.
3182           $column_chart->combine( $line_chart );
3183
3184           # Insert the chart into the worksheet.
3185           $worksheet->insert_chart( 'F2', $column_chart );
3186
3187           $workbook->close();
3188
3189           __END__
3190
3191       Download this example:
3192       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_pareto.pl>
3193
3194   Example: chart_stock.pl
3195       A demo of a Stock chart in Excel::Writer::XLSX.
3196
3197       Source code for this example:
3198
3199           #!/usr/bin/perl
3200
3201           #######################################################################
3202           #
3203           # A demo of a Stock chart in Excel::Writer::XLSX.
3204           #
3205           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
3206           #
3207
3208           use strict;
3209           use warnings;
3210           use Excel::Writer::XLSX;
3211           use Excel::Writer::XLSX;
3212
3213           my $workbook    = Excel::Writer::XLSX->new( 'chart_stock.xlsx' );
3214           my $worksheet   = $workbook->add_worksheet();
3215           my $bold        = $workbook->add_format( bold => 1 );
3216           my $date_format = $workbook->add_format( num_format => 'dd/mm/yyyy' );
3217           my $chart       = $workbook->add_chart( type => 'stock', embedded => 1 );
3218
3219
3220           # Add the worksheet data that the charts will refer to.
3221           my $headings = [ 'Date', 'High', 'Low', 'Close' ];
3222           my $data = [
3223
3224               [ '2007-01-01T', '2007-01-02T', '2007-01-03T', '2007-01-04T', '2007-01-05T' ],
3225               [ 27.2,  25.03, 19.05, 20.34, 18.5 ],
3226               [ 23.49, 19.55, 15.12, 17.84, 16.34 ],
3227               [ 25.45, 23.05, 17.32, 20.45, 17.34 ],
3228
3229           ];
3230
3231           $worksheet->write( 'A1', $headings, $bold );
3232
3233           for my $row ( 0 .. 4 ) {
3234               $worksheet->write_date_time( $row+1, 0, $data->[0]->[$row], $date_format );
3235               $worksheet->write( $row+1, 1, $data->[1]->[$row] );
3236               $worksheet->write( $row+1, 2, $data->[2]->[$row] );
3237               $worksheet->write( $row+1, 3, $data->[3]->[$row] );
3238
3239           }
3240
3241           $worksheet->set_column( 'A:D', 11 );
3242
3243           # Add a series for each of the High-Low-Close columns.
3244           $chart->add_series(
3245               categories => '=Sheet1!$A$2:$A$6',
3246               values     => '=Sheet1!$B$2:$B$6',
3247           );
3248
3249           $chart->add_series(
3250               categories => '=Sheet1!$A$2:$A$6',
3251               values     => '=Sheet1!$C$2:$C$6',
3252           );
3253
3254           $chart->add_series(
3255               categories => '=Sheet1!$A$2:$A$6',
3256               values     => '=Sheet1!$D$2:$D$6',
3257           );
3258
3259           # Add a chart title and some axis labels.
3260           $chart->set_title ( name => 'High-Low-Close', );
3261           $chart->set_x_axis( name => 'Date', );
3262           $chart->set_y_axis( name => 'Share price', );
3263
3264
3265           $worksheet->insert_chart( 'E9', $chart );
3266
3267           $workbook->close();
3268
3269           __END__
3270
3271       Download this example:
3272       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_stock.pl>
3273
3274   Example: chart_data_table.pl
3275       A demo of an Column chart with a data table on the X-axis using
3276       Excel::Writer::XLSX.
3277
3278       Source code for this example:
3279
3280           #!/usr/bin/perl
3281
3282           #######################################################################
3283           #
3284           # A demo of an Column chart with a data table on the X-axis using
3285           # Excel::Writer::XLSX.
3286           #
3287           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
3288           #
3289
3290           use strict;
3291           use warnings;
3292           use Excel::Writer::XLSX;
3293
3294           my $workbook  = Excel::Writer::XLSX->new( 'chart_data_table.xlsx' );
3295           my $worksheet = $workbook->add_worksheet();
3296           my $bold      = $workbook->add_format( bold => 1 );
3297
3298           # Add the worksheet data that the charts will refer to.
3299           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
3300           my $data = [
3301               [ 2,  3,  4,  5,  6,  7 ],
3302               [ 10, 40, 50, 20, 10, 50 ],
3303               [ 30, 60, 70, 50, 40, 30 ],
3304
3305           ];
3306
3307           $worksheet->write( 'A1', $headings, $bold );
3308           $worksheet->write( 'A2', $data );
3309
3310           # Create a column chart with a data table.
3311           my $chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
3312
3313           # Configure the first series.
3314           $chart1->add_series(
3315               name       => '=Sheet1!$B$1',
3316               categories => '=Sheet1!$A$2:$A$7',
3317               values     => '=Sheet1!$B$2:$B$7',
3318           );
3319
3320           # Configure second series. Note alternative use of array ref to define
3321           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
3322           $chart1->add_series(
3323               name       => '=Sheet1!$C$1',
3324               categories => [ 'Sheet1', 1, 6, 0, 0 ],
3325               values     => [ 'Sheet1', 1, 6, 2, 2 ],
3326           );
3327
3328           # Add a chart title and some axis labels.
3329           $chart1->set_title( name => 'Chart with Data Table' );
3330           $chart1->set_x_axis( name => 'Test number' );
3331           $chart1->set_y_axis( name => 'Sample length (mm)' );
3332
3333           # Set a default data table on the X-Axis.
3334           $chart1->set_table();
3335
3336           # Insert the chart into the worksheet (with an offset).
3337           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
3338
3339
3340           #
3341           # Create a second chart.
3342           #
3343           my $chart2 = $workbook->add_chart( type => 'column', embedded => 1 );
3344
3345           # Configure the first series.
3346           $chart2->add_series(
3347               name       => '=Sheet1!$B$1',
3348               categories => '=Sheet1!$A$2:$A$7',
3349               values     => '=Sheet1!$B$2:$B$7',
3350           );
3351
3352           # Configure second series.
3353           $chart2->add_series(
3354               name       => '=Sheet1!$C$1',
3355               categories => [ 'Sheet1', 1, 6, 0, 0 ],
3356               values     => [ 'Sheet1', 1, 6, 2, 2 ],
3357           );
3358
3359           # Add a chart title and some axis labels.
3360           $chart2->set_title( name => 'Data Table with legend keys' );
3361           $chart2->set_x_axis( name => 'Test number' );
3362           $chart2->set_y_axis( name => 'Sample length (mm)' );
3363
3364           # Set a data table on the X-Axis with the legend keys showm.
3365           $chart2->set_table( show_keys => 1 );
3366
3367           # Hide the chart legend since the keys are show on the data table.
3368           $chart2->set_legend( position => 'none' );
3369
3370           # Insert the chart into the worksheet (with an offset).
3371           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
3372
3373           $workbook->close();
3374
3375           __END__
3376
3377       Download this example:
3378       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_data_table.pl>
3379
3380   Example: chart_data_tools.pl
3381       A demo of an various Excel chart data tools that are available via an
3382       Excel::Writer::XLSX chart.
3383
3384       These include, Trendlines, Data Labels, Error Bars, Drop Lines, High-
3385       Low Lines and Up-Down Bars.
3386
3387       Source code for this example:
3388
3389           #!/usr/bin/perl
3390
3391           #######################################################################
3392           #
3393           # A demo of an various Excel chart data tools that are available via
3394           # an Excel::Writer::XLSX chart.
3395           #
3396           # These include, Trendlines, Data Labels, Error Bars, Drop Lines,
3397           # High-Low Lines and Up-Down Bars.
3398           #
3399           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
3400           #
3401
3402           use strict;
3403           use warnings;
3404           use Excel::Writer::XLSX;
3405
3406           my $workbook  = Excel::Writer::XLSX->new( 'chart_data_tools.xlsx' );
3407           my $worksheet = $workbook->add_worksheet();
3408           my $bold      = $workbook->add_format( bold => 1 );
3409
3410           # Add the worksheet data that the charts will refer to.
3411           my $headings = [ 'Number', 'Data 1', 'Data 2' ];
3412           my $data = [
3413               [ 2,  3,  4,  5,  6,  7 ],
3414               [ 10, 40, 50, 20, 10, 50 ],
3415               [ 30, 60, 70, 50, 40, 30 ],
3416
3417           ];
3418
3419           $worksheet->write( 'A1', $headings, $bold );
3420           $worksheet->write( 'A2', $data );
3421
3422
3423           #######################################################################
3424           #
3425           # Trendline example.
3426           #
3427
3428           # Create a Line chart.
3429           my $chart1 = $workbook->add_chart( type => 'line', embedded => 1 );
3430
3431           # Configure the first series with a polynomial trendline.
3432           $chart1->add_series(
3433               categories => '=Sheet1!$A$2:$A$7',
3434               values     => '=Sheet1!$B$2:$B$7',
3435               trendline  => {
3436                   type  => 'polynomial',
3437                   order => 3,
3438               },
3439           );
3440
3441           # Configure the second series with a moving average trendline.
3442           $chart1->add_series(
3443               categories => '=Sheet1!$A$2:$A$7',
3444               values     => '=Sheet1!$C$2:$C$7',
3445               trendline  => { type => 'linear' },
3446           );
3447
3448           # Add a chart title. and some axis labels.
3449           $chart1->set_title( name => 'Chart with Trendlines' );
3450
3451           # Insert the chart into the worksheet (with an offset).
3452           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
3453
3454
3455           #######################################################################
3456           #
3457           # Data Labels and Markers example.
3458           #
3459
3460           # Create a Line chart.
3461           my $chart2 = $workbook->add_chart( type => 'line', embedded => 1 );
3462
3463           # Configure the first series.
3464           $chart2->add_series(
3465               categories  => '=Sheet1!$A$2:$A$7',
3466               values      => '=Sheet1!$B$2:$B$7',
3467               data_labels => { value => 1 },
3468               marker      => { type => 'automatic' },
3469           );
3470
3471           # Configure the second series.
3472           $chart2->add_series(
3473               categories => '=Sheet1!$A$2:$A$7',
3474               values     => '=Sheet1!$C$2:$C$7',
3475           );
3476
3477           # Add a chart title. and some axis labels.
3478           $chart2->set_title( name => 'Chart with Data Labels and Markers' );
3479
3480           # Insert the chart into the worksheet (with an offset).
3481           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
3482
3483
3484           #######################################################################
3485           #
3486           # Error Bars example.
3487           #
3488
3489           # Create a Line chart.
3490           my $chart3 = $workbook->add_chart( type => 'line', embedded => 1 );
3491
3492           # Configure the first series.
3493           $chart3->add_series(
3494               categories   => '=Sheet1!$A$2:$A$7',
3495               values       => '=Sheet1!$B$2:$B$7',
3496               y_error_bars => { type => 'standard_error' },
3497           );
3498
3499           # Configure the second series.
3500           $chart3->add_series(
3501               categories => '=Sheet1!$A$2:$A$7',
3502               values     => '=Sheet1!$C$2:$C$7',
3503           );
3504
3505           # Add a chart title. and some axis labels.
3506           $chart3->set_title( name => 'Chart with Error Bars' );
3507
3508           # Insert the chart into the worksheet (with an offset).
3509           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
3510
3511
3512           #######################################################################
3513           #
3514           # Up-Down Bars example.
3515           #
3516
3517           # Create a Line chart.
3518           my $chart4 = $workbook->add_chart( type => 'line', embedded => 1 );
3519
3520           # Add the Up-Down Bars.
3521           $chart4->set_up_down_bars();
3522
3523           # Configure the first series.
3524           $chart4->add_series(
3525               categories => '=Sheet1!$A$2:$A$7',
3526               values     => '=Sheet1!$B$2:$B$7',
3527           );
3528
3529           # Configure the second series.
3530           $chart4->add_series(
3531               categories => '=Sheet1!$A$2:$A$7',
3532               values     => '=Sheet1!$C$2:$C$7',
3533           );
3534
3535           # Add a chart title. and some axis labels.
3536           $chart4->set_title( name => 'Chart with Up-Down Bars' );
3537
3538           # Insert the chart into the worksheet (with an offset).
3539           $worksheet->insert_chart( 'D50', $chart4, { x_offset => 25, y_offset => 10 } );
3540
3541
3542           #######################################################################
3543           #
3544           # High-Low Lines example.
3545           #
3546
3547           # Create a Line chart.
3548           my $chart5 = $workbook->add_chart( type => 'line', embedded => 1 );
3549
3550           # Add the High-Low lines.
3551           $chart5->set_high_low_lines();
3552
3553           # Configure the first series.
3554           $chart5->add_series(
3555               categories => '=Sheet1!$A$2:$A$7',
3556               values     => '=Sheet1!$B$2:$B$7',
3557           );
3558
3559           # Configure the second series.
3560           $chart5->add_series(
3561               categories => '=Sheet1!$A$2:$A$7',
3562               values     => '=Sheet1!$C$2:$C$7',
3563           );
3564
3565           # Add a chart title. and some axis labels.
3566           $chart5->set_title( name => 'Chart with High-Low Lines' );
3567
3568           # Insert the chart into the worksheet (with an offset).
3569           $worksheet->insert_chart( 'D66', $chart5, { x_offset => 25, y_offset => 10 } );
3570
3571
3572           #######################################################################
3573           #
3574           # Drop Lines example.
3575           #
3576
3577           # Create a Line chart.
3578           my $chart6 = $workbook->add_chart( type => 'line', embedded => 1 );
3579
3580           # Add Drop Lines.
3581           $chart6->set_drop_lines();
3582
3583           # Configure the first series.
3584           $chart6->add_series(
3585               categories => '=Sheet1!$A$2:$A$7',
3586               values     => '=Sheet1!$B$2:$B$7',
3587           );
3588
3589           # Configure the second series.
3590           $chart6->add_series(
3591               categories => '=Sheet1!$A$2:$A$7',
3592               values     => '=Sheet1!$C$2:$C$7',
3593           );
3594
3595           # Add a chart title. and some axis labels.
3596           $chart6->set_title( name => 'Chart with Drop Lines' );
3597
3598           # Insert the chart into the worksheet (with an offset).
3599           $worksheet->insert_chart( 'D82', $chart6, { x_offset => 25, y_offset => 10 } );
3600
3601           $workbook->close();
3602
3603           __END__
3604
3605       Download this example:
3606       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_data_tools.pl>
3607
3608   Example: chart_data_labels.pl
3609       A demo of an various Excel chart data label features that are available
3610       via an Excel::Writer::XLSX chart.
3611
3612           #!/usr/bin/perl
3613
3614           #######################################################################
3615           #
3616           # A demo of an various Excel chart data label features that are available
3617           # via an Excel::Writer::XLSX chart.
3618           #
3619           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
3620           #
3621
3622           use strict;
3623           use warnings;
3624           use Excel::Writer::XLSX;
3625
3626           my $workbook  = Excel::Writer::XLSX->new( 'chart_data_labels.xlsx' );
3627           my $worksheet = $workbook->add_worksheet();
3628           my $bold      = $workbook->add_format( bold => 1 );
3629
3630           # Add the worksheet data that the charts will refer to.
3631           my $headings = [ 'Number', 'Data', 'Text' ];
3632           my $data = [
3633               [ 2,  3,  4,  5,  6,  7 ],
3634               [ 20, 10, 20, 30, 40, 30 ],
3635               [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun' ],
3636           ];
3637
3638           $worksheet->write( 'A1', $headings, $bold );
3639           $worksheet->write( 'A2', $data );
3640
3641
3642           #######################################################################
3643           #
3644           # Example with standard data labels.
3645           #
3646
3647           # Create a Column chart.
3648           my $chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
3649
3650           # Configure the data series and add the data labels.
3651           $chart1->add_series(
3652               categories => '=Sheet1!$A$2:$A$7',
3653               values     => '=Sheet1!$B$2:$B$7',
3654               data_labels => { value => 1 },
3655           );
3656
3657           # Add a chart title.
3658           $chart1->set_title( name => 'Chart with standard data labels' );
3659
3660           # Turn off the chart legend.
3661           $chart1->set_legend( none => 1 );
3662
3663           # Insert the chart into the worksheet (with an offset).
3664           $worksheet->insert_chart( 'D2', $chart1, { x_offset => 25, y_offset => 10 } );
3665
3666
3667           #######################################################################
3668           #
3669           # Example with value and category data labels.
3670           #
3671
3672           # Create a Column chart.
3673           my $chart2 = $workbook->add_chart( type => 'column', embedded => 1 );
3674
3675           # Configure the data series and add the data labels.
3676           $chart2->add_series(
3677               categories => '=Sheet1!$A$2:$A$7',
3678               values     => '=Sheet1!$B$2:$B$7',
3679               data_labels => { value => 1, category => 1 },
3680           );
3681
3682           # Add a chart title.
3683           $chart2->set_title( name => 'Category and Value data labels' );
3684
3685           # Turn off the chart legend.
3686           $chart2->set_legend( none => 1 );
3687
3688           # Insert the chart into the worksheet (with an offset).
3689           $worksheet->insert_chart( 'D18', $chart2, { x_offset => 25, y_offset => 10 } );
3690
3691
3692           #######################################################################
3693           #
3694           # Example with standard data labels with different font.
3695           #
3696
3697           # Create a Column chart.
3698           my $chart3 = $workbook->add_chart( type => 'column', embedded => 1 );
3699
3700           # Configure the data series and add the data labels.
3701           $chart3->add_series(
3702               categories => '=Sheet1!$A$2:$A$7',
3703               values     => '=Sheet1!$B$2:$B$7',
3704               data_labels => { value => 1,
3705                                font => { bold => 1,
3706                                          color => 'red',
3707                                          rotation => -30} },
3708           );
3709
3710           # Add a chart title.
3711           $chart3->set_title( name => 'Data labels with user defined font' );
3712
3713           # Turn off the chart legend.
3714           $chart3->set_legend( none => 1 );
3715
3716           # Insert the chart into the worksheet (with an offset).
3717           $worksheet->insert_chart( 'D34', $chart3, { x_offset => 25, y_offset => 10 } );
3718
3719
3720           #######################################################################
3721           #
3722           # Example with standard data labels and formatting.
3723           #
3724
3725           # Create a Column chart.
3726           my $chart4 = $workbook->add_chart( type => 'column', embedded => 1 );
3727
3728           # Configure the data series and add the data labels.
3729           $chart4->add_series(
3730               categories => '=Sheet1!$A$2:$A$7',
3731               values     => '=Sheet1!$B$2:$B$7',
3732               data_labels => { value  => 1,
3733                                border => {color => 'red'},
3734                                fill   => {color => 'yellow'} },
3735           );
3736
3737           # Add a chart title.
3738           $chart4->set_title( name => 'Data labels with formatting' );
3739
3740           # Turn off the chart legend.
3741           $chart4->set_legend( none => 1 );
3742
3743           # Insert the chart into the worksheet (with an offset).
3744           $worksheet->insert_chart( 'D50', $chart4, { x_offset => 25, y_offset => 10 } );
3745
3746
3747           #######################################################################
3748           #
3749           # Example with custom string data labels.
3750           #
3751
3752           # Create a Column chart.
3753           my $chart5 = $workbook->add_chart( type => 'column', embedded => 1 );
3754
3755           # Some custom labels.
3756           my $custom_labels = [
3757               { value => 'Amy' },
3758               { value => 'Bea' },
3759               { value => 'Eva' },
3760               { value => 'Fay' },
3761               { value => 'Liv' },
3762               { value => 'Una' },
3763           ];
3764
3765
3766           # Configure the data series and add the data labels.
3767           $chart5->add_series(
3768               categories => '=Sheet1!$A$2:$A$7',
3769               values     => '=Sheet1!$B$2:$B$7',
3770               data_labels => { value => 1, custom => $custom_labels },
3771           );
3772
3773           # Add a chart title.
3774           $chart5->set_title( name => 'Chart with custom string data labels' );
3775
3776           # Turn off the chart legend.
3777           $chart5->set_legend( none => 1 );
3778
3779           # Insert the chart into the worksheet (with an offset).
3780           $worksheet->insert_chart( 'D66', $chart5, { x_offset => 25, y_offset => 10 } );
3781
3782
3783           #######################################################################
3784           #
3785           # Example with custom data labels from cells.
3786           #
3787
3788           # Create a Column chart.
3789           my $chart6 = $workbook->add_chart( type => 'column', embedded => 1 );
3790
3791           # Some custom labels.
3792           $custom_labels = [
3793               { value => '=Sheet1!$C$2' },
3794               { value => '=Sheet1!$C$3' },
3795               { value => '=Sheet1!$C$4' },
3796               { value => '=Sheet1!$C$5' },
3797               { value => '=Sheet1!$C$6' },
3798               { value => '=Sheet1!$C$7' },
3799           ];
3800
3801
3802           # Configure the data series and add the data labels.
3803           $chart6->add_series(
3804               categories => '=Sheet1!$A$2:$A$7',
3805               values     => '=Sheet1!$B$2:$B$7',
3806               data_labels => { value => 1, custom => $custom_labels },
3807           );
3808
3809           # Add a chart title.
3810           $chart6->set_title( name => 'Chart with custom data labels from cells' );
3811
3812           # Turn off the chart legend.
3813           $chart6->set_legend( none => 1 );
3814
3815           # Insert the chart into the worksheet (with an offset).
3816           $worksheet->insert_chart( 'D82', $chart6, { x_offset => 25, y_offset => 10 } );
3817
3818
3819           #######################################################################
3820           #
3821           # Example with custom and default data labels.
3822           #
3823
3824           # Create a Column chart.
3825           my $chart7 = $workbook->add_chart( type => 'column', embedded => 1 );
3826
3827           # Some custom labels. The undef items will get the default value.
3828           # We also set a font for the custom items as an extra example.
3829           $custom_labels = [
3830               { value => '=Sheet1!$C$2', font => { color => 'red' } },
3831               undef,
3832               { value => '=Sheet1!$C$4', font => { color => 'red' } },
3833               { value => '=Sheet1!$C$5', font => { color => 'red' } },
3834           ];
3835
3836
3837           # Configure the data series and add the data labels.
3838           $chart7->add_series(
3839               categories => '=Sheet1!$A$2:$A$7',
3840               values     => '=Sheet1!$B$2:$B$7',
3841               data_labels => { value => 1, custom => $custom_labels },
3842           );
3843
3844           # Add a chart title.
3845           $chart7->set_title( name => 'Mixed custom and default data labels' );
3846
3847           # Turn off the chart legend.
3848           $chart7->set_legend( none => 1 );
3849
3850           # Insert the chart into the worksheet (with an offset).
3851           $worksheet->insert_chart( 'D98', $chart7, { x_offset => 25, y_offset => 10 } );
3852
3853
3854           #######################################################################
3855           #
3856           # Example with deleted custom data labels.
3857           #
3858
3859           # Create a Column chart.
3860           my $chart8 = $workbook->add_chart( type => 'column', embedded => 1 );
3861
3862           # Some deleted custom labels and defaults (undef). This allows us to
3863           # highlight certain values such as the minimum and maximum.
3864           $custom_labels = [
3865               { delete => 1 },
3866               undef,
3867               { delete => 1 },
3868               { delete => 1 },
3869               undef,
3870               { delete => 1 },
3871           ];
3872
3873           # Configure the data series and add the data labels.
3874           $chart8->add_series(
3875               categories => '=Sheet1!$A$2:$A$7',
3876               values     => '=Sheet1!$B$2:$B$7',
3877               data_labels => { value => 1, custom => $custom_labels },
3878           );
3879
3880           # Add a chart title.
3881           $chart8->set_title( name => 'Chart with deleted data labels' );
3882
3883           # Turn off the chart legend.
3884           $chart8->set_legend( none => 1 );
3885
3886           # Insert the chart into the worksheet (with an offset).
3887           $worksheet->insert_chart( 'D114', $chart8, { x_offset => 25, y_offset => 10 } );
3888
3889
3890           #######################################################################
3891           #
3892           # Example with custom string data labels and formatting.
3893           #
3894
3895           # Create a Column chart.
3896           my $chart9 = $workbook->add_chart( type => 'column', embedded => 1 );
3897
3898           # Some custom labels.
3899           $custom_labels = [
3900               { value => 'Amy', border => {color => 'blue'} },
3901               { value => 'Bea' },
3902               { value => 'Eva' },
3903               { value => 'Fay' },
3904               { value => 'Liv' },
3905               { value => 'Una', fill   => {color => 'green'} },
3906           ];
3907
3908
3909           # Configure the data series and add the data labels.
3910           $chart9->add_series(
3911               categories => '=Sheet1!$A$2:$A$7',
3912               values     => '=Sheet1!$B$2:$B$7',
3913               data_labels => { value => 1,
3914                                custom => $custom_labels,
3915                                border => {color => 'red'},
3916                                fill   => {color => 'yellow'} },
3917           );
3918
3919           # Add a chart title.
3920           $chart9->set_title( name => 'Chart with custom labels and formatting' );
3921
3922           # Turn off the chart legend.
3923           $chart9->set_legend( none => 1 );
3924
3925           # Insert the chart into the worksheet (with an offset).
3926           $worksheet->insert_chart( 'D130', $chart9, { x_offset => 25, y_offset => 10 } );
3927
3928
3929           $workbook->close();
3930
3931           __END__
3932
3933       Download this example:
3934       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_data_labels.pl>
3935
3936   Example: chart_clustered.pl
3937       A demo of a clustered category chart in Excel::Writer::XLSX.
3938
3939           #!/usr/bin/perl
3940
3941           #######################################################################
3942           #
3943           # A demo of a clustered category chart in Excel::Writer::XLSX.
3944           #
3945           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
3946           #
3947
3948           use strict;
3949           use warnings;
3950           use Excel::Writer::XLSX;
3951
3952           my $workbook  = Excel::Writer::XLSX->new( 'chart_clustered.xlsx' );
3953           my $worksheet = $workbook->add_worksheet();
3954           my $bold      = $workbook->add_format( bold => 1 );
3955
3956           # Add the worksheet data that the charts will refer to.
3957           my $headings = [ 'Types',  'Sub Type',   'Value 1', 'Value 2', 'Value 3' ];
3958           my $data = [
3959               [ 'Type 1', 'Sub Type A', 5000,      8000,      6000 ],
3960               [ '',       'Sub Type B', 2000,      3000,      4000 ],
3961               [ '',       'Sub Type C', 250,       1000,      2000 ],
3962               [ 'Type 2', 'Sub Type D', 6000,      6000,      6500 ],
3963               [ '',       'Sub Type E', 500,       300,       200 ],
3964           ];
3965
3966           $worksheet->write( 'A1', $headings, $bold );
3967           $worksheet->write_col( 'A2', $data );
3968
3969           # Create a new chart object. In this case an embedded chart.
3970           my $chart = $workbook->add_chart( type => 'column', embedded => 1 );
3971
3972           # Configure the series. Note, that the categories are 2D ranges (from column A
3973           # to column B). This creates the clusters. The series are shown as formula
3974           # strings for clarity but you can also use the array syntax. See the docs.
3975           $chart->add_series(
3976               name       => '=Sheet1!$C$1',
3977               categories => '=Sheet1!$A$2:$B$6',
3978               values     => '=Sheet1!$C$2:$C$6',
3979           );
3980
3981           $chart->add_series(
3982               name       => '=Sheet1!$D$1',
3983               categories => '=Sheet1!$A$2:$B$6',
3984               values     => '=Sheet1!$D$2:$D$6',
3985           );
3986
3987           $chart->add_series(
3988               name       => '=Sheet1!$E$1',
3989               categories => '=Sheet1!$A$2:$B$6',
3990               values     => '=Sheet1!$E$2:$E$6',
3991           );
3992
3993           # Set the Excel chart style.
3994           $chart->set_style( 37 );
3995
3996           # Turn off the legend.
3997           $chart->set_legend( position => 'none' );
3998
3999           # Insert the chart into the worksheet.
4000           $worksheet->insert_chart( 'G3', $chart );
4001
4002           $workbook->close();
4003
4004           __END__
4005
4006       Download this example:
4007       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_clustered.pl>
4008
4009   Example: chart_styles.pl
4010       An example showing all 48 default chart styles available in Excel 2007
4011       using Excel::Writer::XLSX.. Note, these styles are not the same as the
4012       styles available in Excel 2013.
4013
4014           #!/usr/bin/perl
4015
4016           #######################################################################
4017           #
4018           # An example showing all 48 default chart styles available in Excel 2007
4019           # using Excel::Writer::XLSX.. Note, these styles are not the same as the
4020           # styles available in Excel 2013.
4021           #
4022           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
4023           #
4024
4025           use strict;
4026           use warnings;
4027           use Excel::Writer::XLSX;
4028
4029           my $workbook = Excel::Writer::XLSX->new( 'chart_styles.xlsx' );
4030
4031           # Show the styles for all of these chart types.
4032           my @chart_types = ( 'column', 'area', 'line', 'pie' );
4033
4034
4035           for my $chart_type ( @chart_types ) {
4036
4037               # Add a worksheet for each chart type.
4038               my $worksheet = $workbook->add_worksheet( ucfirst( $chart_type ) );
4039               $worksheet->set_zoom( 30 );
4040               my $style_number = 1;
4041
4042               # Create 48 charts, each with a different style.
4043               for ( my $row_num = 0 ; $row_num < 90 ; $row_num += 15 ) {
4044                   for ( my $col_num = 0 ; $col_num < 64 ; $col_num += 8 ) {
4045
4046                       my $chart = $workbook->add_chart(
4047                           type     => $chart_type,
4048                           embedded => 1
4049                       );
4050
4051                       $chart->add_series( values => '=Data!$A$1:$A$6' );
4052                       $chart->set_title( name => 'Style ' . $style_number );
4053                       $chart->set_legend( none => 1 );
4054                       $chart->set_style( $style_number );
4055
4056                       $worksheet->insert_chart( $row_num, $col_num, $chart );
4057                       $style_number++;
4058                   }
4059               }
4060           }
4061
4062           # Create a worksheet with data for the charts.
4063           my $data = [ 10, 40, 50, 20, 10, 50 ];
4064           my $data_worksheet = $workbook->add_worksheet( 'Data' );
4065           $data_worksheet->write_col( 'A1', $data );
4066           $data_worksheet->hide();
4067
4068           $workbook->close();
4069
4070           __END__
4071
4072       Download this example:
4073       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_styles.pl>
4074
4075   Example: chart_gauge.pl
4076       A demo of an Gauge Chart in Excel::Writer::XLSX.
4077
4078       A Gauge Chart isn't a native chart type in Excel. It is constructed by
4079       combining a doughnut chart and a pie chart and by using some non-filled
4080       elements. This example follows the following online example of how to
4081       create a Gauge Chart in Excel:
4082       https://www.excel-easy.com/examples/gauge-chart.html
4083
4084           #!/usr/bin/perl
4085
4086           #######################################################################
4087           #
4088           # A demo of an Gauge Chart in Excel::Writer::XLSX.
4089           #
4090           # A Gauge Chart isn't a native chart type in Excel. It is constructed by
4091           # combining a doughnut chart and a pie chart and by using some non-filled
4092           # elements. This example follows the following online example of how to create
4093           # a Gauge Chart in Excel: https://www.excel-easy.com/examples/gauge-chart.html
4094           #
4095           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
4096           #
4097
4098           use strict;
4099           use warnings;
4100           use Excel::Writer::XLSX;
4101
4102           my $workbook  = Excel::Writer::XLSX->new( 'chart_gauge.xlsx' );
4103           my $worksheet = $workbook->add_worksheet();
4104
4105           my $chart_doughnut = $workbook->add_chart( type => 'doughnut', embedded => 1 );
4106           my $chart_pie      = $workbook->add_chart( type => 'pie', embedded => 1 );
4107
4108           # Add some data for the Doughnut and Pie charts. This is set up so the
4109           # gauge goes from 0-100. It is initially set at 75%.
4110           $worksheet->write_col( 'H2', ['Donut', 25, 50, 25, 100] );
4111           $worksheet->write_col( 'I2', ['Pie', 75, 1, '=200-I4-I3'] );
4112
4113           # Configure the doughnut chart as the background for the gauge.
4114           $chart_doughnut->add_series(
4115               name   => '=Sheet1!$H$2',
4116               values => '=Sheet1!$H$3:$H$6',
4117               points => [
4118                   { fill => { color => 'green' } },
4119                   { fill => { color => 'yellow' } },
4120                   { fill => { color => 'red' } },
4121                   { fill => { none  => 1 } },
4122               ],
4123           );
4124
4125           # Rotate chart so the gauge parts are above the horizontal.
4126           $chart_doughnut->set_rotation( 270 );
4127
4128           # Turn off the chart legend.
4129           $chart_doughnut->set_legend( none => 1 );
4130
4131           # Turn off the chart fill and border.
4132           $chart_doughnut->set_chartarea(
4133               border => { none  => 1 },
4134               fill   => { none  => 1 },
4135           );
4136
4137           # Configure the pie chart as the needle for the gauge.
4138           $chart_pie->add_series(
4139               name   => '=Sheet1!$I$2',
4140               values => '=Sheet1!$I$3:$I$6',
4141               points => [
4142                   { fill => { none  => 1 } },
4143                   { fill => { color => 'black' } },
4144                   { fill => { none  => 1 } },
4145               ],
4146           );
4147
4148           # Rotate the pie chart/needle to align with the doughnut/gauge.
4149           $chart_pie->set_rotation( 270 );
4150
4151           # Combine the pie and doughnut charts.
4152           $chart_doughnut->combine($chart_pie);
4153
4154           # Insert the chart into the worksheet.
4155           $worksheet->insert_chart( 'A1', $chart_doughnut );
4156
4157           $workbook->close();
4158
4159       Download this example:
4160       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/chart_gauge.pl>
4161
4162   Example: colors.pl
4163       Demonstrates Excel::Writer::XLSX's named colours and the Excel colour
4164       palette.
4165
4166       The set_custom_color() Worksheet method can be used to override one of
4167       the built-in palette values with a more suitable colour. See the main
4168       docs.
4169
4170       Source code for this example:
4171
4172           #!/usr/bin/perl -w
4173
4174           ################################################################################
4175           #
4176           # Demonstrates Excel::Writer::XLSX's named colours and the Excel colour
4177           # palette.
4178           #
4179           # The set_custom_color() Worksheet method can be used to override one of the
4180           # built-in palette values with a more suitable colour. See the main docs.
4181           #
4182           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
4183           #
4184
4185           use strict;
4186           use Excel::Writer::XLSX;
4187
4188           my $workbook = Excel::Writer::XLSX->new( 'colors.xlsx' );
4189
4190           # Some common formats
4191           my $center = $workbook->add_format( align => 'center' );
4192           my $heading = $workbook->add_format( align => 'center', bold => 1 );
4193
4194
4195           ######################################################################
4196           #
4197           # Demonstrate the named colors.
4198           #
4199
4200           my %colors = (
4201               0x08, 'black',
4202               0x0C, 'blue',
4203               0x10, 'brown',
4204               0x0F, 'cyan',
4205               0x17, 'gray',
4206               0x11, 'green',
4207               0x0B, 'lime',
4208               0x0E, 'magenta',
4209               0x12, 'navy',
4210               0x35, 'orange',
4211               0x21, 'pink',
4212               0x14, 'purple',
4213               0x0A, 'red',
4214               0x16, 'silver',
4215               0x09, 'white',
4216               0x0D, 'yellow',
4217
4218           );
4219
4220           my $worksheet1 = $workbook->add_worksheet( 'Named colors' );
4221
4222           $worksheet1->set_column( 0, 3, 15 );
4223
4224           $worksheet1->write( 0, 0, "Index", $heading );
4225           $worksheet1->write( 0, 1, "Index", $heading );
4226           $worksheet1->write( 0, 2, "Name",  $heading );
4227           $worksheet1->write( 0, 3, "Color", $heading );
4228
4229           my $i = 1;
4230
4231           while ( my ( $index, $color ) = each %colors ) {
4232               my $format = $workbook->add_format(
4233                   fg_color => $color,
4234                   pattern  => 1,
4235                   border   => 1
4236               );
4237
4238               $worksheet1->write( $i + 1, 0, $index, $center );
4239               $worksheet1->write( $i + 1, 1, sprintf( "0x%02X", $index ), $center );
4240               $worksheet1->write( $i + 1, 2, $color, $center );
4241               $worksheet1->write( $i + 1, 3, '',     $format );
4242               $i++;
4243           }
4244
4245
4246           ######################################################################
4247           #
4248           # Demonstrate the standard Excel colors in the range 8..63.
4249           #
4250
4251           my $worksheet2 = $workbook->add_worksheet( 'Standard colors' );
4252
4253           $worksheet2->set_column( 0, 3, 15 );
4254
4255           $worksheet2->write( 0, 0, "Index", $heading );
4256           $worksheet2->write( 0, 1, "Index", $heading );
4257           $worksheet2->write( 0, 2, "Color", $heading );
4258           $worksheet2->write( 0, 3, "Name",  $heading );
4259
4260           for my $i ( 8 .. 63 ) {
4261               my $format = $workbook->add_format(
4262                   fg_color => $i,
4263                   pattern  => 1,
4264                   border   => 1
4265               );
4266
4267               $worksheet2->write( ( $i - 7 ), 0, $i, $center );
4268               $worksheet2->write( ( $i - 7 ), 1, sprintf( "0x%02X", $i ), $center );
4269               $worksheet2->write( ( $i - 7 ), 2, '', $format );
4270
4271               # Add the  color names
4272               if ( exists $colors{$i} ) {
4273                   $worksheet2->write( ( $i - 7 ), 3, $colors{$i}, $center );
4274
4275               }
4276           }
4277
4278
4279           ######################################################################
4280           #
4281           # Demonstrate the Html colors.
4282           #
4283
4284
4285
4286           %colors = (
4287               '#000000',  'black',
4288               '#0000FF',  'blue',
4289               '#800000',  'brown',
4290               '#00FFFF',  'cyan',
4291               '#808080',  'gray',
4292               '#008000',  'green',
4293               '#00FF00',  'lime',
4294               '#FF00FF',  'magenta',
4295               '#000080',  'navy',
4296               '#FF6600',  'orange',
4297               '#FF00FF',  'pink',
4298               '#800080',  'purple',
4299               '#FF0000',  'red',
4300               '#C0C0C0',  'silver',
4301               '#FFFFFF',  'white',
4302               '#FFFF00',  'yellow',
4303           );
4304
4305           my $worksheet3 = $workbook->add_worksheet( 'Html colors' );
4306
4307           $worksheet3->set_column( 0, 3, 15 );
4308
4309           $worksheet3->write( 0, 0, "Html", $heading );
4310           $worksheet3->write( 0, 1, "Name",  $heading );
4311           $worksheet3->write( 0, 2, "Color", $heading );
4312
4313           $i = 1;
4314
4315           while ( my ( $html_color, $color ) = each %colors ) {
4316               my $format = $workbook->add_format(
4317                   fg_color => $html_color,
4318                   pattern  => 1,
4319                   border   => 1
4320               );
4321
4322               $worksheet3->write( $i + 1, 1, $html_color, $center );
4323               $worksheet3->write( $i + 1, 2, $color,      $center );
4324               $worksheet3->write( $i + 1, 3, '',          $format );
4325               $i++;
4326           }
4327
4328           $workbook->close();
4329
4330           __END__
4331
4332       Download this example:
4333       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/colors.pl>
4334
4335   Example: comments1.pl
4336       This example demonstrates writing cell comments.
4337
4338       A cell comment is indicated in Excel by a small red triangle in the
4339       upper right-hand corner of the cell.
4340
4341       For more advanced comment options see comments2.pl.
4342
4343       Source code for this example:
4344
4345           #!/usr/bin/perl
4346
4347           ###############################################################################
4348           #
4349           # This example demonstrates writing cell comments.
4350           #
4351           # A cell comment is indicated in Excel by a small red triangle in the upper
4352           # right-hand corner of the cell.
4353           #
4354           # For more advanced comment options see comments2.pl.
4355           #
4356           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
4357           #
4358
4359           use strict;
4360           use warnings;
4361           use Excel::Writer::XLSX;
4362
4363           my $workbook  = Excel::Writer::XLSX->new( 'comments1.xlsx' );
4364           my $worksheet = $workbook->add_worksheet();
4365
4366
4367           $worksheet->write( 'A1', 'Hello' );
4368           $worksheet->write_comment( 'A1', 'This is a comment' );
4369
4370           $workbook->close();
4371
4372           __END__
4373
4374       Download this example:
4375       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/comments1.pl>
4376
4377   Example: comments2.pl
4378       This example demonstrates writing cell comments.
4379
4380       A cell comment is indicated in Excel by a small red triangle in the
4381       upper right-hand corner of the cell.
4382
4383       Each of the worksheets demonstrates different features of cell
4384       comments.
4385
4386       Source code for this example:
4387
4388           #!/usr/bin/perl
4389
4390           ###############################################################################
4391           #
4392           # This example demonstrates writing cell comments.
4393           #
4394           # A cell comment is indicated in Excel by a small red triangle in the upper
4395           # right-hand corner of the cell.
4396           #
4397           # Each of the worksheets demonstrates different features of cell comments.
4398           #
4399           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
4400           #
4401
4402           use strict;
4403           use warnings;
4404           use Excel::Writer::XLSX;
4405
4406           my $workbook   = Excel::Writer::XLSX->new( 'comments2.xlsx' );
4407           my $text_wrap  = $workbook->add_format( text_wrap => 1, valign => 'top' );
4408           my $worksheet1 = $workbook->add_worksheet();
4409           my $worksheet2 = $workbook->add_worksheet();
4410           my $worksheet3 = $workbook->add_worksheet();
4411           my $worksheet4 = $workbook->add_worksheet();
4412           my $worksheet5 = $workbook->add_worksheet();
4413           my $worksheet6 = $workbook->add_worksheet();
4414           my $worksheet7 = $workbook->add_worksheet();
4415           my $worksheet8 = $workbook->add_worksheet();
4416
4417
4418           # Variables that we will use in each example.
4419           my $cell_text = '';
4420           my $comment   = '';
4421
4422
4423           ###############################################################################
4424           #
4425           # Example 1. Demonstrates a simple cell comments without formatting.
4426           #            comments.
4427           #
4428
4429           # Set up some formatting.
4430           $worksheet1->set_column( 'C:C', 25 );
4431           $worksheet1->set_row( 2, 50 );
4432           $worksheet1->set_row( 5, 50 );
4433
4434
4435           # Simple ascii string.
4436           $cell_text = 'Hold the mouse over this cell to see the comment.';
4437
4438           $comment = 'This is a comment.';
4439
4440           $worksheet1->write( 'C3', $cell_text, $text_wrap );
4441           $worksheet1->write_comment( 'C3', $comment );
4442
4443           $cell_text = 'This is a UTF-8 string.';
4444           $comment   = chr 0x263a;
4445
4446           $worksheet1->write( 'C6', $cell_text, $text_wrap );
4447           $worksheet1->write_comment( 'C6', $comment );
4448
4449
4450
4451           ###############################################################################
4452           #
4453           # Example 2. Demonstrates visible and hidden comments.
4454           #
4455
4456           # Set up some formatting.
4457           $worksheet2->set_column( 'C:C', 25 );
4458           $worksheet2->set_row( 2, 50 );
4459           $worksheet2->set_row( 5, 50 );
4460
4461
4462           $cell_text = 'This cell comment is visible.';
4463
4464           $comment = 'Hello.';
4465
4466           $worksheet2->write( 'C3', $cell_text, $text_wrap );
4467           $worksheet2->write_comment( 'C3', $comment, visible => 1 );
4468
4469
4470           $cell_text = "This cell comment isn't visible (the default).";
4471
4472           $comment = 'Hello.';
4473
4474           $worksheet2->write( 'C6', $cell_text, $text_wrap );
4475           $worksheet2->write_comment( 'C6', $comment );
4476
4477
4478           ###############################################################################
4479           #
4480           # Example 3. Demonstrates visible and hidden comments set at the worksheet
4481           #            level.
4482           #
4483
4484           # Set up some formatting.
4485           $worksheet3->set_column( 'C:C', 25 );
4486           $worksheet3->set_row( 2, 50 );
4487           $worksheet3->set_row( 5, 50 );
4488           $worksheet3->set_row( 8, 50 );
4489
4490           # Make all comments on the worksheet visible.
4491           $worksheet3->show_comments();
4492
4493           $cell_text = 'This cell comment is visible, explicitly.';
4494
4495           $comment = 'Hello.';
4496
4497           $worksheet3->write( 'C3', $cell_text, $text_wrap );
4498           $worksheet3->write_comment( 'C3', $comment, visible => 1 );
4499
4500
4501           $cell_text =
4502             'This cell comment is also visible because ' . 'we used show_comments().';
4503
4504           $comment = 'Hello.';
4505
4506           $worksheet3->write( 'C6', $cell_text, $text_wrap );
4507           $worksheet3->write_comment( 'C6', $comment );
4508
4509
4510           $cell_text = 'However, we can still override it locally.';
4511
4512           $comment = 'Hello.';
4513
4514           $worksheet3->write( 'C9', $cell_text, $text_wrap );
4515           $worksheet3->write_comment( 'C9', $comment, visible => 0 );
4516
4517
4518           ###############################################################################
4519           #
4520           # Example 4. Demonstrates changes to the comment box dimensions.
4521           #
4522
4523           # Set up some formatting.
4524           $worksheet4->set_column( 'C:C', 25 );
4525           $worksheet4->set_row( 2,  50 );
4526           $worksheet4->set_row( 5,  50 );
4527           $worksheet4->set_row( 8,  50 );
4528           $worksheet4->set_row( 15, 50 );
4529
4530           $worksheet4->show_comments();
4531
4532           $cell_text = 'This cell comment is default size.';
4533
4534           $comment = 'Hello.';
4535
4536           $worksheet4->write( 'C3', $cell_text, $text_wrap );
4537           $worksheet4->write_comment( 'C3', $comment );
4538
4539
4540           $cell_text = 'This cell comment is twice as wide.';
4541
4542           $comment = 'Hello.';
4543
4544           $worksheet4->write( 'C6', $cell_text, $text_wrap );
4545           $worksheet4->write_comment( 'C6', $comment, x_scale => 2 );
4546
4547
4548           $cell_text = 'This cell comment is twice as high.';
4549
4550           $comment = 'Hello.';
4551
4552           $worksheet4->write( 'C9', $cell_text, $text_wrap );
4553           $worksheet4->write_comment( 'C9', $comment, y_scale => 2 );
4554
4555
4556           $cell_text = 'This cell comment is scaled in both directions.';
4557
4558           $comment = 'Hello.';
4559
4560           $worksheet4->write( 'C16', $cell_text, $text_wrap );
4561           $worksheet4->write_comment( 'C16', $comment, x_scale => 1.2, y_scale => 0.8 );
4562
4563
4564           $cell_text = 'This cell comment has width and height specified in pixels.';
4565
4566           $comment = 'Hello.';
4567
4568           $worksheet4->write( 'C19', $cell_text, $text_wrap );
4569           $worksheet4->write_comment( 'C19', $comment, width => 200, height => 20 );
4570
4571
4572           ###############################################################################
4573           #
4574           # Example 5. Demonstrates changes to the cell comment position.
4575           #
4576
4577           $worksheet5->set_column( 'C:C', 25 );
4578           $worksheet5->set_row( 2,  50 );
4579           $worksheet5->set_row( 5,  50 );
4580           $worksheet5->set_row( 8,  50 );
4581           $worksheet5->set_row( 11, 50 );
4582
4583           $worksheet5->show_comments();
4584
4585           $cell_text = 'This cell comment is in the default position.';
4586
4587           $comment = 'Hello.';
4588
4589           $worksheet5->write( 'C3', $cell_text, $text_wrap );
4590           $worksheet5->write_comment( 'C3', $comment );
4591
4592
4593           $cell_text = 'This cell comment has been moved to another cell.';
4594
4595           $comment = 'Hello.';
4596
4597           $worksheet5->write( 'C6', $cell_text, $text_wrap );
4598           $worksheet5->write_comment( 'C6', $comment, start_cell => 'E4' );
4599
4600
4601           $cell_text = 'This cell comment has been moved to another cell.';
4602
4603           $comment = 'Hello.';
4604
4605           $worksheet5->write( 'C9', $cell_text, $text_wrap );
4606           $worksheet5->write_comment( 'C9', $comment, start_row => 8, start_col => 4 );
4607
4608
4609           $cell_text = 'This cell comment has been shifted within its default cell.';
4610
4611           $comment = 'Hello.';
4612
4613           $worksheet5->write( 'C12', $cell_text, $text_wrap );
4614           $worksheet5->write_comment( 'C12', $comment, x_offset => 30, y_offset => 12 );
4615
4616
4617           ###############################################################################
4618           #
4619           # Example 6. Demonstrates changes to the comment background colour.
4620           #
4621
4622           $worksheet6->set_column( 'C:C', 25 );
4623           $worksheet6->set_row( 2, 50 );
4624           $worksheet6->set_row( 5, 50 );
4625           $worksheet6->set_row( 8, 50 );
4626
4627           $worksheet6->show_comments();
4628
4629           $cell_text = 'This cell comment has a different colour.';
4630
4631           $comment = 'Hello.';
4632
4633           $worksheet6->write( 'C3', $cell_text, $text_wrap );
4634           $worksheet6->write_comment( 'C3', $comment, color => 'green' );
4635
4636
4637           $cell_text = 'This cell comment has the default colour.';
4638
4639           $comment = 'Hello.';
4640
4641           $worksheet6->write( 'C6', $cell_text, $text_wrap );
4642           $worksheet6->write_comment( 'C6', $comment );
4643
4644
4645           $cell_text = 'This cell comment has a different colour.';
4646
4647           $comment = 'Hello.';
4648
4649           $worksheet6->write( 'C9', $cell_text, $text_wrap );
4650           $worksheet6->write_comment( 'C9', $comment, color => '#FF6600' );
4651
4652
4653           ###############################################################################
4654           #
4655           # Example 7. Demonstrates how to set the cell comment author.
4656           #
4657
4658           $worksheet7->set_column( 'C:C', 30 );
4659           $worksheet7->set_row( 2,  50 );
4660           $worksheet7->set_row( 5,  50 );
4661           $worksheet7->set_row( 8,  50 );
4662
4663           my $author = '';
4664           my $cell   = 'C3';
4665
4666           $cell_text = "Move the mouse over this cell and you will see 'Cell commented "
4667             . "by $author' (blank) in the status bar at the bottom";
4668
4669           $comment = 'Hello.';
4670
4671           $worksheet7->write( $cell, $cell_text, $text_wrap );
4672           $worksheet7->write_comment( $cell, $comment );
4673
4674
4675           $author    = 'Perl';
4676           $cell      = 'C6';
4677           $cell_text = "Move the mouse over this cell and you will see 'Cell commented "
4678             . "by $author' in the status bar at the bottom";
4679
4680           $comment = 'Hello.';
4681
4682           $worksheet7->write( $cell, $cell_text, $text_wrap );
4683           $worksheet7->write_comment( $cell, $comment, author => $author );
4684
4685
4686           $author    = chr 0x20AC;
4687           $cell      = 'C9';
4688           $cell_text = "Move the mouse over this cell and you will see 'Cell commented "
4689             . "by $author' in the status bar at the bottom";
4690           $comment = 'Hello.';
4691
4692           $worksheet7->write( $cell, $cell_text, $text_wrap );
4693           $worksheet7->write_comment( $cell, $comment, author => $author );
4694
4695
4696
4697
4698           ###############################################################################
4699           #
4700           # Example 8. Demonstrates the need to explicitly set the row height.
4701           #
4702
4703           # Set up some formatting.
4704           $worksheet8->set_column( 'C:C', 25 );
4705           $worksheet8->set_row( 2, 80 );
4706
4707           $worksheet8->show_comments();
4708
4709
4710           $cell_text =
4711               'The height of this row has been adjusted explicitly using '
4712             . 'set_row(). The size of the comment box is adjusted '
4713             . 'accordingly by Excel::Writer::XLSX.';
4714
4715           $comment = 'Hello.';
4716
4717           $worksheet8->write( 'C3', $cell_text, $text_wrap );
4718           $worksheet8->write_comment( 'C3', $comment );
4719
4720
4721           $cell_text =
4722               'The height of this row has been adjusted by Excel due to the '
4723             . 'text wrap property being set. Unfortunately this means that '
4724             . 'the height of the row is unknown to Excel::Writer::XLSX at '
4725             . "run time and thus the comment box is stretched as well.\n\n"
4726             . 'Use set_row() to specify the row height explicitly to avoid '
4727             . 'this problem.';
4728
4729           $comment = 'Hello.';
4730
4731           $worksheet8->write( 'C6', $cell_text, $text_wrap );
4732           $worksheet8->write_comment( 'C6', $comment );
4733
4734           $workbook->close();
4735
4736           __END__
4737
4738       Download this example:
4739       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/comments2.pl>
4740
4741   Example: conditional_format.pl
4742       Example of how to add conditional formatting to an Excel::Writer::XLSX
4743       file.
4744
4745       Conditional formatting allows you to apply a format to a cell or a
4746       range of cells based on certain criteria.
4747
4748       Source code for this example:
4749
4750           #!/usr/bin/perl
4751
4752           ###############################################################################
4753           #
4754           # Example of how to add conditional formatting to an Excel::Writer::XLSX file.
4755           #
4756           # Conditional formatting allows you to apply a format to a cell or a range of
4757           # cells based on certain criteria.
4758           #
4759           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
4760           #
4761
4762           use strict;
4763           use warnings;
4764           use Excel::Writer::XLSX;
4765
4766           my $workbook   = Excel::Writer::XLSX->new( 'conditional_format.xlsx' );
4767           my $worksheet1 = $workbook->add_worksheet();
4768           my $worksheet2 = $workbook->add_worksheet();
4769           my $worksheet3 = $workbook->add_worksheet();
4770           my $worksheet4 = $workbook->add_worksheet();
4771           my $worksheet5 = $workbook->add_worksheet();
4772           my $worksheet6 = $workbook->add_worksheet();
4773           my $worksheet7 = $workbook->add_worksheet();
4774           my $worksheet8 = $workbook->add_worksheet();
4775           my $worksheet9 = $workbook->add_worksheet();
4776
4777
4778           # Light red fill with dark red text.
4779           my $format1 = $workbook->add_format(
4780               bg_color => '#FFC7CE',
4781               color    => '#9C0006',
4782
4783           );
4784
4785           # Green fill with dark green text.
4786           my $format2 = $workbook->add_format(
4787               bg_color => '#C6EFCE',
4788               color    => '#006100',
4789
4790           );
4791
4792           # Some sample data to run the conditional formatting against.
4793           my $data = [
4794               [ 34, 72,  38, 30, 75, 48, 75, 66, 84, 86 ],
4795               [ 6,  24,  1,  84, 54, 62, 60, 3,  26, 59 ],
4796               [ 28, 79,  97, 13, 85, 93, 93, 22, 5,  14 ],
4797               [ 27, 71,  40, 17, 18, 79, 90, 93, 29, 47 ],
4798               [ 88, 25,  33, 23, 67, 1,  59, 79, 47, 36 ],
4799               [ 24, 100, 20, 88, 29, 33, 38, 54, 54, 88 ],
4800               [ 6,  57,  88, 28, 10, 26, 37, 7,  41, 48 ],
4801               [ 52, 78,  1,  96, 26, 45, 47, 33, 96, 36 ],
4802               [ 60, 54,  81, 66, 81, 90, 80, 93, 12, 55 ],
4803               [ 70, 5,   46, 14, 71, 19, 66, 36, 41, 21 ],
4804           ];
4805
4806
4807           ###############################################################################
4808           #
4809           # Example 1.
4810           #
4811           my $caption = 'Cells with values >= 50 are in light red. '
4812             . 'Values < 50 are in light green.';
4813
4814           # Write the data.
4815           $worksheet1->write( 'A1', $caption );
4816           $worksheet1->write_col( 'B3', $data );
4817
4818           # Write a conditional format over a range.
4819           $worksheet1->conditional_formatting( 'B3:K12',
4820               {
4821                   type     => 'cell',
4822                   criteria => '>=',
4823                   value    => 50,
4824                   format   => $format1,
4825               }
4826           );
4827
4828           # Write another conditional format over the same range.
4829           $worksheet1->conditional_formatting( 'B3:K12',
4830               {
4831                   type     => 'cell',
4832                   criteria => '<',
4833                   value    => 50,
4834                   format   => $format2,
4835               }
4836           );
4837
4838
4839           ###############################################################################
4840           #
4841           # Example 2.
4842           #
4843           $caption = 'Values between 30 and 70 are in light red. '
4844             . 'Values outside that range are in light green.';
4845
4846           $worksheet2->write( 'A1', $caption );
4847           $worksheet2->write_col( 'B3', $data );
4848
4849           $worksheet2->conditional_formatting( 'B3:K12',
4850               {
4851                   type     => 'cell',
4852                   criteria => 'between',
4853                   minimum  => 30,
4854                   maximum  => 70,
4855                   format   => $format1,
4856               }
4857           );
4858
4859           $worksheet2->conditional_formatting( 'B3:K12',
4860               {
4861                   type     => 'cell',
4862                   criteria => 'not between',
4863                   minimum  => 30,
4864                   maximum  => 70,
4865                   format   => $format2,
4866               }
4867           );
4868
4869
4870           ###############################################################################
4871           #
4872           # Example 3.
4873           #
4874           $caption = 'Duplicate values are in light red. '
4875             . 'Unique values are in light green.';
4876
4877           $worksheet3->write( 'A1', $caption );
4878           $worksheet3->write_col( 'B3', $data );
4879
4880           $worksheet3->conditional_formatting( 'B3:K12',
4881               {
4882                   type     => 'duplicate',
4883                   format   => $format1,
4884               }
4885           );
4886
4887           $worksheet3->conditional_formatting( 'B3:K12',
4888               {
4889                   type     => 'unique',
4890                   format   => $format2,
4891               }
4892           );
4893
4894
4895           ###############################################################################
4896           #
4897           # Example 4.
4898           #
4899           $caption = 'Above average values are in light red. '
4900             . 'Below average values are in light green.';
4901
4902           $worksheet4->write( 'A1', $caption );
4903           $worksheet4->write_col( 'B3', $data );
4904
4905           $worksheet4->conditional_formatting( 'B3:K12',
4906               {
4907                   type     => 'average',
4908                   criteria => 'above',
4909                   format   => $format1,
4910               }
4911           );
4912
4913           $worksheet4->conditional_formatting( 'B3:K12',
4914               {
4915                   type     => 'average',
4916                   criteria => 'below',
4917                   format   => $format2,
4918               }
4919           );
4920
4921
4922           ###############################################################################
4923           #
4924           # Example 5.
4925           #
4926           $caption = 'Top 10 values are in light red. '
4927             . 'Bottom 10 values are in light green.';
4928
4929           $worksheet5->write( 'A1', $caption );
4930           $worksheet5->write_col( 'B3', $data );
4931
4932           $worksheet5->conditional_formatting( 'B3:K12',
4933               {
4934                   type     => 'top',
4935                   value    => '10',
4936                   format   => $format1,
4937               }
4938           );
4939
4940           $worksheet5->conditional_formatting( 'B3:K12',
4941               {
4942                   type     => 'bottom',
4943                   value    => '10',
4944                   format   => $format2,
4945               }
4946           );
4947
4948
4949           ###############################################################################
4950           #
4951           # Example 6.
4952           #
4953           $caption = 'Cells with values >= 50 are in light red. '
4954             . 'Values < 50 are in light green. Non-contiguous ranges.';
4955
4956           # Write the data.
4957           $worksheet6->write( 'A1', $caption );
4958           $worksheet6->write_col( 'B3', $data );
4959
4960           # Write a conditional format over a range.
4961           $worksheet6->conditional_formatting( 'B3:K6,B9:K12',
4962               {
4963                   type     => 'cell',
4964                   criteria => '>=',
4965                   value    => 50,
4966                   format   => $format1,
4967               }
4968           );
4969
4970           # Write another conditional format over the same range.
4971           $worksheet6->conditional_formatting( 'B3:K6,B9:K12',
4972               {
4973                   type     => 'cell',
4974                   criteria => '<',
4975                   value    => 50,
4976                   format   => $format2,
4977               }
4978           );
4979
4980
4981           ###############################################################################
4982           #
4983           # Example 7.
4984           #
4985           $caption = 'Examples of color scales with default and user colors.';
4986
4987           $data = [ 1 .. 12 ];
4988
4989           $worksheet7->write( 'A1', $caption );
4990
4991           $worksheet7->write    ( 'B2', "2 Color Scale" );
4992           $worksheet7->write_col( 'B3', $data );
4993
4994           $worksheet7->write    ( 'D2', "2 Color Scale + user colors" );
4995           $worksheet7->write_col( 'D3', $data );
4996
4997           $worksheet7->write    ( 'G2', "3 Color Scale" );
4998           $worksheet7->write_col( 'G3', $data );
4999
5000           $worksheet7->write    ( 'I2', "3 Color Scale + user colors" );
5001           $worksheet7->write_col( 'I3', $data );
5002
5003
5004           $worksheet7->conditional_formatting( 'B3:B14',
5005               {
5006                   type => '2_color_scale',
5007               }
5008           );
5009
5010           $worksheet7->conditional_formatting( 'D3:D14',
5011               {
5012                   type => '3_color_scale',
5013               }
5014           );
5015
5016           $worksheet7->conditional_formatting( 'G3:G14',
5017               {
5018                   type      => '2_color_scale',
5019                   min_color => "#FF0000",
5020                   max_color => "#00FF00",
5021
5022               }
5023           );
5024
5025           $worksheet7->conditional_formatting( 'I3:I14',
5026               {
5027                   type      => '3_color_scale',
5028                   min_color => "#C5D9F1",
5029                   mid_color => "#8DB4E3",
5030                   max_color => "#538ED5",
5031               }
5032           );
5033
5034
5035           ###############################################################################
5036           #
5037           # Example 8.
5038           #
5039           $caption = 'Examples of data bars.';
5040
5041           $data = [ 1 .. 12 ];
5042
5043           $worksheet8->write( 'A1', $caption );
5044
5045           $worksheet8->write    ( 'B2', "Default data bars" );
5046           $worksheet8->write_col( 'B3', $data );
5047
5048           $worksheet8->write    ( 'D2', "Bars only" );
5049           $worksheet8->write_col( 'D3', $data );
5050
5051           $worksheet8->write    ( 'F2', "With user color" );
5052           $worksheet8->write_col( 'F3', $data );
5053
5054           $worksheet8->write    ( 'H2', "Solid bars" );
5055           $worksheet8->write_col( 'H3', $data );
5056
5057           $worksheet8->write    ( 'J2', "Right to left" );
5058           $worksheet8->write_col( 'J3', $data );
5059
5060           $data = [-1, -2, -3, -2, -1, 0, 1, 2, 3, 2, 1, 0];
5061
5062           $worksheet8->write    ( 'L2', "Excel 2010 style" );
5063           $worksheet8->write_col( 'L3', $data );
5064
5065           $worksheet8->write    ( 'N2', "Negative same as positive" );
5066           $worksheet8->write_col( 'N3', $data );
5067
5068
5069           $worksheet8->conditional_formatting( 'B3:B14',
5070               {
5071                   type      => 'data_bar'
5072               }
5073           );
5074
5075           $worksheet8->conditional_formatting( 'D3:D14',
5076               {
5077                   type     => 'data_bar',
5078                   bar_only => 1
5079               }
5080           );
5081
5082           $worksheet8->conditional_formatting( 'F3:F14',
5083               {
5084                   type      => 'data_bar',
5085                   bar_color => '#63C384'
5086               }
5087           );
5088
5089           $worksheet8->conditional_formatting( 'H3:H14',
5090               {
5091                   type      => 'data_bar',
5092                   bar_solid => 1
5093               }
5094           );
5095
5096           $worksheet8->conditional_formatting( 'J3:J14',
5097               {
5098                   type          => 'data_bar',
5099                   bar_direction => 'right'
5100               }
5101           );
5102
5103           $worksheet8->conditional_formatting( 'L3:L14',
5104               {
5105                   type          => 'data_bar',
5106                   data_bar_2010 => 1
5107               }
5108           );
5109
5110           $worksheet8->conditional_formatting( 'N3:N14',
5111               {
5112                   type                           => 'data_bar',
5113                   bar_negative_color_same        => 1,
5114                   bar_negative_border_color_same => 1
5115               }
5116           );
5117
5118
5119           ###############################################################################
5120           #
5121           # Example 9.
5122           #
5123           $caption = 'Examples of conditional formats with icon sets.';
5124
5125           $data = [
5126               [ 1, 2, 3 ],
5127               [ 1, 2, 3 ],
5128               [ 1, 2, 3 ],
5129               [ 1, 2, 3 ],
5130               [ 1, 2, 3, 4 ],
5131               [ 1, 2, 3, 4, 5 ],
5132               [ 1, 2, 3, 4, 5 ],
5133           ];
5134
5135           $worksheet9->write( 'A1', $caption );
5136           $worksheet9->write_col( 'B3', $data );
5137
5138           $worksheet9->conditional_formatting( 'B3:D3',
5139               {
5140                   type         => 'icon_set',
5141                   icon_style   => '3_traffic_lights',
5142               }
5143           );
5144
5145           $worksheet9->conditional_formatting( 'B4:D4',
5146               {
5147                   type         => 'icon_set',
5148                   icon_style   => '3_traffic_lights',
5149                   reverse_icons => 1,
5150               }
5151           );
5152
5153           $worksheet9->conditional_formatting( 'B5:D5',
5154               {
5155                   type         => 'icon_set',
5156                   icon_style   => '3_traffic_lights',
5157                   icons_only   => 1,
5158               }
5159           );
5160
5161           $worksheet9->conditional_formatting( 'B6:D6',
5162               {
5163                   type         => 'icon_set',
5164                   icon_style   => '3_arrows',
5165               }
5166           );
5167
5168           $worksheet9->conditional_formatting( 'B7:E8',
5169               {
5170                   type         => 'icon_set',
5171                   icon_style   => '4_arrows',
5172               }
5173           );
5174
5175           $worksheet9->conditional_formatting( 'B8:F8',
5176               {
5177                   type         => 'icon_set',
5178                   icon_style   => '5_arrows',
5179               }
5180           );
5181
5182
5183           $worksheet9->conditional_formatting( 'B9:F9',
5184               {
5185                   type         => 'icon_set',
5186                   icon_style   => '5_ratings',
5187               }
5188           );
5189
5190           $workbook->close();
5191
5192           __END__
5193
5194       Download this example:
5195       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/conditional_format.pl>
5196
5197   Example: data_validate.pl
5198       Example of how to add data validation and dropdown lists to an
5199       Excel::Writer::XLSX file.
5200
5201       Data validation is a feature of Excel which allows you to restrict the
5202       data that a user enters in a cell and to display help and warning
5203       messages. It also allows you to restrict input to values in a drop down
5204       list.
5205
5206       Source code for this example:
5207
5208           #!/usr/bin/perl
5209
5210           ###############################################################################
5211           #
5212           # Example of how to add data validation and dropdown lists to an
5213           # Excel::Writer::XLSX file.
5214           #
5215           # Data validation is a feature of Excel which allows you to restrict the data
5216           # that a user enters in a cell and to display help and warning messages. It
5217           # also allows you to restrict input to values in a drop down list.
5218           #
5219           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
5220           #
5221
5222           use strict;
5223           use warnings;
5224           use Excel::Writer::XLSX;
5225
5226           my $workbook  = Excel::Writer::XLSX->new( 'data_validate.xlsx' );
5227           my $worksheet = $workbook->add_worksheet();
5228
5229           # Add a format for the header cells.
5230           my $header_format = $workbook->add_format(
5231               border    => 1,
5232               bg_color  => '#C6EFCE',
5233               bold      => 1,
5234               text_wrap => 1,
5235               valign    => 'vcenter',
5236               indent    => 1,
5237           );
5238
5239           # Set up layout of the worksheet.
5240           $worksheet->set_column( 'A:A', 68 );
5241           $worksheet->set_column( 'B:B', 15 );
5242           $worksheet->set_column( 'D:D', 15 );
5243           $worksheet->set_row( 0, 36 );
5244           $worksheet->set_selection( 'B3' );
5245
5246
5247           # Write the header cells and some data that will be used in the examples.
5248           my $row = 0;
5249           my $txt;
5250           my $heading1 = 'Some examples of data validation in Excel::Writer::XLSX';
5251           my $heading2 = 'Enter values in this column';
5252           my $heading3 = 'Sample Data';
5253
5254           $worksheet->write( 'A1', $heading1, $header_format );
5255           $worksheet->write( 'B1', $heading2, $header_format );
5256           $worksheet->write( 'D1', $heading3, $header_format );
5257
5258           $worksheet->write( 'D3', [ 'Integers', 1, 10 ] );
5259           $worksheet->write( 'D4', [ 'List data', 'open', 'high', 'close' ] );
5260           $worksheet->write( 'D5', [ 'Formula', '=AND(F5=50,G5=60)', 50, 60 ] );
5261
5262
5263           #
5264           # Example 1. Limiting input to an integer in a fixed range.
5265           #
5266           $txt = 'Enter an integer between 1 and 10';
5267           $row += 2;
5268
5269           $worksheet->write( $row, 0, $txt );
5270           $worksheet->data_validation(
5271               $row, 1,
5272               {
5273                   validate => 'integer',
5274                   criteria => 'between',
5275                   minimum  => 1,
5276                   maximum  => 10,
5277               }
5278           );
5279
5280
5281           #
5282           # Example 2. Limiting input to an integer outside a fixed range.
5283           #
5284           $txt = 'Enter an integer that is not between 1 and 10 (using cell references)';
5285           $row += 2;
5286
5287           $worksheet->write( $row, 0, $txt );
5288           $worksheet->data_validation(
5289               $row, 1,
5290               {
5291                   validate => 'integer',
5292                   criteria => 'not between',
5293                   minimum  => '=E3',
5294                   maximum  => '=F3',
5295               }
5296           );
5297
5298
5299           #
5300           # Example 3. Limiting input to an integer greater than a fixed value.
5301           #
5302           $txt = 'Enter an integer greater than 0';
5303           $row += 2;
5304
5305           $worksheet->write( $row, 0, $txt );
5306           $worksheet->data_validation(
5307               $row, 1,
5308               {
5309                   validate => 'integer',
5310                   criteria => '>',
5311                   value    => 0,
5312               }
5313           );
5314
5315
5316           #
5317           # Example 4. Limiting input to an integer less than a fixed value.
5318           #
5319           $txt = 'Enter an integer less than 10';
5320           $row += 2;
5321
5322           $worksheet->write( $row, 0, $txt );
5323           $worksheet->data_validation(
5324               $row, 1,
5325               {
5326                   validate => 'integer',
5327                   criteria => '<',
5328                   value    => 10,
5329               }
5330           );
5331
5332
5333           #
5334           # Example 5. Limiting input to a decimal in a fixed range.
5335           #
5336           $txt = 'Enter a decimal between 0.1 and 0.5';
5337           $row += 2;
5338
5339           $worksheet->write( $row, 0, $txt );
5340           $worksheet->data_validation(
5341               $row, 1,
5342               {
5343                   validate => 'decimal',
5344                   criteria => 'between',
5345                   minimum  => 0.1,
5346                   maximum  => 0.5,
5347               }
5348           );
5349
5350
5351           #
5352           # Example 6. Limiting input to a value in a dropdown list.
5353           #
5354           $txt = 'Select a value from a drop down list';
5355           $row += 2;
5356
5357           $worksheet->write( $row, 0, $txt );
5358           $worksheet->data_validation(
5359               $row, 1,
5360               {
5361                   validate => 'list',
5362                   source   => [ 'open', 'high', 'close' ],
5363               }
5364           );
5365
5366
5367           #
5368           # Example 6. Limiting input to a value in a dropdown list.
5369           #
5370           $txt = 'Select a value from a drop down list (using a cell range)';
5371           $row += 2;
5372
5373           $worksheet->write( $row, 0, $txt );
5374           $worksheet->data_validation(
5375               $row, 1,
5376               {
5377                   validate => 'list',
5378                   source   => '=$E$4:$G$4',
5379               }
5380           );
5381
5382
5383           #
5384           # Example 7. Limiting input to a date in a fixed range.
5385           #
5386           $txt = 'Enter a date between 1/1/2008 and 12/12/2008';
5387           $row += 2;
5388
5389           $worksheet->write( $row, 0, $txt );
5390           $worksheet->data_validation(
5391               $row, 1,
5392               {
5393                   validate => 'date',
5394                   criteria => 'between',
5395                   minimum  => '2008-01-01T',
5396                   maximum  => '2008-12-12T',
5397               }
5398           );
5399
5400
5401           #
5402           # Example 8. Limiting input to a time in a fixed range.
5403           #
5404           $txt = 'Enter a time between 6:00 and 12:00';
5405           $row += 2;
5406
5407           $worksheet->write( $row, 0, $txt );
5408           $worksheet->data_validation(
5409               $row, 1,
5410               {
5411                   validate => 'time',
5412                   criteria => 'between',
5413                   minimum  => 'T06:00',
5414                   maximum  => 'T12:00',
5415               }
5416           );
5417
5418
5419           #
5420           # Example 9. Limiting input to a string greater than a fixed length.
5421           #
5422           $txt = 'Enter a string longer than 3 characters';
5423           $row += 2;
5424
5425           $worksheet->write( $row, 0, $txt );
5426           $worksheet->data_validation(
5427               $row, 1,
5428               {
5429                   validate => 'length',
5430                   criteria => '>',
5431                   value    => 3,
5432               }
5433           );
5434
5435
5436           #
5437           # Example 10. Limiting input based on a formula.
5438           #
5439           $txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"';
5440           $row += 2;
5441
5442           $worksheet->write( $row, 0, $txt );
5443           $worksheet->data_validation(
5444               $row, 1,
5445               {
5446                   validate => 'custom',
5447                   value    => '=AND(F5=50,G5=60)',
5448               }
5449           );
5450
5451
5452           #
5453           # Example 11. Displaying and modify data validation messages.
5454           #
5455           $txt = 'Displays a message when you select the cell';
5456           $row += 2;
5457
5458           $worksheet->write( $row, 0, $txt );
5459           $worksheet->data_validation(
5460               $row, 1,
5461               {
5462                   validate      => 'integer',
5463                   criteria      => 'between',
5464                   minimum       => 1,
5465                   maximum       => 100,
5466                   input_title   => 'Enter an integer:',
5467                   input_message => 'between 1 and 100',
5468               }
5469           );
5470
5471
5472           #
5473           # Example 12. Displaying and modify data validation messages.
5474           #
5475           $txt = 'Display a custom error message when integer isn\'t between 1 and 100';
5476           $row += 2;
5477
5478           $worksheet->write( $row, 0, $txt );
5479           $worksheet->data_validation(
5480               $row, 1,
5481               {
5482                   validate      => 'integer',
5483                   criteria      => 'between',
5484                   minimum       => 1,
5485                   maximum       => 100,
5486                   input_title   => 'Enter an integer:',
5487                   input_message => 'between 1 and 100',
5488                   error_title   => 'Input value is not valid!',
5489                   error_message => 'It should be an integer between 1 and 100',
5490               }
5491           );
5492
5493
5494           #
5495           # Example 13. Displaying and modify data validation messages.
5496           #
5497           $txt =
5498             'Display a custom information message when integer isn\'t between 1 and 100';
5499           $row += 2;
5500
5501           $worksheet->write( $row, 0, $txt );
5502           $worksheet->data_validation(
5503               $row, 1,
5504               {
5505                   validate      => 'integer',
5506                   criteria      => 'between',
5507                   minimum       => 1,
5508                   maximum       => 100,
5509                   input_title   => 'Enter an integer:',
5510                   input_message => 'between 1 and 100',
5511                   error_title   => 'Input value is not valid!',
5512                   error_message => 'It should be an integer between 1 and 100',
5513                   error_type    => 'information',
5514               }
5515           );
5516
5517           $workbook->close();
5518
5519           __END__
5520
5521       Download this example:
5522       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/data_validate.pl>
5523
5524   Example: date_time.pl
5525       Excel::Writer::XLSX example of writing dates and times using the
5526       write_date_time() Worksheet method.
5527
5528       Source code for this example:
5529
5530           #!/usr/bin/perl
5531
5532           ###############################################################################
5533           #
5534           # Excel::Writer::XLSX example of writing dates and times using the
5535           # write_date_time() Worksheet method.
5536           #
5537           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
5538           #
5539
5540           use strict;
5541           use warnings;
5542           use Excel::Writer::XLSX;
5543
5544
5545           # Create a new workbook and add a worksheet
5546           my $workbook  = Excel::Writer::XLSX->new( 'date_time.xlsx' );
5547           my $worksheet = $workbook->add_worksheet();
5548           my $bold      = $workbook->add_format( bold => 1 );
5549
5550
5551           # Expand the first columns so that the date is visible.
5552           $worksheet->set_column( "A:B", 30 );
5553
5554
5555           # Write the column headers
5556           $worksheet->write( 'A1', 'Formatted date', $bold );
5557           $worksheet->write( 'B1', 'Format',         $bold );
5558
5559
5560           # Examples date and time formats. In the output file compare how changing
5561           # the format codes change the appearance of the date.
5562           #
5563           my @date_formats = (
5564               'dd/mm/yy',
5565               'mm/dd/yy',
5566               '',
5567               'd mm yy',
5568               'dd mm yy',
5569               '',
5570               'dd m yy',
5571               'dd mm yy',
5572               'dd mmm yy',
5573               'dd mmmm yy',
5574               '',
5575               'dd mm y',
5576               'dd mm yyy',
5577               'dd mm yyyy',
5578               '',
5579               'd mmmm yyyy',
5580               '',
5581               'dd/mm/yy',
5582               'dd/mm/yy hh:mm',
5583               'dd/mm/yy hh:mm:ss',
5584               'dd/mm/yy hh:mm:ss.000',
5585               '',
5586               'hh:mm',
5587               'hh:mm:ss',
5588               'hh:mm:ss.000',
5589           );
5590
5591
5592           # Write the same date and time using each of the above formats. The empty
5593           # string formats create a blank line to make the example clearer.
5594           #
5595           my $row = 0;
5596           for my $date_format ( @date_formats ) {
5597               $row++;
5598               next if $date_format eq '';
5599
5600               # Create a format for the date or time.
5601               my $format = $workbook->add_format(
5602                   num_format => $date_format,
5603                   align      => 'left'
5604               );
5605
5606               # Write the same date using different formats.
5607               $worksheet->write_date_time( $row, 0, '2004-08-01T12:30:45.123', $format );
5608               $worksheet->write( $row, 1, $date_format );
5609           }
5610
5611
5612           # The following is an example of an invalid date. It is written as a string
5613           # instead of a number. This is also Excel's default behaviour.
5614           #
5615           $row += 2;
5616           $worksheet->write_date_time( $row, 0, '2004-13-01T12:30:45.123' );
5617           $worksheet->write( $row, 1, 'Invalid date. Written as string.', $bold );
5618
5619           $workbook->close();
5620
5621           __END__
5622
5623       Download this example:
5624       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/date_time.pl>
5625
5626   Example: defined_name.pl
5627       Example of how to create defined names in an Excel::Writer::XLSX file.
5628
5629       This method is used to define a user friendly name to represent a
5630       value, a single cell or a range of cells in a workbook.
5631
5632       Source code for this example:
5633
5634           #!/usr/bin/perl
5635
5636           ##############################################################################
5637           #
5638           # Example of how to create defined names in an Excel::Writer::XLSX file.
5639           #
5640           # This method is used to define a user friendly name to represent a value,
5641           # a single cell or a range of cells in a workbook.
5642           #
5643           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
5644           #
5645
5646           use strict;
5647           use warnings;
5648           use Excel::Writer::XLSX;
5649
5650           my $workbook   = Excel::Writer::XLSX->new( 'defined_name.xlsx' );
5651           my $worksheet1 = $workbook->add_worksheet();
5652           my $worksheet2 = $workbook->add_worksheet();
5653
5654           # Define some global/workbook names.
5655           $workbook->define_name( 'Exchange_rate', '=0.96' );
5656           $workbook->define_name( 'Sales',         '=Sheet1!$G$1:$H$10' );
5657
5658           # Define a local/worksheet name.
5659           $workbook->define_name( 'Sheet2!Sales', '=Sheet2!$G$1:$G$10' );
5660
5661           # Write some text in the file and one of the defined names in a formula.
5662           for my $worksheet ( $workbook->sheets() ) {
5663               $worksheet->set_column( 'A:A', 45 );
5664               $worksheet->write( 'A1', 'This worksheet contains some defined names.' );
5665               $worksheet->write( 'A2', 'See Formulas -> Name Manager above.' );
5666               $worksheet->write( 'A3', 'Example formula in cell B3 ->' );
5667
5668               $worksheet->write( 'B3', '=Exchange_rate' );
5669           }
5670
5671           $workbook->close();
5672
5673           __END__
5674
5675       Download this example:
5676       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/defined_name.pl>
5677
5678   Example: diag_border.pl
5679       A simple formatting example that demonstrates how to add a diagonal
5680       cell border with Excel::Writer::XLSX
5681
5682       Source code for this example:
5683
5684           #!/usr/bin/perl -w
5685
5686           ##############################################################################
5687           #
5688           # A simple formatting example that demonstrates how to add a diagonal cell
5689           # border with Excel::Writer::XLSX
5690           #
5691           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
5692           #
5693
5694           use strict;
5695           use Excel::Writer::XLSX;
5696
5697
5698           my $workbook  = Excel::Writer::XLSX->new( 'diag_border.xlsx' );
5699           my $worksheet = $workbook->add_worksheet();
5700
5701
5702           my $format1 = $workbook->add_format( diag_type => 1 );
5703
5704           my $format2 = $workbook->add_format( diag_type => 2 );
5705
5706           my $format3 = $workbook->add_format( diag_type => 3 );
5707
5708           my $format4 = $workbook->add_format(
5709               diag_type   => 3,
5710               diag_border => 7,
5711               diag_color  => 'red',
5712           );
5713
5714
5715           $worksheet->write( 'B3',  'Text', $format1 );
5716           $worksheet->write( 'B6',  'Text', $format2 );
5717           $worksheet->write( 'B9',  'Text', $format3 );
5718           $worksheet->write( 'B12', 'Text', $format4 );
5719
5720           $workbook->close();
5721
5722           __END__
5723
5724       Download this example:
5725       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/diag_border.pl>
5726
5727   Example: dynamic_arrays.pl
5728       An example of how to use the Excel::Writer::XLSX module to write
5729       functions that create dynamic arrays. These functions are new to Excel
5730       365. The examples mirror the examples in the Excel documentation on
5731       these functions.
5732
5733           #!/usr/bin/perl -w
5734
5735           #######################################################################
5736           #
5737           # An example of how to use the Excel::Writer::XLSX module to write functions
5738           # that create dynamic arrays. These functions are new to Excel 365. The
5739           # examples mirror the examples in the Excel documentation on these functions.
5740           #
5741           # Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
5742           #
5743
5744           use strict;
5745           use Excel::Writer::XLSX;
5746
5747           sub write_worksheet_data;
5748
5749           # Create a new workbook called simple.xls and add a worksheet
5750           my $workbook    = Excel::Writer::XLSX->new('dynamic_arrays.xlsx');
5751           my $worksheet1  = $workbook->add_worksheet('Filter');
5752           my $worksheet2  = $workbook->add_worksheet('Unique');
5753           my $worksheet3  = $workbook->add_worksheet('Sort');
5754           my $worksheet4  = $workbook->add_worksheet('Sortby');
5755           my $worksheet5  = $workbook->add_worksheet('Xlookup');
5756           my $worksheet6  = $workbook->add_worksheet('Xmatch');
5757           my $worksheet7  = $workbook->add_worksheet('Randarray');
5758           my $worksheet8  = $workbook->add_worksheet('Sequence');
5759           my $worksheet9  = $workbook->add_worksheet('Spill ranges');
5760           my $worksheet10 = $workbook->add_worksheet('Older functions');
5761           my $header1     = $workbook->add_format(fg_color => '#74AC4C', color => '#FFFFFF');
5762           my $header2     = $workbook->add_format(fg_color => '#528FD3', color => '#FFFFFF');
5763
5764
5765           #
5766           # Example of using the FILTER() function.
5767           #
5768           $worksheet1->write('F2', '=FILTER(A1:D17,C1:C17=K2)');
5769
5770
5771           # Write the data the function will work on.
5772           $worksheet1->write('K1', 'Product',   $header2);
5773           $worksheet1->write('K2', 'Apple');
5774           $worksheet1->write('F1', 'Region',    $header2);
5775           $worksheet1->write('G1', 'Sales Rep', $header2);
5776           $worksheet1->write('H1', 'Product',   $header2);
5777           $worksheet1->write('I1', 'Units',     $header2);
5778
5779           write_worksheet_data($worksheet1, $header1);
5780           $worksheet1->set_column_pixels('E:E', 20);
5781           $worksheet1->set_column_pixels('J:J', 20);
5782
5783           #
5784           # Example of using the UNIQUE() function.
5785           #
5786           $worksheet2->write('F2', '=UNIQUE(B2:B17)');
5787
5788
5789           # A more complex example combining SORT and UNIQUE.
5790           $worksheet2->write('H2', '=SORT(UNIQUE(B2:B17))');
5791
5792           # Write the data the function will work on.
5793           $worksheet2->write('F1', 'Sales Rep', $header2);
5794           $worksheet2->write('H1', 'Sales Rep', $header2);
5795
5796           write_worksheet_data($worksheet2, $header1);
5797           $worksheet2->set_column_pixels('E:E', 20);
5798           $worksheet2->set_column_pixels('G:G', 20);
5799
5800
5801           #
5802           # Example of using the SORT() function.
5803           #
5804           $worksheet3->write('F2', '=SORT(B2:B17)');
5805
5806           # A more complex example combining SORT and FILTER.
5807           $worksheet3->write('H2', '=SORT(FILTER(C2:D17,D2:D17>5000,""),2,1)');
5808
5809
5810           # Write the data the function will work on.
5811           $worksheet3->write('F1', 'Sales Rep', $header2);
5812           $worksheet3->write('H1', 'Product',   $header2);
5813           $worksheet3->write('I1', 'Units',     $header2);
5814
5815           write_worksheet_data($worksheet3, $header1);
5816           $worksheet3->set_column_pixels('E:E', 20);
5817           $worksheet3->set_column_pixels('G:G', 20);
5818
5819
5820           #
5821           # Example of using the SORTBY() function.
5822           #
5823           $worksheet4->write('D2', '=SORTBY(A2:B9,B2:B9)');
5824
5825
5826           # Write the data the function will work on.
5827           $worksheet4->write('A1', 'Name', $header1);
5828           $worksheet4->write('B1', 'Age',  $header1);
5829
5830           $worksheet4->write('A2', 'Tom');
5831           $worksheet4->write('A3', 'Fred');
5832           $worksheet4->write('A4', 'Amy');
5833           $worksheet4->write('A5', 'Sal');
5834           $worksheet4->write('A6', 'Fritz');
5835           $worksheet4->write('A7', 'Srivan');
5836           $worksheet4->write('A8', 'Xi');
5837           $worksheet4->write('A9', 'Hector');
5838
5839           $worksheet4->write('B2', 52);
5840           $worksheet4->write('B3', 65);
5841           $worksheet4->write('B4', 22);
5842           $worksheet4->write('B5', 73);
5843           $worksheet4->write('B6', 19);
5844           $worksheet4->write('B7', 39);
5845           $worksheet4->write('B8', 19);
5846           $worksheet4->write('B9', 66);
5847
5848           $worksheet4->write('D1', 'Name', $header2);
5849           $worksheet4->write('E1', 'Age',  $header2);
5850
5851           $worksheet4->set_column_pixels('C:C', 20);
5852
5853
5854           #
5855           # Example of using the XLOOKUP() function.
5856           #
5857           $worksheet5->write('F1', '=XLOOKUP(E1,A2:A9,C2:C9)');
5858
5859
5860           # Write the data the function will work on.
5861           $worksheet5->write('A1', 'Country', $header1);
5862           $worksheet5->write('B1', 'Abr',     $header1);
5863           $worksheet5->write('C1', 'Prefix',  $header1);
5864
5865           $worksheet5->write('A2', 'China');
5866           $worksheet5->write('A3', 'India');
5867           $worksheet5->write('A4', 'United States');
5868           $worksheet5->write('A5', 'Indonesia');
5869           $worksheet5->write('A6', 'Brazil');
5870           $worksheet5->write('A7', 'Pakistan');
5871           $worksheet5->write('A8', 'Nigeria');
5872           $worksheet5->write('A9', 'Bangladesh');
5873
5874           $worksheet5->write('B2', 'CN');
5875           $worksheet5->write('B3', 'IN');
5876           $worksheet5->write('B4', 'US');
5877           $worksheet5->write('B5', 'ID');
5878           $worksheet5->write('B6', 'BR');
5879           $worksheet5->write('B7', 'PK');
5880           $worksheet5->write('B8', 'NG');
5881           $worksheet5->write('B9', 'BD');
5882
5883           $worksheet5->write('C2', 86);
5884           $worksheet5->write('C3', 91);
5885           $worksheet5->write('C4', 1);
5886           $worksheet5->write('C5', 62);
5887           $worksheet5->write('C6', 55);
5888           $worksheet5->write('C7', 92);
5889           $worksheet5->write('C8', 234);
5890           $worksheet5->write('C9', 880);
5891
5892           $worksheet5->write('E1', 'Brazil', $header2);
5893
5894           $worksheet5->set_column_pixels('A:A', 100);
5895           $worksheet5->set_column_pixels('D:D', 20);
5896
5897
5898           #
5899           # Example of using the XMATCH() function.
5900           #
5901           $worksheet6->write('D2', '=XMATCH(C2,A2:A6)');
5902
5903
5904           # Write the data the function will work on.
5905           $worksheet6->write('A1', 'Product', $header1);
5906
5907           $worksheet6->write('A2', 'Apple');
5908           $worksheet6->write('A3', 'Grape');
5909           $worksheet6->write('A4', 'Pear');
5910           $worksheet6->write('A5', 'Banana');
5911           $worksheet6->write('A6', 'Cherry');
5912
5913           $worksheet6->write('C1', 'Product' , $header2);
5914           $worksheet6->write('D1', 'Position', $header2);
5915           $worksheet6->write('C2', 'Grape');
5916
5917           $worksheet6->set_column_pixels('B:B', 20);
5918
5919
5920           #
5921           # Example of using the RANDARRAY() function.
5922           #
5923           $worksheet7->write('A1', '=RANDARRAY(5,3,1,100, TRUE)');
5924
5925
5926           #
5927           # Example of using the SEQUENCE() function.
5928           #
5929           $worksheet8->write('A1', '=SEQUENCE(4,5)');
5930
5931
5932           #
5933           # Example of using the Spill range operator.
5934           #
5935           $worksheet9->write('H2', '=ANCHORARRAY(F2)');
5936
5937           $worksheet9->write('J2', '=COUNTA(ANCHORARRAY(F2))');
5938
5939
5940           # Write the data the to work on.
5941           $worksheet9->write( 'F2', '=UNIQUE(B2:B17)');
5942           $worksheet9->write('F1', 'Unique', $header2);
5943           $worksheet9->write('H1', 'Spill', $header2);
5944           $worksheet9->write('J1', 'Spill', $header2);
5945
5946           write_worksheet_data($worksheet9, $header1);
5947           $worksheet9->set_column_pixels('E:E', 20);
5948           $worksheet9->set_column_pixels('G:G', 20);
5949           $worksheet9->set_column_pixels('I:I', 20);
5950
5951           #
5952           # Example of using dynamic ranges with older Excel functions.
5953           #
5954           $worksheet10->write_dynamic_array_formula('B1:B3', '=LEN(A1:A3)');
5955
5956           # Write the data the to work on.
5957           $worksheet10->write('A1', 'Foo');
5958           $worksheet10->write('A2', 'Food');
5959           $worksheet10->write('A3', 'Frood');
5960
5961
5962           # Close the workbook.
5963           $workbook->close();
5964
5965           # Utility function to write the data some of the functions work on.
5966           sub write_worksheet_data {
5967               my $worksheet = shift;
5968               my $header    = shift;
5969
5970               $worksheet->write('A1', 'Region',    $header);
5971               $worksheet->write('B1', 'Sales Rep', $header);
5972               $worksheet->write('C1', 'Product',   $header);
5973               $worksheet->write('D1', 'Units',     $header);
5974
5975               my @data = (
5976                   ['East',  'Tom',    'Apple',  6380],
5977                   ['West',  'Fred',   'Grape',  5619],
5978                   ['North', 'Amy',    'Pear',   4565],
5979                   ['South', 'Sal',    'Banana', 5323],
5980                   ['East',  'Fritz',  'Apple',  4394],
5981                   ['West',  'Sravan', 'Grape',  7195],
5982                   ['North', 'Xi',     'Pear',   5231],
5983                   ['South', 'Hector', 'Banana', 2427],
5984                   ['East',  'Tom',    'Banana', 4213],
5985                   ['West',  'Fred',   'Pear',   3239],
5986                   ['North', 'Amy',    'Grape',  6520],
5987                   ['South', 'Sal',    'Apple',  1310],
5988                   ['East',  'Fritz',  'Banana', 6274],
5989                   ['West',  'Sravan', 'Pear',   4894],
5990                   ['North', 'Xi',     'Grape',  7580],
5991                   ['South', 'Hector', 'Apple',  9814],
5992              );
5993
5994               my $row_num = 1;
5995               for my $row_data (@data) {
5996                   $worksheet->write_row($row_num, 0, $row_data);
5997                   $row_num++;
5998               }
5999           }
6000
6001
6002           __END__
6003
6004       Download this example:
6005       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/dynamic_arrays.pl>
6006
6007   Example: filehandle.pl
6008       Example of using Excel::Writer::XLSX to write Excel files to different
6009       filehandles.
6010
6011       Source code for this example:
6012
6013           #!/usr/bin/perl
6014
6015           ###############################################################################
6016           #
6017           # Example of using Excel::Writer::XLSX to write Excel files to different
6018           # filehandles.
6019           #
6020           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6021           #
6022
6023           use strict;
6024           use warnings;
6025           use Excel::Writer::XLSX;
6026           use IO::Scalar;
6027
6028
6029           ###############################################################################
6030           #
6031           # Example 1. This demonstrates the standard way of creating an Excel file by
6032           # specifying a file name.
6033           #
6034
6035           my $workbook1  = Excel::Writer::XLSX->new( 'fh_01.xlsx' );
6036           my $worksheet1 = $workbook1->add_worksheet();
6037
6038           $worksheet1->write( 0, 0, 'Hi Excel 1' );
6039
6040           $workbook1->close();
6041
6042
6043           ###############################################################################
6044           #
6045           # Example 2. Write an Excel file to an existing filehandle.
6046           #
6047
6048           open TEST, '>', 'fh_02.xlsx' or die "Couldn't open file: $!";
6049           binmode TEST;   # Always do this regardless of whether the platform requires it.
6050
6051           my $workbook2  = Excel::Writer::XLSX->new( \*TEST );
6052           my $worksheet2 = $workbook2->add_worksheet();
6053
6054           $worksheet2->write( 0, 0, 'Hi Excel 2' );
6055
6056           $workbook2->close();
6057
6058           ###############################################################################
6059           #
6060           # Example 3. Write an Excel file to an existing OO style filehandle.
6061           #
6062
6063           my $fh = FileHandle->new( '> fh_03.xlsx' ) or die "Couldn't open file: $!";
6064
6065           binmode( $fh );
6066
6067           my $workbook3  = Excel::Writer::XLSX->new( $fh );
6068           my $worksheet3 = $workbook3->add_worksheet();
6069
6070           $worksheet3->write( 0, 0, 'Hi Excel 3' );
6071
6072           $workbook3->close();
6073
6074
6075           ###############################################################################
6076           #
6077           # Example 4. Write an Excel file to a string via IO::Scalar. Please refer to
6078           # the IO::Scalar documentation for further details.
6079           #
6080
6081           my $xlsx_str;
6082
6083           tie *XLSX, 'IO::Scalar', \$xlsx_str;
6084
6085           my $workbook4  = Excel::Writer::XLSX->new( \*XLSX );
6086           my $worksheet4 = $workbook4->add_worksheet();
6087
6088           $worksheet4->write( 0, 0, 'Hi Excel 4' );
6089           $workbook4->close();    # This is required before we use the scalar
6090
6091
6092           # The Excel file is now in $xlsx_str. As a demonstration, print it to a file.
6093           open TMP, '>', 'fh_04.xlsx' or die "Couldn't open file: $!";
6094           binmode TMP;
6095           print TMP $xlsx_str;
6096           close TMP;
6097
6098
6099           ###############################################################################
6100           #
6101           # Example 5. Write an Excel file to a string via IO::Scalar's newer interface.
6102           # Please refer to the IO::Scalar documentation for further details.
6103           #
6104           my $xlsx_str2;
6105
6106           my $fh5 = IO::Scalar->new( \$xlsx_str2 );
6107
6108           my $workbook5  = Excel::Writer::XLSX->new( $fh5 );
6109           my $worksheet5 = $workbook5->add_worksheet();
6110
6111           $worksheet5->write( 0, 0, 'Hi Excel 5' );
6112           $workbook5->close();    # This is required before we use the scalar
6113
6114           # The Excel file is now in $xlsx_str. As a demonstration, print it to a file.
6115           open TMP, '>', 'fh_05.xlsx' or die "Couldn't open file: $!";
6116           binmode TMP;
6117           print TMP $xlsx_str2;
6118           close TMP;
6119
6120           __END__
6121
6122       Download this example:
6123       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/filehandle.pl>
6124
6125   Example: headers.pl
6126       This program shows several examples of how to set up headers and
6127       footers with Excel::Writer::XLSX.
6128
6129       The control characters used in the header/footer strings are:
6130
6131           Control             Category            Description
6132           =======             ========            ===========
6133           &L                  Justification       Left
6134           &C                                      Center
6135           &R                                      Right
6136
6137           &P                  Information         Page number
6138           &N                                      Total number of pages
6139           &D                                      Date
6140           &T                                      Time
6141           &F                                      File name
6142           &A                                      Worksheet name
6143
6144           &fontsize           Font                Font size
6145           &"font,style"                           Font name and style
6146           &U                                      Single underline
6147           &E                                      Double underline
6148           &S                                      Strikethrough
6149           &X                                      Superscript
6150           &Y                                      Subscript
6151
6152           &[Picture]          Images              Image placeholder
6153           &G                                      Same as &[Picture]
6154
6155           &&                  Miscellaneous       Literal ampersand &
6156
6157       See the main Excel::Writer::XLSX documentation for more information.
6158
6159       Source code for this example:
6160
6161           #!/usr/bin/perl
6162
6163           ######################################################################
6164           #
6165           # This program shows several examples of how to set up headers and
6166           # footers with Excel::Writer::XLSX.
6167           #
6168           # The control characters used in the header/footer strings are:
6169           #
6170           #     Control             Category            Description
6171           #     =======             ========            ===========
6172           #     &L                  Justification       Left
6173           #     &C                                      Center
6174           #     &R                                      Right
6175           #
6176           #     &P                  Information         Page number
6177           #     &N                                      Total number of pages
6178           #     &D                                      Date
6179           #     &T                                      Time
6180           #     &F                                      File name
6181           #     &A                                      Worksheet name
6182           #
6183           #     &fontsize           Font                Font size
6184           #     &"font,style"                           Font name and style
6185           #     &U                                      Single underline
6186           #     &E                                      Double underline
6187           #     &S                                      Strikethrough
6188           #     &X                                      Superscript
6189           #     &Y                                      Subscript
6190           #
6191           #     &[Picture]          Images              Image placeholder
6192           #     &G                                      Same as &[Picture]
6193           #
6194           #     &&                  Miscellaneous       Literal ampersand &
6195           #
6196           # See the main Excel::Writer::XLSX documentation for more information.
6197           #
6198           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6199           #
6200
6201
6202           use strict;
6203           use warnings;
6204           use Excel::Writer::XLSX;
6205
6206           my $workbook = Excel::Writer::XLSX->new( 'headers.xlsx' );
6207           my $preview  = 'Select Print Preview to see the header and footer';
6208
6209
6210           ######################################################################
6211           #
6212           # A simple example to start
6213           #
6214           my $worksheet1 = $workbook->add_worksheet( 'Simple' );
6215           my $header1    = '&CHere is some centred text.';
6216           my $footer1    = '&LHere is some left aligned text.';
6217
6218           $worksheet1->set_header( $header1 );
6219           $worksheet1->set_footer( $footer1 );
6220
6221           $worksheet1->set_column( 'A:A', 50 );
6222           $worksheet1->write( 'A1', $preview );
6223
6224
6225           ######################################################################
6226           #
6227           # A simple example to start
6228           #
6229           my $worksheet2 = $workbook->add_worksheet( 'Image' );
6230           my $header2    = '&L&[Picture]';
6231
6232           # Adjust the page top margin to allow space for the header image.
6233           $worksheet2->set_margin_top(1.75);
6234
6235           $worksheet2->set_header( $header2, 0.3, {image_left => 'republic.png'});
6236
6237           $worksheet2->set_column( 'A:A', 50 );
6238           $worksheet2->write( 'A1', $preview );
6239
6240
6241           ######################################################################
6242           #
6243           # This is an example of some of the header/footer variables.
6244           #
6245           my $worksheet3 = $workbook->add_worksheet( 'Variables' );
6246           my $header3    = '&LPage &P of &N' . '&CFilename: &F' . '&RSheetname: &A';
6247           my $footer3    = '&LCurrent date: &D' . '&RCurrent time: &T';
6248
6249           $worksheet3->set_header( $header3 );
6250           $worksheet3->set_footer( $footer3 );
6251
6252           $worksheet3->set_column( 'A:A', 50 );
6253           $worksheet3->write( 'A1',  $preview );
6254           $worksheet3->write( 'A21', 'Next sheet' );
6255           $worksheet3->set_h_pagebreaks( 20 );
6256
6257
6258           ######################################################################
6259           #
6260           # This example shows how to use more than one font
6261           #
6262           my $worksheet4 = $workbook->add_worksheet( 'Mixed fonts' );
6263           my $header4    = q(&C&"Courier New,Bold"Hello &"Arial,Italic"World);
6264           my $footer4    = q(&C&"Symbol"e&"Arial" = mc&X2);
6265
6266           $worksheet4->set_header( $header4 );
6267           $worksheet4->set_footer( $footer4 );
6268
6269           $worksheet4->set_column( 'A:A', 50 );
6270           $worksheet4->write( 'A1', $preview );
6271
6272
6273           ######################################################################
6274           #
6275           # Example of line wrapping
6276           #
6277           my $worksheet5 = $workbook->add_worksheet( 'Word wrap' );
6278           my $header5    = "&CHeading 1\nHeading 2";
6279
6280           $worksheet5->set_header( $header5 );
6281
6282           $worksheet5->set_column( 'A:A', 50 );
6283           $worksheet5->write( 'A1', $preview );
6284
6285
6286           ######################################################################
6287           #
6288           # Example of inserting a literal ampersand &
6289           #
6290           my $worksheet6 = $workbook->add_worksheet( 'Ampersand' );
6291           my $header6    = '&CCuriouser && Curiouser - Attorneys at Law';
6292
6293           $worksheet6->set_header( $header6 );
6294
6295           $worksheet6->set_column( 'A:A', 50 );
6296           $worksheet6->write( 'A1', $preview );
6297
6298           $workbook->close();
6299
6300           __END__
6301
6302       Download this example:
6303       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/headers.pl>
6304
6305   Example: hide_row_col.pl
6306       Example of how to hide rows and columns in Excel::Writer::XLSX. In
6307       order to hide rows without setting each one, (of approximately 1
6308       million rows), Excel uses an optimisation to hide all rows that don't
6309       have data.
6310
6311       Source code for this example:
6312
6313           #!/usr/bin/perl
6314
6315           ###############################################################################
6316           #
6317           # Example of how to hide rows and columns in Excel::Writer::XLSX. In order to
6318           # hide rows without setting each one, (of approximately 1 million rows),
6319           # Excel uses an optimisation to hide all rows that don't have data.
6320           #
6321           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6322           #
6323
6324           use strict;
6325           use warnings;
6326           use Excel::Writer::XLSX;
6327
6328           my $workbook  = Excel::Writer::XLSX->new( 'hide_row_col.xlsx' );
6329           my $worksheet = $workbook->add_worksheet();
6330
6331
6332           # Write some data.
6333           $worksheet->write( 'D1', 'Some hidden columns.' );
6334           $worksheet->write( 'A8', 'Some hidden rows.' );
6335
6336           # Hide all rows without data.
6337           $worksheet->set_default_row( undef, 1 );
6338
6339           # Set emptys row that we do want to display. All other will be hidden.
6340           for my $row (1 .. 6) {
6341               $worksheet->set_row( $row, 15 );
6342           }
6343
6344           # Hide a range of columns.
6345           $worksheet->set_column( 'G:XFD', undef, undef, 1);
6346
6347           $workbook->close();
6348
6349           __END__
6350
6351       Download this example:
6352       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/hide_row_col.pl>
6353
6354   Example: hide_sheet.pl
6355       Example of how to hide a worksheet with Excel::Writer::XLSX.
6356
6357       Source code for this example:
6358
6359           #!/usr/bin/perl
6360
6361           #######################################################################
6362           #
6363           # Example of how to hide a worksheet with Excel::Writer::XLSX.
6364           #
6365           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6366           #
6367
6368           use strict;
6369           use warnings;
6370           use Excel::Writer::XLSX;
6371
6372           my $workbook   = Excel::Writer::XLSX->new( 'hide_sheet.xlsx' );
6373           my $worksheet1 = $workbook->add_worksheet();
6374           my $worksheet2 = $workbook->add_worksheet();
6375           my $worksheet3 = $workbook->add_worksheet();
6376
6377           $worksheet1->set_column( 'A:A', 30 );
6378           $worksheet2->set_column( 'A:A', 30 );
6379           $worksheet3->set_column( 'A:A', 30 );
6380
6381           # Sheet2 won't be visible until it is unhidden in Excel.
6382           $worksheet2->hide();
6383
6384           $worksheet1->write( 0, 0, 'Sheet2 is hidden' );
6385           $worksheet2->write( 0, 0, "Now it's my turn to find you." );
6386           $worksheet3->write( 0, 0, 'Sheet2 is hidden' );
6387
6388           $workbook->close();
6389
6390           __END__
6391
6392       Download this example:
6393       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/hide_sheet.pl>
6394
6395   Example: hyperlink1.pl
6396       Example of how to use the Excel::Writer::XLSX module to write
6397       hyperlinks
6398
6399       See also hyperlink2.pl for worksheet URL examples.
6400
6401       Source code for this example:
6402
6403           #!/usr/bin/perl
6404
6405           ###############################################################################
6406           #
6407           # Example of how to use the Excel::Writer::XLSX module to write hyperlinks
6408           #
6409           # See also hyperlink2.pl for worksheet URL examples.
6410           #
6411           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6412           #
6413
6414           use strict;
6415           use warnings;
6416           use Excel::Writer::XLSX;
6417
6418           # Create a new workbook and add a worksheet
6419           my $workbook = Excel::Writer::XLSX->new( 'hyperlink.xlsx' );
6420
6421
6422           my $worksheet = $workbook->add_worksheet( 'Hyperlinks' );
6423
6424           # Format the first column
6425           $worksheet->set_column( 'A:A', 30 );
6426           $worksheet->set_selection( 'B1' );
6427
6428           # Add a user defined hyperlink format.
6429           my $red_format = $workbook->add_format(
6430               color     => 'red',
6431               bold      => 1,
6432               underline => 1,
6433               size      => 12,
6434           );
6435
6436           # Add an alternate description string to the URL.
6437           my $str = 'Perl home.';
6438
6439           # Add a "tool tip" to the URL.
6440           my $tip = 'Get the latest Perl news here.';
6441
6442
6443           # Write some hyperlinks. Unspecified or undefined format paraamters will be
6444           # replace with the defuault Excel hyperlink style.
6445           $worksheet->write( 'A1', 'http://www.perl.com/' );
6446           $worksheet->write( 'A3', 'http://www.perl.com/', undef, $str );
6447           $worksheet->write( 'A5', 'http://www.perl.com/', undef, $str, $tip );
6448           $worksheet->write( 'A7', 'http://www.perl.com/', $red_format );
6449           $worksheet->write( 'A9', 'mailto:jmcnamara@cpan.org', undef, 'Mail me' );
6450
6451           # Write a URL that isn't a hyperlink
6452           $worksheet->write_string( 'A11', 'http://www.perl.com/' );
6453
6454           $workbook->close();
6455
6456           __END__
6457
6458       Download this example:
6459       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/hyperlink1.pl>
6460
6461   Example: hyperlink2.pl
6462       Example of how to use the Excel::Writer::XLSX module to write internal
6463       and external hyperlinks.
6464
6465       If you wish to run this program and follow the hyperlinks you should
6466       create the following directory structure:
6467
6468       C:\ -- Temp --+-- Europe
6469                     |
6470                     \-- Asia
6471
6472       See also hyperlink1.pl for web URL examples.
6473
6474           #!/usr/bin/perl
6475
6476           ###############################################################################
6477           #
6478           # Example of how to use the Excel::Writer::XLSX module to write internal and
6479           # external hyperlinks.
6480           #
6481           # If you wish to run this program and follow the hyperlinks you should create
6482           # the following directory structure:
6483           #
6484           # C:\ -- Temp --+-- Europe
6485           #               |
6486           #               \-- Asia
6487           #
6488           #
6489           # See also hyperlink1.pl for web URL examples.
6490           #
6491           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6492           #
6493
6494
6495           use strict;
6496           use warnings;
6497           use Excel::Writer::XLSX;
6498
6499           # Create three workbooks:
6500           #   C:\Temp\Europe\Ireland.xlsx
6501           #   C:\Temp\Europe\Italy.xlsx
6502           #   C:\Temp\Asia\China.xlsx
6503           #
6504
6505           my $ireland = Excel::Writer::XLSX->new( 'C:\Temp\Europe\Ireland.xlsx' );
6506
6507           my $ire_links      = $ireland->add_worksheet( 'Links' );
6508           my $ire_sales      = $ireland->add_worksheet( 'Sales' );
6509           my $ire_data       = $ireland->add_worksheet( 'Product Data' );
6510           my $ire_url_format = $ireland->get_default_url_format();
6511
6512
6513           my $italy = Excel::Writer::XLSX->new( 'C:\Temp\Europe\Italy.xlsx' );
6514
6515           my $ita_links      = $italy->add_worksheet( 'Links' );
6516           my $ita_sales      = $italy->add_worksheet( 'Sales' );
6517           my $ita_data       = $italy->add_worksheet( 'Product Data' );
6518           my $ita_url_format = $italy->get_default_url_format();
6519
6520
6521           my $china = Excel::Writer::XLSX->new( 'C:\Temp\Asia\China.xlsx' );
6522
6523           my $cha_links      = $china->add_worksheet( 'Links' );
6524           my $cha_sales      = $china->add_worksheet( 'Sales' );
6525           my $cha_data       = $china->add_worksheet( 'Product Data' );
6526           my $cha_url_format = $china->get_default_url_format();
6527
6528
6529           # Add an alternative format
6530           my $format = $ireland->add_format( color => 'green', bold => 1 );
6531           $ire_links->set_column( 'A:B', 25 );
6532
6533
6534           ###############################################################################
6535           #
6536           # Examples of internal links
6537           #
6538           $ire_links->write( 'A1', 'Internal links', $format );
6539
6540           # Internal link
6541           $ire_links->write_url( 'A2', 'internal:Sales!A2', $ire_url_format );
6542
6543           # Internal link to a range
6544           $ire_links->write_url( 'A3', 'internal:Sales!A3:D3', $ire_url_format );
6545
6546           # Internal link with an alternative string
6547           $ire_links->write_url( 'A4', 'internal:Sales!A4', $ire_url_format, 'Link' );
6548
6549           # Internal link with an alternative format
6550           $ire_links->write_url( 'A5', 'internal:Sales!A5', $format );
6551
6552           # Internal link with an alternative string and format
6553           $ire_links->write_url( 'A6', 'internal:Sales!A6', $ire_url_format, 'Link' );
6554
6555           # Internal link (spaces in worksheet name)
6556           $ire_links->write_url( 'A7', q{internal:'Product Data'!A7}, $ire_url_format );
6557
6558
6559           ###############################################################################
6560           #
6561           # Examples of external links
6562           #
6563           $ire_links->write( 'B1', 'External links', $format );
6564
6565           # External link to a local file
6566           $ire_links->write_url( 'B2', 'external:Italy.xlsx', $ire_url_format );
6567
6568           # External link to a local file with worksheet
6569           $ire_links->write_url( 'B3', 'external:Italy.xlsx#Sales!B3', $ire_url_format );
6570
6571           # External link to a local file with worksheet and alternative string
6572           $ire_links->write_url( 'B4', 'external:Italy.xlsx#Sales!B4', $ire_url_format, 'Link' );
6573
6574           # External link to a local file with worksheet and format
6575           $ire_links->write_url( 'B5', 'external:Italy.xlsx#Sales!B5', $format );
6576
6577           # External link to a remote file, absolute path
6578           $ire_links->write_url( 'B6', 'external:C:/Temp/Asia/China.xlsx', $ire_url_format );
6579
6580           # External link to a remote file, relative path
6581           $ire_links->write_url( 'B7', 'external:../Asia/China.xlsx', $ire_url_format );
6582
6583           # External link to a remote file with worksheet
6584           $ire_links->write_url( 'B8', 'external:C:/Temp/Asia/China.xlsx#Sales!B8', $ire_url_format );
6585
6586           # External link to a remote file with worksheet (with spaces in the name)
6587           $ire_links->write_url( 'B9', q{external:C:/Temp/Asia/China.xlsx#'Product Data'!B9}, $ire_url_format );
6588
6589
6590           ###############################################################################
6591           #
6592           # Some utility links to return to the main sheet
6593           #
6594           $ire_sales->write_url( 'A2', 'internal:Links!A2', $ire_url_format, 'Back' );
6595           $ire_sales->write_url( 'A3', 'internal:Links!A3', $ire_url_format, 'Back' );
6596           $ire_sales->write_url( 'A4', 'internal:Links!A4', $ire_url_format, 'Back' );
6597           $ire_sales->write_url( 'A5', 'internal:Links!A5', $ire_url_format, 'Back' );
6598           $ire_sales->write_url( 'A6', 'internal:Links!A6', $ire_url_format, 'Back' );
6599           $ire_data->write_url ( 'A7', 'internal:Links!A7', $ire_url_format, 'Back' );
6600
6601           $ita_links->write_url( 'A1', 'external:Ireland.xlsx#Links!B2', $ita_url_format, 'Back' );
6602           $ita_sales->write_url( 'B3', 'external:Ireland.xlsx#Links!B3', $ita_url_format, 'Back' );
6603           $ita_sales->write_url( 'B4', 'external:Ireland.xlsx#Links!B4', $ita_url_format, 'Back' );
6604           $ita_sales->write_url( 'B5', 'external:Ireland.xlsx#Links!B5', $ita_url_format, 'Back' );
6605           $cha_links->write_url( 'A1', 'external:C:/Temp/Europe/Ireland.xlsx#Links!B6', $cha_url_format, 'Back' );
6606           $cha_sales->write_url( 'B8', 'external:C:/Temp/Europe/Ireland.xlsx#Links!B8', $cha_url_format, 'Back' );
6607           $cha_data->write_url ( 'B9', 'external:C:/Temp/Europe/Ireland.xlsx#Links!B9', $cha_url_format, 'Back' );
6608
6609           $ireland->close();
6610           $italy->close();
6611           $china->close();
6612
6613           __END__
6614
6615       Download this example:
6616       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/hyperlink2.pl>
6617
6618   Example: indent.pl
6619       A simple formatting example using Excel::Writer::XLSX.
6620
6621       This program demonstrates the indentation cell format.
6622
6623       Source code for this example:
6624
6625           #!/usr/bin/perl -w
6626
6627           ##############################################################################
6628           #
6629           # A simple formatting example using Excel::Writer::XLSX.
6630           #
6631           # This program demonstrates the indentation cell format.
6632           #
6633           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6634           #
6635
6636
6637           use strict;
6638           use Excel::Writer::XLSX;
6639
6640           my $workbook = Excel::Writer::XLSX->new( 'indent.xlsx' );
6641
6642           my $worksheet = $workbook->add_worksheet();
6643           my $indent1   = $workbook->add_format( indent => 1 );
6644           my $indent2   = $workbook->add_format( indent => 2 );
6645
6646           $worksheet->set_column( 'A:A', 40 );
6647
6648
6649           $worksheet->write( 'A1', "This text is indented 1 level",  $indent1 );
6650           $worksheet->write( 'A2', "This text is indented 2 levels", $indent2 );
6651
6652           $workbook->close();
6653
6654           __END__
6655
6656       Download this example:
6657       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/indent.pl>
6658
6659   Example: ignore_errors.pl
6660       An example of turning off worksheet cells errors/warnings using the
6661       Excel::Writer::XLSX module.
6662
6663           #!/usr/bin/perl -w
6664
6665           #######################################################################
6666           #
6667           # An example of turning off worksheet cells errors/warnings using the
6668           # Excel::Writer::XLSX module.
6669           #
6670           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6671           #
6672
6673           use strict;
6674           use Excel::Writer::XLSX;
6675
6676           my $workbook  = Excel::Writer::XLSX->new( 'ignore_errors.xlsx' );
6677           my $worksheet = $workbook->add_worksheet();
6678
6679           # Write strings that looks like numbers. This will cause an Excel warning.
6680           $worksheet->write_string('C2', '123');
6681           $worksheet->write_string('C3', '123');
6682
6683           # Write a divide by zero formula. This will also cause an Excel warning.
6684           $worksheet->write_formula('C5', '=1/0');
6685           $worksheet->write_formula('C6', '=1/0');
6686
6687           # Turn off some of the warnings:
6688           $worksheet->ignore_errors({number_stored_as_text => 'C3', eval_error => 'C6'});
6689
6690           # Write some descriptions for the cells and make the column wider for clarity.
6691           $worksheet->set_column('B:B', 16);
6692           $worksheet->write('B2', 'Warning:');
6693           $worksheet->write('B3', 'Warning turned off:');
6694           $worksheet->write('B5', 'Warning:');
6695           $worksheet->write('B6', 'Warning turned off:');
6696
6697           $workbook->close();
6698
6699           __END__
6700
6701       Download this example:
6702       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/ignore_errors.pl>
6703
6704   Example: lambda.pl
6705       An example of using the new Excel LAMBDA() function with the
6706       Excel::Writer::XLSX module. Note, this function is only currently
6707       available if you are subscribed to the Microsoft Office Beta program.
6708
6709           #!/usr/bin/perl -w
6710
6711           #######################################################################
6712           #
6713           # An example of using the new Excel LAMBDA() function with the
6714           # Excel::Writer::XLSX module. Note, this function is only currently available
6715           # if you are subscribed to the Microsoft Office Beta program.
6716           #
6717           # Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
6718           #
6719
6720           use strict;
6721           use Excel::Writer::XLSX;
6722
6723           my $workbook  = Excel::Writer::XLSX->new( 'lambda.xlsx' );
6724           my $worksheet = $workbook->add_worksheet();
6725
6726           $worksheet->write('A1', 'Note: Lambda functions currently only work with the Beta Channel versions of Excel 365');
6727
6728           # Write a Lambda function to convert Fahrenheit to Celsius to a cell.
6729           #
6730           # Note that the lambda function parameters must be prefixed with
6731           # "_xlpm.". These prefixes won't show up in Excel.
6732           $worksheet->write('A2', '=LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))(32)');
6733
6734           # Create the same formula (without an argument) as a defined name and use that
6735           # to calculate a value.
6736           #
6737           # Note that the formula name is prefixed with "_xlfn." (this is normally
6738           # converted automatically by write_formula() but isn't for defined names)
6739           # and note that the lambda function parameters are prefixed with
6740           # "_xlpm.". These prefixes won't show up in Excel.
6741           $workbook->define_name('ToCelsius',
6742                                  '=_xlfn.LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))');
6743           $worksheet->write_dynamic_array_formula( 'A3', '=ToCelsius(212)' );
6744
6745           $workbook->close();
6746
6747           __END__
6748
6749       Download this example:
6750       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/lambda.pl>
6751
6752   Example: macros.pl
6753       An example of adding macros to an Excel::Writer::XLSX file using a VBA
6754       project file extracted from an existing Excel xlsm file.
6755
6756       The "extract_vba" utility supplied with Excel::Writer::XLSX can be used
6757       to extract the vbaProject.bin file.
6758
6759       An embedded macro is connected to a form button on the worksheet.
6760
6761       Source code for this example:
6762
6763           #!/usr/bin/perl
6764
6765           #######################################################################
6766           #
6767           # An example of adding macros to an Excel::Writer::XLSX file using
6768           # a VBA project file extracted from an existing Excel xlsm file.
6769           #
6770           # The C<extract_vba> utility supplied with Excel::Writer::XLSX can be
6771           # used to extract the vbaProject.bin file.
6772           #
6773           # An embedded macro is connected to a form button on the worksheet.
6774           #
6775           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6776           #
6777
6778           use strict;
6779           use warnings;
6780           use Excel::Writer::XLSX;
6781
6782           # Note the file extension should be .xlsm.
6783           my $workbook  = Excel::Writer::XLSX->new( 'macros.xlsm' );
6784           my $worksheet = $workbook->add_worksheet();
6785
6786           $worksheet->set_column( 'A:A', 30 );
6787
6788           # Add the VBA project binary.
6789           $workbook->add_vba_project( './vbaProject.bin' );
6790
6791           # Show text for the end user.
6792           $worksheet->write( 'A3', 'Press the button to say hello.' );
6793
6794           # Add a button tied to a macro in the VBA project.
6795           $worksheet->insert_button(
6796               'B3',
6797               {
6798                   macro   => 'say_hello',
6799                   caption => 'Press Me',
6800                   width   => 80,
6801                   height  => 30
6802               }
6803           );
6804
6805           $workbook->close();
6806
6807           __END__
6808
6809       Download this example:
6810       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/macros.pl>
6811
6812   Example: merge1.pl
6813       Simple example of merging cells using the Excel::Writer::XLSX module.
6814
6815       This example merges three cells using the "Centre Across Selection"
6816       alignment which was the Excel 5 method of achieving a merge. For a more
6817       modern approach use the merge_range() worksheet method instead.  See
6818       the merge3.pl - merge6.pl programs.
6819
6820       Source code for this example:
6821
6822           #!/usr/bin/perl
6823
6824           ###############################################################################
6825           #
6826           # Simple example of merging cells using the Excel::Writer::XLSX module.
6827           #
6828           # This example merges three cells using the "Centre Across Selection"
6829           # alignment which was the Excel 5 method of achieving a merge. For a more
6830           # modern approach use the merge_range() worksheet method instead.
6831           # See the merge3.pl - merge6.pl programs.
6832           #
6833           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6834           #
6835
6836           use strict;
6837           use warnings;
6838           use Excel::Writer::XLSX;
6839
6840           # Create a new workbook and add a worksheet
6841           my $workbook  = Excel::Writer::XLSX->new( 'merge1.xlsx' );
6842           my $worksheet = $workbook->add_worksheet();
6843
6844
6845           # Increase the cell size of the merged cells to highlight the formatting.
6846           $worksheet->set_column( 'B:D', 20 );
6847           $worksheet->set_row( 2, 30 );
6848
6849
6850           # Create a merge format
6851           my $format = $workbook->add_format( center_across => 1 );
6852
6853
6854           # Only one cell should contain text, the others should be blank.
6855           $worksheet->write( 2, 1, "Center across selection", $format );
6856           $worksheet->write_blank( 2, 2, $format );
6857           $worksheet->write_blank( 2, 3, $format );
6858
6859           $workbook->close();
6860
6861           __END__
6862
6863       Download this example:
6864       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/merge1.pl>
6865
6866   Example: merge2.pl
6867       Simple example of merging cells using the Excel::Writer::XLSX module
6868
6869       This example merges three cells using the "Centre Across Selection"
6870       alignment which was the Excel 5 method of achieving a merge. For a more
6871       modern approach use the merge_range() worksheet method instead.  See
6872       the merge3.pl - merge6.pl programs.
6873
6874       Source code for this example:
6875
6876           #!/usr/bin/perl
6877
6878           ###############################################################################
6879           #
6880           # Simple example of merging cells using the Excel::Writer::XLSX module
6881           #
6882           # This example merges three cells using the "Centre Across Selection"
6883           # alignment which was the Excel 5 method of achieving a merge. For a more
6884           # modern approach use the merge_range() worksheet method instead.
6885           # See the merge3.pl - merge6.pl programs.
6886           #
6887           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6888           #
6889
6890           use strict;
6891           use warnings;
6892           use Excel::Writer::XLSX;
6893
6894           # Create a new workbook and add a worksheet
6895           my $workbook  = Excel::Writer::XLSX->new( 'merge2.xlsx' );
6896           my $worksheet = $workbook->add_worksheet();
6897
6898
6899           # Increase the cell size of the merged cells to highlight the formatting.
6900           $worksheet->set_column( 1, 2, 30 );
6901           $worksheet->set_row( 2, 40 );
6902
6903
6904           # Create a merged format
6905           my $format = $workbook->add_format(
6906               center_across => 1,
6907               bold          => 1,
6908               size          => 15,
6909               pattern       => 1,
6910               border        => 6,
6911               color         => 'white',
6912               fg_color      => 'green',
6913               border_color  => 'yellow',
6914               align         => 'vcenter',
6915           );
6916
6917
6918           # Only one cell should contain text, the others should be blank.
6919           $worksheet->write( 2, 1, "Center across selection", $format );
6920           $worksheet->write_blank( 2, 2, $format );
6921
6922           $workbook->close();
6923
6924           __END__
6925
6926       Download this example:
6927       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/merge2.pl>
6928
6929   Example: merge3.pl
6930       Example of how to use Excel::Writer::XLSX to write a hyperlink in a
6931       merged cell.
6932
6933       Source code for this example:
6934
6935           #!/usr/bin/perl
6936
6937           ###############################################################################
6938           #
6939           # Example of how to use Excel::Writer::XLSX to write a hyperlink in a
6940           # merged cell.
6941           #
6942           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
6943           #
6944
6945           use strict;
6946           use warnings;
6947           use Excel::Writer::XLSX;
6948
6949           # Create a new workbook and add a worksheet
6950           my $workbook  = Excel::Writer::XLSX->new( 'merge3.xlsx' );
6951           my $worksheet = $workbook->add_worksheet();
6952
6953
6954           # Increase the cell size of the merged cells to highlight the formatting.
6955           $worksheet->set_row( $_, 30 ) for ( 3, 6, 7 );
6956           $worksheet->set_column( 'B:D', 20 );
6957
6958
6959           ###############################################################################
6960           #
6961           # Example: Merge cells containing a hyperlink using merge_range().
6962           #
6963           my $format = $workbook->add_format(
6964               border    => 1,
6965               underline => 1,
6966               color     => 'blue',
6967               align     => 'center',
6968               valign    => 'vcenter',
6969           );
6970
6971           # Merge 3 cells
6972           $worksheet->merge_range( 'B4:D4', 'http://www.perl.com', $format );
6973
6974
6975           # Merge 3 cells over two rows
6976           $worksheet->merge_range( 'B7:D8', 'http://www.perl.com', $format );
6977
6978
6979           $workbook->close();
6980
6981           __END__
6982
6983       Download this example:
6984       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/merge3.pl>
6985
6986   Example: merge4.pl
6987       Example of how to use the Excel::Writer::XLSX merge_range() workbook
6988       method with complex formatting.
6989
6990       Source code for this example:
6991
6992           #!/usr/bin/perl
6993
6994           ###############################################################################
6995           #
6996           # Example of how to use the Excel::Writer::XLSX merge_range() workbook
6997           # method with complex formatting.
6998           #
6999           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
7000           #
7001
7002           use strict;
7003           use warnings;
7004           use Excel::Writer::XLSX;
7005
7006           # Create a new workbook and add a worksheet
7007           my $workbook  = Excel::Writer::XLSX->new( 'merge4.xlsx' );
7008           my $worksheet = $workbook->add_worksheet();
7009
7010
7011           # Increase the cell size of the merged cells to highlight the formatting.
7012           $worksheet->set_row( $_, 30 ) for ( 1 .. 11 );
7013           $worksheet->set_column( 'B:D', 20 );
7014
7015
7016           ###############################################################################
7017           #
7018           # Example 1: Text centered vertically and horizontally
7019           #
7020           my $format1 = $workbook->add_format(
7021               border => 6,
7022               bold   => 1,
7023               color  => 'red',
7024               valign => 'vcenter',
7025               align  => 'center',
7026           );
7027
7028
7029           $worksheet->merge_range( 'B2:D3', 'Vertical and horizontal', $format1 );
7030
7031
7032           ###############################################################################
7033           #
7034           # Example 2: Text aligned to the top and left
7035           #
7036           my $format2 = $workbook->add_format(
7037               border => 6,
7038               bold   => 1,
7039               color  => 'red',
7040               valign => 'top',
7041               align  => 'left',
7042           );
7043
7044
7045           $worksheet->merge_range( 'B5:D6', 'Aligned to the top and left', $format2 );
7046
7047
7048           ###############################################################################
7049           #
7050           # Example 3:  Text aligned to the bottom and right
7051           #
7052           my $format3 = $workbook->add_format(
7053               border => 6,
7054               bold   => 1,
7055               color  => 'red',
7056               valign => 'bottom',
7057               align  => 'right',
7058           );
7059
7060
7061           $worksheet->merge_range( 'B8:D9', 'Aligned to the bottom and right', $format3 );
7062
7063
7064           ###############################################################################
7065           #
7066           # Example 4:  Text justified (i.e. wrapped) in the cell
7067           #
7068           my $format4 = $workbook->add_format(
7069               border => 6,
7070               bold   => 1,
7071               color  => 'red',
7072               valign => 'top',
7073               align  => 'justify',
7074           );
7075
7076
7077           $worksheet->merge_range( 'B11:D12', 'Justified: ' . 'so on and ' x 18,
7078               $format4 );
7079
7080           $workbook->close();
7081
7082           __END__
7083
7084       Download this example:
7085       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/merge4.pl>
7086
7087   Example: merge5.pl
7088       Example of how to use the Excel::Writer::XLSX merge_cells() workbook
7089       method with complex formatting and rotation.
7090
7091       Source code for this example:
7092
7093           #!/usr/bin/perl
7094
7095           ###############################################################################
7096           #
7097           # Example of how to use the Excel::Writer::XLSX merge_cells() workbook
7098           # method with complex formatting and rotation.
7099           #
7100           #
7101           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
7102           #
7103
7104           use strict;
7105           use warnings;
7106           use Excel::Writer::XLSX;
7107
7108           # Create a new workbook and add a worksheet
7109           my $workbook  = Excel::Writer::XLSX->new( 'merge5.xlsx' );
7110           my $worksheet = $workbook->add_worksheet();
7111
7112
7113           # Increase the cell size of the merged cells to highlight the formatting.
7114           $worksheet->set_row( $_, 36 ) for ( 3 .. 8 );
7115           $worksheet->set_column( $_, $_, 15 ) for ( 1, 3, 5 );
7116
7117
7118           ###############################################################################
7119           #
7120           # Rotation 1, letters run from top to bottom
7121           #
7122           my $format1 = $workbook->add_format(
7123               border   => 6,
7124               bold     => 1,
7125               color    => 'red',
7126               valign   => 'vcentre',
7127               align    => 'centre',
7128               rotation => 270,
7129           );
7130
7131
7132           $worksheet->merge_range( 'B4:B9', 'Rotation 270', $format1 );
7133
7134
7135           ###############################################################################
7136           #
7137           # Rotation 2, 90° anticlockwise
7138           #
7139           my $format2 = $workbook->add_format(
7140               border   => 6,
7141               bold     => 1,
7142               color    => 'red',
7143               valign   => 'vcentre',
7144               align    => 'centre',
7145               rotation => 90,
7146           );
7147
7148
7149           $worksheet->merge_range( 'D4:D9', 'Rotation 90°', $format2 );
7150
7151
7152           ###############################################################################
7153           #
7154           # Rotation 3, 90° clockwise
7155           #
7156           my $format3 = $workbook->add_format(
7157               border   => 6,
7158               bold     => 1,
7159               color    => 'red',
7160               valign   => 'vcentre',
7161               align    => 'centre',
7162               rotation => -90,
7163           );
7164
7165
7166           $worksheet->merge_range( 'F4:F9', 'Rotation -90°', $format3 );
7167
7168           $workbook->close();
7169
7170           __END__
7171
7172       Download this example:
7173       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/merge5.pl>
7174
7175   Example: merge6.pl
7176       Example of how to use the Excel::Writer::XLSX merge_cells() workbook
7177       method with Unicode strings.
7178
7179       Source code for this example:
7180
7181           #!/usr/bin/perl
7182
7183           ###############################################################################
7184           #
7185           # Example of how to use the Excel::Writer::XLSX merge_cells() workbook
7186           # method with Unicode strings.
7187           #
7188           #
7189           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
7190           #
7191
7192           use strict;
7193           use warnings;
7194           use Excel::Writer::XLSX;
7195
7196           # Create a new workbook and add a worksheet
7197           my $workbook  = Excel::Writer::XLSX->new( 'merge6.xlsx' );
7198           my $worksheet = $workbook->add_worksheet();
7199
7200
7201           # Increase the cell size of the merged cells to highlight the formatting.
7202           $worksheet->set_row( $_, 36 ) for 2 .. 9;
7203           $worksheet->set_column( 'B:D', 25 );
7204
7205
7206           # Format for the merged cells.
7207           my $format = $workbook->add_format(
7208               border => 6,
7209               bold   => 1,
7210               color  => 'red',
7211               size   => 20,
7212               valign => 'vcentre',
7213               align  => 'left',
7214               indent => 1,
7215           );
7216
7217
7218           ###############################################################################
7219           #
7220           # Write an Ascii string.
7221           #
7222           $worksheet->merge_range( 'B3:D4', 'ASCII: A simple string', $format );
7223
7224
7225           ###############################################################################
7226           #
7227           # Write a UTF-8 Unicode string.
7228           #
7229           my $smiley = chr 0x263a;
7230           $worksheet->merge_range( 'B6:D7', "UTF-8: A Unicode smiley $smiley", $format );
7231
7232           $workbook->close();
7233
7234           __END__
7235
7236       Download this example:
7237       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/merge6.pl>
7238
7239   Example: mod_perl1.pl
7240       Example of how to use the Excel::Writer::XLSX module to send an Excel
7241       file to a browser using mod_perl 1 and Apache
7242
7243       This module ties *XLSX directly to Apache, and with the correct
7244       content-disposition/types it will prompt the user to save the file, or
7245       open it at this location.
7246
7247       This script is a modification of the Excel::Writer::XLSX cgi.pl
7248       example.
7249
7250       Change the name of this file to Cgi.pm.  Change the package location to
7251       wherever you locate this package.  In the example below it is located
7252       in the Excel::Writer::XLSX directory.
7253
7254       Your httpd.conf entry for this module, should you choose to use it as a
7255       stand alone app, should look similar to the following:
7256
7257           <Location /spreadsheet-test>
7258             SetHandler perl-script
7259             PerlHandler Excel::Writer::XLSX::Cgi
7260             PerlSendHeader On
7261           </Location>
7262
7263       The PerlHandler name above and the package name below *have* to match.
7264
7265           ###############################################################################
7266           #
7267           # Example of how to use the Excel::Writer::XLSX module to send an Excel
7268           # file to a browser using mod_perl 1 and Apache
7269           #
7270           # This module ties *XLSX directly to Apache, and with the correct
7271           # content-disposition/types it will prompt the user to save
7272           # the file, or open it at this location.
7273           #
7274           # This script is a modification of the Excel::Writer::XLSX cgi.pl example.
7275           #
7276           # Change the name of this file to Cgi.pm.
7277           # Change the package location to wherever you locate this package.
7278           # In the example below it is located in the Excel::Writer::XLSX directory.
7279           #
7280           # Your httpd.conf entry for this module, should you choose to use it
7281           # as a stand alone app, should look similar to the following:
7282           #
7283           #     <Location /spreadsheet-test>
7284           #       SetHandler perl-script
7285           #       PerlHandler Excel::Writer::XLSX::Cgi
7286           #       PerlSendHeader On
7287           #     </Location>
7288           #
7289           # The PerlHandler name above and the package name below *have* to match.
7290
7291           # Apr 2001, Thomas Sullivan, webmaster@860.org
7292           # Feb 2001, John McNamara, jmcnamara@cpan.org
7293
7294           package Excel::Writer::XLSX::Cgi;
7295
7296           ##########################################
7297           # Pragma Definitions
7298           ##########################################
7299           use strict;
7300
7301           ##########################################
7302           # Required Modules
7303           ##########################################
7304           use Apache::Constants qw(:common);
7305           use Apache::Request;
7306           use Apache::URI;    # This may not be needed
7307           use Excel::Writer::XLSX;
7308
7309           ##########################################
7310           # Main App Body
7311           ##########################################
7312           sub handler {
7313
7314               # New apache object
7315               # Should you decide to use it.
7316               my $r = Apache::Request->new( shift );
7317
7318               # Set the filename and send the content type
7319               # This will appear when they save the spreadsheet
7320               my $filename = "cgitest.xlsx";
7321
7322               ####################################################
7323               ## Send the content type headers
7324               ####################################################
7325               print "Content-disposition: attachment;filename=$filename\n";
7326               print "Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n\n";
7327
7328               ####################################################
7329               # Tie a filehandle to Apache's STDOUT.
7330               # Create a new workbook and add a worksheet.
7331               ####################################################
7332               tie *XLSX => 'Apache';
7333               binmode( *XLSX );
7334
7335               my $workbook  = Excel::Writer::XLSX->new( \*XLSX );
7336               my $worksheet = $workbook->add_worksheet();
7337
7338
7339               # Set the column width for column 1
7340               $worksheet->set_column( 0, 0, 20 );
7341
7342
7343               # Create a format
7344               my $format = $workbook->add_format();
7345               $format->set_bold();
7346               $format->set_size( 15 );
7347               $format->set_color( 'blue' );
7348
7349
7350               # Write to the workbook
7351               $worksheet->write( 0, 0, "Hi Excel!", $format );
7352
7353               # You must close the workbook for Content-disposition
7354               $workbook->close();
7355           }
7356
7357           1;
7358
7359       Download this example:
7360       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/mod_perl1.pl>
7361
7362   Example: mod_perl2.pl
7363       Example of how to use the Excel::Writer::XLSX module to send an Excel
7364       file to a browser using mod_perl 2 and Apache.
7365
7366       This module ties *XLSX directly to Apache, and with the correct
7367       content-disposition/types it will prompt the user to save the file, or
7368       open it at this location.
7369
7370       This script is a modification of the Excel::Writer::XLSX cgi.pl
7371       example.
7372
7373       Change the name of this file to MP2Test.pm.  Change the package
7374       location to wherever you locate this package.  In the example below it
7375       is located in the Excel::Writer::XLSX directory.
7376
7377       Your httpd.conf entry for this module, should you choose to use it as a
7378       stand alone app, should look similar to the following:
7379
7380           PerlModule Apache2::RequestRec
7381           PerlModule APR::Table
7382           PerlModule Apache2::RequestIO
7383
7384           <Location /spreadsheet-test>
7385              SetHandler perl-script
7386              PerlResponseHandler Excel::Writer::XLSX::MP2Test
7387           </Location>
7388
7389       The PerlResponseHandler must match the package name below.
7390
7391           ###############################################################################
7392           #
7393           # Example of how to use the Excel::Writer::XLSX module to send an Excel
7394           # file to a browser using mod_perl 2 and Apache.
7395           #
7396           # This module ties *XLSX directly to Apache, and with the correct
7397           # content-disposition/types it will prompt the user to save
7398           # the file, or open it at this location.
7399           #
7400           # This script is a modification of the Excel::Writer::XLSX cgi.pl example.
7401           #
7402           # Change the name of this file to MP2Test.pm.
7403           # Change the package location to wherever you locate this package.
7404           # In the example below it is located in the Excel::Writer::XLSX directory.
7405           #
7406           # Your httpd.conf entry for this module, should you choose to use it
7407           # as a stand alone app, should look similar to the following:
7408           #
7409           #     PerlModule Apache2::RequestRec
7410           #     PerlModule APR::Table
7411           #     PerlModule Apache2::RequestIO
7412           #
7413           #     <Location /spreadsheet-test>
7414           #        SetHandler perl-script
7415           #        PerlResponseHandler Excel::Writer::XLSX::MP2Test
7416           #     </Location>
7417           #
7418           # The PerlResponseHandler must match the package name below.
7419
7420           # Jun 2004, Matisse Enzer, matisse@matisse.net  (mod_perl 2 version)
7421           # Apr 2001, Thomas Sullivan, webmaster@860.org
7422           # Feb 2001, John McNamara, jmcnamara@cpan.org
7423
7424           package Excel::Writer::XLSX::MP2Test;
7425
7426           ##########################################
7427           # Pragma Definitions
7428           ##########################################
7429           use strict;
7430
7431           ##########################################
7432           # Required Modules
7433           ##########################################
7434           use Apache2::Const -compile => qw( :common );
7435           use Excel::Writer::XLSX;
7436
7437           ##########################################
7438           # Main App Body
7439           ##########################################
7440           sub handler {
7441               my ( $r ) = @_;   # Apache request object is passed to handler in mod_perl 2
7442
7443               # Set the filename and send the content type
7444               # This will appear when they save the spreadsheet
7445               my $filename = "mod_perl2_test.xlsx";
7446
7447               ####################################################
7448               ## Send the content type headers the mod_perl 2 way
7449               ####################################################
7450               $r->headers_out->{'Content-Disposition'} = "attachment;filename=$filename";
7451               $r->content_type( 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
7452
7453               ####################################################
7454               # Tie a filehandle to Apache's STDOUT.
7455               # Create a new workbook and add a worksheet.
7456               ####################################################
7457               tie *XLSX => $r;  # The mod_perl 2 way. Tie to the Apache::RequestRec object
7458               binmode( *XLSX );
7459
7460               my $workbook  = Excel::Writer::XLSX->new( \*XLSX );
7461               my $worksheet = $workbook->add_worksheet();
7462
7463
7464               # Set the column width for column 1
7465               $worksheet->set_column( 0, 0, 20 );
7466
7467
7468               # Create a format
7469               my $format = $workbook->add_format();
7470               $format->set_bold();
7471               $format->set_size( 15 );
7472               $format->set_color( 'blue' );
7473
7474
7475               # Write to the workbook
7476               $worksheet->write( 0, 0, 'Hi Excel! from ' . $r->hostname, $format );
7477
7478               # You must close the workbook for Content-disposition
7479               $workbook->close();
7480               return Apache2::Const::OK;
7481           }
7482
7483           1;
7484
7485       Download this example:
7486       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/mod_perl2.pl>
7487
7488   Example: outline.pl
7489       Example of how use Excel::Writer::XLSX to generate Excel outlines and
7490       grouping.
7491
7492       Excel allows you to group rows or columns so that they can be hidden or
7493       displayed with a single mouse click. This feature is referred to as
7494       outlines.
7495
7496       Outlines can reduce complex data down to a few salient sub-totals or
7497       summaries.
7498
7499       This feature is best viewed in Excel but the following is an ASCII
7500       representation of what a worksheet with three outlines might look like.
7501       Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
7502       level 1. The lines at the left hand side are called outline level bars.
7503
7504                   ------------------------------------------
7505            1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7506                   ------------------------------------------
7507             _    | 1 |   A   |       |       |       |  ...
7508            |  _  | 2 |   B   |       |       |       |  ...
7509            | |   | 3 |  (C)  |       |       |       |  ...
7510            | |   | 4 |  (D)  |       |       |       |  ...
7511            | -   | 5 |   E   |       |       |       |  ...
7512            |  _  | 6 |   F   |       |       |       |  ...
7513            | |   | 7 |  (G)  |       |       |       |  ...
7514            | |   | 8 |  (H)  |       |       |       |  ...
7515            | -   | 9 |   I   |       |       |       |  ...
7516            -     | . |  ...  |  ...  |  ...  |  ...  |  ...
7517
7518       Clicking the minus sign on each of the level 2 outlines will collapse
7519       and hide the data as shown in the next figure. The minus sign changes
7520       to a plus sign to indicate that the data in the outline is hidden.
7521
7522                   ------------------------------------------
7523            1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7524                   ------------------------------------------
7525             _    | 1 |   A   |       |       |       |  ...
7526            |     | 2 |   B   |       |       |       |  ...
7527            | +   | 5 |   E   |       |       |       |  ...
7528            |     | 6 |   F   |       |       |       |  ...
7529            | +   | 9 |   I   |       |       |       |  ...
7530            -     | . |  ...  |  ...  |  ...  |  ...  |  ...
7531
7532       Clicking on the minus sign on the level 1 outline will collapse the
7533       remaining rows as follows:
7534
7535                   ------------------------------------------
7536            1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7537                   ------------------------------------------
7538                  | 1 |   A   |       |       |       |  ...
7539            +     | . |  ...  |  ...  |  ...  |  ...  |  ...
7540
7541       See the main Excel::Writer::XLSX documentation for more information.
7542
7543       Source code for this example:
7544
7545           #!/usr/bin/perl
7546
7547           ###############################################################################
7548           #
7549           # Example of how use Excel::Writer::XLSX to generate Excel outlines and
7550           # grouping.
7551           #
7552           #
7553           # Excel allows you to group rows or columns so that they can be hidden or
7554           # displayed with a single mouse click. This feature is referred to as outlines.
7555           #
7556           # Outlines can reduce complex data down to a few salient sub-totals or
7557           # summaries.
7558           #
7559           # This feature is best viewed in Excel but the following is an ASCII
7560           # representation of what a worksheet with three outlines might look like.
7561           # Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
7562           # level 1. The lines at the left hand side are called outline level bars.
7563           #
7564           #
7565           #             ------------------------------------------
7566           #      1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7567           #             ------------------------------------------
7568           #       _    | 1 |   A   |       |       |       |  ...
7569           #      |  _  | 2 |   B   |       |       |       |  ...
7570           #      | |   | 3 |  (C)  |       |       |       |  ...
7571           #      | |   | 4 |  (D)  |       |       |       |  ...
7572           #      | -   | 5 |   E   |       |       |       |  ...
7573           #      |  _  | 6 |   F   |       |       |       |  ...
7574           #      | |   | 7 |  (G)  |       |       |       |  ...
7575           #      | |   | 8 |  (H)  |       |       |       |  ...
7576           #      | -   | 9 |   I   |       |       |       |  ...
7577           #      -     | . |  ...  |  ...  |  ...  |  ...  |  ...
7578           #
7579           #
7580           # Clicking the minus sign on each of the level 2 outlines will collapse and
7581           # hide the data as shown in the next figure. The minus sign changes to a plus
7582           # sign to indicate that the data in the outline is hidden.
7583           #
7584           #             ------------------------------------------
7585           #      1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7586           #             ------------------------------------------
7587           #       _    | 1 |   A   |       |       |       |  ...
7588           #      |     | 2 |   B   |       |       |       |  ...
7589           #      | +   | 5 |   E   |       |       |       |  ...
7590           #      |     | 6 |   F   |       |       |       |  ...
7591           #      | +   | 9 |   I   |       |       |       |  ...
7592           #      -     | . |  ...  |  ...  |  ...  |  ...  |  ...
7593           #
7594           #
7595           # Clicking on the minus sign on the level 1 outline will collapse the remaining
7596           # rows as follows:
7597           #
7598           #             ------------------------------------------
7599           #      1 2 3 |   |   A   |   B   |   C   |   D   |  ...
7600           #             ------------------------------------------
7601           #            | 1 |   A   |       |       |       |  ...
7602           #      +     | . |  ...  |  ...  |  ...  |  ...  |  ...
7603           #
7604           # See the main Excel::Writer::XLSX documentation for more information.
7605           #
7606           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
7607           #
7608
7609
7610           use strict;
7611           use warnings;
7612           use Excel::Writer::XLSX;
7613
7614           # Create a new workbook and add some worksheets
7615           my $workbook   = Excel::Writer::XLSX->new( 'outline.xlsx' );
7616           my $worksheet1 = $workbook->add_worksheet( 'Outlined Rows' );
7617           my $worksheet2 = $workbook->add_worksheet( 'Collapsed Rows' );
7618           my $worksheet3 = $workbook->add_worksheet( 'Outline Columns' );
7619           my $worksheet4 = $workbook->add_worksheet( 'Outline levels' );
7620
7621           # Add a general format
7622           my $bold = $workbook->add_format( bold => 1 );
7623
7624
7625           ###############################################################################
7626           #
7627           # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
7628           # functions so that it looks like the type of automatic outlines that are
7629           # generated when you use the Excel Data->SubTotals menu item.
7630           #
7631
7632
7633           # For outlines the important parameters are $hidden and $level. Rows with the
7634           # same $level are grouped together. The group will be collapsed if $hidden is
7635           # non-zero. $height and $XF are assigned default values if they are undef.
7636           #
7637           # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
7638           #
7639           $worksheet1->set_row( 1, undef, undef, 0, 2 );
7640           $worksheet1->set_row( 2, undef, undef, 0, 2 );
7641           $worksheet1->set_row( 3, undef, undef, 0, 2 );
7642           $worksheet1->set_row( 4, undef, undef, 0, 2 );
7643           $worksheet1->set_row( 5, undef, undef, 0, 1 );
7644
7645           $worksheet1->set_row( 6,  undef, undef, 0, 2 );
7646           $worksheet1->set_row( 7,  undef, undef, 0, 2 );
7647           $worksheet1->set_row( 8,  undef, undef, 0, 2 );
7648           $worksheet1->set_row( 9,  undef, undef, 0, 2 );
7649           $worksheet1->set_row( 10, undef, undef, 0, 1 );
7650
7651
7652           # Add a column format for clarity
7653           $worksheet1->set_column( 'A:A', 20 );
7654
7655           # Add the data, labels and formulas
7656           $worksheet1->write( 'A1', 'Region', $bold );
7657           $worksheet1->write( 'A2', 'North' );
7658           $worksheet1->write( 'A3', 'North' );
7659           $worksheet1->write( 'A4', 'North' );
7660           $worksheet1->write( 'A5', 'North' );
7661           $worksheet1->write( 'A6', 'North Total', $bold );
7662
7663           $worksheet1->write( 'B1', 'Sales', $bold );
7664           $worksheet1->write( 'B2', 1000 );
7665           $worksheet1->write( 'B3', 1200 );
7666           $worksheet1->write( 'B4', 900 );
7667           $worksheet1->write( 'B5', 1200 );
7668           $worksheet1->write( 'B6', '=SUBTOTAL(9,B2:B5)', $bold );
7669
7670           $worksheet1->write( 'A7',  'South' );
7671           $worksheet1->write( 'A8',  'South' );
7672           $worksheet1->write( 'A9',  'South' );
7673           $worksheet1->write( 'A10', 'South' );
7674           $worksheet1->write( 'A11', 'South Total', $bold );
7675
7676           $worksheet1->write( 'B7',  400 );
7677           $worksheet1->write( 'B8',  600 );
7678           $worksheet1->write( 'B9',  500 );
7679           $worksheet1->write( 'B10', 600 );
7680           $worksheet1->write( 'B11', '=SUBTOTAL(9,B7:B10)', $bold );
7681
7682           $worksheet1->write( 'A12', 'Grand Total',         $bold );
7683           $worksheet1->write( 'B12', '=SUBTOTAL(9,B2:B10)', $bold );
7684
7685
7686           ###############################################################################
7687           #
7688           # Example 2: Create a worksheet with outlined rows. This is the same as the
7689           # previous example except that the rows are collapsed.
7690           # Note: We need to indicate the row that contains the collapsed symbol '+'
7691           # with the optional parameter, $collapsed.
7692
7693           # The group will be collapsed if $hidden is non-zero.
7694           # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
7695           #
7696           $worksheet2->set_row( 1, undef, undef, 1, 2 );
7697           $worksheet2->set_row( 2, undef, undef, 1, 2 );
7698           $worksheet2->set_row( 3, undef, undef, 1, 2 );
7699           $worksheet2->set_row( 4, undef, undef, 1, 2 );
7700           $worksheet2->set_row( 5, undef, undef, 1, 1 );
7701
7702           $worksheet2->set_row( 6,  undef, undef, 1, 2 );
7703           $worksheet2->set_row( 7,  undef, undef, 1, 2 );
7704           $worksheet2->set_row( 8,  undef, undef, 1, 2 );
7705           $worksheet2->set_row( 9,  undef, undef, 1, 2 );
7706           $worksheet2->set_row( 10, undef, undef, 1, 1 );
7707           $worksheet2->set_row( 11, undef, undef, 0, 0, 1 );
7708
7709
7710           # Add a column format for clarity
7711           $worksheet2->set_column( 'A:A', 20 );
7712
7713           # Add the data, labels and formulas
7714           $worksheet2->write( 'A1', 'Region', $bold );
7715           $worksheet2->write( 'A2', 'North' );
7716           $worksheet2->write( 'A3', 'North' );
7717           $worksheet2->write( 'A4', 'North' );
7718           $worksheet2->write( 'A5', 'North' );
7719           $worksheet2->write( 'A6', 'North Total', $bold );
7720
7721           $worksheet2->write( 'B1', 'Sales', $bold );
7722           $worksheet2->write( 'B2', 1000 );
7723           $worksheet2->write( 'B3', 1200 );
7724           $worksheet2->write( 'B4', 900 );
7725           $worksheet2->write( 'B5', 1200 );
7726           $worksheet2->write( 'B6', '=SUBTOTAL(9,B2:B5)', $bold );
7727
7728           $worksheet2->write( 'A7',  'South' );
7729           $worksheet2->write( 'A8',  'South' );
7730           $worksheet2->write( 'A9',  'South' );
7731           $worksheet2->write( 'A10', 'South' );
7732           $worksheet2->write( 'A11', 'South Total', $bold );
7733
7734           $worksheet2->write( 'B7',  400 );
7735           $worksheet2->write( 'B8',  600 );
7736           $worksheet2->write( 'B9',  500 );
7737           $worksheet2->write( 'B10', 600 );
7738           $worksheet2->write( 'B11', '=SUBTOTAL(9,B7:B10)', $bold );
7739
7740           $worksheet2->write( 'A12', 'Grand Total',         $bold );
7741           $worksheet2->write( 'B12', '=SUBTOTAL(9,B2:B10)', $bold );
7742
7743
7744           ###############################################################################
7745           #
7746           # Example 3: Create a worksheet with outlined columns.
7747           #
7748           my $data = [
7749               [ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ' Total' ],
7750               [ 'North', 50,    20,    15,    25,    65,    80,    '=SUM(B2:G2)' ],
7751               [ 'South', 10,    20,    30,    50,    50,    50,    '=SUM(B3:G3)' ],
7752               [ 'East',  45,    75,    50,    15,    75,    100,   '=SUM(B4:G4)' ],
7753               [ 'West',  15,    15,    55,    35,    20,    50,    '=SUM(B5:G5)' ],
7754           ];
7755
7756           # Add bold format to the first row
7757           $worksheet3->set_row( 0, undef, $bold );
7758
7759           # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
7760           $worksheet3->set_column( 'A:A', 10, $bold );
7761           $worksheet3->set_column( 'B:G', 5, undef, 0, 1 );
7762           $worksheet3->set_column( 'H:H', 10 );
7763
7764           # Write the data and a formula
7765           $worksheet3->write_col( 'A1', $data );
7766           $worksheet3->write( 'H6', '=SUM(H2:H5)', $bold );
7767
7768
7769           ###############################################################################
7770           #
7771           # Example 4: Show all possible outline levels.
7772           #
7773           my $levels = [
7774               "Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6",
7775               "Level 7", "Level 6", "Level 5", "Level 4", "Level 3", "Level 2",
7776               "Level 1"
7777           ];
7778
7779
7780           $worksheet4->write_col( 'A1', $levels );
7781
7782           $worksheet4->set_row( 0,  undef, undef, undef, 1 );
7783           $worksheet4->set_row( 1,  undef, undef, undef, 2 );
7784           $worksheet4->set_row( 2,  undef, undef, undef, 3 );
7785           $worksheet4->set_row( 3,  undef, undef, undef, 4 );
7786           $worksheet4->set_row( 4,  undef, undef, undef, 5 );
7787           $worksheet4->set_row( 5,  undef, undef, undef, 6 );
7788           $worksheet4->set_row( 6,  undef, undef, undef, 7 );
7789           $worksheet4->set_row( 7,  undef, undef, undef, 6 );
7790           $worksheet4->set_row( 8,  undef, undef, undef, 5 );
7791           $worksheet4->set_row( 9,  undef, undef, undef, 4 );
7792           $worksheet4->set_row( 10, undef, undef, undef, 3 );
7793           $worksheet4->set_row( 11, undef, undef, undef, 2 );
7794           $worksheet4->set_row( 12, undef, undef, undef, 1 );
7795
7796           $workbook->close();
7797
7798           __END__
7799
7800       Download this example:
7801       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/outline.pl>
7802
7803   Example: outline_collapsed.pl
7804       Example of how to use Excel::Writer::XLSX to generate Excel outlines
7805       and grouping.
7806
7807       These examples focus mainly on collapsed outlines. See also the
7808       outlines.pl example program for more general examples.
7809
7810       Source code for this example:
7811
7812           #!/usr/bin/perl
7813
7814           ###############################################################################
7815           #
7816           # Example of how to use Excel::Writer::XLSX to generate Excel outlines and
7817           # grouping.
7818           #
7819           # These examples focus mainly on collapsed outlines. See also the
7820           # outlines.pl example program for more general examples.
7821           #
7822           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
7823           #
7824
7825           use strict;
7826           use warnings;
7827           use Excel::Writer::XLSX;
7828
7829           # Create a new workbook and add some worksheets
7830           my $workbook   = Excel::Writer::XLSX->new( 'outline_collapsed.xlsx' );
7831           my $worksheet1 = $workbook->add_worksheet( 'Outlined Rows' );
7832           my $worksheet2 = $workbook->add_worksheet( 'Collapsed Rows 1' );
7833           my $worksheet3 = $workbook->add_worksheet( 'Collapsed Rows 2' );
7834           my $worksheet4 = $workbook->add_worksheet( 'Collapsed Rows 3' );
7835           my $worksheet5 = $workbook->add_worksheet( 'Outline Columns' );
7836           my $worksheet6 = $workbook->add_worksheet( 'Collapsed Columns' );
7837
7838
7839           # Add a general format
7840           my $bold = $workbook->add_format( bold => 1 );
7841
7842
7843           #
7844           # This function will generate the same data and sub-totals on each worksheet.
7845           #
7846           sub create_sub_totals {
7847
7848               my $worksheet = $_[0];
7849
7850               # Add a column format for clarity
7851               $worksheet->set_column( 'A:A', 20 );
7852
7853               # Add the data, labels and formulas
7854               $worksheet->write( 'A1', 'Region', $bold );
7855               $worksheet->write( 'A2', 'North' );
7856               $worksheet->write( 'A3', 'North' );
7857               $worksheet->write( 'A4', 'North' );
7858               $worksheet->write( 'A5', 'North' );
7859               $worksheet->write( 'A6', 'North Total', $bold );
7860
7861               $worksheet->write( 'B1', 'Sales', $bold );
7862               $worksheet->write( 'B2', 1000 );
7863               $worksheet->write( 'B3', 1200 );
7864               $worksheet->write( 'B4', 900 );
7865               $worksheet->write( 'B5', 1200 );
7866               $worksheet->write( 'B6', '=SUBTOTAL(9,B2:B5)', $bold );
7867
7868               $worksheet->write( 'A7',  'South' );
7869               $worksheet->write( 'A8',  'South' );
7870               $worksheet->write( 'A9',  'South' );
7871               $worksheet->write( 'A10', 'South' );
7872               $worksheet->write( 'A11', 'South Total', $bold );
7873
7874               $worksheet->write( 'B7',  400 );
7875               $worksheet->write( 'B8',  600 );
7876               $worksheet->write( 'B9',  500 );
7877               $worksheet->write( 'B10', 600 );
7878               $worksheet->write( 'B11', '=SUBTOTAL(9,B7:B10)', $bold );
7879
7880               $worksheet->write( 'A12', 'Grand Total',         $bold );
7881               $worksheet->write( 'B12', '=SUBTOTAL(9,B2:B10)', $bold );
7882
7883           }
7884
7885
7886           ###############################################################################
7887           #
7888           # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
7889           # functions so that it looks like the type of automatic outlines that are
7890           # generated when you use the Excel Data->SubTotals menu item.
7891           #
7892
7893           # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
7894           $worksheet1->set_row( 1, undef, undef, 0, 2 );
7895           $worksheet1->set_row( 2, undef, undef, 0, 2 );
7896           $worksheet1->set_row( 3, undef, undef, 0, 2 );
7897           $worksheet1->set_row( 4, undef, undef, 0, 2 );
7898           $worksheet1->set_row( 5, undef, undef, 0, 1 );
7899
7900           $worksheet1->set_row( 6,  undef, undef, 0, 2 );
7901           $worksheet1->set_row( 7,  undef, undef, 0, 2 );
7902           $worksheet1->set_row( 8,  undef, undef, 0, 2 );
7903           $worksheet1->set_row( 9,  undef, undef, 0, 2 );
7904           $worksheet1->set_row( 10, undef, undef, 0, 1 );
7905
7906           # Write the sub-total data that is common to the row examples.
7907           create_sub_totals( $worksheet1 );
7908
7909
7910           ###############################################################################
7911           #
7912           # Example 2: Create a worksheet with collapsed outlined rows.
7913           # This is the same as the example 1  except that the all rows are collapsed.
7914           # Note: We need to indicate the row that contains the collapsed symbol '+' with
7915           # the optional parameter, $collapsed.
7916
7917           $worksheet2->set_row( 1, undef, undef, 1, 2 );
7918           $worksheet2->set_row( 2, undef, undef, 1, 2 );
7919           $worksheet2->set_row( 3, undef, undef, 1, 2 );
7920           $worksheet2->set_row( 4, undef, undef, 1, 2 );
7921           $worksheet2->set_row( 5, undef, undef, 1, 1 );
7922
7923           $worksheet2->set_row( 6,  undef, undef, 1, 2 );
7924           $worksheet2->set_row( 7,  undef, undef, 1, 2 );
7925           $worksheet2->set_row( 8,  undef, undef, 1, 2 );
7926           $worksheet2->set_row( 9,  undef, undef, 1, 2 );
7927           $worksheet2->set_row( 10, undef, undef, 1, 1 );
7928
7929           $worksheet2->set_row( 11, undef, undef, 0, 0, 1 );
7930
7931           # Write the sub-total data that is common to the row examples.
7932           create_sub_totals( $worksheet2 );
7933
7934
7935           ###############################################################################
7936           #
7937           # Example 3: Create a worksheet with collapsed outlined rows.
7938           # Same as the example 1  except that the two sub-totals are collapsed.
7939
7940           $worksheet3->set_row( 1, undef, undef, 1, 2 );
7941           $worksheet3->set_row( 2, undef, undef, 1, 2 );
7942           $worksheet3->set_row( 3, undef, undef, 1, 2 );
7943           $worksheet3->set_row( 4, undef, undef, 1, 2 );
7944           $worksheet3->set_row( 5, undef, undef, 0, 1, 1 );
7945
7946           $worksheet3->set_row( 6,  undef, undef, 1, 2 );
7947           $worksheet3->set_row( 7,  undef, undef, 1, 2 );
7948           $worksheet3->set_row( 8,  undef, undef, 1, 2 );
7949           $worksheet3->set_row( 9,  undef, undef, 1, 2 );
7950           $worksheet3->set_row( 10, undef, undef, 0, 1, 1 );
7951
7952
7953           # Write the sub-total data that is common to the row examples.
7954           create_sub_totals( $worksheet3 );
7955
7956
7957           ###############################################################################
7958           #
7959           # Example 4: Create a worksheet with outlined rows.
7960           # Same as the example 1  except that the two sub-totals are collapsed.
7961
7962           $worksheet4->set_row( 1, undef, undef, 1, 2 );
7963           $worksheet4->set_row( 2, undef, undef, 1, 2 );
7964           $worksheet4->set_row( 3, undef, undef, 1, 2 );
7965           $worksheet4->set_row( 4, undef, undef, 1, 2 );
7966           $worksheet4->set_row( 5, undef, undef, 1, 1, 1 );
7967
7968           $worksheet4->set_row( 6,  undef, undef, 1, 2 );
7969           $worksheet4->set_row( 7,  undef, undef, 1, 2 );
7970           $worksheet4->set_row( 8,  undef, undef, 1, 2 );
7971           $worksheet4->set_row( 9,  undef, undef, 1, 2 );
7972           $worksheet4->set_row( 10, undef, undef, 1, 1, 1 );
7973
7974           $worksheet4->set_row( 11, undef, undef, 0, 0, 1 );
7975
7976           # Write the sub-total data that is common to the row examples.
7977           create_sub_totals( $worksheet4 );
7978
7979
7980           ###############################################################################
7981           #
7982           # Example 5: Create a worksheet with outlined columns.
7983           #
7984           my $data = [
7985               [ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Total' ],
7986               [ 'North', 50,    20,    15,    25,    65,    80,,   '=SUM(B2:G2)' ],
7987               [ 'South', 10,    20,    30,    50,    50,    50,,   '=SUM(B3:G3)' ],
7988               [ 'East',  45,    75,    50,    15,    75,    100,,  '=SUM(B4:G4)' ],
7989               [ 'West',  15,    15,    55,    35,    20,    50,,   '=SUM(B5:G6)' ],
7990           ];
7991
7992           # Add bold format to the first row
7993           $worksheet5->set_row( 0, undef, $bold );
7994
7995           # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
7996           $worksheet5->set_column( 'A:A', 10, $bold );
7997           $worksheet5->set_column( 'B:G', 5, undef, 0, 1 );
7998           $worksheet5->set_column( 'H:H', 10 );
7999
8000           # Write the data and a formula
8001           $worksheet5->write_col( 'A1', $data );
8002           $worksheet5->write( 'H6', '=SUM(H2:H5)', $bold );
8003
8004
8005           ###############################################################################
8006           #
8007           # Example 6: Create a worksheet with collapsed outlined columns.
8008           # This is the same as the previous example except collapsed columns.
8009
8010           # Add bold format to the first row
8011           $worksheet6->set_row( 0, undef, $bold );
8012
8013           # Syntax: set_column($col1, $col2, $width, $XF, $hidden, $level, $collapsed)
8014           $worksheet6->set_column( 'A:A', 10, $bold );
8015           $worksheet6->set_column( 'B:G', 5,  undef, 1, 1 );
8016           $worksheet6->set_column( 'H:H', 10, undef, 0, 0, 1 );
8017
8018           # Write the data and a formula
8019           $worksheet6->write_col( 'A1', $data );
8020           $worksheet6->write( 'H6', '=SUM(H2:H5)', $bold );
8021
8022           $workbook->close();
8023
8024           __END__
8025
8026       Download this example:
8027       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/outline_collapsed.pl>
8028
8029   Example: panes.pl
8030       Example of using the Excel::Writer::XLSX module to create worksheet
8031       panes.
8032
8033       Source code for this example:
8034
8035           #!/usr/bin/perl
8036
8037           #######################################################################
8038           #
8039           # Example of using the Excel::Writer::XLSX module to create worksheet panes.
8040           #
8041           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8042           #
8043
8044           use strict;
8045           use warnings;
8046           use Excel::Writer::XLSX;
8047
8048           my $workbook = Excel::Writer::XLSX->new( 'panes.xlsx' );
8049
8050           my $worksheet1 = $workbook->add_worksheet( 'Panes 1' );
8051           my $worksheet2 = $workbook->add_worksheet( 'Panes 2' );
8052           my $worksheet3 = $workbook->add_worksheet( 'Panes 3' );
8053           my $worksheet4 = $workbook->add_worksheet( 'Panes 4' );
8054
8055           # Freeze panes
8056           $worksheet1->freeze_panes( 1, 0 );    # 1 row
8057
8058           $worksheet2->freeze_panes( 0, 1 );    # 1 column
8059           $worksheet3->freeze_panes( 1, 1 );    # 1 row and column
8060
8061           # Split panes.
8062           # The divisions must be specified in terms of row and column dimensions.
8063           # The default row height is 15 and the default column width is 8.43
8064           #
8065           $worksheet4->split_panes( 15, 8.43 );    # 1 row and column
8066
8067
8068           #######################################################################
8069           #
8070           # Set up some formatting and text to highlight the panes
8071           #
8072
8073           my $header = $workbook->add_format(
8074               align    => 'center',
8075               valign   => 'vcenter',
8076               fg_color => '#C3FFC0',
8077           );
8078
8079           my $center = $workbook->add_format( align => 'center' );
8080
8081
8082           #######################################################################
8083           #
8084           # Sheet 1
8085           #
8086
8087           $worksheet1->set_column( 'A:I', 16 );
8088           $worksheet1->set_row( 0, 20 );
8089           $worksheet1->set_selection( 'C3' );
8090
8091           for my $i ( 0 .. 8 ) {
8092               $worksheet1->write( 0, $i, 'Scroll down', $header );
8093           }
8094
8095           for my $i ( 1 .. 100 ) {
8096               for my $j ( 0 .. 8 ) {
8097                   $worksheet1->write( $i, $j, $i + 1, $center );
8098               }
8099           }
8100
8101
8102           #######################################################################
8103           #
8104           # Sheet 2
8105           #
8106
8107           $worksheet2->set_column( 'A:A', 16 );
8108           $worksheet2->set_selection( 'C3' );
8109
8110           for my $i ( 0 .. 49 ) {
8111               $worksheet2->set_row( $i, 15 );
8112               $worksheet2->write( $i, 0, 'Scroll right', $header );
8113           }
8114
8115           for my $i ( 0 .. 49 ) {
8116               for my $j ( 1 .. 25 ) {
8117                   $worksheet2->write( $i, $j, $j, $center );
8118               }
8119           }
8120
8121
8122           #######################################################################
8123           #
8124           # Sheet 3
8125           #
8126
8127           $worksheet3->set_column( 'A:Z', 16 );
8128           $worksheet3->set_selection( 'C3' );
8129
8130           $worksheet3->write( 0, 0, '', $header );
8131
8132           for my $i ( 1 .. 25 ) {
8133               $worksheet3->write( 0, $i, 'Scroll down', $header );
8134           }
8135
8136           for my $i ( 1 .. 49 ) {
8137               $worksheet3->write( $i, 0, 'Scroll right', $header );
8138           }
8139
8140           for my $i ( 1 .. 49 ) {
8141               for my $j ( 1 .. 25 ) {
8142                   $worksheet3->write( $i, $j, $j, $center );
8143               }
8144           }
8145
8146
8147           #######################################################################
8148           #
8149           # Sheet 4
8150           #
8151
8152           $worksheet4->set_selection( 'C3' );
8153
8154           for my $i ( 1 .. 25 ) {
8155               $worksheet4->write( 0, $i, 'Scroll', $center );
8156           }
8157
8158           for my $i ( 1 .. 49 ) {
8159               $worksheet4->write( $i, 0, 'Scroll', $center );
8160           }
8161
8162           for my $i ( 1 .. 49 ) {
8163               for my $j ( 1 .. 25 ) {
8164                   $worksheet4->write( $i, $j, $j, $center );
8165               }
8166           }
8167
8168           $workbook->close();
8169
8170           __END__
8171
8172       Download this example:
8173       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/panes.pl>
8174
8175   Example: properties.pl
8176       An example of adding document properties to a Excel::Writer::XLSX file.
8177
8178       Source code for this example:
8179
8180           #!/usr/bin/perl
8181
8182           ##############################################################################
8183           #
8184           # An example of adding document properties to a Excel::Writer::XLSX file.
8185           #
8186           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8187           #
8188
8189           use strict;
8190           use warnings;
8191           use Excel::Writer::XLSX;
8192
8193           my $workbook  = Excel::Writer::XLSX->new( 'properties.xlsx' );
8194           my $worksheet = $workbook->add_worksheet();
8195
8196
8197           $workbook->set_properties(
8198               title    => 'This is an example spreadsheet',
8199               subject  => 'With document properties',
8200               author   => 'John McNamara',
8201               manager  => 'Dr. Heinz Doofenshmirtz',
8202               company  => 'of Wolves',
8203               category => 'Example spreadsheets',
8204               keywords => 'Sample, Example, Properties',
8205               comments => 'Created with Perl and Excel::Writer::XLSX',
8206               status   => 'Quo',
8207           );
8208
8209
8210           $worksheet->set_column( 'A:A', 70 );
8211           $worksheet->write( 'A1', qq{Select 'Office Button -> Prepare -> Properties' to see the file properties.} );
8212
8213           $workbook->close();
8214
8215           __END__
8216
8217       Download this example:
8218       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/properties.pl>
8219
8220   Example: protection.pl
8221       Example of cell locking and formula hiding in an Excel worksheet via
8222       the Excel::Writer::XLSX module.
8223
8224       Source code for this example:
8225
8226           #!/usr/bin/perl
8227
8228           ########################################################################
8229           #
8230           # Example of cell locking and formula hiding in an Excel worksheet via
8231           # the Excel::Writer::XLSX module.
8232           #
8233           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8234           #
8235
8236           use strict;
8237           use warnings;
8238           use Excel::Writer::XLSX;
8239
8240           my $workbook  = Excel::Writer::XLSX->new( 'protection.xlsx' );
8241           my $worksheet = $workbook->add_worksheet();
8242
8243           # Create some format objects
8244           my $unlocked = $workbook->add_format( locked => 0 );
8245           my $hidden   = $workbook->add_format( hidden => 1 );
8246
8247           # Format the columns
8248           $worksheet->set_column( 'A:A', 45 );
8249           $worksheet->set_selection( 'B3' );
8250
8251           # Protect the worksheet
8252           $worksheet->protect();
8253
8254           # Examples of cell locking and hiding.
8255           $worksheet->write( 'A1', 'Cell B1 is locked. It cannot be edited.' );
8256           $worksheet->write_formula( 'B1', '=1+2', undef, 3 );    # Locked by default.
8257
8258           $worksheet->write( 'A2', 'Cell B2 is unlocked. It can be edited.' );
8259           $worksheet->write_formula( 'B2', '=1+2', $unlocked, 3 );
8260
8261           $worksheet->write( 'A3', "Cell B3 is hidden. The formula isn't visible." );
8262           $worksheet->write_formula( 'B3', '=1+2', $hidden, 3 );
8263
8264           $worksheet->write( 'A5', 'Use Menu->Tools->Protection->Unprotect Sheet' );
8265           $worksheet->write( 'A6', 'to remove the worksheet protection.' );
8266
8267           $workbook->close();
8268
8269           __END__
8270
8271       Download this example:
8272       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/protection.pl>
8273
8274   Example: rich_strings.pl
8275       An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
8276       strings with multiple formatting.
8277
8278       Source code for this example:
8279
8280           #!/usr/bin/perl
8281
8282           #######################################################################
8283           #
8284           # An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
8285           # strings with multiple formatting.
8286           #
8287           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8288           #
8289
8290           use strict;
8291           use warnings;
8292           use Excel::Writer::XLSX;
8293
8294           my $workbook  = Excel::Writer::XLSX->new( 'rich_strings.xlsx' );
8295           my $worksheet = $workbook->add_worksheet();
8296
8297           $worksheet->set_column( 'A:A', 30 );
8298
8299           # Set some formats to use.
8300           my $bold   = $workbook->add_format( bold        => 1 );
8301           my $italic = $workbook->add_format( italic      => 1 );
8302           my $red    = $workbook->add_format( color       => 'red' );
8303           my $blue   = $workbook->add_format( color       => 'blue' );
8304           my $center = $workbook->add_format( align       => 'center' );
8305           my $super  = $workbook->add_format( font_script => 1 );
8306
8307
8308           # Write some strings with multiple formats.
8309           $worksheet->write_rich_string( 'A1',
8310               'This is ', $bold, 'bold', ' and this is ', $italic, 'italic' );
8311
8312           $worksheet->write_rich_string( 'A3',
8313               'This is ', $red, 'red', ' and this is ', $blue, 'blue' );
8314
8315           $worksheet->write_rich_string( 'A5',
8316               'Some ', $bold, 'bold text', ' centered', $center );
8317
8318           $worksheet->write_rich_string( 'A7',
8319               $italic, 'j = k', $super, '(n-1)', $center );
8320
8321           $workbook->close();
8322
8323           __END__
8324
8325       Download this example:
8326       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/rich_strings.pl>
8327
8328   Example: right_to_left.pl
8329       Example of how to change the default worksheet direction from left-to-
8330       right to right-to-left as required by some eastern verions of Excel.
8331
8332       Source code for this example:
8333
8334           #!/usr/bin/perl
8335
8336           #######################################################################
8337           #
8338           # Example of how to change the default worksheet direction from
8339           # left-to-right to right-to-left as required by some eastern verions
8340           # of Excel.
8341           #
8342           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8343           #
8344
8345           use strict;
8346           use warnings;
8347           use Excel::Writer::XLSX;
8348
8349           my $workbook   = Excel::Writer::XLSX->new( 'right_to_left.xlsx' );
8350           my $worksheet1 = $workbook->add_worksheet();
8351           my $worksheet2 = $workbook->add_worksheet();
8352
8353           $worksheet2->right_to_left();
8354
8355           $worksheet1->write( 0, 0, 'Hello' );    #  A1, B1, C1, ...
8356           $worksheet2->write( 0, 0, 'Hello' );    # ..., C1, B1, A1
8357
8358           $workbook->close();
8359
8360           __END__
8361
8362       Download this example:
8363       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/right_to_left.pl>
8364
8365   Example: sales.pl
8366       Example of a sales worksheet to demonstrate several different features.
8367       Also uses functions from the Excel::Writer::XLSX::Utility module.
8368
8369       Source code for this example:
8370
8371           #!/usr/bin/perl -w
8372
8373           ###############################################################################
8374           #
8375           # Example of a sales worksheet to demonstrate several different features.
8376           # Also uses functions from the L<Excel::Writer::XLSX::Utility> module.
8377           #
8378           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8379           #
8380
8381           use strict;
8382           use Excel::Writer::XLSX;
8383           use Excel::Writer::XLSX::Utility;
8384
8385           # Create a new workbook and add a worksheet
8386           my $workbook  = Excel::Writer::XLSX->new( 'sales.xlsx' );
8387           my $worksheet = $workbook->add_worksheet( 'May Sales' );
8388
8389
8390           # Set up some formats
8391           my %heading = (
8392               bold     => 1,
8393               pattern  => 1,
8394               fg_color => '#C3FFC0',
8395               border   => 1,
8396               align    => 'center',
8397           );
8398
8399           my %total = (
8400               bold       => 1,
8401               top        => 1,
8402               num_format => '$#,##0.00'
8403           );
8404
8405           my $heading      = $workbook->add_format( %heading );
8406           my $total_format = $workbook->add_format( %total );
8407           my $price_format = $workbook->add_format( num_format => '$#,##0.00' );
8408           my $date_format  = $workbook->add_format( num_format => 'mmm d yyy' );
8409
8410
8411           # Write the main headings
8412           $worksheet->freeze_panes( 1 );    # Freeze the first row
8413           $worksheet->write( 'A1', 'Item',     $heading );
8414           $worksheet->write( 'B1', 'Quantity', $heading );
8415           $worksheet->write( 'C1', 'Price',    $heading );
8416           $worksheet->write( 'D1', 'Total',    $heading );
8417           $worksheet->write( 'E1', 'Date',     $heading );
8418
8419           # Set the column widths
8420           $worksheet->set_column( 'A:A', 25 );
8421           $worksheet->set_column( 'B:B', 10 );
8422           $worksheet->set_column( 'C:E', 16 );
8423
8424
8425           # Extract the sales data from the __DATA__ section at the end of the file.
8426           # In reality this information would probably come from a database
8427           my @sales;
8428
8429           foreach my $line ( <DATA> ) {
8430               chomp $line;
8431               next if $line eq '';
8432
8433               # Simple-minded processing of CSV data. Refer to the Text::CSV_XS
8434               # and Text::xSV modules for a more complete CSV handling.
8435               my @items = split /,/, $line;
8436               push @sales, \@items;
8437           }
8438
8439
8440           # Write out the items from each row
8441           my $row = 1;
8442           foreach my $sale ( @sales ) {
8443
8444               $worksheet->write( $row, 0, @$sale[0] );
8445               $worksheet->write( $row, 1, @$sale[1] );
8446               $worksheet->write( $row, 2, @$sale[2], $price_format );
8447
8448               # Create a formula like '=B2*C2'
8449               my $formula =
8450                 '=' . xl_rowcol_to_cell( $row, 1 ) . "*" . xl_rowcol_to_cell( $row, 2 );
8451
8452               $worksheet->write( $row, 3, $formula, $price_format );
8453
8454               # Parse the date
8455               my $date = xl_decode_date_US( @$sale[3] );
8456               $worksheet->write( $row, 4, $date, $date_format );
8457               $row++;
8458           }
8459
8460           # Create a formula to sum the totals, like '=SUM(D2:D6)'
8461           my $total = '=SUM(D2:' . xl_rowcol_to_cell( $row - 1, 3 ) . ")";
8462
8463           $worksheet->write( $row, 3, $total, $total_format );
8464
8465           $workbook->close();
8466
8467           __DATA__
8468           586 card,20,125.50,5/12/01
8469           Flat Screen Monitor,1,1300.00,5/12/01
8470           64 MB dimms,45,49.99,5/13/01
8471           15 GB HD,12,300.00,5/13/01
8472           Speakers (pair),5,15.50,5/14/01
8473
8474       Download this example:
8475       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/sales.pl>
8476
8477   Example: shape1.pl
8478       A simple example of how to use the Excel::Writer::XLSX module to add
8479       shapes to an Excel xlsx file.
8480
8481       Source code for this example:
8482
8483           #!/usr/bin/perl
8484
8485           #######################################################################
8486           #
8487           # A simple example of how to use the Excel::Writer::XLSX module to
8488           # add shapes to an Excel xlsx file.
8489           #
8490           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8491           #
8492
8493           use strict;
8494           use warnings;
8495           use Excel::Writer::XLSX;
8496
8497           my $workbook  = Excel::Writer::XLSX->new( 'shape1.xlsx' );
8498           my $worksheet = $workbook->add_worksheet();
8499
8500           # Add a circle, with centered text.
8501           my $ellipse = $workbook->add_shape(
8502               type   => 'ellipse',
8503               text   => "Hello\nWorld",
8504               width  => 60,
8505               height => 60
8506           );
8507
8508           $worksheet->insert_shape( 'A1', $ellipse, 50, 50 );
8509
8510           # Add a plus sign.
8511           my $plus = $workbook->add_shape( type => 'plus', width => 20, height => 20 );
8512           $worksheet->insert_shape( 'D8', $plus );
8513
8514           $workbook->close();
8515
8516           __END__
8517
8518       Download this example:
8519       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/shape1.pl>
8520
8521   Example: shape2.pl
8522       A simple example of how to use the Excel::Writer::XLSX module to modify
8523       shape properties in an Excel xlsx file.
8524
8525       Source code for this example:
8526
8527           #!/usr/bin/perl
8528
8529           #######################################################################
8530           #
8531           # A simple example of how to use the Excel::Writer::XLSX module to
8532           # modify shape properties in an Excel xlsx file.
8533           #
8534           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8535           #
8536
8537           use strict;
8538           use warnings;
8539           use Excel::Writer::XLSX;
8540
8541           my $workbook  = Excel::Writer::XLSX->new( 'shape2.xlsx' );
8542           my $worksheet = $workbook->add_worksheet();
8543
8544           $worksheet->hide_gridlines( 2 );
8545
8546           my $plain = $workbook->add_shape(
8547               type   => 'smileyFace',
8548               text   => "Plain",
8549               width  => 100,
8550               height => 100,
8551           );
8552
8553           my $bbformat = $workbook->add_format(
8554               color => 'red',
8555               font  => 'Lucida Calligraphy',
8556           );
8557
8558           $bbformat->set_bold();
8559           $bbformat->set_underline();
8560           $bbformat->set_italic();
8561
8562           my $decor = $workbook->add_shape(
8563               type        => 'smileyFace',
8564               text        => "Decorated",
8565               rotation    => 45,
8566               width       => 200,
8567               height      => 100,
8568               format      => $bbformat,
8569               line_type   => 'sysDot',
8570               line_weight => 3,
8571               fill        => 'FFFF00',
8572               line        => '3366FF',
8573           );
8574
8575           $worksheet->insert_shape( 'A1', $plain, 50,  50 );
8576           $worksheet->insert_shape( 'A1', $decor, 250, 50 );
8577
8578           $workbook->close();
8579
8580           __END__
8581
8582       Download this example:
8583       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/shape2.pl>
8584
8585   Example: shape3.pl
8586       A simple example of how to use the Excel::Writer::XLSX module to scale
8587       shapes in an Excel xlsx file.
8588
8589       Source code for this example:
8590
8591           #!/usr/bin/perl
8592
8593           #######################################################################
8594           #
8595           # A simple example of how to use the Excel::Writer::XLSX module to
8596           # scale shapes in an Excel xlsx file.
8597           #
8598           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8599           #
8600
8601           use strict;
8602           use warnings;
8603           use Excel::Writer::XLSX;
8604
8605           my $workbook  = Excel::Writer::XLSX->new( 'shape3.xlsx' );
8606           my $worksheet = $workbook->add_worksheet();
8607
8608           my $normal = $workbook->add_shape(
8609               name   => 'chip',
8610               type   => 'diamond',
8611               text   => "Normal",
8612               width  => 100,
8613               height => 100,
8614           );
8615
8616           $worksheet->insert_shape( 'A1', $normal, 50, 50 );
8617           $normal->set_text( 'Scaled 3w x 2h' );
8618           $normal->set_name( 'Hope' );
8619           $worksheet->insert_shape( 'A1', $normal, 250, 50, 3, 2 );
8620
8621           $workbook->close();
8622
8623           __END__
8624
8625       Download this example:
8626       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/shape3.pl>
8627
8628   Example: shape4.pl
8629       A simple example of how to use the Excel::Writer::XLSX module to
8630       demonstrate stenciling in an Excel xlsx file.
8631
8632       Source code for this example:
8633
8634           #!/usr/bin/perl
8635
8636           #######################################################################
8637           #
8638           # A simple example of how to use the Excel::Writer::XLSX module to
8639           # demonstrate stenciling in an Excel xlsx file.
8640           #
8641           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8642           #
8643
8644           use strict;
8645           use warnings;
8646           use Excel::Writer::XLSX;
8647
8648           my $workbook  = Excel::Writer::XLSX->new( 'shape4.xlsx' );
8649           my $worksheet = $workbook->add_worksheet();
8650
8651           $worksheet->hide_gridlines( 2 );
8652
8653           my $type  = 'rect';
8654           my $shape = $workbook->add_shape(
8655               type   => $type,
8656               width  => 90,
8657               height => 90,
8658           );
8659
8660           for my $n ( 1 .. 10 ) {
8661
8662               # Change the last 5 rectangles to stars. Previously inserted shapes stay
8663               # as rectangles.
8664               $type = 'star5' if $n == 6;
8665               $shape->set_type( $type );
8666               $shape->set_text( "$type $n" );
8667               $worksheet->insert_shape( 'A1', $shape, $n * 100, 50 );
8668           }
8669
8670
8671           my $stencil = $workbook->add_shape(
8672               stencil => 1,                    # The default.
8673               width   => 90,
8674               height  => 90,
8675               text    => 'started as a box',
8676           );
8677           $worksheet->insert_shape( 'A1', $stencil, 100, 150 );
8678
8679           $stencil->set_stencil( 0 );
8680           $worksheet->insert_shape( 'A1', $stencil, 200, 150 );
8681           $worksheet->insert_shape( 'A1', $stencil, 300, 150 );
8682
8683           # Ooops!  Changed my mind.  Change the rectangle to an ellipse (circle),
8684           # for the last two shapes.
8685           $stencil->set_type( 'ellipse' );
8686           $stencil->set_text( 'Now its a circle' );
8687
8688           $workbook->close();
8689
8690           __END__
8691
8692       Download this example:
8693       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/shape4.pl>
8694
8695   Example: shape5.pl
8696       A simple example of how to use the Excel::Writer::XLSX module to add
8697       shapes (objects and top/bottom connectors) to an Excel xlsx file.
8698
8699       Source code for this example:
8700
8701           #!/usr/bin/perl
8702
8703           #######################################################################
8704           #
8705           # A simple example of how to use the Excel::Writer::XLSX module to
8706           # add shapes (objects and top/bottom connectors) to an Excel xlsx file.
8707           #
8708           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8709           #
8710
8711           use strict;
8712           use warnings;
8713           use Excel::Writer::XLSX;
8714
8715           my $workbook  = Excel::Writer::XLSX->new( 'shape5.xlsx' );
8716           my $worksheet = $workbook->add_worksheet();
8717
8718           my $s1 = $workbook->add_shape( type => 'ellipse', width => 60, height => 60 );
8719           $worksheet->insert_shape( 'A1', $s1, 50, 50 );
8720
8721           my $s2 = $workbook->add_shape( type => 'plus', width => 20, height => 20 );
8722           $worksheet->insert_shape( 'A1', $s2, 250, 200 );
8723
8724           # Create a connector to link the two shapes.
8725           my $cxn_shape = $workbook->add_shape( type => 'bentConnector3' );
8726
8727           # Link the start of the connector to the right side.
8728           $cxn_shape->set_start( $s1->get_id() );
8729           $cxn_shape->set_start_index( 4 );  # 4th connection pt, clockwise from top(0).
8730           $cxn_shape->set_start_side( 'b' ); # r)ight or b)ottom.
8731
8732           # Link the end of the connector to the left side.
8733           $cxn_shape->set_end( $s2->get_id() );
8734           $cxn_shape->set_end_index( 0 );     # clockwise from top(0).
8735           $cxn_shape->set_end_side( 't' );    # t)top.
8736
8737           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8738
8739           $workbook->close();
8740
8741           __END__
8742
8743       Download this example:
8744       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/shape5.pl>
8745
8746   Example: shape6.pl
8747       A simple example of how to use the Excel::Writer::XLSX module to add
8748       shapes (objects and right/left connectors) to an Excel xlsx file.
8749
8750       Source code for this example:
8751
8752           #!/usr/bin/perl
8753
8754           #######################################################################
8755           #
8756           # A simple example of how to use the Excel::Writer::XLSX module to
8757           # add shapes (objects and right/left connectors) to an Excel xlsx file.
8758           #
8759           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8760           #
8761
8762           use strict;
8763           use warnings;
8764           use Excel::Writer::XLSX;
8765
8766           my $workbook  = Excel::Writer::XLSX->new( 'shape6.xlsx' );
8767           my $worksheet = $workbook->add_worksheet();
8768
8769           my $s1 = $workbook->add_shape( type => 'chevron', width => 60, height => 60 );
8770           $worksheet->insert_shape( 'A1', $s1, 50, 50 );
8771
8772           my $s2 = $workbook->add_shape( type => 'pentagon', width => 20, height => 20 );
8773           $worksheet->insert_shape( 'A1', $s2, 250, 200 );
8774
8775           # Create a connector to link the two shapes.
8776           my $cxn_shape = $workbook->add_shape( type => 'curvedConnector3' );
8777
8778           # Link the start of the connector to the right side.
8779           $cxn_shape->set_start( $s1->get_id() );
8780           $cxn_shape->set_start_index( 2 );    # 2nd connection pt, clockwise from top(0).
8781           $cxn_shape->set_start_side( 'r' );   # r)ight or b)ottom.
8782
8783           # Link the end of the connector to the left side.
8784           $cxn_shape->set_end( $s2->get_id() );
8785           $cxn_shape->set_end_index( 4 );      # 4th connection pt, clockwise from top(0).
8786           $cxn_shape->set_end_side( 'l' );     # l)eft or t)op.
8787
8788           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8789
8790           $workbook->close();
8791
8792           __END__
8793
8794       Download this example:
8795       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/shape6.pl>
8796
8797   Example: shape7.pl
8798       A simple example of how to use the Excel::Writer::XLSX module to add
8799       shapes and one-to-many connectors to an Excel xlsx file.
8800
8801       Source code for this example:
8802
8803           #!/usr/bin/perl
8804
8805           #######################################################################
8806           #
8807           # A simple example of how to use the Excel::Writer::XLSX module to
8808           # add shapes and one-to-many connectors to an Excel xlsx file.
8809           #
8810           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8811           #
8812
8813           use strict;
8814           use warnings;
8815           use Excel::Writer::XLSX;
8816
8817           my $workbook  = Excel::Writer::XLSX->new( 'shape7.xlsx' );
8818           my $worksheet = $workbook->add_worksheet();
8819
8820           # Add a circle, with centered text. c is for circle, not center.
8821           my $cw = 60;
8822           my $ch = 60;
8823           my $cx = 210;
8824           my $cy = 190;
8825
8826           my $ellipse = $workbook->add_shape(
8827               type   => 'ellipse',
8828               id     => 2,
8829               text   => "Hello\nWorld",
8830               width  => $cw,
8831               height => $ch
8832           );
8833           $worksheet->insert_shape( 'A1', $ellipse, $cx, $cy );
8834
8835           # Add a plus sign at 4 different positions around the circle.
8836           my $pw = 20;
8837           my $ph = 20;
8838           my $px = 120;
8839           my $py = 250;
8840           my $plus =
8841             $workbook->add_shape( type => 'plus', id => 3, width => $pw, height => $ph );
8842           my $p1 = $worksheet->insert_shape( 'A1', $plus, 350, 350 );
8843           my $p2 = $worksheet->insert_shape( 'A1', $plus, 150, 350 );
8844           my $p3 = $worksheet->insert_shape( 'A1', $plus, 350, 150 );
8845           $plus->set_adjustments( 35 );    # change shape of plus symbol.
8846           my $p4 = $worksheet->insert_shape( 'A1', $plus, 150, 150 );
8847
8848           my $cxn_shape = $workbook->add_shape( type => 'bentConnector3', fill => 0 );
8849
8850           $cxn_shape->set_start( $ellipse->get_id() );
8851           $cxn_shape->set_start_index( 4 );    # 4nd connection pt, clockwise from top(0).
8852           $cxn_shape->set_start_side( 'b' );   # r)ight or b)ottom.
8853
8854           $cxn_shape->set_end( $p1->get_id() );
8855           $cxn_shape->set_end_index( 0 );
8856           $cxn_shape->set_end_side( 't' );
8857           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8858
8859           $cxn_shape->set_end( $p2->get_id() );
8860           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8861
8862           $cxn_shape->set_end( $p3->get_id() );
8863           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8864
8865           $cxn_shape->set_end( $p4->get_id() );
8866           $cxn_shape->set_adjustments( -50, 45, 120 );
8867           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8868
8869           $workbook->close();
8870
8871           __END__
8872
8873       Download this example:
8874       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/shape7.pl>
8875
8876   Example: shape8.pl
8877       A simple example of how to use the Excel::Writer::XLSX module to add
8878       shapes and one-to-many connectors to an Excel xlsx file.
8879
8880       Source code for this example:
8881
8882           #!/usr/bin/perl
8883
8884           #######################################################################
8885           #
8886           # A simple example of how to use the Excel::Writer::XLSX module to
8887           # add shapes and one-to-many connectors to an Excel xlsx file.
8888           #
8889           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8890           #
8891
8892           use strict;
8893           use warnings;
8894           use Excel::Writer::XLSX;
8895
8896           my $workbook  = Excel::Writer::XLSX->new( 'shape8.xlsx' );
8897           my $worksheet = $workbook->add_worksheet();
8898
8899           # Add a circle, with centered text. c is for circle, not center.
8900           my $cw = 60;
8901           my $ch = 60;
8902           my $cx = 210;
8903           my $cy = 190;
8904
8905           my $ellipse = $workbook->add_shape(
8906               type   => 'ellipse',
8907               id     => 2,
8908               text   => "Hello\nWorld",
8909               width  => $cw,
8910               height => $ch
8911           );
8912           $worksheet->insert_shape( 'A1', $ellipse, $cx, $cy );
8913
8914           # Add a plus sign at 4 different positions around the circle.
8915           my $pw = 20;
8916           my $ph = 20;
8917           my $px = 120;
8918           my $py = 250;
8919           my $plus =
8920             $workbook->add_shape( type => 'plus', id => 3, width => $pw, height => $ph );
8921           my $p1 = $worksheet->insert_shape( 'A1', $plus, 350, 150 );    #  2:00
8922           my $p2 = $worksheet->insert_shape( 'A1', $plus, 350, 350 );    #  4:00
8923           my $p3 = $worksheet->insert_shape( 'A1', $plus, 150, 350 );    #  8:00
8924           my $p4 = $worksheet->insert_shape( 'A1', $plus, 150, 150 );    # 10:00
8925
8926           my $cxn_shape = $workbook->add_shape( type => 'bentConnector3', fill => 0 );
8927
8928           $cxn_shape->set_start( $ellipse->get_id() );
8929           $cxn_shape->set_start_index( 2 );    # 2nd connection pt, clockwise from top(0).
8930           $cxn_shape->set_start_side( 'r' );   # r)ight or b)ottom.
8931
8932           $cxn_shape->set_end( $p1->get_id() );
8933           $cxn_shape->set_end_index( 3 );      # 3rd connection point on plus, right side
8934           $cxn_shape->set_end_side( 'l' );
8935           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8936
8937           $cxn_shape->set_end( $p2->get_id() );
8938           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8939
8940           $cxn_shape->set_end( $p3->get_id() );
8941           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8942
8943           $cxn_shape->set_end( $p4->get_id() );
8944           $cxn_shape->set_adjustments( -50, 45, 120 );
8945           $worksheet->insert_shape( 'A1', $cxn_shape, 0, 0 );
8946
8947           $workbook->close();
8948
8949           __END__
8950
8951       Download this example:
8952       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/shape8.pl>
8953
8954   Example: shape_all.pl
8955       A simple example of how to use the Excel::Writer::XLSX module to add
8956       all shapes (as currently implemented) to an Excel xlsx file.
8957
8958       The list at the end consists of all the shape types defined as
8959       ST_ShapeType in ECMA-376, Office Open XML File Formats Part 4.
8960
8961       The grouping by worksheet name is for illustration only. It isn't part
8962       of the ECMA-376 standard.
8963
8964       Source code for this example:
8965
8966           #!/usr/bin/perl
8967
8968           #######################################################################
8969           #
8970           # A simple example of how to use the Excel::Writer::XLSX module to
8971           # add all shapes (as currently implemented) to an Excel xlsx file.
8972           #
8973           # The list at the end consists of all the shape types defined as
8974           # ST_ShapeType in ECMA-376, Office Open XML File Formats Part 4.
8975           #
8976           # The grouping by worksheet name is for illustration only. It isn't
8977           # part of the ECMA-376 standard.
8978           #
8979           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
8980           #
8981
8982           use strict;
8983           use warnings;
8984           use Excel::Writer::XLSX;
8985
8986           my $workbook = Excel::Writer::XLSX->new( 'shape_all.xlsx' );
8987
8988           my ( $worksheet, $last_sheet, $shape, $r ) = ( 0, '', '', undef, 0 );
8989
8990           while ( <DATA> ) {
8991               chomp;
8992               next unless m/^\w/;    # Skip blank lines and comments.
8993
8994               my ( $sheet, $name ) = split( /\t/, $_ );
8995               if ( $last_sheet ne $sheet ) {
8996                   $worksheet = $workbook->add_worksheet( $sheet );
8997                   $r         = 2;
8998               }
8999               $last_sheet = $sheet;
9000               $shape      = $workbook->add_shape(
9001                   type   => $name,
9002                   text   => $name,
9003                   width  => 90,
9004                   height => 90
9005               );
9006
9007               # Connectors can not have labels, so write the connector name in the cell
9008               # to the left.
9009               $worksheet->write( $r, 0, $name ) if $sheet eq 'Connector';
9010               $worksheet->insert_shape( $r, 2, $shape, 0, 0 );
9011               $r += 5;
9012           }
9013
9014           $workbook->close();
9015
9016           __END__
9017           Action      actionButtonBackPrevious
9018           Action      actionButtonBeginning
9019           Action      actionButtonBlank
9020           Action      actionButtonDocument
9021           Action      actionButtonEnd
9022           Action      actionButtonForwardNext
9023           Action      actionButtonHelp
9024           Action      actionButtonHome
9025           Action      actionButtonInformation
9026           Action      actionButtonMovie
9027           Action      actionButtonReturn
9028           Action      actionButtonSound
9029           Arrow       bentArrow
9030           Arrow       bentUpArrow
9031           Arrow       circularArrow
9032           Arrow       curvedDownArrow
9033           Arrow       curvedLeftArrow
9034           Arrow       curvedRightArrow
9035           Arrow       curvedUpArrow
9036           Arrow       downArrow
9037           Arrow       leftArrow
9038           Arrow       leftCircularArrow
9039           Arrow       leftRightArrow
9040           Arrow       leftRightCircularArrow
9041           Arrow       leftRightUpArrow
9042           Arrow       leftUpArrow
9043           Arrow       notchedRightArrow
9044           Arrow       quadArrow
9045           Arrow       rightArrow
9046           Arrow       stripedRightArrow
9047           Arrow       swooshArrow
9048           Arrow       upArrow
9049           Arrow       upDownArrow
9050           Arrow       uturnArrow
9051           Basic       blockArc
9052           Basic       can
9053           Basic       chevron
9054           Basic       cube
9055           Basic       decagon
9056           Basic       diamond
9057           Basic       dodecagon
9058           Basic       donut
9059           Basic       ellipse
9060           Basic       funnel
9061           Basic       gear6
9062           Basic       gear9
9063           Basic       heart
9064           Basic       heptagon
9065           Basic       hexagon
9066           Basic       homePlate
9067           Basic       lightningBolt
9068           Basic       line
9069           Basic       lineInv
9070           Basic       moon
9071           Basic       nonIsoscelesTrapezoid
9072           Basic       noSmoking
9073           Basic       octagon
9074           Basic       parallelogram
9075           Basic       pentagon
9076           Basic       pie
9077           Basic       pieWedge
9078           Basic       plaque
9079           Basic       rect
9080           Basic       round1Rect
9081           Basic       round2DiagRect
9082           Basic       round2SameRect
9083           Basic       roundRect
9084           Basic       rtTriangle
9085           Basic       smileyFace
9086           Basic       snip1Rect
9087           Basic       snip2DiagRect
9088           Basic       snip2SameRect
9089           Basic       snipRoundRect
9090           Basic       star10
9091           Basic       star12
9092           Basic       star16
9093           Basic       star24
9094           Basic       star32
9095           Basic       star4
9096           Basic       star5
9097           Basic       star6
9098           Basic       star7
9099           Basic       star8
9100           Basic       sun
9101           Basic       teardrop
9102           Basic       trapezoid
9103           Basic       triangle
9104           Callout     accentBorderCallout1
9105           Callout     accentBorderCallout2
9106           Callout     accentBorderCallout3
9107           Callout     accentCallout1
9108           Callout     accentCallout2
9109           Callout     accentCallout3
9110           Callout     borderCallout1
9111           Callout     borderCallout2
9112           Callout     borderCallout3
9113           Callout     callout1
9114           Callout     callout2
9115           Callout     callout3
9116           Callout     cloudCallout
9117           Callout     downArrowCallout
9118           Callout     leftArrowCallout
9119           Callout     leftRightArrowCallout
9120           Callout     quadArrowCallout
9121           Callout     rightArrowCallout
9122           Callout     upArrowCallout
9123           Callout     upDownArrowCallout
9124           Callout     wedgeEllipseCallout
9125           Callout     wedgeRectCallout
9126           Callout     wedgeRoundRectCallout
9127           Chart       chartPlus
9128           Chart       chartStar
9129           Chart       chartX
9130           Connector   bentConnector2
9131           Connector   bentConnector3
9132           Connector   bentConnector4
9133           Connector   bentConnector5
9134           Connector   curvedConnector2
9135           Connector   curvedConnector3
9136           Connector   curvedConnector4
9137           Connector   curvedConnector5
9138           Connector   straightConnector1
9139           FlowChart   flowChartAlternateProcess
9140           FlowChart   flowChartCollate
9141           FlowChart   flowChartConnector
9142           FlowChart   flowChartDecision
9143           FlowChart   flowChartDelay
9144           FlowChart   flowChartDisplay
9145           FlowChart   flowChartDocument
9146           FlowChart   flowChartExtract
9147           FlowChart   flowChartInputOutput
9148           FlowChart   flowChartInternalStorage
9149           FlowChart   flowChartMagneticDisk
9150           FlowChart   flowChartMagneticDrum
9151           FlowChart   flowChartMagneticTape
9152           FlowChart   flowChartManualInput
9153           FlowChart   flowChartManualOperation
9154           FlowChart   flowChartMerge
9155           FlowChart   flowChartMultidocument
9156           FlowChart   flowChartOfflineStorage
9157           FlowChart   flowChartOffpageConnector
9158           FlowChart   flowChartOnlineStorage
9159           FlowChart   flowChartOr
9160           FlowChart   flowChartPredefinedProcess
9161           FlowChart   flowChartPreparation
9162           FlowChart   flowChartProcess
9163           FlowChart   flowChartPunchedCard
9164           FlowChart   flowChartPunchedTape
9165           FlowChart   flowChartSort
9166           FlowChart   flowChartSummingJunction
9167           FlowChart   flowChartTerminator
9168           Math        mathDivide
9169           Math        mathEqual
9170           Math        mathMinus
9171           Math        mathMultiply
9172           Math        mathNotEqual
9173           Math        mathPlus
9174           Star_Banner arc
9175           Star_Banner bevel
9176           Star_Banner bracePair
9177           Star_Banner bracketPair
9178           Star_Banner chord
9179           Star_Banner cloud
9180           Star_Banner corner
9181           Star_Banner diagStripe
9182           Star_Banner doubleWave
9183           Star_Banner ellipseRibbon
9184           Star_Banner ellipseRibbon2
9185           Star_Banner foldedCorner
9186           Star_Banner frame
9187           Star_Banner halfFrame
9188           Star_Banner horizontalScroll
9189           Star_Banner irregularSeal1
9190           Star_Banner irregularSeal2
9191           Star_Banner leftBrace
9192           Star_Banner leftBracket
9193           Star_Banner leftRightRibbon
9194           Star_Banner plus
9195           Star_Banner ribbon
9196           Star_Banner ribbon2
9197           Star_Banner rightBrace
9198           Star_Banner rightBracket
9199           Star_Banner verticalScroll
9200           Star_Banner wave
9201           Tabs        cornerTabs
9202           Tabs        plaqueTabs
9203           Tabs        squareTabs
9204
9205       Download this example:
9206       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/shape_all.pl>
9207
9208   Example: sparklines1.pl
9209       Example of how to add sparklines to an Excel::Writer::XLSX file.
9210
9211       Sparklines are small charts that fit in a single cell and are used to
9212       show trends in data. See sparklines2.pl for examples of more complex
9213       sparkline formatting.
9214
9215       Source code for this example:
9216
9217           #!/usr/bin/perl
9218
9219           ###############################################################################
9220           #
9221           # Example of how to add sparklines to an Excel::Writer::XLSX file.
9222           #
9223           # Sparklines are small charts that fit in a single cell and are
9224           # used to show trends in data. See sparklines2.pl for examples
9225           # of more complex sparkline formatting.
9226           #
9227           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
9228           #
9229
9230           use strict;
9231           use warnings;
9232           use Excel::Writer::XLSX;
9233
9234           my $workbook  = Excel::Writer::XLSX->new( 'sparklines1.xlsx' );
9235           my $worksheet = $workbook->add_worksheet();
9236
9237           # Some sample data to plot.
9238           my $data = [
9239
9240               [ -2, 2,  3,  -1, 0 ],
9241               [ 30, 20, 33, 20, 15 ],
9242               [ 1,  -1, -1, 1,  -1 ],
9243
9244           ];
9245
9246           # Write the sample data to the worksheet.
9247           $worksheet->write_col( 'A1', $data );
9248
9249
9250           # Add a line sparkline (the default) with markers.
9251           $worksheet->add_sparkline(
9252               {
9253                   location => 'F1',
9254                   range    => 'Sheet1!A1:E1',
9255                   markers  => 1,
9256               }
9257           );
9258
9259           # Add a column sparkline with non-default style.
9260           $worksheet->add_sparkline(
9261               {
9262                   location => 'F2',
9263                   range    => 'Sheet1!A2:E2',
9264                   type     => 'column',
9265                   style    => 12,
9266               }
9267           );
9268
9269           # Add a win/loss sparkline with negative values highlighted.
9270           $worksheet->add_sparkline(
9271               {
9272                   location        => 'F3',
9273                   range           => 'Sheet1!A3:E3',
9274                   type            => 'win_loss',
9275                   negative_points => 1,
9276               }
9277           );
9278
9279           $workbook->close();
9280
9281           __END__
9282
9283       Download this example:
9284       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/sparklines1.pl>
9285
9286   Example: sparklines2.pl
9287       Example of how to add sparklines to an Excel::Writer::XLSX file.
9288
9289       Sparklines are small charts that fit in a single cell and are used to
9290       show trends in data. This example shows the majority of options that
9291       can be applied to sparklines.
9292
9293       Source code for this example:
9294
9295           #!/usr/bin/perl
9296
9297           ###############################################################################
9298           #
9299           # Example of how to add sparklines to an Excel::Writer::XLSX file.
9300           #
9301           # Sparklines are small charts that fit in a single cell and are
9302           # used to show trends in data. This example shows the majority of
9303           # options that can be applied to sparklines.
9304           #
9305           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
9306           #
9307
9308           use strict;
9309           use warnings;
9310           use Excel::Writer::XLSX;
9311
9312           my $workbook    = Excel::Writer::XLSX->new( 'sparklines2.xlsx' );
9313           my $worksheet1  = $workbook->add_worksheet();
9314           my $worksheet2  = $workbook->add_worksheet();
9315           my $bold        = $workbook->add_format( bold => 1 );
9316           my $str;
9317           my $row = 1;
9318
9319           # Set the columns widths to make the output clearer.
9320           $worksheet1->set_column( 'A:A', 14 );
9321           $worksheet1->set_column( 'B:B', 50 );
9322           $worksheet1->set_zoom( 150 );
9323
9324           # Headings.
9325           $worksheet1->write( 'A1', 'Sparkline',   $bold );
9326           $worksheet1->write( 'B1', 'Description', $bold );
9327
9328
9329           ###############################################################################
9330           #
9331           $str = 'A default "line" sparkline.';
9332
9333           $worksheet1->add_sparkline(
9334               {
9335                   location => 'A2',
9336                   range    => 'Sheet2!A1:J1',
9337               }
9338           );
9339
9340           $worksheet1->write( $row++, 1, $str );
9341
9342
9343           ###############################################################################
9344           #
9345           $str = 'A default "column" sparkline.';
9346
9347           $worksheet1->add_sparkline(
9348               {
9349                   location => 'A3',
9350                   range    => 'Sheet2!A2:J2',
9351                   type     => 'column',
9352               }
9353           );
9354
9355           $worksheet1->write( $row++, 1, $str );
9356
9357
9358           ###############################################################################
9359           #
9360           $str = 'A default "win/loss" sparkline.';
9361
9362           $worksheet1->add_sparkline(
9363               {
9364                   location => 'A4',
9365                   range    => 'Sheet2!A3:J3',
9366                   type     => 'win_loss',
9367               }
9368           );
9369
9370           $worksheet1->write( $row++, 1, $str );
9371           $row++;
9372
9373
9374           ###############################################################################
9375           #
9376           $str = 'Line with markers.';
9377
9378           $worksheet1->add_sparkline(
9379               {
9380                   location => 'A6',
9381                   range    => 'Sheet2!A1:J1',
9382                   markers  => 1,
9383               }
9384           );
9385
9386           $worksheet1->write( $row++, 1, $str );
9387
9388
9389           ###############################################################################
9390           #
9391           $str = 'Line with high and low points.';
9392
9393           $worksheet1->add_sparkline(
9394               {
9395                   location   => 'A7',
9396                   range      => 'Sheet2!A1:J1',
9397                   high_point => 1,
9398                   low_point  => 1,
9399               }
9400           );
9401
9402           $worksheet1->write( $row++, 1, $str );
9403
9404
9405           ###############################################################################
9406           #
9407           $str = 'Line with first and last point markers.';
9408
9409           $worksheet1->add_sparkline(
9410               {
9411                   location    => 'A8',
9412                   range       => 'Sheet2!A1:J1',
9413                   first_point => 1,
9414                   last_point  => 1,
9415               }
9416           );
9417
9418           $worksheet1->write( $row++, 1, $str );
9419
9420
9421           ###############################################################################
9422           #
9423           $str = 'Line with negative point markers.';
9424
9425           $worksheet1->add_sparkline(
9426               {
9427                   location        => 'A9',
9428                   range           => 'Sheet2!A1:J1',
9429                   negative_points => 1,
9430               }
9431           );
9432
9433           $worksheet1->write( $row++, 1, $str );
9434
9435
9436           ###############################################################################
9437           #
9438           $str = 'Line with axis.';
9439
9440           $worksheet1->add_sparkline(
9441               {
9442                   location => 'A10',
9443                   range    => 'Sheet2!A1:J1',
9444                   axis     => 1,
9445               }
9446           );
9447
9448           $worksheet1->write( $row++, 1, $str );
9449           $row++;
9450
9451
9452           ###############################################################################
9453           #
9454           $str = 'Column with default style (1).';
9455
9456           $worksheet1->add_sparkline(
9457               {
9458                   location => 'A12',
9459                   range    => 'Sheet2!A2:J2',
9460                   type     => 'column',
9461               }
9462           );
9463
9464           $worksheet1->write( $row++, 1, $str );
9465
9466
9467           ###############################################################################
9468           #
9469           $str = 'Column with style 2.';
9470
9471           $worksheet1->add_sparkline(
9472               {
9473                   location => 'A13',
9474                   range    => 'Sheet2!A2:J2',
9475                   type     => 'column',
9476                   style    => 2,
9477               }
9478           );
9479
9480           $worksheet1->write( $row++, 1, $str );
9481
9482
9483           ###############################################################################
9484           #
9485           $str = 'Column with style 3.';
9486
9487           $worksheet1->add_sparkline(
9488               {
9489                   location => 'A14',
9490                   range    => 'Sheet2!A2:J2',
9491                   type     => 'column',
9492                   style    => 3,
9493               }
9494           );
9495
9496           $worksheet1->write( $row++, 1, $str );
9497
9498
9499           ###############################################################################
9500           #
9501           $str = 'Column with style 4.';
9502
9503           $worksheet1->add_sparkline(
9504               {
9505                   location => 'A15',
9506                   range    => 'Sheet2!A2:J2',
9507                   type     => 'column',
9508                   style    => 4,
9509               }
9510           );
9511
9512           $worksheet1->write( $row++, 1, $str );
9513
9514
9515           ###############################################################################
9516           #
9517           $str = 'Column with style 5.';
9518
9519           $worksheet1->add_sparkline(
9520               {
9521                   location => 'A16',
9522                   range    => 'Sheet2!A2:J2',
9523                   type     => 'column',
9524                   style    => 5,
9525               }
9526           );
9527
9528           $worksheet1->write( $row++, 1, $str );
9529
9530
9531           ###############################################################################
9532           #
9533           $str = 'Column with style 6.';
9534
9535           $worksheet1->add_sparkline(
9536               {
9537                   location => 'A17',
9538                   range    => 'Sheet2!A2:J2',
9539                   type     => 'column',
9540                   style    => 6,
9541               }
9542           );
9543
9544           $worksheet1->write( $row++, 1, $str );
9545
9546
9547           ###############################################################################
9548           #
9549           $str = 'Column with a user defined colour.';
9550
9551           $worksheet1->add_sparkline(
9552               {
9553                   location     => 'A18',
9554                   range        => 'Sheet2!A2:J2',
9555                   type         => 'column',
9556                   series_color => '#E965E0',
9557               }
9558           );
9559
9560           $worksheet1->write( $row++, 1, $str );
9561           $row++;
9562
9563
9564           ###############################################################################
9565           #
9566           $str = 'A win/loss sparkline.';
9567
9568           $worksheet1->add_sparkline(
9569               {
9570                   location => 'A20',
9571                   range    => 'Sheet2!A3:J3',
9572                   type     => 'win_loss',
9573               }
9574           );
9575
9576           $worksheet1->write( $row++, 1, $str );
9577
9578
9579           ###############################################################################
9580           #
9581           $str = 'A win/loss sparkline with negative points highlighted.';
9582
9583           $worksheet1->add_sparkline(
9584               {
9585                   location        => 'A21',
9586                   range           => 'Sheet2!A3:J3',
9587                   type            => 'win_loss',
9588                   negative_points => 1,
9589               }
9590           );
9591
9592           $worksheet1->write( $row++, 1, $str );
9593           $row++;
9594
9595
9596           ###############################################################################
9597           #
9598           $str = 'A left to right column (the default).';
9599
9600           $worksheet1->add_sparkline(
9601               {
9602                   location => 'A23',
9603                   range    => 'Sheet2!A4:J4',
9604                   type     => 'column',
9605                   style    => 20,
9606               }
9607           );
9608
9609           $worksheet1->write( $row++, 1, $str );
9610
9611
9612           ###############################################################################
9613           #
9614           $str = 'A right to left column.';
9615
9616           $worksheet1->add_sparkline(
9617               {
9618                   location => 'A24',
9619                   range    => 'Sheet2!A4:J4',
9620                   type     => 'column',
9621                   style    => 20,
9622                   reverse  => 1,
9623               }
9624           );
9625
9626           $worksheet1->write( $row++, 1, $str );
9627
9628
9629           ###############################################################################
9630           #
9631           $str = 'Sparkline and text in one cell.';
9632
9633           $worksheet1->add_sparkline(
9634               {
9635                   location => 'A25',
9636                   range    => 'Sheet2!A4:J4',
9637                   type     => 'column',
9638                   style    => 20,
9639               }
9640           );
9641
9642           $worksheet1->write( $row,   0, 'Growth' );
9643           $worksheet1->write( $row++, 1, $str );
9644           $row++;
9645
9646
9647           ###############################################################################
9648           #
9649           $str = 'A grouped sparkline. Changes are applied to all three.';
9650
9651           $worksheet1->add_sparkline(
9652               {
9653                   location => [ 'A27',          'A28',          'A29' ],
9654                   range    => [ 'Sheet2!A5:J5', 'Sheet2!A6:J6', 'Sheet2!A7:J7' ],
9655                   markers  => 1,
9656               }
9657           );
9658
9659           $worksheet1->write( $row++, 1, $str );
9660
9661
9662
9663
9664           ###############################################################################
9665           #
9666           # Create a second worksheet with data to plot.
9667           #
9668
9669           $worksheet2->set_column( 'A:J', 11 );
9670
9671           my $data = [
9672
9673               # Simple line data.
9674               [ -2, 2, 3, -1, 0, -2, 3, 2, 1, 0 ],
9675
9676               # Simple column data.
9677               [ 30, 20, 33, 20, 15, 5, 5, 15, 10, 15 ],
9678
9679               # Simple win/loss data.
9680               [ 1, 1, -1, -1, 1, -1, 1, 1, 1, -1 ],
9681
9682               # Unbalanced histogram.
9683               [ 5, 6, 7, 10, 15, 20, 30, 50, 70, 100 ],
9684
9685               # Data for the grouped sparkline example.
9686               [ -2, 2,  3, -1, 0, -2, 3, 2, 1, 0 ],
9687               [ 3,  -1, 0, -2, 3, 2,  1, 0, 2, 1 ],
9688               [ 0,  -2, 3, 2,  1, 0,  1, 2, 3, 1 ],
9689
9690
9691           ];
9692
9693           # Write the sample data to the worksheet.
9694           $worksheet2->write_col( 'A1', $data );
9695
9696           $workbook->close();
9697
9698           __END__
9699
9700       Download this example:
9701       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/sparklines2.pl>
9702
9703   Example: stats_ext.pl
9704       Example of formatting using the Excel::Writer::XLSX module
9705
9706       This is a simple example of how to use functions that reference cells
9707       in other worksheets within the same workbook.
9708
9709       Source code for this example:
9710
9711           #!/usr/bin/perl -w
9712
9713           ###############################################################################
9714           #
9715           # Example of formatting using the Excel::Writer::XLSX module
9716           #
9717           # This is a simple example of how to use functions that reference cells in
9718           # other worksheets within the same workbook.
9719           #
9720           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
9721           #
9722
9723           use strict;
9724           use Excel::Writer::XLSX;
9725
9726           # Create a new workbook and add a worksheet
9727           my $workbook   = Excel::Writer::XLSX->new( 'stats_ext.xlsx' );
9728           my $worksheet1 = $workbook->add_worksheet( 'Test results' );
9729           my $worksheet2 = $workbook->add_worksheet( 'Data' );
9730
9731           # Set the column width for columns 1
9732           $worksheet1->set_column( 'A:A', 20 );
9733
9734
9735           # Create a format for the headings
9736           my $heading = $workbook->add_format();
9737           $heading->set_bold();
9738
9739           # Create a numerical format
9740           my $numformat = $workbook->add_format();
9741           $numformat->set_num_format( '0.00' );
9742
9743
9744           # Write some statistical functions
9745           $worksheet1->write( 'A1', 'Count', $heading );
9746           $worksheet1->write( 'B1', '=COUNT(Data!B2:B9)' );
9747
9748           $worksheet1->write( 'A2', 'Sum', $heading );
9749           $worksheet1->write( 'B2', '=SUM(Data!B2:B9)' );
9750
9751           $worksheet1->write( 'A3', 'Average', $heading );
9752           $worksheet1->write( 'B3', '=AVERAGE(Data!B2:B9)' );
9753
9754           $worksheet1->write( 'A4', 'Min', $heading );
9755           $worksheet1->write( 'B4', '=MIN(Data!B2:B9)' );
9756
9757           $worksheet1->write( 'A5', 'Max', $heading );
9758           $worksheet1->write( 'B5', '=MAX(Data!B2:B9)' );
9759
9760           $worksheet1->write( 'A6', 'Standard Deviation', $heading );
9761           $worksheet1->write( 'B6', '=STDEV(Data!B2:B9)' );
9762
9763           $worksheet1->write( 'A7', 'Kurtosis', $heading );
9764           $worksheet1->write( 'B7', '=KURT(Data!B2:B9)' );
9765
9766
9767           # Write the sample data
9768           $worksheet2->write( 'A1', 'Sample', $heading );
9769           $worksheet2->write( 'A2', 1 );
9770           $worksheet2->write( 'A3', 2 );
9771           $worksheet2->write( 'A4', 3 );
9772           $worksheet2->write( 'A5', 4 );
9773           $worksheet2->write( 'A6', 5 );
9774           $worksheet2->write( 'A7', 6 );
9775           $worksheet2->write( 'A8', 7 );
9776           $worksheet2->write( 'A9', 8 );
9777
9778           $worksheet2->write( 'B1', 'Length', $heading );
9779           $worksheet2->write( 'B2', 25.4,     $numformat );
9780           $worksheet2->write( 'B3', 25.4,     $numformat );
9781           $worksheet2->write( 'B4', 24.8,     $numformat );
9782           $worksheet2->write( 'B5', 25.0,     $numformat );
9783           $worksheet2->write( 'B6', 25.3,     $numformat );
9784           $worksheet2->write( 'B7', 24.9,     $numformat );
9785           $worksheet2->write( 'B8', 25.2,     $numformat );
9786           $worksheet2->write( 'B9', 24.8,     $numformat );
9787
9788           $workbook->close();
9789
9790           __END__
9791
9792       Download this example:
9793       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/stats_ext.pl>
9794
9795   Example: stocks.pl
9796       Example of formatting using the Excel::Writer::XLSX module
9797
9798       This example shows how to use a conditional numerical format with
9799       colours to indicate if a share price has gone up or down.
9800
9801       Source code for this example:
9802
9803           #!/usr/bin/perl -w
9804
9805           ###############################################################################
9806           #
9807           # Example of formatting using the Excel::Writer::XLSX module
9808           #
9809           # This example shows how to use a conditional numerical format
9810           # with colours to indicate if a share price has gone up or down.
9811           #
9812           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
9813           #
9814
9815           use strict;
9816           use Excel::Writer::XLSX;
9817
9818           # Create a new workbook and add a worksheet
9819           my $workbook  = Excel::Writer::XLSX->new( 'stocks.xlsx' );
9820           my $worksheet = $workbook->add_worksheet();
9821
9822           # Set the column width for columns 1, 2, 3 and 4
9823           $worksheet->set_column( 0, 3, 15 );
9824
9825
9826           # Create a format for the column headings
9827           my $header = $workbook->add_format();
9828           $header->set_bold();
9829           $header->set_size( 12 );
9830           $header->set_color( 'blue' );
9831
9832
9833           # Create a format for the stock price
9834           my $f_price = $workbook->add_format();
9835           $f_price->set_align( 'left' );
9836           $f_price->set_num_format( '$0.00' );
9837
9838
9839           # Create a format for the stock volume
9840           my $f_volume = $workbook->add_format();
9841           $f_volume->set_align( 'left' );
9842           $f_volume->set_num_format( '#,##0' );
9843
9844
9845           # Create a format for the price change. This is an example of a conditional
9846           # format. The number is formatted as a percentage. If it is positive it is
9847           # formatted in green, if it is negative it is formatted in red and if it is
9848           # zero it is formatted as the default font colour (in this case black).
9849           # Note: the [Green] format produces an unappealing lime green. Try
9850           # [Color 10] instead for a dark green.
9851           #
9852           my $f_change = $workbook->add_format();
9853           $f_change->set_align( 'left' );
9854           $f_change->set_num_format( '[Green]0.0%;[Red]-0.0%;0.0%' );
9855
9856
9857           # Write out the data
9858           $worksheet->write( 0, 0, 'Company', $header );
9859           $worksheet->write( 0, 1, 'Price',   $header );
9860           $worksheet->write( 0, 2, 'Volume',  $header );
9861           $worksheet->write( 0, 3, 'Change',  $header );
9862
9863           $worksheet->write( 1, 0, 'Damage Inc.' );
9864           $worksheet->write( 1, 1, 30.25, $f_price );       # $30.25
9865           $worksheet->write( 1, 2, 1234567, $f_volume );    # 1,234,567
9866           $worksheet->write( 1, 3, 0.085, $f_change );      # 8.5% in green
9867
9868           $worksheet->write( 2, 0, 'Dump Corp.' );
9869           $worksheet->write( 2, 1, 1.56, $f_price );        # $1.56
9870           $worksheet->write( 2, 2, 7564, $f_volume );       # 7,564
9871           $worksheet->write( 2, 3, -0.015, $f_change );     # -1.5% in red
9872
9873           $worksheet->write( 3, 0, 'Rev Ltd.' );
9874           $worksheet->write( 3, 1, 0.13, $f_price );        # $0.13
9875           $worksheet->write( 3, 2, 321, $f_volume );        # 321
9876           $worksheet->write( 3, 3, 0, $f_change );          # 0 in the font color (black)
9877
9878
9879           $workbook->close();
9880
9881           __END__
9882
9883       Download this example:
9884       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/stocks.pl>
9885
9886   Example: watermark.pl
9887       An example of adding a worksheet watermark image using the
9888       Excel::Writer::XLSX module. This is based on the method of putting an
9889       image in the worksheet header as suggested in the Microsoft
9890       documentation:
9891       https://support.microsoft.com/en-us/office/add-a-watermark-in-excel-a372182a-d733-484e-825c-18ddf3edf009
9892
9893           #!/usr/bin/perl -w
9894
9895           #######################################################################
9896           #
9897           # An example of adding a worksheet watermark image using the Excel::Writer::XLSX
9898           # module. This is based on the method of putting an image in the worksheet
9899           # header as suggested in the Microsoft documentation:
9900           # https://support.microsoft.com/en-us/office/add-a-watermark-in-excel-a372182a-d733-484e-825c-18ddf3edf009
9901           #
9902           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
9903           #
9904
9905           use strict;
9906           use Excel::Writer::XLSX;
9907
9908           my $workbook  = Excel::Writer::XLSX->new( 'watermark.xlsx' );
9909           my $worksheet = $workbook->add_worksheet();
9910
9911           # Set a worksheet header with the watermark image.
9912           $worksheet->set_header( '&C&C&[Picture]', undef, { image_center => 'watermark.png' } );
9913
9914           $workbook->close();
9915
9916           __END__
9917
9918       Download this example:
9919       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/watermark.pl>
9920
9921   Example: background.pl
9922       An example of setting a worksheet background image with
9923       Excel::Writer::XLSX.
9924
9925           #!/usr/bin/perl -w
9926
9927           #######################################################################
9928           #
9929           # An example of setting a worksheet background image with Excel::Writer::XLSX.
9930           #
9931           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
9932           #
9933
9934           use strict;
9935           use Excel::Writer::XLSX;
9936
9937           my $workbook   = Excel::Writer::XLSX->new( 'background.xlsx' );
9938           my $worksheet  = $workbook->add_worksheet();
9939
9940           $worksheet->set_background( 'republic.png' );
9941
9942           $workbook->close();
9943
9944           __END__
9945
9946       Download this example:
9947       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/background.pl>
9948
9949   Example: tab_colors.pl
9950       Example of how to set Excel worksheet tab colours.
9951
9952       Source code for this example:
9953
9954           #!/usr/bin/perl
9955
9956           #######################################################################
9957           #
9958           # Example of how to set Excel worksheet tab colours.
9959           #
9960           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
9961           #
9962
9963           use strict;
9964           use warnings;
9965           use Excel::Writer::XLSX;
9966
9967
9968           my $workbook = Excel::Writer::XLSX->new( 'tab_colors.xlsx' );
9969
9970           my $worksheet1 = $workbook->add_worksheet();
9971           my $worksheet2 = $workbook->add_worksheet();
9972           my $worksheet3 = $workbook->add_worksheet();
9973           my $worksheet4 = $workbook->add_worksheet();
9974
9975           # Worksheet1 will have the default tab colour.
9976           $worksheet2->set_tab_color( 'red' );
9977           $worksheet3->set_tab_color( 'green' );
9978           $worksheet4->set_tab_color( '#FF6600'); # Orange
9979
9980           $workbook->close();
9981
9982           __END__
9983
9984       Download this example:
9985       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/tab_colors.pl>
9986
9987   Example: tables.pl
9988       Example of how to add tables to an Excel::Writer::XLSX worksheet.
9989
9990       Tables in Excel are used to group rows and columns of data into a
9991       single structure that can be referenced in a formula or formatted
9992       collectively.
9993
9994       Source code for this example:
9995
9996           #!/usr/bin/perl
9997
9998           ###############################################################################
9999           #
10000           # Example of how to add tables to an Excel::Writer::XLSX worksheet.
10001           #
10002           # Tables in Excel are used to group rows and columns of data into a single
10003           # structure that can be referenced in a formula or formatted collectively.
10004           #
10005           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10006           #
10007
10008           use strict;
10009           use warnings;
10010           use Excel::Writer::XLSX;
10011
10012           my $workbook    = Excel::Writer::XLSX->new( 'tables.xlsx' );
10013           my $worksheet1  = $workbook->add_worksheet();
10014           my $worksheet2  = $workbook->add_worksheet();
10015           my $worksheet3  = $workbook->add_worksheet();
10016           my $worksheet4  = $workbook->add_worksheet();
10017           my $worksheet5  = $workbook->add_worksheet();
10018           my $worksheet6  = $workbook->add_worksheet();
10019           my $worksheet7  = $workbook->add_worksheet();
10020           my $worksheet8  = $workbook->add_worksheet();
10021           my $worksheet9  = $workbook->add_worksheet();
10022           my $worksheet10 = $workbook->add_worksheet();
10023           my $worksheet11 = $workbook->add_worksheet();
10024           my $worksheet12 = $workbook->add_worksheet();
10025           my $worksheet13 = $workbook->add_worksheet();
10026
10027           my $currency_format = $workbook->add_format( num_format => '$#,##0' );
10028
10029
10030           # Some sample data for the table.
10031           my $data = [
10032               [ 'Apples',  10000, 5000, 8000, 6000 ],
10033               [ 'Pears',   2000,  3000, 4000, 5000 ],
10034               [ 'Bananas', 6000,  6000, 6500, 6000 ],
10035               [ 'Oranges', 500,   300,  200,  700 ],
10036
10037           ];
10038
10039
10040           ###############################################################################
10041           #
10042           # Example 1.
10043           #
10044           my $caption = 'Default table with no data.';
10045
10046           # Set the columns widths.
10047           $worksheet1->set_column( 'B:G', 12 );
10048
10049           # Write the caption.
10050           $worksheet1->write( 'B1', $caption );
10051
10052           # Add a table to the worksheet.
10053           $worksheet1->add_table( 'B3:F7' );
10054
10055
10056           ###############################################################################
10057           #
10058           # Example 2.
10059           #
10060           $caption = 'Default table with data.';
10061
10062           # Set the columns widths.
10063           $worksheet2->set_column( 'B:G', 12 );
10064
10065           # Write the caption.
10066           $worksheet2->write( 'B1', $caption );
10067
10068           # Add a table to the worksheet.
10069           $worksheet2->add_table( 'B3:F7', { data => $data } );
10070
10071
10072           ###############################################################################
10073           #
10074           # Example 3.
10075           #
10076           $caption = 'Table without default autofilter.';
10077
10078           # Set the columns widths.
10079           $worksheet3->set_column( 'B:G', 12 );
10080
10081           # Write the caption.
10082           $worksheet3->write( 'B1', $caption );
10083
10084           # Add a table to the worksheet.
10085           $worksheet3->add_table( 'B3:F7', { autofilter => 0 } );
10086
10087           # Table data can also be written separately, as an array or individual cells.
10088           $worksheet3->write_col( 'B4', $data );
10089
10090
10091           ###############################################################################
10092           #
10093           # Example 4.
10094           #
10095           $caption = 'Table without default header row.';
10096
10097           # Set the columns widths.
10098           $worksheet4->set_column( 'B:G', 12 );
10099
10100           # Write the caption.
10101           $worksheet4->write( 'B1', $caption );
10102
10103           # Add a table to the worksheet.
10104           $worksheet4->add_table( 'B4:F7', { header_row => 0 } );
10105
10106           # Table data can also be written separately, as an array or individual cells.
10107           $worksheet4->write_col( 'B4', $data );
10108
10109
10110           ###############################################################################
10111           #
10112           # Example 5.
10113           #
10114           $caption = 'Default table with "First Column" and "Last Column" options.';
10115
10116           # Set the columns widths.
10117           $worksheet5->set_column( 'B:G', 12 );
10118
10119           # Write the caption.
10120           $worksheet5->write( 'B1', $caption );
10121
10122           # Add a table to the worksheet.
10123           $worksheet5->add_table( 'B3:F7', { first_column => 1, last_column => 1 } );
10124
10125           # Table data can also be written separately, as an array or individual cells.
10126           $worksheet5->write_col( 'B4', $data );
10127
10128
10129           ###############################################################################
10130           #
10131           # Example 6.
10132           #
10133           $caption = 'Table with banded columns but without default banded rows.';
10134
10135           # Set the columns widths.
10136           $worksheet6->set_column( 'B:G', 12 );
10137
10138           # Write the caption.
10139           $worksheet6->write( 'B1', $caption );
10140
10141           # Add a table to the worksheet.
10142           $worksheet6->add_table( 'B3:F7', { banded_rows => 0, banded_columns => 1 } );
10143
10144           # Table data can also be written separately, as an array or individual cells.
10145           $worksheet6->write_col( 'B4', $data );
10146
10147
10148           ###############################################################################
10149           #
10150           # Example 7.
10151           #
10152           $caption = 'Table with user defined column headers';
10153
10154           # Set the columns widths.
10155           $worksheet7->set_column( 'B:G', 12 );
10156
10157           # Write the caption.
10158           $worksheet7->write( 'B1', $caption );
10159
10160           # Add a table to the worksheet.
10161           $worksheet7->add_table(
10162               'B3:F7',
10163               {
10164                   data    => $data,
10165                   columns => [
10166                       { header => 'Product' },
10167                       { header => 'Quarter 1' },
10168                       { header => 'Quarter 2' },
10169                       { header => 'Quarter 3' },
10170                       { header => 'Quarter 4' },
10171                   ]
10172               }
10173           );
10174
10175
10176           ###############################################################################
10177           #
10178           # Example 8.
10179           #
10180           $caption = 'Table with user defined column headers';
10181
10182           # Set the columns widths.
10183           $worksheet8->set_column( 'B:G', 12 );
10184
10185           # Write the caption.
10186           $worksheet8->write( 'B1', $caption );
10187
10188           # Add a table to the worksheet.
10189           $worksheet8->add_table(
10190               'B3:G7',
10191               {
10192                   data    => $data,
10193                   columns => [
10194                       { header => 'Product' },
10195                       { header => 'Quarter 1' },
10196                       { header => 'Quarter 2' },
10197                       { header => 'Quarter 3' },
10198                       { header => 'Quarter 4' },
10199                       {
10200                           header  => 'Year',
10201                           formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])'
10202                       },
10203                   ]
10204               }
10205           );
10206
10207
10208           ###############################################################################
10209           #
10210           # Example 9.
10211           #
10212           $caption = 'Table with totals row (but no caption or totals).';
10213
10214           # Set the columns widths.
10215           $worksheet9->set_column( 'B:G', 12 );
10216
10217           # Write the caption.
10218           $worksheet9->write( 'B1', $caption );
10219
10220           # Add a table to the worksheet.
10221           $worksheet9->add_table(
10222               'B3:G8',
10223               {
10224                   data      => $data,
10225                   total_row => 1,
10226                   columns   => [
10227                       { header => 'Product' },
10228                       { header => 'Quarter 1' },
10229                       { header => 'Quarter 2' },
10230                       { header => 'Quarter 3' },
10231                       { header => 'Quarter 4' },
10232                       {
10233                           header  => 'Year',
10234                           formula => '=SUM(Table9[@[Quarter 1]:[Quarter 4]])'
10235                       },
10236                   ]
10237               }
10238           );
10239
10240
10241           ###############################################################################
10242           #
10243           # Example 10.
10244           #
10245           $caption = 'Table with totals row with user captions and functions.';
10246
10247           # Set the columns widths.
10248           $worksheet10->set_column( 'B:G', 12 );
10249
10250           # Write the caption.
10251           $worksheet10->write( 'B1', $caption );
10252
10253           # Add a table to the worksheet.
10254           $worksheet10->add_table(
10255               'B3:G8',
10256               {
10257                   data      => $data,
10258                   total_row => 1,
10259                   columns   => [
10260                       { header => 'Product',   total_string   => 'Totals' },
10261                       { header => 'Quarter 1', total_function => 'sum' },
10262                       { header => 'Quarter 2', total_function => 'sum' },
10263                       { header => 'Quarter 3', total_function => 'sum' },
10264                       { header => 'Quarter 4', total_function => 'sum' },
10265                       {
10266                           header         => 'Year',
10267                           formula        => '=SUM(Table10[@[Quarter 1]:[Quarter 4]])',
10268                           total_function => 'sum'
10269                       },
10270                   ]
10271               }
10272           );
10273
10274
10275           ###############################################################################
10276           #
10277           # Example 11.
10278           #
10279           $caption = 'Table with alternative Excel style.';
10280
10281           # Set the columns widths.
10282           $worksheet11->set_column( 'B:G', 12 );
10283
10284           # Write the caption.
10285           $worksheet11->write( 'B1', $caption );
10286
10287           # Add a table to the worksheet.
10288           $worksheet11->add_table(
10289               'B3:G8',
10290               {
10291                   data      => $data,
10292                   style     => 'Table Style Light 11',
10293                   total_row => 1,
10294                   columns   => [
10295                       { header => 'Product',   total_string   => 'Totals' },
10296                       { header => 'Quarter 1', total_function => 'sum' },
10297                       { header => 'Quarter 2', total_function => 'sum' },
10298                       { header => 'Quarter 3', total_function => 'sum' },
10299                       { header => 'Quarter 4', total_function => 'sum' },
10300                       {
10301                           header         => 'Year',
10302                           formula        => '=SUM(Table11[@[Quarter 1]:[Quarter 4]])',
10303                           total_function => 'sum'
10304                       },
10305                   ]
10306               }
10307           );
10308
10309
10310           ###############################################################################
10311           #
10312           # Example 12.
10313           #
10314           $caption = 'Table with no Excel style.';
10315
10316           # Set the columns widths.
10317           $worksheet12->set_column( 'B:G', 12 );
10318
10319           # Write the caption.
10320           $worksheet12->write( 'B1', $caption );
10321
10322           # Add a table to the worksheet.
10323           $worksheet12->add_table(
10324               'B3:G8',
10325               {
10326                   data      => $data,
10327                   style     => 'None',
10328                   total_row => 1,
10329                   columns   => [
10330                       { header => 'Product',   total_string   => 'Totals' },
10331                       { header => 'Quarter 1', total_function => 'sum' },
10332                       { header => 'Quarter 2', total_function => 'sum' },
10333                       { header => 'Quarter 3', total_function => 'sum' },
10334                       { header => 'Quarter 4', total_function => 'sum' },
10335                       {
10336                           header         => 'Year',
10337                           formula        => '=SUM(Table12[@[Quarter 1]:[Quarter 4]])',
10338                           total_function => 'sum'
10339                       },
10340                   ]
10341               }
10342           );
10343
10344
10345           ###############################################################################
10346           #
10347           # Example 13.
10348           #
10349           $caption = 'Table with column formats.';
10350
10351           # Set the columns widths.
10352           $worksheet13->set_column( 'B:G', 12 );
10353
10354           # Write the caption.
10355           $worksheet13->write( 'B1', $caption );
10356
10357           # Add a table to the worksheet.
10358           $worksheet13->add_table(
10359               'B3:G8',
10360               {
10361                   data      => $data,
10362                   total_row => 1,
10363                   columns   => [
10364                       { header => 'Product', total_string => 'Totals' },
10365                       {
10366                           header         => 'Quarter 1',
10367                           total_function => 'sum',
10368                           format         => $currency_format,
10369                       },
10370                       {
10371                           header         => 'Quarter 2',
10372                           total_function => 'sum',
10373                           format         => $currency_format,
10374                       },
10375                       {
10376                           header         => 'Quarter 3',
10377                           total_function => 'sum',
10378                           format         => $currency_format,
10379                       },
10380                       {
10381                           header         => 'Quarter 4',
10382                           total_function => 'sum',
10383                           format         => $currency_format,
10384                       },
10385                       {
10386                           header         => 'Year',
10387                           formula        => '=SUM(Table13[@[Quarter 1]:[Quarter 4]])',
10388                           total_function => 'sum',
10389                           format         => $currency_format,
10390                       },
10391                   ]
10392               }
10393           );
10394
10395
10396           $workbook->close();
10397
10398           __END__
10399
10400       Download this example:
10401       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/tables.pl>
10402
10403   Example: write_handler1.pl
10404       Example of how to add a user defined data handler to the
10405       Excel::Writer::XLSX write() method.
10406
10407       The following example shows how to add a handler for a 7 digit ID
10408       number.
10409
10410       Source code for this example:
10411
10412           #!/usr/bin/perl -w
10413
10414           ###############################################################################
10415           #
10416           # Example of how to add a user defined data handler to the
10417           # Excel::Writer::XLSX write() method.
10418           #
10419           # The following example shows how to add a handler for a 7 digit ID number.
10420           #
10421           #
10422           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10423           #
10424
10425           use strict;
10426           use Excel::Writer::XLSX;
10427
10428
10429           my $workbook  = Excel::Writer::XLSX->new( 'write_handler1.xlsx' );
10430           my $worksheet = $workbook->add_worksheet();
10431
10432
10433           ###############################################################################
10434           #
10435           # Add a handler for 7 digit id numbers. This is useful when you want a string
10436           # such as 0000001 written as a string instead of a number and thus preserve
10437           # the leading zeroes.
10438           #
10439           # Note: you can get the same effect using the keep_leading_zeros() method but
10440           # this serves as a simple example.
10441           #
10442           $worksheet->add_write_handler( qr[^\d{7}$], \&write_my_id );
10443
10444
10445           ###############################################################################
10446           #
10447           # The following function processes the data when a match is found.
10448           #
10449           sub write_my_id {
10450
10451               my $worksheet = shift;
10452
10453               return $worksheet->write_string( @_ );
10454           }
10455
10456
10457           # This format maintains the cell as text even if it is edited.
10458           my $id_format = $workbook->add_format( num_format => '@' );
10459
10460
10461           # Write some numbers in the user defined format
10462           $worksheet->write( 'A1', '0000000', $id_format );
10463           $worksheet->write( 'A2', '0000001', $id_format );
10464           $worksheet->write( 'A3', '0004000', $id_format );
10465           $worksheet->write( 'A4', '1234567', $id_format );
10466
10467           # Write some numbers that don't match the defined format
10468           $worksheet->write( 'A6', '000000', $id_format );
10469           $worksheet->write( 'A7', '000001', $id_format );
10470           $worksheet->write( 'A8', '004000', $id_format );
10471           $worksheet->write( 'A9', '123456', $id_format );
10472
10473           $workbook->close();
10474
10475           __END__
10476
10477       Download this example:
10478       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/write_handler1.pl>
10479
10480   Example: write_handler2.pl
10481       Example of how to add a user defined data handler to the
10482       Excel::Writer::XLSX write() method.
10483
10484       The following example shows how to add a handler for a 7 digit ID
10485       number.  It adds an additional constraint to the write_handler1.pl in
10486       that it only filters data that isn't in the third column.
10487
10488       Source code for this example:
10489
10490           #!/usr/bin/perl -w
10491
10492           ###############################################################################
10493           #
10494           # Example of how to add a user defined data handler to the
10495           # Excel::Writer::XLSX write() method.
10496           #
10497           # The following example shows how to add a handler for a 7 digit ID number.
10498           # It adds an additional constraint to the write_handler1.pl in that it only
10499           # filters data that isn't in the third column.
10500           #
10501           #
10502           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10503           #
10504
10505           use strict;
10506           use Excel::Writer::XLSX;
10507
10508
10509           my $workbook  = Excel::Writer::XLSX->new( 'write_handler2.xlsx' );
10510           my $worksheet = $workbook->add_worksheet();
10511
10512
10513           ###############################################################################
10514           #
10515           # Add a handler for 7 digit id numbers. This is useful when you want a string
10516           # such as 0000001 written as a string instead of a number and thus preserve
10517           # the leading zeroes.
10518           #
10519           # Note: you can get the same effect using the keep_leading_zeros() method but
10520           # this serves as a simple example.
10521           #
10522           $worksheet->add_write_handler( qr[^\d{7}$], \&write_my_id );
10523
10524
10525           ###############################################################################
10526           #
10527           # The following function processes the data when a match is found. The handler
10528           # is set up so that it only filters data if it is in the third column.
10529           #
10530           sub write_my_id {
10531
10532               my $worksheet = shift;
10533               my $col       = $_[1];
10534
10535               # col is zero based
10536               if ( $col != 2 ) {
10537                   return $worksheet->write_string( @_ );
10538               }
10539               else {
10540
10541                   # Reject the match and return control to write()
10542                   return undef;
10543               }
10544
10545           }
10546
10547
10548           # This format maintains the cell as text even if it is edited.
10549           my $id_format = $workbook->add_format( num_format => '@' );
10550
10551
10552           # Write some numbers in the user defined format
10553           $worksheet->write( 'A1', '0000000', $id_format );
10554           $worksheet->write( 'B1', '0000001', $id_format );
10555           $worksheet->write( 'C1', '0000002', $id_format );
10556           $worksheet->write( 'D1', '0000003', $id_format );
10557
10558           $workbook->close();
10559
10560           __END__
10561
10562       Download this example:
10563       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/write_handler2.pl>
10564
10565   Example: write_handler3.pl
10566       Example of how to add a user defined data handler to the
10567       Excel::Writer::XLSX write() method.
10568
10569       The following example shows how to add a handler for dates in a
10570       specific format.
10571
10572       See write_handler4.pl for a more rigorous example with error handling.
10573
10574       Source code for this example:
10575
10576           #!/usr/bin/perl -w
10577
10578           ###############################################################################
10579           #
10580           # Example of how to add a user defined data handler to the
10581           # Excel::Writer::XLSX write() method.
10582           #
10583           # The following example shows how to add a handler for dates in a specific
10584           # format.
10585           #
10586           # See write_handler4.pl for a more rigorous example with error handling.
10587           #
10588           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10589           #
10590
10591           use strict;
10592           use Excel::Writer::XLSX;
10593
10594
10595           my $workbook    = Excel::Writer::XLSX->new( 'write_handler3.xlsx' );
10596           my $worksheet   = $workbook->add_worksheet();
10597           my $date_format = $workbook->add_format( num_format => 'dd/mm/yy' );
10598
10599
10600           ###############################################################################
10601           #
10602           # Add a handler to match dates in the following format: d/m/yyyy
10603           #
10604           # The day and month can be single or double digits.
10605           #
10606           $worksheet->add_write_handler( qr[^\d{1,2}/\d{1,2}/\d{4}$], \&write_my_date );
10607
10608
10609           ###############################################################################
10610           #
10611           # The following function processes the data when a match is found.
10612           # See write_handler4.pl for a more rigorous example with error handling.
10613           #
10614           sub write_my_date {
10615
10616               my $worksheet = shift;
10617               my @args      = @_;
10618
10619               my $token = $args[2];
10620               $token =~ qr[^(\d{1,2})/(\d{1,2})/(\d{4})$];
10621
10622               # Change to the date format required by write_date_time().
10623               my $date = sprintf "%4d-%02d-%02dT", $3, $2, $1;
10624
10625               $args[2] = $date;
10626
10627               return $worksheet->write_date_time( @args );
10628           }
10629
10630
10631           # Write some dates in the user defined format
10632           $worksheet->write( 'A1', '22/12/2004', $date_format );
10633           $worksheet->write( 'A2', '1/1/1995',   $date_format );
10634           $worksheet->write( 'A3', '01/01/1995', $date_format );
10635
10636           $workbook->close();
10637
10638           __END__
10639
10640       Download this example:
10641       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/write_handler3.pl>
10642
10643   Example: write_handler4.pl
10644       Example of how to add a user defined data handler to the
10645       Excel::Writer::XLSX write() method.
10646
10647       The following example shows how to add a handler for dates in a
10648       specific format.
10649
10650       This is a more rigorous version of write_handler3.pl.
10651
10652       Source code for this example:
10653
10654           #!/usr/bin/perl -w
10655
10656           ###############################################################################
10657           #
10658           # Example of how to add a user defined data handler to the
10659           # Excel::Writer::XLSX write() method.
10660           #
10661           # The following example shows how to add a handler for dates in a specific
10662           # format.
10663           #
10664           # This is a more rigorous version of write_handler3.pl.
10665           #
10666           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10667           #
10668
10669           use strict;
10670           use Excel::Writer::XLSX;
10671
10672
10673           my $workbook    = Excel::Writer::XLSX->new( 'write_handler4.xlsx' );
10674           my $worksheet   = $workbook->add_worksheet();
10675           my $date_format = $workbook->add_format( num_format => 'dd/mm/yy' );
10676
10677
10678           ###############################################################################
10679           #
10680           # Add a handler to match dates in the following formats: d/m/yy, d/m/yyyy
10681           #
10682           # The day and month can be single or double digits and the year can be  2 or 4
10683           # digits.
10684           #
10685           $worksheet->add_write_handler( qr[^\d{1,2}/\d{1,2}/\d{2,4}$], \&write_my_date );
10686
10687
10688           ###############################################################################
10689           #
10690           # The following function processes the data when a match is found.
10691           #
10692           sub write_my_date {
10693
10694               my $worksheet = shift;
10695               my @args      = @_;
10696
10697               my $token = $args[2];
10698
10699               if ( $token =~ qr[^(\d{1,2})/(\d{1,2})/(\d{2,4})$] ) {
10700
10701                   my $day  = $1;
10702                   my $mon  = $2;
10703                   my $year = $3;
10704
10705                   # Use a window for 2 digit dates. This will keep some ragged Perl
10706                   # programmer employed in thirty years time. :-)
10707                   if ( length $year == 2 ) {
10708                       if ( $year < 50 ) {
10709                           $year += 2000;
10710                       }
10711                       else {
10712                           $year += 1900;
10713                       }
10714                   }
10715
10716                   my $date = sprintf "%4d-%02d-%02dT", $year, $mon, $day;
10717
10718                   # Convert the ISO ISO8601 style string to an Excel date
10719                   $date = $worksheet->convert_date_time( $date );
10720
10721                   if ( defined $date ) {
10722
10723                       # Date was valid
10724                       $args[2] = $date;
10725                       return $worksheet->write_number( @args );
10726                   }
10727                   else {
10728
10729                       # Not a valid date therefore write as a string
10730                       return $worksheet->write_string( @args );
10731                   }
10732               }
10733               else {
10734
10735                   # Shouldn't happen if the same match is used in the re and sub.
10736                   return undef;
10737               }
10738           }
10739
10740
10741           # Write some dates in the user defined format
10742           $worksheet->write( 'A1', '22/12/2004', $date_format );
10743           $worksheet->write( 'A2', '22/12/04',   $date_format );
10744           $worksheet->write( 'A3', '2/12/04',    $date_format );
10745           $worksheet->write( 'A4', '2/5/04',     $date_format );
10746           $worksheet->write( 'A5', '2/5/95',     $date_format );
10747           $worksheet->write( 'A6', '2/5/1995',   $date_format );
10748
10749           # Some erroneous dates
10750           $worksheet->write( 'A8', '2/5/1895',  $date_format ); # Date out of Excel range
10751           $worksheet->write( 'A9', '29/2/2003', $date_format ); # Invalid leap day
10752           $worksheet->write( 'A10', '50/50/50', $date_format ); # Matches but isn't a date
10753
10754           $workbook->close();
10755
10756           __END__
10757
10758       Download this example:
10759       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/write_handler4.pl>
10760
10761   Example: write_to_scalar.pl
10762       An example of writing an Excel::Writer::XLSX file to a perl scalar.
10763
10764           #!/usr/bin/perl
10765
10766           ##############################################################################
10767           #
10768           # An example of writing an Excel::Writer::XLSX file to a perl scalar.
10769           #
10770           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10771           #
10772
10773           use strict;
10774           use warnings;
10775           use Excel::Writer::XLSX;
10776
10777           # Use a scalar as a filehandle.
10778           open my $fh, '>', \my $str or die "Failed to open filehandle: $!";
10779
10780
10781           # Spreadsheet::WriteExce accepts filehandle as well as file names.
10782           my $workbook  = Excel::Writer::XLSX->new( $fh );
10783           my $worksheet = $workbook->add_worksheet();
10784
10785           $worksheet->write( 0, 0, 'Hi Excel!' );
10786
10787           $workbook->close();
10788
10789
10790           # The Excel file in now in $str. Remember to binmode() the output
10791           # filehandle before printing it.
10792           open my $out_fh, '>', 'write_to_scalar.xlsx'
10793             or die "Failed to open out filehandle: $!";
10794
10795           binmode $out_fh;
10796           print   $out_fh $str;
10797           close   $out_fh;
10798
10799           __END__
10800
10801       Download this example:
10802       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/write_to_scalar.pl>
10803
10804   Example: unicode_2022_jp.pl
10805       A simple example of converting some Unicode text to an Excel file using
10806       Excel::Writer::XLSX.
10807
10808       This example generates some Japanese from a file with ISO-2022-JP
10809       encoded text.
10810
10811       Source code for this example:
10812
10813           #!/usr/bin/perl
10814
10815           ##############################################################################
10816           #
10817           # A simple example of converting some Unicode text to an Excel file using
10818           # Excel::Writer::XLSX.
10819           #
10820           # This example generates some Japanese from a file with ISO-2022-JP
10821           # encoded text.
10822           #
10823           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10824           #
10825
10826           use strict;
10827           use warnings;
10828           use Excel::Writer::XLSX;
10829
10830
10831           my $workbook = Excel::Writer::XLSX->new( 'unicode_2022_jp.xlsx' );
10832
10833           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10834
10835           my $worksheet = $workbook->add_worksheet();
10836           $worksheet->set_column( 'A:A', 50 );
10837
10838
10839           my $file = 'unicode_2022_jp.txt';
10840
10841           open FH, '<:encoding(iso-2022-jp)', $file or die "Couldn't open $file: $!\n";
10842
10843           my $row = 0;
10844
10845           while ( <FH> ) {
10846               next if /^#/;    # Ignore the comments in the sample file.
10847               chomp;
10848               $worksheet->write( $row++, 0, $_ );
10849           }
10850
10851           $workbook->close();
10852
10853           __END__
10854
10855       Download this example:
10856       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_2022_jp.pl>
10857
10858   Example: unicode_8859_11.pl
10859       A simple example of converting some Unicode text to an Excel file using
10860       Excel::Writer::XLSX.
10861
10862       This example generates some Thai from a file with ISO-8859-11 encoded
10863       text.
10864
10865       Source code for this example:
10866
10867           #!/usr/bin/perl
10868
10869           ##############################################################################
10870           #
10871           # A simple example of converting some Unicode text to an Excel file using
10872           # Excel::Writer::XLSX.
10873           #
10874           # This example generates some Thai from a file with ISO-8859-11 encoded text.
10875           #
10876           #
10877           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10878           #
10879
10880           use strict;
10881           use warnings;
10882           use Excel::Writer::XLSX;
10883
10884
10885           my $workbook = Excel::Writer::XLSX->new( 'unicode_8859_11.xlsx' );
10886
10887           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10888
10889           my $worksheet = $workbook->add_worksheet();
10890           $worksheet->set_column( 'A:A', 50 );
10891
10892
10893           my $file = 'unicode_8859_11.txt';
10894
10895           open FH, '<:encoding(iso-8859-11)', $file or die "Couldn't open $file: $!\n";
10896
10897           my $row = 0;
10898
10899           while ( <FH> ) {
10900               next if /^#/;    # Ignore the comments in the sample file.
10901               chomp;
10902               $worksheet->write( $row++, 0, $_ );
10903           }
10904
10905           $workbook->close();
10906
10907           __END__
10908
10909       Download this example:
10910       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_8859_11.pl>
10911
10912   Example: unicode_8859_7.pl
10913       A simple example of converting some Unicode text to an Excel file using
10914       Excel::Writer::XLSX.
10915
10916       This example generates some Greek from a file with ISO-8859-7 encoded
10917       text.
10918
10919       Source code for this example:
10920
10921           #!/usr/bin/perl
10922
10923           ##############################################################################
10924           #
10925           # A simple example of converting some Unicode text to an Excel file using
10926           # Excel::Writer::XLSX.
10927           #
10928           # This example generates some Greek from a file with ISO-8859-7 encoded text.
10929           #
10930           #
10931           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10932           #
10933
10934           use strict;
10935           use warnings;
10936           use Excel::Writer::XLSX;
10937
10938
10939           my $workbook = Excel::Writer::XLSX->new( 'unicode_8859_7.xlsx' );
10940
10941           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10942
10943           my $worksheet = $workbook->add_worksheet();
10944           $worksheet->set_column( 'A:A', 50 );
10945
10946
10947           my $file = 'unicode_8859_7.txt';
10948
10949           open FH, '<:encoding(iso-8859-7)', $file or die "Couldn't open $file: $!\n";
10950
10951           my $row = 0;
10952
10953           while ( <FH> ) {
10954               next if /^#/;    # Ignore the comments in the sample file.
10955               chomp;
10956               $worksheet->write( $row++, 0, $_ );
10957           }
10958
10959           $workbook->close();
10960
10961           __END__
10962
10963       Download this example:
10964       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_8859_7.pl>
10965
10966   Example: unicode_big5.pl
10967       A simple example of converting some Unicode text to an Excel file using
10968       Excel::Writer::XLSX.
10969
10970       This example generates some Chinese from a file with BIG5 encoded text.
10971
10972       Source code for this example:
10973
10974           #!/usr/bin/perl
10975
10976           ##############################################################################
10977           #
10978           # A simple example of converting some Unicode text to an Excel file using
10979           # Excel::Writer::XLSX.
10980           #
10981           # This example generates some Chinese from a file with BIG5 encoded text.
10982           #
10983           #
10984           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
10985           #
10986
10987           use strict;
10988           use warnings;
10989           use Excel::Writer::XLSX;
10990
10991
10992           my $workbook = Excel::Writer::XLSX->new( 'unicode_big5.xlsx' );
10993
10994           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
10995
10996           my $worksheet = $workbook->add_worksheet();
10997           $worksheet->set_column( 'A:A', 80 );
10998
10999
11000           my $file = 'unicode_big5.txt';
11001
11002           open FH, '<:encoding(big5)', $file or die "Couldn't open $file: $!\n";
11003
11004           my $row = 0;
11005
11006           while ( <FH> ) {
11007               next if /^#/;    # Ignore the comments in the sample file.
11008               chomp;
11009               $worksheet->write( $row++, 0, $_ );
11010           }
11011
11012           $workbook->close();
11013
11014           __END__
11015
11016       Download this example:
11017       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_big5.pl>
11018
11019   Example: unicode_cp1251.pl
11020       A simple example of converting some Unicode text to an Excel file using
11021       Excel::Writer::XLSX.
11022
11023       This example generates some Russian from a file with CP1251 encoded
11024       text.
11025
11026       Source code for this example:
11027
11028           #!/usr/bin/perl
11029
11030           ##############################################################################
11031           #
11032           # A simple example of converting some Unicode text to an Excel file using
11033           # Excel::Writer::XLSX.
11034           #
11035           # This example generates some Russian from a file with CP1251 encoded text.
11036           #
11037           #
11038           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
11039           #
11040
11041           use strict;
11042           use warnings;
11043           use Excel::Writer::XLSX;
11044
11045
11046           my $workbook = Excel::Writer::XLSX->new( 'unicode_cp1251.xlsx' );
11047
11048           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
11049
11050           my $worksheet = $workbook->add_worksheet();
11051           $worksheet->set_column( 'A:A', 50 );
11052
11053
11054           my $file = 'unicode_cp1251.txt';
11055
11056           open FH, '<:encoding(cp1251)', $file or die "Couldn't open $file: $!\n";
11057
11058           my $row = 0;
11059
11060           while ( <FH> ) {
11061               next if /^#/;    # Ignore the comments in the sample file.
11062               chomp;
11063               $worksheet->write( $row++, 0, $_ );
11064           }
11065
11066           $workbook->close();
11067
11068           __END__
11069
11070       Download this example:
11071       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_cp1251.pl>
11072
11073   Example: unicode_cp1256.pl
11074       A simple example of converting some Unicode text to an Excel file using
11075       Excel::Writer::XLSX.
11076
11077       This example generates some Arabic text from a CP-1256 encoded file.
11078
11079       Source code for this example:
11080
11081           #!/usr/bin/perl
11082
11083           ##############################################################################
11084           #
11085           # A simple example of converting some Unicode text to an Excel file using
11086           # Excel::Writer::XLSX.
11087           #
11088           # This example generates some Arabic text from a CP-1256 encoded file.
11089           #
11090           #
11091           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
11092           #
11093
11094           use strict;
11095           use warnings;
11096           use Excel::Writer::XLSX;
11097
11098
11099           my $workbook = Excel::Writer::XLSX->new( 'unicode_cp1256.xlsx' );
11100
11101           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
11102
11103           my $worksheet = $workbook->add_worksheet();
11104           $worksheet->set_column( 'A:A', 50 );
11105
11106
11107           my $file = 'unicode_cp1256.txt';
11108
11109           open FH, '<:encoding(cp1256)', $file or die "Couldn't open $file: $!\n";
11110
11111           my $row = 0;
11112
11113           while ( <FH> ) {
11114               next if /^#/;    # Ignore the comments in the sample file.
11115               chomp;
11116               $worksheet->write( $row++, 0, $_ );
11117           }
11118
11119           $workbook->close();
11120
11121           __END__
11122
11123       Download this example:
11124       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_cp1256.pl>
11125
11126   Example: unicode_cyrillic.pl
11127       A simple example of writing some Russian cyrillic text using
11128       Excel::Writer::XLSX.
11129
11130       Source code for this example:
11131
11132           #!/usr/bin/perl
11133
11134           ##############################################################################
11135           #
11136           # A simple example of writing some Russian cyrillic text using
11137           # Excel::Writer::XLSX.
11138           #
11139           #
11140           #
11141           #
11142           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
11143           #
11144
11145           use strict;
11146           use warnings;
11147           use Excel::Writer::XLSX;
11148
11149
11150           # In this example we generate utf8 strings from character data but in a
11151           # real application we would expect them to come from an external source.
11152           #
11153
11154
11155           # Create a Russian worksheet name in utf8.
11156           my $sheet = pack "U*", 0x0421, 0x0442, 0x0440, 0x0430, 0x043D, 0x0438,
11157             0x0446, 0x0430;
11158
11159
11160           # Create a Russian string.
11161           my $str = pack "U*", 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441,
11162             0x0442, 0x0432, 0x0443, 0x0439, 0x0020, 0x041C,
11163             0x0438, 0x0440, 0x0021;
11164
11165
11166           my $workbook = Excel::Writer::XLSX->new( 'unicode_cyrillic.xlsx' );
11167
11168           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
11169
11170           my $worksheet = $workbook->add_worksheet( $sheet . '1' );
11171
11172           $worksheet->set_column( 'A:A', 18 );
11173           $worksheet->write( 'A1', $str );
11174
11175           $workbook->close();
11176
11177           __END__
11178
11179       Download this example:
11180       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_cyrillic.pl>
11181
11182   Example: unicode_koi8r.pl
11183       A simple example of converting some Unicode text to an Excel file using
11184       Excel::Writer::XLSX.
11185
11186       This example generates some Russian from a file with KOI8-R encoded
11187       text.
11188
11189       Source code for this example:
11190
11191           #!/usr/bin/perl
11192
11193           ##############################################################################
11194           #
11195           # A simple example of converting some Unicode text to an Excel file using
11196           # Excel::Writer::XLSX.
11197           #
11198           # This example generates some Russian from a file with KOI8-R encoded text.
11199           #
11200           #
11201           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
11202           #
11203
11204           use strict;
11205           use warnings;
11206           use Excel::Writer::XLSX;
11207
11208
11209           my $workbook = Excel::Writer::XLSX->new( 'unicode_koi8r.xlsx' );
11210
11211           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
11212
11213           my $worksheet = $workbook->add_worksheet();
11214           $worksheet->set_column( 'A:A', 50 );
11215
11216
11217           my $file = 'unicode_koi8r.txt';
11218
11219           open FH, '<:encoding(koi8-r)', $file or die "Couldn't open $file: $!\n";
11220
11221           my $row = 0;
11222
11223           while ( <FH> ) {
11224               next if /^#/;    # Ignore the comments in the sample file.
11225               chomp;
11226               $worksheet->write( $row++, 0, $_ );
11227           }
11228
11229           $workbook->close();
11230
11231           __END__
11232
11233       Download this example:
11234       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_koi8r.pl>
11235
11236   Example: unicode_polish_utf8.pl
11237       A simple example of converting some Unicode text to an Excel file using
11238       Excel::Writer::XLSX.
11239
11240       This example generates some Polish from a file with UTF8 encoded text.
11241
11242       Source code for this example:
11243
11244           #!/usr/bin/perl
11245
11246           ##############################################################################
11247           #
11248           # A simple example of converting some Unicode text to an Excel file using
11249           # Excel::Writer::XLSX.
11250           #
11251           # This example generates some Polish from a file with UTF8 encoded text.
11252           #
11253           #
11254           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
11255           #
11256
11257           use strict;
11258           use warnings;
11259           use Excel::Writer::XLSX;
11260
11261
11262           my $workbook = Excel::Writer::XLSX->new( 'unicode_polish_utf8.xlsx' );
11263
11264           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
11265
11266           my $worksheet = $workbook->add_worksheet();
11267           $worksheet->set_column( 'A:A', 50 );
11268
11269
11270           my $file = 'unicode_polish_utf8.txt';
11271
11272           open FH, '<:encoding(utf8)', $file or die "Couldn't open $file: $!\n";
11273
11274           my $row = 0;
11275
11276           while ( <FH> ) {
11277               next if /^#/;    # Ignore the comments in the sample file.
11278               chomp;
11279               $worksheet->write( $row++, 0, $_ );
11280           }
11281
11282           $workbook->close();
11283
11284           __END__
11285
11286       Download this example:
11287       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_polish_utf8.pl>
11288
11289   Example: unicode_shift_jis.pl
11290       A simple example of converting some Unicode text to an Excel file using
11291       Excel::Writer::XLSX.
11292
11293       This example generates some Japenese text from a file with Shift-JIS
11294       encoded text.
11295
11296       Source code for this example:
11297
11298           #!/usr/bin/perl
11299
11300           ##############################################################################
11301           #
11302           # A simple example of converting some Unicode text to an Excel file using
11303           # Excel::Writer::XLSX.
11304           #
11305           # This example generates some Japenese text from a file with Shift-JIS
11306           # encoded text.
11307           #
11308           # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
11309           #
11310
11311           use strict;
11312           use warnings;
11313           use Excel::Writer::XLSX;
11314
11315
11316           my $workbook = Excel::Writer::XLSX->new( 'unicode_shift_jis.xlsx' );
11317
11318           die "Couldn't create new Excel file: $!.\n" unless defined $workbook;
11319
11320           my $worksheet = $workbook->add_worksheet();
11321           $worksheet->set_column( 'A:A', 50 );
11322
11323
11324           my $file = 'unicode_shift_jis.txt';
11325
11326           open FH, '<:encoding(shiftjis)', $file or die "Couldn't open $file: $!\n";
11327
11328           my $row = 0;
11329
11330           while ( <FH> ) {
11331               next if /^#/;    # Ignore the comments in the sample file.
11332               chomp;
11333               $worksheet->write( $row++, 0, $_ );
11334           }
11335
11336           $workbook->close();
11337
11338           __END__
11339
11340       Download this example:
11341       <http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.11/examples/unicode_shift_jis.pl>
11342

AUTHOR

11344       John McNamara jmcnamara@cpan.org
11345
11346       Contributed examples contain the original author's name.
11347
11349       Copyright 2000-2023, John McNamara.
11350
11351       All Rights Reserved. This module is free software. It may be used,
11352       redistributed and/or modified under the same terms as Perl itself.
11353
11354
11355
11356perl v5.38.0                      2023-07-20  Excel::Writer::XLSX::Examples(3)
Impressum