.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Excel::Writer::XLSX 3" .TH Excel::Writer::XLSX 3 "2015-04-21" "perl v5.12.5" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Excel::Writer::XLSX \- Create a new file in the Excel 2007+ XLSX format. .SH "VERSION" .IX Header "VERSION" This document refers to version 0.84 of Excel::Writer::XLSX, released April 21, 2015. .SH "SYNOPSIS" .IX Header "SYNOPSIS" To write a string, a formatted string, a number and a formula to the first worksheet in an Excel workbook called perl.xlsx: .PP .Vb 1 \& use Excel::Writer::XLSX; \& \& # Create a new Excel workbook \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqperl.xlsx\*(Aq ); \& \& # Add a worksheet \& $worksheet = $workbook\->add_worksheet(); \& \& # Add and define a format \& $format = $workbook\->add_format(); \& $format\->set_bold(); \& $format\->set_color( \*(Aqred\*(Aq ); \& $format\->set_align( \*(Aqcenter\*(Aq ); \& \& # Write a formatted and unformatted string, row and column notation. \& $col = $row = 0; \& $worksheet\->write( $row, $col, \*(AqHi Excel!\*(Aq, $format ); \& $worksheet\->write( 1, $col, \*(AqHi Excel!\*(Aq ); \& \& # Write a number and a formula using A1 notation \& $worksheet\->write( \*(AqA3\*(Aq, 1.2345 ); \& $worksheet\->write( \*(AqA4\*(Aq, \*(Aq=SIN(PI()/4)\*(Aq ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR module can be used to create an Excel file in the 2007+ \s-1XLSX\s0 format. .PP The \s-1XLSX\s0 format is the Office Open \s-1XML\s0 (\s-1OOXML\s0) format used by Excel 2007 and later. .PP Multiple worksheets can be added to a workbook and formatting can be applied to cells. Text, numbers, and formulas can be written to the cells. .PP This module cannot, as yet, be used to write to an existing Excel \s-1XLSX\s0 file. .SH "Excel::Writer::XLSX and Spreadsheet::WriteExcel" .IX Header "Excel::Writer::XLSX and Spreadsheet::WriteExcel" \&\f(CW\*(C`Excel::Writer::XLSX\*(C'\fR uses the same interface as the Spreadsheet::WriteExcel module which produces an Excel file in binary \s-1XLS\s0 format. .PP Excel::Writer::XLSX supports all of the features of Spreadsheet::WriteExcel and in some cases has more functionality. For more details see \*(L"Compatibility with Spreadsheet::WriteExcel\*(R". .PP The main advantage of the \s-1XLSX\s0 format over the \s-1XLS\s0 format is that it allows a larger number of rows and columns in a worksheet. The \s-1XLSX\s0 file format also produces much smaller files than the \s-1XLS\s0 file format. .SH "QUICK START" .IX Header "QUICK START" Excel::Writer::XLSX tries to provide an interface to as many of Excel's features as possible. As a result there is a lot of documentation to accompany the interface and it can be difficult at first glance to see what it important and what is not. So for those of you who prefer to assemble Ikea furniture first and then read the instructions, here are three easy steps: .PP 1. Create a new Excel \fIworkbook\fR (i.e. file) using \f(CW\*(C`new()\*(C'\fR. .PP 2. Add a worksheet to the new workbook using \f(CW\*(C`add_worksheet()\*(C'\fR. .PP 3. Write to the worksheet using \f(CW\*(C`write()\*(C'\fR. .PP Like this: .PP .Vb 1 \& use Excel::Writer::XLSX; # Step 0 \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqperl.xlsx\*(Aq ); # Step 1 \& $worksheet = $workbook\->add_worksheet(); # Step 2 \& $worksheet\->write( \*(AqA1\*(Aq, \*(AqHi Excel!\*(Aq ); # Step 3 .Ve .PP This will create an Excel file called \f(CW\*(C`perl.xlsx\*(C'\fR with a single worksheet and the text \f(CW\*(AqHi Excel!\*(Aq\fR in the relevant cell. And that's it. Okay, so there is actually a zeroth step as well, but \f(CW\*(C`use module\*(C'\fR goes without saying. There are many examples that come with the distribution and which you can use to get you started. See \*(L"\s-1EXAMPLES\s0\*(R". .PP Those of you who read the instructions first and assemble the furniture afterwards will know how to proceed. ;\-) .SH "WORKBOOK METHODS" .IX Header "WORKBOOK METHODS" The Excel::Writer::XLSX module provides an object oriented interface to a new Excel workbook. The following methods are available through a new workbook. .PP .Vb 10 \& new() \& add_worksheet() \& add_format() \& add_chart() \& add_shape() \& add_vba_project() \& set_vba_name() \& close() \& set_properties() \& define_name() \& set_tempdir() \& set_custom_color() \& sheets() \& set_1904() \& set_optimization() \& set_calc_mode() .Ve .PP If you are unfamiliar with object oriented interfaces or the way that they are implemented in Perl have a look at \f(CW\*(C`perlobj\*(C'\fR and \f(CW\*(C`perltoot\*(C'\fR in the main Perl documentation. .SS "\fInew()\fP" .IX Subsection "new()" A new Excel workbook is created using the \f(CW\*(C`new()\*(C'\fR constructor which accepts either a filename or a filehandle as a parameter. The following example creates a new Excel file based on a filename: .PP .Vb 3 \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqfilename.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& $worksheet\->write( 0, 0, \*(AqHi Excel!\*(Aq ); .Ve .PP Here are some other examples of using \f(CW\*(C`new()\*(C'\fR with filenames: .PP .Vb 4 \& my $workbook1 = Excel::Writer::XLSX\->new( $filename ); \& my $workbook2 = Excel::Writer::XLSX\->new( \*(Aq/tmp/filename.xlsx\*(Aq ); \& my $workbook3 = Excel::Writer::XLSX\->new( "c:\e\etmp\e\efilename.xlsx" ); \& my $workbook4 = Excel::Writer::XLSX\->new( \*(Aqc:\etmp\efilename.xlsx\*(Aq ); .Ve .PP The last two examples demonstrates how to create a file on \s-1DOS\s0 or Windows where it is necessary to either escape the directory separator \f(CW\*(C`\e\*(C'\fR or to use single quotes to ensure that it isn't interpolated. For more information see \f(CW\*(C`perlfaq5: Why can\*(Aqt I use "C:\etemp\efoo" in DOS paths?\*(C'\fR. .PP It is recommended that the filename uses the extension \f(CW\*(C`.xlsx\*(C'\fR rather than \f(CW\*(C`.xls\*(C'\fR since the latter causes an Excel warning when used with the \s-1XLSX\s0 format. .PP The \f(CW\*(C`new()\*(C'\fR constructor returns a Excel::Writer::XLSX object that you can use to add worksheets and store data. It should be noted that although \f(CW\*(C`my\*(C'\fR is not specifically required it defines the scope of the new workbook variable and, in the majority of cases, ensures that the workbook is closed properly without explicitly calling the \f(CW\*(C`close()\*(C'\fR method. .PP If the file cannot be created, due to file permissions or some other reason, \f(CW\*(C`new\*(C'\fR will return \f(CW\*(C`undef\*(C'\fR. Therefore, it is good practice to check the return value of \f(CW\*(C`new\*(C'\fR before proceeding. As usual the Perl variable \f(CW$!\fR will be set if there is a file creation error. You will also see one of the warning messages detailed in \*(L"\s-1DIAGNOSTICS\s0\*(R": .PP .Vb 2 \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqprotected.xlsx\*(Aq ); \& die "Problems creating new Excel file: $!" unless defined $workbook; .Ve .PP You can also pass a valid filehandle to the \f(CW\*(C`new()\*(C'\fR constructor. For example in a \s-1CGI\s0 program you could do something like this: .PP .Vb 2 \& binmode( STDOUT ); \& my $workbook = Excel::Writer::XLSX\->new( \e*STDOUT ); .Ve .PP The requirement for \f(CW\*(C`binmode()\*(C'\fR is explained below. .PP See also, the \f(CW\*(C`cgi.pl\*(C'\fR program in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .PP In \f(CW\*(C`mod_perl\*(C'\fR programs where you will have to do something like the following: .PP .Vb 6 \& # mod_perl 1 \& ... \& tie *XLSX, \*(AqApache\*(Aq; \& binmode( XLSX ); \& my $workbook = Excel::Writer::XLSX\->new( \e*XLSX ); \& ... \& \& # mod_perl 2 \& ... \& tie *XLSX => $r; # Tie to the Apache::RequestRec object \& binmode( *XLSX ); \& my $workbook = Excel::Writer::XLSX\->new( \e*XLSX ); \& ... .Ve .PP See also, the \f(CW\*(C`mod_perl1.pl\*(C'\fR and \f(CW\*(C`mod_perl2.pl\*(C'\fR programs in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .PP Filehandles can also be useful if you want to stream an Excel file over a socket or if you want to store an Excel file in a scalar. .PP For example here is a way to write an Excel file to a scalar: .PP .Vb 1 \& #!/usr/bin/perl \-w \& \& use strict; \& use Excel::Writer::XLSX; \& \& open my $fh, \*(Aq>\*(Aq, \emy $str or die "Failed to open filehandle: $!"; \& \& my $workbook = Excel::Writer::XLSX\->new( $fh ); \& my $worksheet = $workbook\->add_worksheet(); \& \& $worksheet\->write( 0, 0, \*(AqHi Excel!\*(Aq ); \& \& $workbook\->close(); \& \& # The Excel file in now in $str. Remember to binmode() the output \& # filehandle before printing it. \& binmode STDOUT; \& print $str; .Ve .PP See also the \f(CW\*(C`write_to_scalar.pl\*(C'\fR and \f(CW\*(C`filehandle.pl\*(C'\fR programs in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .PP \&\fBNote about the requirement for\fR \f(CW\*(C`binmode()\*(C'\fR. An Excel file is comprised of binary data. Therefore, if you are using a filehandle you should ensure that you \f(CW\*(C`binmode()\*(C'\fR it prior to passing it to \f(CW\*(C`new()\*(C'\fR.You should do this regardless of whether you are on a Windows platform or not. .PP You don't have to worry about \f(CW\*(C`binmode()\*(C'\fR if you are using filenames instead of filehandles. Excel::Writer::XLSX performs the \f(CW\*(C`binmode()\*(C'\fR internally when it converts the filename to a filehandle. For more information about \f(CW\*(C`binmode()\*(C'\fR see \f(CW\*(C`perlfunc\*(C'\fR and \f(CW\*(C`perlopentut\*(C'\fR in the main Perl documentation. .ie n .SS "add_worksheet( $sheetname )" .el .SS "add_worksheet( \f(CW$sheetname\fP )" .IX Subsection "add_worksheet( $sheetname )" At least one worksheet should be added to a new workbook. A worksheet is used to write data into cells: .PP .Vb 4 \& $worksheet1 = $workbook\->add_worksheet(); # Sheet1 \& $worksheet2 = $workbook\->add_worksheet( \*(AqFoglio2\*(Aq ); # Foglio2 \& $worksheet3 = $workbook\->add_worksheet( \*(AqData\*(Aq ); # Data \& $worksheet4 = $workbook\->add_worksheet(); # Sheet4 .Ve .PP If \f(CW$sheetname\fR is not specified the default Excel convention will be followed, i.e. Sheet1, Sheet2, etc. .PP The worksheet name must be a valid Excel worksheet name, i.e. it cannot contain any of the following characters, \f(CW\*(C`[ ] : * ? / \e\*(C'\fR and it must be less than 32 characters. In addition, you cannot use the same, case insensitive, \f(CW$sheetname\fR for more than one worksheet. .ie n .SS "add_format( %properties )" .el .SS "add_format( \f(CW%properties\fP )" .IX Subsection "add_format( %properties )" The \f(CW\*(C`add_format()\*(C'\fR method can be used to create new Format objects which are used to apply formatting to a cell. You can either define the properties at creation time via a hash of property values or later via method calls. .PP .Vb 2 \& $format1 = $workbook\->add_format( %props ); # Set properties at creation \& $format2 = $workbook\->add_format(); # Set properties later .Ve .PP See the \*(L"\s-1CELL\s0 \s-1FORMATTING\s0\*(R" section for more details about Format properties and how to set them. .ie n .SS "add_chart( %properties )" .el .SS "add_chart( \f(CW%properties\fP )" .IX Subsection "add_chart( %properties )" This method is use to create a new chart either as a standalone worksheet (the default) or as an embeddable object that can be inserted into a worksheet via the \f(CW\*(C`insert_chart()\*(C'\fR Worksheet method. .PP .Vb 1 \& my $chart = $workbook\->add_chart( type => \*(Aqcolumn\*(Aq ); .Ve .PP The properties that can be set are: .PP .Vb 4 \& type (required) \& subtype (optional) \& name (optional) \& embedded (optional) .Ve .IP "\(bu" 4 \&\f(CW\*(C`type\*(C'\fR .Sp This is a required parameter. It defines the type of chart that will be created. .Sp .Vb 1 \& my $chart = $workbook\->add_chart( type => \*(Aqline\*(Aq ); .Ve .Sp The available types are: .Sp .Vb 8 \& area \& bar \& column \& line \& pie \& doughnut \& scatter \& stock .Ve .IP "\(bu" 4 \&\f(CW\*(C`subtype\*(C'\fR .Sp Used to define a chart subtype where available. .Sp .Vb 1 \& my $chart = $workbook\->add_chart( type => \*(Aqbar\*(Aq, subtype => \*(Aqstacked\*(Aq ); .Ve .Sp See the Excel::Writer::XLSX::Chart documentation for a list of available chart subtypes. .IP "\(bu" 4 \&\f(CW\*(C`name\*(C'\fR .Sp Set the name for the chart sheet. The name property is optional and if it isn't supplied will default to \f(CW\*(C`Chart1 .. n\*(C'\fR. The name must be a valid Excel worksheet name. See \f(CW\*(C`add_worksheet()\*(C'\fR for more details on valid sheet names. The \f(CW\*(C`name\*(C'\fR property can be omitted for embedded charts. .Sp .Vb 1 \& my $chart = $workbook\->add_chart( type => \*(Aqline\*(Aq, name => \*(AqResults Chart\*(Aq ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`embedded\*(C'\fR .Sp Specifies that the Chart object will be inserted in a worksheet via the \f(CW\*(C`insert_chart()\*(C'\fR Worksheet method. It is an error to try insert a Chart that doesn't have this flag set. .Sp .Vb 1 \& my $chart = $workbook\->add_chart( type => \*(Aqline\*(Aq, embedded => 1 ); \& \& # Configure the chart. \& ... \& \& # Insert the chart into the a worksheet. \& $worksheet\->insert_chart( \*(AqE2\*(Aq, $chart ); .Ve .PP See Excel::Writer::XLSX::Chart for details on how to configure the chart object once it is created. See also the \f(CW\*(C`chart_*.pl\*(C'\fR programs in the examples directory of the distro. .ie n .SS "add_shape( %properties )" .el .SS "add_shape( \f(CW%properties\fP )" .IX Subsection "add_shape( %properties )" The \f(CW\*(C`add_shape()\*(C'\fR method can be used to create new shapes that may be inserted into a worksheet. .PP You can either define the properties at creation time via a hash of property values or later via method calls. .PP .Vb 7 \& # Set properties at creation. \& $plus = $workbook\->add_shape( \& type => \*(Aqplus\*(Aq, \& id => 3, \& width => $pw, \& height => $ph \& ); \& \& \& # Default rectangle shape. Set properties later. \& $rect = $workbook\->add_shape(); .Ve .PP See Excel::Writer::XLSX::Shape for details on how to configure the shape object once it is created. .PP See also the \f(CW\*(C`shape*.pl\*(C'\fR programs in the examples directory of the distro. .SS "add_vba_project( 'vbaProject.bin' )" .IX Subsection "add_vba_project( 'vbaProject.bin' )" The \f(CW\*(C`add_vba_project()\*(C'\fR method can be used to add macros or functions to an Excel::Writer::XLSX file using a binary \s-1VBA\s0 project file that has been extracted from an existing Excel \f(CW\*(C`xlsm\*(C'\fR file. .PP .Vb 1 \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqfile.xlsm\*(Aq ); \& \& $workbook\->add_vba_project( \*(Aq./vbaProject.bin\*(Aq ); .Ve .PP The supplied \f(CW\*(C`extract_vba\*(C'\fR utility can be used to extract the required \f(CW\*(C`vbaProject.bin\*(C'\fR file from an existing Excel file: .PP .Vb 2 \& $ extract_vba file.xlsm \& Extracted \*(AqvbaProject.bin\*(Aq successfully .Ve .PP Macros can be tied to buttons using the worksheet \f(CW\*(C`insert_button()\*(C'\fR method (see the \*(L"\s-1WORKSHEET\s0 \s-1METHODS\s0\*(R" section for details): .PP .Vb 1 \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq } ); .Ve .PP Note, Excel uses the file extension \f(CW\*(C`xlsm\*(C'\fR instead of \f(CW\*(C`xlsx\*(C'\fR for files that contain macros. It is advisable to follow the same convention. .PP See also the \f(CW\*(C`macros.pl\*(C'\fR example file and the \*(L"\s-1WORKING\s0 \s-1WITH\s0 \s-1VBA\s0 \s-1MACROS\s0\*(R". .SS "\fIset_vba_name()\fP" .IX Subsection "set_vba_name()" The \f(CW\*(C`set_vba_name()\*(C'\fR method can be used to set the \s-1VBA\s0 codename for the workbook. This is sometimes required when a \f(CW\*(C`vbaProject macro\*(C'\fR included via \f(CW\*(C`add_vba_project()\*(C'\fR refers to the workbook. The default Excel \s-1VBA\s0 name of \f(CW\*(C`ThisWorkbook\*(C'\fR is used if a user defined name isn't specified. See also \*(L"\s-1WORKING\s0 \s-1WITH\s0 \s-1VBA\s0 \s-1MACROS\s0\*(R". .SS "\fIclose()\fP" .IX Subsection "close()" In general your Excel file will be closed automatically when your program ends or when the Workbook object goes out of scope, however the \f(CW\*(C`close()\*(C'\fR method can be used to explicitly close an Excel file. .PP .Vb 1 \& $workbook\->close(); .Ve .PP An explicit \f(CW\*(C`close()\*(C'\fR is required if the file must be closed prior to performing some external action on it such as copying it, reading its size or attaching it to an email. .PP In addition, \f(CW\*(C`close()\*(C'\fR may be required to prevent perl's garbage collector from disposing of the Workbook, Worksheet and Format objects in the wrong order. Situations where this can occur are: .IP "\(bu" 4 If \f(CW\*(C`my()\*(C'\fR was not used to declare the scope of a workbook variable created using \f(CW\*(C`new()\*(C'\fR. .IP "\(bu" 4 If the \f(CW\*(C`new()\*(C'\fR, \f(CW\*(C`add_worksheet()\*(C'\fR or \f(CW\*(C`add_format()\*(C'\fR methods are called in subroutines. .PP The reason for this is that Excel::Writer::XLSX relies on Perl's \f(CW\*(C`DESTROY\*(C'\fR mechanism to trigger destructor methods in a specific sequence. This may not happen in cases where the Workbook, Worksheet and Format variables are not lexically scoped or where they have different lexical scopes. .PP In general, if you create a file with a size of 0 bytes or you fail to create a file you need to call \f(CW\*(C`close()\*(C'\fR. .PP The return value of \f(CW\*(C`close()\*(C'\fR is the same as that returned by perl when it closes the file created by \f(CW\*(C`new()\*(C'\fR. This allows you to handle error conditions in the usual way: .PP .Vb 1 \& $workbook\->close() or die "Error closing file: $!"; .Ve .SS "\fIset_properties()\fP" .IX Subsection "set_properties()" The \f(CW\*(C`set_properties\*(C'\fR method can be used to set the document properties of the Excel file created by \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR. These properties are visible when you use the \f(CW\*(C`Office Button \-> Prepare \-> Properties\*(C'\fR option in Excel and are also available to external applications that read or index windows files. .PP The properties should be passed in hash format as follows: .PP .Vb 5 \& $workbook\->set_properties( \& title => \*(AqThis is an example spreadsheet\*(Aq, \& author => \*(AqJohn McNamara\*(Aq, \& comments => \*(AqCreated with Perl and Excel::Writer::XLSX\*(Aq, \& ); .Ve .PP The properties that can be set are: .PP .Vb 9 \& title \& subject \& author \& manager \& company \& category \& keywords \& comments \& status .Ve .PP See also the \f(CW\*(C`properties.pl\*(C'\fR program in the examples directory of the distro. .SS "\fIdefine_name()\fP" .IX Subsection "define_name()" This method is used to defined a name that can be used to represent a value, a single cell or a range of cells in a workbook. .PP For example to set a global/workbook name: .PP .Vb 3 \& # Global/workbook names. \& $workbook\->define_name( \*(AqExchange_rate\*(Aq, \*(Aq=0.96\*(Aq ); \& $workbook\->define_name( \*(AqSales\*(Aq, \*(Aq=Sheet1!$G$1:$H$10\*(Aq ); .Ve .PP It is also possible to define a local/worksheet name by prefixing the name with the sheet name using the syntax \f(CW\*(C`sheetname!definedname\*(C'\fR: .PP .Vb 2 \& # Local/worksheet name. \& $workbook\->define_name( \*(AqSheet2!Sales\*(Aq, \*(Aq=Sheet2!$G$1:$G$10\*(Aq ); .Ve .PP If the sheet name contains spaces or special characters you must enclose it in single quotes like in Excel: .PP .Vb 1 \& $workbook\->define_name( "\*(AqNew Data\*(Aq!Sales", \*(Aq=Sheet2!$G$1:$G$10\*(Aq ); .Ve .PP See the defined_name.pl program in the examples dir of the distro. .PP Refer to the following to see Excel's syntax rules for defined names: http://office.microsoft.com/en\-001/excel\-help/define\-and\-use\-names\-in\-formulas\-HA010147120.aspx#BMsyntax_rules_for_names .SS "\fIset_tempdir()\fP" .IX Subsection "set_tempdir()" \&\f(CW\*(C`Excel::Writer::XLSX\*(C'\fR stores worksheet data in temporary files prior to assembling the final workbook. .PP The \f(CW\*(C`File::Temp\*(C'\fR module is used to create these temporary files. File::Temp uses \f(CW\*(C`File::Spec\*(C'\fR to determine an appropriate location for these files such as \f(CW\*(C`/tmp\*(C'\fR or \f(CW\*(C`c:\ewindows\etemp\*(C'\fR. You can find out which directory is used on your system as follows: .PP .Vb 1 \& perl \-MFile::Spec \-le "print File::Spec\->tmpdir()" .Ve .PP If the default temporary file directory isn't accessible to your application, or doesn't contain enough space, you can specify an alternative location using the \f(CW\*(C`set_tempdir()\*(C'\fR method: .PP .Vb 2 \& $workbook\->set_tempdir( \*(Aq/tmp/writeexcel\*(Aq ); \& $workbook\->set_tempdir( \*(Aqc:\ewindows\etemp\ewriteexcel\*(Aq ); .Ve .PP The directory for the temporary file must exist, \f(CW\*(C`set_tempdir()\*(C'\fR will not create a new directory. .ie n .SS "set_custom_color( $index, $red, $green, $blue )" .el .SS "set_custom_color( \f(CW$index\fP, \f(CW$red\fP, \f(CW$green\fP, \f(CW$blue\fP )" .IX Subsection "set_custom_color( $index, $red, $green, $blue )" The \f(CW\*(C`set_custom_color()\*(C'\fR method can be used to override one of the built-in palette values with a more suitable colour. .PP The value for \f(CW$index\fR should be in the range 8..63, see \*(L"\s-1COLOURS\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". .PP The default named colours use the following indices: .PP .Vb 10 \& 8 => black \& 9 => white \& 10 => red \& 11 => lime \& 12 => blue \& 13 => yellow \& 14 => magenta \& 15 => cyan \& 16 => brown \& 17 => green \& 18 => navy \& 20 => purple \& 22 => silver \& 23 => gray \& 33 => pink \& 53 => orange .Ve .PP A new colour is set using its \s-1RGB\s0 (red green blue) components. The \f(CW$red\fR, \f(CW$green\fR and \f(CW$blue\fR values must be in the range 0..255. You can determine the required values in Excel using the \f(CW\*(C`Tools\->Options\->Colors\->Modify\*(C'\fR dialog. .PP The \f(CW\*(C`set_custom_color()\*(C'\fR workbook method can also be used with a \s-1HTML\s0 style \f(CW\*(C`#rrggbb\*(C'\fR hex value: .PP .Vb 3 \& $workbook\->set_custom_color( 40, 255, 102, 0 ); # Orange \& $workbook\->set_custom_color( 40, 0xFF, 0x66, 0x00 ); # Same thing \& $workbook\->set_custom_color( 40, \*(Aq#FF6600\*(Aq ); # Same thing \& \& my $font = $workbook\->add_format( color => 40 ); # Modified colour .Ve .PP The return value from \f(CW\*(C`set_custom_color()\*(C'\fR is the index of the colour that was changed: .PP .Vb 1 \& my $ferrari = $workbook\->set_custom_color( 40, 216, 12, 12 ); \& \& my $format = $workbook\->add_format( \& bg_color => $ferrari, \& pattern => 1, \& border => 1 \& ); .Ve .PP Note, In the \s-1XLSX\s0 format the color palette isn't actually confined to 53 unique colors. The Excel::Writer::XLSX module will be extended at a later stage to support the newer, semi-infinite, palette. .SS "sheets( 0, 1, ... )" .IX Subsection "sheets( 0, 1, ... )" The \f(CW\*(C`sheets()\*(C'\fR method returns a list, or a sliced list, of the worksheets in a workbook. .PP If no arguments are passed the method returns a list of all the worksheets in the workbook. This is useful if you want to repeat an operation on each worksheet: .PP .Vb 3 \& for $worksheet ( $workbook\->sheets() ) { \& print $worksheet\->get_name(); \& } .Ve .PP You can also specify a slice list to return one or more worksheet objects: .PP .Vb 2 \& $worksheet = $workbook\->sheets( 0 ); \& $worksheet\->write( \*(AqA1\*(Aq, \*(AqHello\*(Aq ); .Ve .PP Or since the return value from \f(CW\*(C`sheets()\*(C'\fR is a reference to a worksheet object you can write the above example as: .PP .Vb 1 \& $workbook\->sheets( 0 )\->write( \*(AqA1\*(Aq, \*(AqHello\*(Aq ); .Ve .PP The following example returns the first and last worksheet in a workbook: .PP .Vb 3 \& for $worksheet ( $workbook\->sheets( 0, \-1 ) ) { \& # Do something \& } .Ve .PP Array slices are explained in the \f(CW\*(C`perldata\*(C'\fR manpage. .SS "\fIset_1904()\fP" .IX Subsection "set_1904()" Excel stores dates as real numbers where the integer part stores the number of days since the epoch and the fractional part stores the percentage of the day. The epoch can be either 1900 or 1904. Excel for Windows uses 1900 and Excel for Macintosh uses 1904. However, Excel on either platform will convert automatically between one system and the other. .PP Excel::Writer::XLSX stores dates in the 1900 format by default. If you wish to change this you can call the \f(CW\*(C`set_1904()\*(C'\fR workbook method. You can query the current value by calling the \f(CW\*(C`get_1904()\*(C'\fR workbook method. This returns 0 for 1900 and 1 for 1904. .PP See also \*(L"\s-1DATES\s0 \s-1AND\s0 \s-1TIME\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R" for more information about working with Excel's date system. .PP In general you probably won't need to use \f(CW\*(C`set_1904()\*(C'\fR. .SS "\fIset_optimization()\fP" .IX Subsection "set_optimization()" The \f(CW\*(C`set_optimization()\*(C'\fR method is used to turn on optimizations in the Excel::Writer::XLSX module. Currently there is only one optimization available and that is to reduce memory usage. .PP .Vb 1 \& $workbook\->set_optimization(); .Ve .PP See \*(L"\s-1SPEED\s0 \s-1AND\s0 \s-1MEMORY\s0 \s-1USAGE\s0\*(R" for more background information. .PP Note, that with this optimization turned on a row of data is written and then discarded when a cell in a new row is added via one of the Worksheet \f(CW\*(C`write_*()\*(C'\fR methods. As such data should be written in sequential row order once the optimization is turned on. .PP This method must be called before any calls to \f(CW\*(C`add_worksheet()\*(C'\fR. .ie n .SS "set_calc_mode( $mode )" .el .SS "set_calc_mode( \f(CW$mode\fP )" .IX Subsection "set_calc_mode( $mode )" Set the calculation mode for formulas in the workbook. This is mainly of use for workbooks with slow formulas where you want to allow the user to calculate them manually. .PP The mode parameter can be one of the following strings: .ie n .IP """auto""" 4 .el .IP "\f(CWauto\fR" 4 .IX Item "auto" The default. Excel will re-calculate formulas when a formula or a value affecting the formula changes. .ie n .IP """manual""" 4 .el .IP "\f(CWmanual\fR" 4 .IX Item "manual" Only re-calculate formulas when the user requires it. Generally by pressing F9. .ie n .IP """auto_except_tables""" 4 .el .IP "\f(CWauto_except_tables\fR" 4 .IX Item "auto_except_tables" Excel will automatically re-calculate formulas except for tables. .SH "WORKSHEET METHODS" .IX Header "WORKSHEET METHODS" A new worksheet is created by calling the \f(CW\*(C`add_worksheet()\*(C'\fR method from a workbook object: .PP .Vb 2 \& $worksheet1 = $workbook\->add_worksheet(); \& $worksheet2 = $workbook\->add_worksheet(); .Ve .PP The following methods are available through a new worksheet: .PP .Vb 10 \& write() \& write_number() \& write_string() \& write_rich_string() \& keep_leading_zeros() \& write_blank() \& write_row() \& write_col() \& write_date_time() \& write_url() \& write_url_range() \& write_formula() \& write_comment() \& show_comments() \& set_comments_author() \& add_write_handler() \& insert_image() \& insert_chart() \& insert_shape() \& insert_button() \& data_validation() \& conditional_formatting() \& add_sparkline() \& add_table() \& get_name() \& activate() \& select() \& hide() \& set_first_sheet() \& protect() \& set_selection() \& set_row() \& set_default_row() \& set_column() \& outline_settings() \& freeze_panes() \& split_panes() \& merge_range() \& merge_range_type() \& set_zoom() \& right_to_left() \& hide_zero() \& set_tab_color() \& autofilter() \& filter_column() \& filter_column_list() \& set_vba_name() .Ve .SS "Cell notation" .IX Subsection "Cell notation" Excel::Writer::XLSX supports two forms of notation to designate the position of cells: Row-column notation and A1 notation. .PP Row-column notation uses a zero based index for both row and column while A1 notation uses the standard Excel alphanumeric sequence of column letter and 1\-based row. For example: .PP .Vb 2 \& (0, 0) # The top left cell in row\-column notation. \& (\*(AqA1\*(Aq) # The top left cell in A1 notation. \& \& (1999, 29) # Row\-column notation. \& (\*(AqAD2000\*(Aq) # The same cell in A1 notation. .Ve .PP Row-column notation is useful if you are referring to cells programmatically: .PP .Vb 3 \& for my $i ( 0 .. 9 ) { \& $worksheet\->write( $i, 0, \*(AqHello\*(Aq ); # Cells A1 to A10 \& } .Ve .PP A1 notation is useful for setting up a worksheet manually and for working with formulas: .PP .Vb 2 \& $worksheet\->write( \*(AqH1\*(Aq, 200 ); \& $worksheet\->write( \*(AqH2\*(Aq, \*(Aq=H1+1\*(Aq ); .Ve .PP In formulas and applicable methods you can also use the \f(CW\*(C`A:A\*(C'\fR column notation: .PP .Vb 1 \& $worksheet\->write( \*(AqA1\*(Aq, \*(Aq=SUM(B:B)\*(Aq ); .Ve .PP The \f(CW\*(C`Excel::Writer::XLSX::Utility\*(C'\fR module that is included in the distro contains helper functions for dealing with A1 notation, for example: .PP .Vb 1 \& use Excel::Writer::XLSX::Utility; \& \& ( $row, $col ) = xl_cell_to_rowcol( \*(AqC2\*(Aq ); # (1, 2) \& $str = xl_rowcol_to_cell( 1, 2 ); # C2 .Ve .PP For simplicity, the parameter lists for the worksheet method calls in the following sections are given in terms of row-column notation. In all cases it is also possible to use A1 notation. .PP Note: in Excel it is also possible to use a R1C1 notation. This is not supported by Excel::Writer::XLSX. .ie n .SS "write( $row, $column, $token, $format )" .el .SS "write( \f(CW$row\fP, \f(CW$column\fP, \f(CW$token\fP, \f(CW$format\fP )" .IX Subsection "write( $row, $column, $token, $format )" Excel makes a distinction between data types such as strings, numbers, blanks, formulas and hyperlinks. To simplify the process of writing data the \f(CW\*(C`write()\*(C'\fR method acts as a general alias for several more specific methods: .PP .Vb 7 \& write_string() \& write_number() \& write_blank() \& write_formula() \& write_url() \& write_row() \& write_col() .Ve .PP The general rule is that if the data looks like a \fIsomething\fR then a \fIsomething\fR is written. Here are some examples in both row-column and A1 notation: .PP .Vb 10 \& # Same as: \& $worksheet\->write( 0, 0, \*(AqHello\*(Aq ); # write_string() \& $worksheet\->write( 1, 0, \*(AqOne\*(Aq ); # write_string() \& $worksheet\->write( 2, 0, 2 ); # write_number() \& $worksheet\->write( 3, 0, 3.00001 ); # write_number() \& $worksheet\->write( 4, 0, "" ); # write_blank() \& $worksheet\->write( 5, 0, \*(Aq\*(Aq ); # write_blank() \& $worksheet\->write( 6, 0, undef ); # write_blank() \& $worksheet\->write( 7, 0 ); # write_blank() \& $worksheet\->write( 8, 0, \*(Aqhttp://www.perl.com/\*(Aq ); # write_url() \& $worksheet\->write( \*(AqA9\*(Aq, \*(Aqftp://ftp.cpan.org/\*(Aq ); # write_url() \& $worksheet\->write( \*(AqA10\*(Aq, \*(Aqinternal:Sheet1!A1\*(Aq ); # write_url() \& $worksheet\->write( \*(AqA11\*(Aq, \*(Aqexternal:c:\efoo.xlsx\*(Aq ); # write_url() \& $worksheet\->write( \*(AqA12\*(Aq, \*(Aq=A3 + 3*A4\*(Aq ); # write_formula() \& $worksheet\->write( \*(AqA13\*(Aq, \*(Aq=SIN(PI()/4)\*(Aq ); # write_formula() \& $worksheet\->write( \*(AqA14\*(Aq, \e@array ); # write_row() \& $worksheet\->write( \*(AqA15\*(Aq, [\e@array] ); # write_col() \& \& # And if the keep_leading_zeros property is set: \& $worksheet\->write( \*(AqA16\*(Aq, \*(Aq2\*(Aq ); # write_number() \& $worksheet\->write( \*(AqA17\*(Aq, \*(Aq02\*(Aq ); # write_string() \& $worksheet\->write( \*(AqA18\*(Aq, \*(Aq00002\*(Aq ); # write_string() \& \& # Write an array formula. Not available in Spreadsheet::WriteExcel. \& $worksheet\->write( \*(AqA19\*(Aq, \*(Aq{=SUM(A1:B1*A2:B2)}\*(Aq ); # write_formula() .Ve .PP The \*(L"looks like\*(R" rule is defined by regular expressions: .PP \&\f(CW\*(C`write_number()\*(C'\fR if \f(CW$token\fR is a number based on the following regex: \f(CW\*(C`$token =~ /^([+\-]?)(?=\ed|\e.\ed)\ed*(\e.\ed*)?([Ee]([+\-]?\ed+))?$/\*(C'\fR. .PP \&\f(CW\*(C`write_string()\*(C'\fR if \f(CW\*(C`keep_leading_zeros()\*(C'\fR is set and \f(CW$token\fR is an integer with leading zeros based on the following regex: \f(CW\*(C`$token =~ /^0\ed+$/\*(C'\fR. .PP \&\f(CW\*(C`write_blank()\*(C'\fR if \f(CW$token\fR is undef or a blank string: \f(CW\*(C`undef\*(C'\fR, \f(CW""\fR or \f(CW\*(Aq\*(Aq\fR. .PP \&\f(CW\*(C`write_url()\*(C'\fR if \f(CW$token\fR is a http, https, ftp or mailto \s-1URL\s0 based on the following regexes: \f(CW\*(C`$token =~ m|^[fh]tt?ps?://|\*(C'\fR or \f(CW\*(C`$token =~ m|^mailto:|\*(C'\fR. .PP \&\f(CW\*(C`write_url()\*(C'\fR if \f(CW$token\fR is an internal or external sheet reference based on the following regex: \f(CW\*(C`$token =~ m[^(in|ex)ternal:]\*(C'\fR. .PP \&\f(CW\*(C`write_formula()\*(C'\fR if the first character of \f(CW$token\fR is \f(CW"="\fR. .PP \&\f(CW\*(C`write_array_formula()\*(C'\fR if the \f(CW$token\fR matches \f(CW\*(C`/^{=.*}$/\*(C'\fR. .PP \&\f(CW\*(C`write_row()\*(C'\fR if \f(CW$token\fR is an array ref. .PP \&\f(CW\*(C`write_col()\*(C'\fR if \f(CW$token\fR is an array ref of array refs. .PP \&\f(CW\*(C`write_string()\*(C'\fR if none of the previous conditions apply. .PP The \f(CW$format\fR parameter is optional. It should be a valid Format object, see \*(L"\s-1CELL\s0 \s-1FORMATTING\s0\*(R": .PP .Vb 4 \& my $format = $workbook\->add_format(); \& $format\->set_bold(); \& $format\->set_color( \*(Aqred\*(Aq ); \& $format\->set_align( \*(Aqcenter\*(Aq ); \& \& $worksheet\->write( 4, 0, \*(AqHello\*(Aq, $format ); # Formatted string .Ve .PP The \fIwrite()\fR method will ignore empty strings or \f(CW\*(C`undef\*(C'\fR tokens unless a format is also supplied. As such you needn't worry about special handling for empty or \f(CW\*(C`undef\*(C'\fR values in your data. See also the \f(CW\*(C`write_blank()\*(C'\fR method. .PP One problem with the \f(CW\*(C`write()\*(C'\fR method is that occasionally data looks like a number but you don't want it treated as a number. For example, zip codes or \s-1ID\s0 numbers often start with a leading zero. If you write this data as a number then the leading zero(s) will be stripped. You can change this default behaviour by using the \f(CW\*(C`keep_leading_zeros()\*(C'\fR method. While this property is in place any integers with leading zeros will be treated as strings and the zeros will be preserved. See the \f(CW\*(C`keep_leading_zeros()\*(C'\fR section for a full discussion of this issue. .PP You can also add your own data handlers to the \f(CW\*(C`write()\*(C'\fR method using \f(CW\*(C`add_write_handler()\*(C'\fR. .PP The \f(CW\*(C`write()\*(C'\fR method will also handle Unicode strings in \f(CW\*(C`UTF\-8\*(C'\fR format. .PP The \f(CW\*(C`write\*(C'\fR methods return: .PP .Vb 4 \& 0 for success. \& \-1 for insufficient number of arguments. \& \-2 for row or column out of bounds. \& \-3 for string too long. .Ve .ie n .SS "write_number( $row, $column, $number, $format )" .el .SS "write_number( \f(CW$row\fP, \f(CW$column\fP, \f(CW$number\fP, \f(CW$format\fP )" .IX Subsection "write_number( $row, $column, $number, $format )" Write an integer or a float to the cell specified by \f(CW$row\fR and \f(CW$column\fR: .PP .Vb 2 \& $worksheet\->write_number( 0, 0, 123456 ); \& $worksheet\->write_number( \*(AqA2\*(Aq, 2.3451 ); .Ve .PP See the note about \*(L"Cell notation\*(R". The \f(CW$format\fR parameter is optional. .PP In general it is sufficient to use the \f(CW\*(C`write()\*(C'\fR method. .PP \&\fBNote\fR: some versions of Excel 2007 do not display the calculated values of formulas written by Excel::Writer::XLSX. Applying all available Service Packs to Excel should fix this. .ie n .SS "write_string( $row, $column, $string, $format )" .el .SS "write_string( \f(CW$row\fP, \f(CW$column\fP, \f(CW$string\fP, \f(CW$format\fP )" .IX Subsection "write_string( $row, $column, $string, $format )" Write a string to the cell specified by \f(CW$row\fR and \f(CW$column\fR: .PP .Vb 2 \& $worksheet\->write_string( 0, 0, \*(AqYour text here\*(Aq ); \& $worksheet\->write_string( \*(AqA2\*(Aq, \*(Aqor here\*(Aq ); .Ve .PP The maximum string size is 32767 characters. However the maximum string segment that Excel can display in a cell is 1000. All 32767 characters can be displayed in the formula bar. .PP The \f(CW$format\fR parameter is optional. .PP The \f(CW\*(C`write()\*(C'\fR method will also handle strings in \f(CW\*(C`UTF\-8\*(C'\fR format. See also the \f(CW\*(C`unicode_*.pl\*(C'\fR programs in the examples directory of the distro. .PP In general it is sufficient to use the \f(CW\*(C`write()\*(C'\fR method. However, you may sometimes wish to use the \f(CW\*(C`write_string()\*(C'\fR method to write data that looks like a number but that you don't want treated as a number. For example, zip codes or phone numbers: .PP .Vb 2 \& # Write as a plain string \& $worksheet\->write_string( \*(AqA1\*(Aq, \*(Aq01209\*(Aq ); .Ve .PP However, if the user edits this string Excel may convert it back to a number. To get around this you can use the Excel text format \f(CW\*(C`@\*(C'\fR: .PP .Vb 3 \& # Format as a string. Doesn\*(Aqt change to a number when edited \& my $format1 = $workbook\->add_format( num_format => \*(Aq@\*(Aq ); \& $worksheet\->write_string( \*(AqA2\*(Aq, \*(Aq01209\*(Aq, $format1 ); .Ve .PP See also the note about \*(L"Cell notation\*(R". .ie n .SS "write_rich_string( $row, $column, $format, $string, ..., $cell_format )" .el .SS "write_rich_string( \f(CW$row\fP, \f(CW$column\fP, \f(CW$format\fP, \f(CW$string\fP, ..., \f(CW$cell_format\fP )" .IX Subsection "write_rich_string( $row, $column, $format, $string, ..., $cell_format )" The \f(CW\*(C`write_rich_string()\*(C'\fR method is used to write strings with multiple formats. For example to write the string "This is \fBbold\fR and this is \fIitalic\fR" you would use the following: .PP .Vb 2 \& my $bold = $workbook\->add_format( bold => 1 ); \& my $italic = $workbook\->add_format( italic => 1 ); \& \& $worksheet\->write_rich_string( \*(AqA1\*(Aq, \& \*(AqThis is \*(Aq, $bold, \*(Aqbold\*(Aq, \*(Aq and this is \*(Aq, $italic, \*(Aqitalic\*(Aq ); .Ve .PP The basic rule is to break the string into fragments and put a \f(CW$format\fR object before the fragment that you want to format. For example: .PP .Vb 2 \& # Unformatted string. \& \*(AqThis is an example string\*(Aq \& \& # Break it into fragments. \& \*(AqThis is an \*(Aq, \*(Aqexample\*(Aq, \*(Aq string\*(Aq \& \& # Add formatting before the fragments you want formatted. \& \*(AqThis is an \*(Aq, $format, \*(Aqexample\*(Aq, \*(Aq string\*(Aq \& \& # In Excel::Writer::XLSX. \& $worksheet\->write_rich_string( \*(AqA1\*(Aq, \& \*(AqThis is an \*(Aq, $format, \*(Aqexample\*(Aq, \*(Aq string\*(Aq ); .Ve .PP String fragments that don't have a format are given a default format. So for example when writing the string "Some \fBbold\fR text" you would use the first example below but it would be equivalent to the second: .PP .Vb 2 \& # With default formatting: \& my $bold = $workbook\->add_format( bold => 1 ); \& \& $worksheet\->write_rich_string( \*(AqA1\*(Aq, \& \*(AqSome \*(Aq, $bold, \*(Aqbold\*(Aq, \*(Aq text\*(Aq ); \& \& # Or more explicitly: \& my $bold = $workbook\->add_format( bold => 1 ); \& my $default = $workbook\->add_format(); \& \& $worksheet\->write_rich_string( \*(AqA1\*(Aq, \& $default, \*(AqSome \*(Aq, $bold, \*(Aqbold\*(Aq, $default, \*(Aq text\*(Aq ); .Ve .PP As with Excel, only the font properties of the format such as font name, style, size, underline, color and effects are applied to the string fragments. Other features such as border, background, text wrap and alignment must be applied to the cell. .PP The \f(CW\*(C`write_rich_string()\*(C'\fR method allows you to do this by using the last argument as a cell format (if it is a format object). The following example centers a rich string in the cell: .PP .Vb 2 \& my $bold = $workbook\->add_format( bold => 1 ); \& my $center = $workbook\->add_format( align => \*(Aqcenter\*(Aq ); \& \& $worksheet\->write_rich_string( \*(AqA5\*(Aq, \& \*(AqSome \*(Aq, $bold, \*(Aqbold text\*(Aq, \*(Aq centered\*(Aq, $center ); .Ve .PP See the \f(CW\*(C`rich_strings.pl\*(C'\fR example in the distro for more examples. .PP .Vb 6 \& my $bold = $workbook\->add_format( bold => 1 ); \& my $italic = $workbook\->add_format( italic => 1 ); \& my $red = $workbook\->add_format( color => \*(Aqred\*(Aq ); \& my $blue = $workbook\->add_format( color => \*(Aqblue\*(Aq ); \& my $center = $workbook\->add_format( align => \*(Aqcenter\*(Aq ); \& my $super = $workbook\->add_format( font_script => 1 ); \& \& \& # Write some strings with multiple formats. \& $worksheet\->write_rich_string( \*(AqA1\*(Aq, \& \*(AqThis is \*(Aq, $bold, \*(Aqbold\*(Aq, \*(Aq and this is \*(Aq, $italic, \*(Aqitalic\*(Aq ); \& \& $worksheet\->write_rich_string( \*(AqA3\*(Aq, \& \*(AqThis is \*(Aq, $red, \*(Aqred\*(Aq, \*(Aq and this is \*(Aq, $blue, \*(Aqblue\*(Aq ); \& \& $worksheet\->write_rich_string( \*(AqA5\*(Aq, \& \*(AqSome \*(Aq, $bold, \*(Aqbold text\*(Aq, \*(Aq centered\*(Aq, $center ); \& \& $worksheet\->write_rich_string( \*(AqA7\*(Aq, \& $italic, \*(Aqj = k\*(Aq, $super, \*(Aq(n\-1)\*(Aq, $center ); .Ve .PP As with \f(CW\*(C`write_sting()\*(C'\fR the maximum string size is 32767 characters. See also the note about \*(L"Cell notation\*(R". .SS "\fIkeep_leading_zeros()\fP" .IX Subsection "keep_leading_zeros()" This method changes the default handling of integers with leading zeros when using the \f(CW\*(C`write()\*(C'\fR method. .PP The \f(CW\*(C`write()\*(C'\fR method uses regular expressions to determine what type of data to write to an Excel worksheet. If the data looks like a number it writes a number using \f(CW\*(C`write_number()\*(C'\fR. One problem with this approach is that occasionally data looks like a number but you don't want it treated as a number. .PP Zip codes and \s-1ID\s0 numbers, for example, often start with a leading zero. If you write this data as a number then the leading zero(s) will be stripped. This is the also the default behaviour when you enter data manually in Excel. .PP To get around this you can use one of three options. Write a formatted number, write the number as a string or use the \f(CW\*(C`keep_leading_zeros()\*(C'\fR method to change the default behaviour of \f(CW\*(C`write()\*(C'\fR: .PP .Vb 2 \& # Implicitly write a number, the leading zero is removed: 1209 \& $worksheet\->write( \*(AqA1\*(Aq, \*(Aq01209\*(Aq ); \& \& # Write a zero padded number using a format: 01209 \& my $format1 = $workbook\->add_format( num_format => \*(Aq00000\*(Aq ); \& $worksheet\->write( \*(AqA2\*(Aq, \*(Aq01209\*(Aq, $format1 ); \& \& # Write explicitly as a string: 01209 \& $worksheet\->write_string( \*(AqA3\*(Aq, \*(Aq01209\*(Aq ); \& \& # Write implicitly as a string: 01209 \& $worksheet\->keep_leading_zeros(); \& $worksheet\->write( \*(AqA4\*(Aq, \*(Aq01209\*(Aq ); .Ve .PP The above code would generate a worksheet that looked like the following: .PP .Vb 7 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | A | B | C | D | ... \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | 1 | 1209 | | | | ... \& | 2 | 01209 | | | | ... \& | 3 | 01209 | | | | ... \& | 4 | 01209 | | | | ... .Ve .PP The examples are on different sides of the cells due to the fact that Excel displays strings with a left justification and numbers with a right justification by default. You can change this by using a format to justify the data, see \*(L"\s-1CELL\s0 \s-1FORMATTING\s0\*(R". .PP It should be noted that if the user edits the data in examples \f(CW\*(C`A3\*(C'\fR and \f(CW\*(C`A4\*(C'\fR the strings will revert back to numbers. Again this is Excel's default behaviour. To avoid this you can use the text format \f(CW\*(C`@\*(C'\fR: .PP .Vb 3 \& # Format as a string (01209) \& my $format2 = $workbook\->add_format( num_format => \*(Aq@\*(Aq ); \& $worksheet\->write_string( \*(AqA5\*(Aq, \*(Aq01209\*(Aq, $format2 ); .Ve .PP The \f(CW\*(C`keep_leading_zeros()\*(C'\fR property is off by default. The \f(CW\*(C`keep_leading_zeros()\*(C'\fR method takes 0 or 1 as an argument. It defaults to 1 if an argument isn't specified: .PP .Vb 3 \& $worksheet\->keep_leading_zeros(); # Set on \& $worksheet\->keep_leading_zeros( 1 ); # Set on \& $worksheet\->keep_leading_zeros( 0 ); # Set off .Ve .PP See also the \f(CW\*(C`add_write_handler()\*(C'\fR method. .ie n .SS "write_blank( $row, $column, $format )" .el .SS "write_blank( \f(CW$row\fP, \f(CW$column\fP, \f(CW$format\fP )" .IX Subsection "write_blank( $row, $column, $format )" Write a blank cell specified by \f(CW$row\fR and \f(CW$column\fR: .PP .Vb 1 \& $worksheet\->write_blank( 0, 0, $format ); .Ve .PP This method is used to add formatting to a cell which doesn't contain a string or number value. .PP Excel differentiates between an \*(L"Empty\*(R" cell and a \*(L"Blank\*(R" cell. An \*(L"Empty\*(R" cell is a cell which doesn't contain data whilst a \*(L"Blank\*(R" cell is a cell which doesn't contain data but does contain formatting. Excel stores \*(L"Blank\*(R" cells but ignores \*(L"Empty\*(R" cells. .PP As such, if you write an empty cell without formatting it is ignored: .PP .Vb 2 \& $worksheet\->write( \*(AqA1\*(Aq, undef, $format ); # write_blank() \& $worksheet\->write( \*(AqA2\*(Aq, undef ); # Ignored .Ve .PP This seemingly uninteresting fact means that you can write arrays of data without special treatment for \f(CW\*(C`undef\*(C'\fR or empty string values. .PP See the note about \*(L"Cell notation\*(R". .ie n .SS "write_row( $row, $column, $array_ref, $format )" .el .SS "write_row( \f(CW$row\fP, \f(CW$column\fP, \f(CW$array_ref\fP, \f(CW$format\fP )" .IX Subsection "write_row( $row, $column, $array_ref, $format )" The \f(CW\*(C`write_row()\*(C'\fR method can be used to write a 1D or 2D array of data in one go. This is useful for converting the results of a database query into an Excel worksheet. You must pass a reference to the array of data rather than the array itself. The \f(CW\*(C`write()\*(C'\fR method is then called for each element of the data. For example: .PP .Vb 2 \& @array = ( \*(Aqawk\*(Aq, \*(Aqgawk\*(Aq, \*(Aqmawk\*(Aq ); \& $array_ref = \e@array; \& \& $worksheet\->write_row( 0, 0, $array_ref ); \& \& # The above example is equivalent to: \& $worksheet\->write( 0, 0, $array[0] ); \& $worksheet\->write( 0, 1, $array[1] ); \& $worksheet\->write( 0, 2, $array[2] ); .Ve .PP Note: For convenience the \f(CW\*(C`write()\*(C'\fR method behaves in the same way as \f(CW\*(C`write_row()\*(C'\fR if it is passed an array reference. Therefore the following two method calls are equivalent: .PP .Vb 2 \& $worksheet\->write_row( \*(AqA1\*(Aq, $array_ref ); # Write a row of data \& $worksheet\->write( \*(AqA1\*(Aq, $array_ref ); # Same thing .Ve .PP As with all of the write methods the \f(CW$format\fR parameter is optional. If a format is specified it is applied to all the elements of the data array. .PP Array references within the data will be treated as columns. This allows you to write 2D arrays of data in one go. For example: .PP .Vb 5 \& @eec = ( \& [\*(Aqmaggie\*(Aq, \*(Aqmilly\*(Aq, \*(Aqmolly\*(Aq, \*(Aqmay\*(Aq ], \& [13, 14, 15, 16 ], \& [\*(Aqshell\*(Aq, \*(Aqstar\*(Aq, \*(Aqcrab\*(Aq, \*(Aqstone\*(Aq] \& ); \& \& $worksheet\->write_row( \*(AqA1\*(Aq, \e@eec ); .Ve .PP Would produce a worksheet as follows: .PP .Vb 9 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | A | B | C | D | E | ... \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | 1 | maggie | 13 | shell | ... | ... | ... \& | 2 | milly | 14 | star | ... | ... | ... \& | 3 | molly | 15 | crab | ... | ... | ... \& | 4 | may | 16 | stone | ... | ... | ... \& | 5 | ... | ... | ... | ... | ... | ... \& | 6 | ... | ... | ... | ... | ... | ... .Ve .PP To write the data in a row-column order refer to the \f(CW\*(C`write_col()\*(C'\fR method below. .PP Any \f(CW\*(C`undef\*(C'\fR values in the data will be ignored unless a format is applied to the data, in which case a formatted blank cell will be written. In either case the appropriate row or column value will still be incremented. .PP To find out more about array references refer to \f(CW\*(C`perlref\*(C'\fR and \f(CW\*(C`perlreftut\*(C'\fR in the main Perl documentation. To find out more about 2D arrays or \*(L"lists of lists\*(R" refer to \f(CW\*(C`perllol\*(C'\fR. .PP The \f(CW\*(C`write_row()\*(C'\fR method returns the first error encountered when writing the elements of the data or zero if no errors were encountered. See the return values described for the \f(CW\*(C`write()\*(C'\fR method above. .PP See also the \f(CW\*(C`write_arrays.pl\*(C'\fR program in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .PP The \f(CW\*(C`write_row()\*(C'\fR method allows the following idiomatic conversion of a text file to an Excel file: .PP .Vb 1 \& #!/usr/bin/perl \-w \& \& use strict; \& use Excel::Writer::XLSX; \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqfile.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& \& open INPUT, \*(Aqfile.txt\*(Aq or die "Couldn\*(Aqt open file: $!"; \& \& $worksheet\->write( $. \-1, 0, [split] ) while ; .Ve .ie n .SS "write_col( $row, $column, $array_ref, $format )" .el .SS "write_col( \f(CW$row\fP, \f(CW$column\fP, \f(CW$array_ref\fP, \f(CW$format\fP )" .IX Subsection "write_col( $row, $column, $array_ref, $format )" The \f(CW\*(C`write_col()\*(C'\fR method can be used to write a 1D or 2D array of data in one go. This is useful for converting the results of a database query into an Excel worksheet. You must pass a reference to the array of data rather than the array itself. The \f(CW\*(C`write()\*(C'\fR method is then called for each element of the data. For example: .PP .Vb 2 \& @array = ( \*(Aqawk\*(Aq, \*(Aqgawk\*(Aq, \*(Aqmawk\*(Aq ); \& $array_ref = \e@array; \& \& $worksheet\->write_col( 0, 0, $array_ref ); \& \& # The above example is equivalent to: \& $worksheet\->write( 0, 0, $array[0] ); \& $worksheet\->write( 1, 0, $array[1] ); \& $worksheet\->write( 2, 0, $array[2] ); .Ve .PP As with all of the write methods the \f(CW$format\fR parameter is optional. If a format is specified it is applied to all the elements of the data array. .PP Array references within the data will be treated as rows. This allows you to write 2D arrays of data in one go. For example: .PP .Vb 5 \& @eec = ( \& [\*(Aqmaggie\*(Aq, \*(Aqmilly\*(Aq, \*(Aqmolly\*(Aq, \*(Aqmay\*(Aq ], \& [13, 14, 15, 16 ], \& [\*(Aqshell\*(Aq, \*(Aqstar\*(Aq, \*(Aqcrab\*(Aq, \*(Aqstone\*(Aq] \& ); \& \& $worksheet\->write_col( \*(AqA1\*(Aq, \e@eec ); .Ve .PP Would produce a worksheet as follows: .PP .Vb 9 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | A | B | C | D | E | ... \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | 1 | maggie | milly | molly | may | ... | ... \& | 2 | 13 | 14 | 15 | 16 | ... | ... \& | 3 | shell | star | crab | stone | ... | ... \& | 4 | ... | ... | ... | ... | ... | ... \& | 5 | ... | ... | ... | ... | ... | ... \& | 6 | ... | ... | ... | ... | ... | ... .Ve .PP To write the data in a column-row order refer to the \f(CW\*(C`write_row()\*(C'\fR method above. .PP Any \f(CW\*(C`undef\*(C'\fR values in the data will be ignored unless a format is applied to the data, in which case a formatted blank cell will be written. In either case the appropriate row or column value will still be incremented. .PP As noted above the \f(CW\*(C`write()\*(C'\fR method can be used as a synonym for \f(CW\*(C`write_row()\*(C'\fR and \f(CW\*(C`write_row()\*(C'\fR handles nested array refs as columns. Therefore, the following two method calls are equivalent although the more explicit call to \f(CW\*(C`write_col()\*(C'\fR would be preferable for maintainability: .PP .Vb 2 \& $worksheet\->write_col( \*(AqA1\*(Aq, $array_ref ); # Write a column of data \& $worksheet\->write( \*(AqA1\*(Aq, [ $array_ref ] ); # Same thing .Ve .PP To find out more about array references refer to \f(CW\*(C`perlref\*(C'\fR and \f(CW\*(C`perlreftut\*(C'\fR in the main Perl documentation. To find out more about 2D arrays or \*(L"lists of lists\*(R" refer to \f(CW\*(C`perllol\*(C'\fR. .PP The \f(CW\*(C`write_col()\*(C'\fR method returns the first error encountered when writing the elements of the data or zero if no errors were encountered. See the return values described for the \f(CW\*(C`write()\*(C'\fR method above. .PP See also the \f(CW\*(C`write_arrays.pl\*(C'\fR program in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .ie n .SS "write_date_time( $row, $col, $date_string, $format )" .el .SS "write_date_time( \f(CW$row\fP, \f(CW$col\fP, \f(CW$date_string\fP, \f(CW$format\fP )" .IX Subsection "write_date_time( $row, $col, $date_string, $format )" The \f(CW\*(C`write_date_time()\*(C'\fR method can be used to write a date or time to the cell specified by \f(CW$row\fR and \f(CW$column\fR: .PP .Vb 1 \& $worksheet\->write_date_time( \*(AqA1\*(Aq, \*(Aq2004\-05\-13T23:20\*(Aq, $date_format ); .Ve .PP The \f(CW$date_string\fR should be in the following format: .PP .Vb 1 \& yyyy\-mm\-ddThh:mm:ss.sss .Ve .PP This conforms to an \s-1ISO8601\s0 date but it should be noted that the full range of \s-1ISO8601\s0 formats are not supported. .PP The following variations on the \f(CW$date_string\fR parameter are permitted: .PP .Vb 6 \& yyyy\-mm\-ddThh:mm:ss.sss # Standard format \& yyyy\-mm\-ddT # No time \& Thh:mm:ss.sss # No date \& yyyy\-mm\-ddThh:mm:ss.sssZ # Additional Z (but not time zones) \& yyyy\-mm\-ddThh:mm:ss # No fractional seconds \& yyyy\-mm\-ddThh:mm # No seconds .Ve .PP Note that the \f(CW\*(C`T\*(C'\fR is required in all cases. .PP A date should always have a \f(CW$format\fR, otherwise it will appear as a number, see \*(L"\s-1DATES\s0 \s-1AND\s0 \s-1TIME\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R" and \*(L"\s-1CELL\s0 \s-1FORMATTING\s0\*(R". Here is a typical example: .PP .Vb 2 \& my $date_format = $workbook\->add_format( num_format => \*(Aqmm/dd/yy\*(Aq ); \& $worksheet\->write_date_time( \*(AqA1\*(Aq, \*(Aq2004\-05\-13T23:20\*(Aq, $date_format ); .Ve .PP Valid dates should be in the range 1900\-01\-01 to 9999\-12\-31, for the 1900 epoch and 1904\-01\-01 to 9999\-12\-31, for the 1904 epoch. As with Excel, dates outside these ranges will be written as a string. .PP See also the date_time.pl program in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .ie n .SS "write_url( $row, $col, $url, $format, $label )" .el .SS "write_url( \f(CW$row\fP, \f(CW$col\fP, \f(CW$url\fP, \f(CW$format\fP, \f(CW$label\fP )" .IX Subsection "write_url( $row, $col, $url, $format, $label )" Write a hyperlink to a \s-1URL\s0 in the cell specified by \f(CW$row\fR and \f(CW$column\fR. The hyperlink is comprised of two elements: the visible label and the invisible link. The visible label is the same as the link unless an alternative label is specified. The \f(CW$label\fR parameter is optional. The label is written using the \f(CW\*(C`write()\*(C'\fR method. Therefore it is possible to write strings, numbers or formulas as labels. .PP The \f(CW$format\fR parameter is also optional, however, without a format the link won't look like a link. .PP The suggested format is: .PP .Vb 1 \& my $format = $workbook\->add_format( color => \*(Aqblue\*(Aq, underline => 1 ); .Ve .PP \&\fBNote\fR, this behaviour is different from Spreadsheet::WriteExcel which provides a default hyperlink format if one isn't specified by the user. .PP There are four web style \s-1URI\s0's supported: \f(CW\*(C`http://\*(C'\fR, \f(CW\*(C`https://\*(C'\fR, \f(CW\*(C`ftp://\*(C'\fR and \f(CW\*(C`mailto:\*(C'\fR: .PP .Vb 3 \& $worksheet\->write_url( 0, 0, \*(Aqftp://www.perl.org/\*(Aq, $format ); \& $worksheet\->write_url( \*(AqA3\*(Aq, \*(Aqhttp://www.perl.com/\*(Aq, $format ); \& $worksheet\->write_url( \*(AqA4\*(Aq, \*(Aqmailto:jmcnamara@cpan.org\*(Aq, $format ); .Ve .PP You can display an alternative string using the \f(CW$label\fR parameter: .PP .Vb 1 \& $worksheet\->write_url( 1, 0, \*(Aqhttp://www.perl.com/\*(Aq, $format, \*(AqPerl\*(Aq ); .Ve .PP If you wish to have some other cell data such as a number or a formula you can overwrite the cell using another call to \f(CW\*(C`write_*()\*(C'\fR: .PP .Vb 1 \& $worksheet\->write_url( \*(AqA1\*(Aq, \*(Aqhttp://www.perl.com/\*(Aq ); \& \& # Overwrite the URL string with a formula. The cell is still a link. \& $worksheet\->write_formula( \*(AqA1\*(Aq, \*(Aq=1+1\*(Aq, $format ); .Ve .PP There are two local URIs supported: \f(CW\*(C`internal:\*(C'\fR and \f(CW\*(C`external:\*(C'\fR. These are used for hyperlinks to internal worksheet references or external workbook and worksheet references: .PP .Vb 9 \& $worksheet\->write_url( \*(AqA6\*(Aq, \*(Aqinternal:Sheet2!A1\*(Aq, $format ); \& $worksheet\->write_url( \*(AqA7\*(Aq, \*(Aqinternal:Sheet2!A1\*(Aq, $format ); \& $worksheet\->write_url( \*(AqA8\*(Aq, \*(Aqinternal:Sheet2!A1:B2\*(Aq, $format ); \& $worksheet\->write_url( \*(AqA9\*(Aq, q{internal:\*(AqSales Data\*(Aq!A1}, $format ); \& $worksheet\->write_url( \*(AqA10\*(Aq, \*(Aqexternal:c:\etemp\efoo.xlsx\*(Aq, $format ); \& $worksheet\->write_url( \*(AqA11\*(Aq, \*(Aqexternal:c:\efoo.xlsx#Sheet2!A1\*(Aq, $format ); \& $worksheet\->write_url( \*(AqA12\*(Aq, \*(Aqexternal:..\efoo.xlsx\*(Aq, $format ); \& $worksheet\->write_url( \*(AqA13\*(Aq, \*(Aqexternal:..\efoo.xlsx#Sheet2!A1\*(Aq, $format ); \& $worksheet\->write_url( \*(AqA13\*(Aq, \*(Aqexternal:\e\e\e\eNET\eshare\efoo.xlsx\*(Aq, $format ); .Ve .PP All of the these \s-1URI\s0 types are recognised by the \f(CW\*(C`write()\*(C'\fR method, see above. .PP Worksheet references are typically of the form \f(CW\*(C`Sheet1!A1\*(C'\fR. You can also refer to a worksheet range using the standard Excel notation: \f(CW\*(C`Sheet1!A1:B2\*(C'\fR. .PP In external links the workbook and worksheet name must be separated by the \f(CW\*(C`#\*(C'\fR character: \f(CW\*(C`external:Workbook.xlsx#Sheet1!A1\*(Aq\*(C'\fR. .PP You can also link to a named range in the target worksheet. For example say you have a named range called \f(CW\*(C`my_name\*(C'\fR in the workbook \f(CW\*(C`c:\etemp\efoo.xlsx\*(C'\fR you could link to it as follows: .PP .Vb 1 \& $worksheet\->write_url( \*(AqA14\*(Aq, \*(Aqexternal:c:\etemp\efoo.xlsx#my_name\*(Aq ); .Ve .PP Excel requires that worksheet names containing spaces or non alphanumeric characters are single quoted as follows \f(CW\*(C`\*(AqSales Data\*(Aq!A1\*(C'\fR. If you need to do this in a single quoted string then you can either escape the single quotes \f(CW\*(C`\e\*(Aq\*(C'\fR or use the quote operator \f(CW\*(C`q{}\*(C'\fR as described in \f(CW\*(C`perlop\*(C'\fR in the main Perl documentation. .PP Links to network files are also supported. MS/Novell Network files normally begin with two back slashes as follows \f(CW\*(C`\e\eNETWORK\eetc\*(C'\fR. In order to generate this in a single or double quoted string you will have to escape the backslashes, \f(CW\*(Aq\e\e\e\eNETWORK\eetc\*(Aq\fR. .PP If you are using double quote strings then you should be careful to escape anything that looks like a metacharacter. For more information see \f(CW\*(C`perlfaq5: Why can\*(Aqt I use "C:\etemp\efoo" in DOS paths?\*(C'\fR. .PP Finally, you can avoid most of these quoting problems by using forward slashes. These are translated internally to backslashes: .PP .Vb 2 \& $worksheet\->write_url( \*(AqA14\*(Aq, "external:c:/temp/foo.xlsx" ); \& $worksheet\->write_url( \*(AqA15\*(Aq, \*(Aqexternal://NETWORK/share/foo.xlsx\*(Aq ); .Ve .PP Note: Excel::Writer::XLSX will escape the following characters in URLs as required by Excel: \f(CW\*(C`\es " < > \e [ ] \` ^ { }\*(C'\fR unless the \s-1URL\s0 already contains \f(CW%xx\fR style escapes. In which case it is assumed that the \s-1URL\s0 was escaped correctly by the user and will by passed directly to Excel. .PP See also, the note about \*(L"Cell notation\*(R". .ie n .SS "write_formula( $row, $column, $formula, $format, $value )" .el .SS "write_formula( \f(CW$row\fP, \f(CW$column\fP, \f(CW$formula\fP, \f(CW$format\fP, \f(CW$value\fP )" .IX Subsection "write_formula( $row, $column, $formula, $format, $value )" Write a formula or function to the cell specified by \f(CW$row\fR and \f(CW$column\fR: .PP .Vb 6 \& $worksheet\->write_formula( 0, 0, \*(Aq=$B$3 + B4\*(Aq ); \& $worksheet\->write_formula( 1, 0, \*(Aq=SIN(PI()/4)\*(Aq ); \& $worksheet\->write_formula( 2, 0, \*(Aq=SUM(B1:B5)\*(Aq ); \& $worksheet\->write_formula( \*(AqA4\*(Aq, \*(Aq=IF(A3>1,"Yes", "No")\*(Aq ); \& $worksheet\->write_formula( \*(AqA5\*(Aq, \*(Aq=AVERAGE(1, 2, 3, 4)\*(Aq ); \& $worksheet\->write_formula( \*(AqA6\*(Aq, \*(Aq=DATEVALUE("1\-Jan\-2001")\*(Aq ); .Ve .PP Array formulas are also supported: .PP .Vb 1 \& $worksheet\->write_formula( \*(AqA7\*(Aq, \*(Aq{=SUM(A1:B1*A2:B2)}\*(Aq ); .Ve .PP See also the \f(CW\*(C`write_array_formula()\*(C'\fR method below. .PP See the note about \*(L"Cell notation\*(R". For more information about writing Excel formulas see \*(L"\s-1FORMULAS\s0 \s-1AND\s0 \s-1FUNCTIONS\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R" .PP If required, it is also possible to specify the calculated value of the formula. This is occasionally necessary when working with non-Excel applications that don't calculate the value of the formula. The calculated \f(CW$value\fR is added at the end of the argument list: .PP .Vb 1 \& $worksheet\->write( \*(AqA1\*(Aq, \*(Aq=2+2\*(Aq, $format, 4 ); .Ve .PP However, this probably isn't something that you will ever need to do. If you do use this feature then do so with care. .ie n .SS "write_array_formula($first_row, $first_col, $last_row, $last_col, $formula, $format, $value)" .el .SS "write_array_formula($first_row, \f(CW$first_col\fP, \f(CW$last_row\fP, \f(CW$last_col\fP, \f(CW$formula\fP, \f(CW$format\fP, \f(CW$value\fP)" .IX Subsection "write_array_formula($first_row, $first_col, $last_row, $last_col, $formula, $format, $value)" Write an array formula to a cell range. In Excel an array formula is a formula that performs a calculation on a set of values. It can return a single value or a range of values. .PP An array formula is indicated by a pair of braces around the formula: \f(CW\*(C`{=SUM(A1:B1*A2:B2)}\*(C'\fR. If the array formula returns a single value then the \f(CW$first_\fR and \f(CW$last_\fR parameters should be the same: .PP .Vb 1 \& $worksheet\->write_array_formula(\*(AqA1:A1\*(Aq, \*(Aq{=SUM(B1:C1*B2:C2)}\*(Aq); .Ve .PP It this case however it is easier to just use the \f(CW\*(C`write_formula()\*(C'\fR or \f(CW\*(C`write()\*(C'\fR methods: .PP .Vb 3 \& # Same as above but more concise. \& $worksheet\->write( \*(AqA1\*(Aq, \*(Aq{=SUM(B1:C1*B2:C2)}\*(Aq ); \& $worksheet\->write_formula( \*(AqA1\*(Aq, \*(Aq{=SUM(B1:C1*B2:C2)}\*(Aq ); .Ve .PP For array formulas that return a range of values you must specify the range that the return values will be written to: .PP .Vb 2 \& $worksheet\->write_array_formula( \*(AqA1:A3\*(Aq, \*(Aq{=TREND(C1:C3,B1:B3)}\*(Aq ); \& $worksheet\->write_array_formula( 0, 0, 2, 0, \*(Aq{=TREND(C1:C3,B1:B3)}\*(Aq ); .Ve .PP If required, it is also possible to specify the calculated value of the formula. This is occasionally necessary when working with non-Excel applications that don't calculate the value of the formula. The calculated \f(CW$value\fR is added at the end of the argument list: .PP .Vb 1 \& $worksheet\->write_array_formula( \*(AqA1:A3\*(Aq, \*(Aq{=TREND(C1:C3,B1:B3)}\*(Aq, $format, 105 ); .Ve .PP In addition, some early versions of Excel 2007 don't calculate the values of array formulas when they aren't supplied. Installing the latest Office Service Pack should fix this issue. .PP See also the \f(CW\*(C`array_formula.pl\*(C'\fR program in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .PP Note: Array formulas are not supported by Spreadsheet::WriteExcel. .ie n .SS "store_formula( $formula )" .el .SS "store_formula( \f(CW$formula\fP )" .IX Subsection "store_formula( $formula )" Deprecated. This is a Spreadsheet::WriteExcel method that is no longer required by Excel::Writer::XLSX. See below. .ie n .SS "repeat_formula( $row, $col, $formula, $format )" .el .SS "repeat_formula( \f(CW$row\fP, \f(CW$col\fP, \f(CW$formula\fP, \f(CW$format\fP )" .IX Subsection "repeat_formula( $row, $col, $formula, $format )" Deprecated. This is a Spreadsheet::WriteExcel method that is no longer required by Excel::Writer::XLSX. .PP In Spreadsheet::WriteExcel it was computationally expensive to write formulas since they were parsed by a recursive descent parser. The \f(CW\*(C`store_formula()\*(C'\fR and \f(CW\*(C`repeat_formula()\*(C'\fR methods were used as a way of avoiding the overhead of repeated formulas by reusing a pre-parsed formula. .PP In Excel::Writer::XLSX this is no longer necessary since it is just as quick to write a formula as it is to write a string or a number. .PP The methods remain for backward compatibility but new Excel::Writer::XLSX programs shouldn't use them. .ie n .SS "write_comment( $row, $column, $string, ... )" .el .SS "write_comment( \f(CW$row\fP, \f(CW$column\fP, \f(CW$string\fP, ... )" .IX Subsection "write_comment( $row, $column, $string, ... )" The \f(CW\*(C`write_comment()\*(C'\fR method is used to add a comment to a cell. A cell comment is indicated in Excel by a small red triangle in the upper right-hand corner of the cell. Moving the cursor over the red triangle will reveal the comment. .PP The following example shows how to add a comment to a cell: .PP .Vb 2 \& $worksheet\->write ( 2, 2, \*(AqHello\*(Aq ); \& $worksheet\->write_comment( 2, 2, \*(AqThis is a comment.\*(Aq ); .Ve .PP As usual you can replace the \f(CW$row\fR and \f(CW$column\fR parameters with an \f(CW\*(C`A1\*(C'\fR cell reference. See the note about \*(L"Cell notation\*(R". .PP .Vb 2 \& $worksheet\->write ( \*(AqC3\*(Aq, \*(AqHello\*(Aq); \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqThis is a comment.\*(Aq ); .Ve .PP The \f(CW\*(C`write_comment()\*(C'\fR method will also handle strings in \f(CW\*(C`UTF\-8\*(C'\fR format. .PP .Vb 2 \& $worksheet\->write_comment( \*(AqC3\*(Aq, "\ex{263a}" ); # Smiley \& $worksheet\->write_comment( \*(AqC4\*(Aq, \*(AqComment ca va?\*(Aq ); .Ve .PP In addition to the basic 3 argument form of \f(CW\*(C`write_comment()\*(C'\fR you can pass in several optional key/value pairs to control the format of the comment. For example: .PP .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, visible => 1, author => \*(AqPerl\*(Aq ); .Ve .PP Most of these options are quite specific and in general the default comment behaviour will be all that you need. However, should you need greater control over the format of the cell comment the following options are available: .PP .Vb 12 \& author \& visible \& x_scale \& width \& y_scale \& height \& color \& start_cell \& start_row \& start_col \& x_offset \& y_offset .Ve .IP "Option: author" 4 .IX Item "Option: author" This option is used to indicate who is the author of the cell comment. Excel displays the author of the comment in the status bar at the bottom of the worksheet. This is usually of interest in corporate environments where several people might review and provide comments to a workbook. .Sp .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqAtonement\*(Aq, author => \*(AqIan McEwan\*(Aq ); .Ve .Sp The default author for all cell comments can be set using the \f(CW\*(C`set_comments_author()\*(C'\fR method (see below). .Sp .Vb 1 \& $worksheet\->set_comments_author( \*(AqPerl\*(Aq ); .Ve .IP "Option: visible" 4 .IX Item "Option: visible" This option is used to make a cell comment visible when the worksheet is opened. The default behaviour in Excel is that comments are initially hidden. However, it is also possible in Excel to make individual or all comments visible. In Excel::Writer::XLSX individual comments can be made visible as follows: .Sp .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, visible => 1 ); .Ve .Sp It is possible to make all comments in a worksheet visible using the \f(CW\*(C`show_comments()\*(C'\fR worksheet method (see below). Alternatively, if all of the cell comments have been made visible you can hide individual comments: .Sp .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, visible => 0 ); .Ve .IP "Option: x_scale" 4 .IX Item "Option: x_scale" This option is used to set the width of the cell comment box as a factor of the default width. .Sp .Vb 2 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, x_scale => 2 ); \& $worksheet\->write_comment( \*(AqC4\*(Aq, \*(AqHello\*(Aq, x_scale => 4.2 ); .Ve .IP "Option: width" 4 .IX Item "Option: width" This option is used to set the width of the cell comment box explicitly in pixels. .Sp .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, width => 200 ); .Ve .IP "Option: y_scale" 4 .IX Item "Option: y_scale" This option is used to set the height of the cell comment box as a factor of the default height. .Sp .Vb 2 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, y_scale => 2 ); \& $worksheet\->write_comment( \*(AqC4\*(Aq, \*(AqHello\*(Aq, y_scale => 4.2 ); .Ve .IP "Option: height" 4 .IX Item "Option: height" This option is used to set the height of the cell comment box explicitly in pixels. .Sp .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, height => 200 ); .Ve .IP "Option: color" 4 .IX Item "Option: color" This option is used to set the background colour of cell comment box. You can use one of the named colours recognised by Excel::Writer::XLSX or a colour index. See \*(L"\s-1COLOURS\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". .Sp .Vb 2 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, color => \*(Aqgreen\*(Aq ); \& $worksheet\->write_comment( \*(AqC4\*(Aq, \*(AqHello\*(Aq, color => 0x35 ); # Orange .Ve .IP "Option: start_cell" 4 .IX Item "Option: start_cell" This option is used to set the cell in which the comment will appear. By default Excel displays comments one cell to the right and one cell above the cell to which the comment relates. However, you can change this behaviour if you wish. In the following example the comment which would appear by default in cell \f(CW\*(C`D2\*(C'\fR is moved to \f(CW\*(C`E2\*(C'\fR. .Sp .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, start_cell => \*(AqE2\*(Aq ); .Ve .IP "Option: start_row" 4 .IX Item "Option: start_row" This option is used to set the row in which the comment will appear. See the \f(CW\*(C`start_cell\*(C'\fR option above. The row is zero indexed. .Sp .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, start_row => 0 ); .Ve .IP "Option: start_col" 4 .IX Item "Option: start_col" This option is used to set the column in which the comment will appear. See the \f(CW\*(C`start_cell\*(C'\fR option above. The column is zero indexed. .Sp .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, start_col => 4 ); .Ve .IP "Option: x_offset" 4 .IX Item "Option: x_offset" This option is used to change the x offset, in pixels, of a comment within a cell: .Sp .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, $comment, x_offset => 30 ); .Ve .IP "Option: y_offset" 4 .IX Item "Option: y_offset" This option is used to change the y offset, in pixels, of a comment within a cell: .Sp .Vb 1 \& $worksheet\->write_comment(\*(AqC3\*(Aq, $comment, x_offset => 30); .Ve .PP You can apply as many of these options as you require. .PP \&\fBNote about using options that adjust the position of the cell comment such as start_cell, start_row, start_col, x_offset and y_offset\fR: Excel only displays offset cell comments when they are displayed as \*(L"visible\*(R". Excel does \fBnot\fR display hidden cells as moved when you mouse over them. .PP \&\fBNote about row height and comments\fR. If you specify the height of a row that contains a comment then Excel::Writer::XLSX will adjust the height of the comment to maintain the default or user specified dimensions. However, the height of a row can also be adjusted automatically by Excel if the text wrap property is set or large fonts are used in the cell. This means that the height of the row is unknown to the module at run time and thus the comment box is stretched with the row. Use the \f(CW\*(C`set_row()\*(C'\fR method to specify the row height explicitly and avoid this problem. .SS "\fIshow_comments()\fP" .IX Subsection "show_comments()" This method is used to make all cell comments visible when a worksheet is opened. .PP .Vb 1 \& $worksheet\->show_comments(); .Ve .PP Individual comments can be made visible using the \f(CW\*(C`visible\*(C'\fR parameter of the \f(CW\*(C`write_comment\*(C'\fR method (see above): .PP .Vb 1 \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, visible => 1 ); .Ve .PP If all of the cell comments have been made visible you can hide individual comments as follows: .PP .Vb 2 \& $worksheet\->show_comments(); \& $worksheet\->write_comment( \*(AqC3\*(Aq, \*(AqHello\*(Aq, visible => 0 ); .Ve .SS "\fIset_comments_author()\fP" .IX Subsection "set_comments_author()" This method is used to set the default author of all cell comments. .PP .Vb 1 \& $worksheet\->set_comments_author( \*(AqPerl\*(Aq ); .Ve .PP Individual comment authors can be set using the \f(CW\*(C`author\*(C'\fR parameter of the \f(CW\*(C`write_comment\*(C'\fR method (see above). .PP The default comment author is an empty string, \f(CW\*(Aq\*(Aq\fR, if no author is specified. .ie n .SS "add_write_handler( $re, $code_ref )" .el .SS "add_write_handler( \f(CW$re\fP, \f(CW$code_ref\fP )" .IX Subsection "add_write_handler( $re, $code_ref )" This method is used to extend the Excel::Writer::XLSX \fIwrite()\fR method to handle user defined data. .PP If you refer to the section on \f(CW\*(C`write()\*(C'\fR above you will see that it acts as an alias for several more specific \f(CW\*(C`write_*\*(C'\fR methods. However, it doesn't always act in exactly the way that you would like it to. .PP One solution is to filter the input data yourself and call the appropriate \f(CW\*(C`write_*\*(C'\fR method. Another approach is to use the \f(CW\*(C`add_write_handler()\*(C'\fR method to add your own automated behaviour to \f(CW\*(C`write()\*(C'\fR. .PP The \f(CW\*(C`add_write_handler()\*(C'\fR method take two arguments, \f(CW$re\fR, a regular expression to match incoming data and \f(CW$code_ref\fR a callback function to handle the matched data: .PP .Vb 1 \& $worksheet\->add_write_handler( qr/^\ed\ed\ed\ed$/, \e&my_write ); .Ve .PP (In the these examples the \f(CW\*(C`qr\*(C'\fR operator is used to quote the regular expression strings, see perlop for more details). .PP The method is used as follows. say you wished to write 7 digit \s-1ID\s0 numbers as a string so that any leading zeros were preserved*, you could do something like the following: .PP .Vb 1 \& $worksheet\->add_write_handler( qr/^\ed{7}$/, \e&write_my_id ); \& \& \& sub write_my_id { \& my $worksheet = shift; \& return $worksheet\->write_string( @_ ); \& } .Ve .PP * You could also use the \f(CW\*(C`keep_leading_zeros()\*(C'\fR method for this. .PP Then if you call \f(CW\*(C`write()\*(C'\fR with an appropriate string it will be handled automatically: .PP .Vb 2 \& # Writes 0000000. It would normally be written as a number; 0. \& $worksheet\->write( \*(AqA1\*(Aq, \*(Aq0000000\*(Aq ); .Ve .PP The callback function will receive a reference to the calling worksheet and all of the other arguments that were passed to \f(CW\*(C`write()\*(C'\fR. The callback will see an \f(CW@_\fR argument list that looks like the following: .PP .Vb 7 \& $_[0] A ref to the calling worksheet. * \& $_[1] Zero based row number. \& $_[2] Zero based column number. \& $_[3] A number or string or token. \& $_[4] A format ref if any. \& $_[5] Any other arguments. \& ... \& \& * It is good style to shift this off the list so the @_ is the same \& as the argument list seen by write(). .Ve .PP Your callback should \f(CW\*(C`return()\*(C'\fR the return value of the \f(CW\*(C`write_*\*(C'\fR method that was called or \f(CW\*(C`undef\*(C'\fR to indicate that you rejected the match and want \f(CW\*(C`write()\*(C'\fR to continue as normal. .PP So for example if you wished to apply the previous filter only to \s-1ID\s0 values that occur in the first column you could modify your callback function as follows: .PP .Vb 3 \& sub write_my_id { \& my $worksheet = shift; \& my $col = $_[1]; \& \& if ( $col == 0 ) { \& return $worksheet\->write_string( @_ ); \& } \& else { \& # Reject the match and return control to write() \& return undef; \& } \& } .Ve .PP Now, you will get different behaviour for the first column and other columns: .PP .Vb 2 \& $worksheet\->write( \*(AqA1\*(Aq, \*(Aq0000000\*(Aq ); # Writes 0000000 \& $worksheet\->write( \*(AqB1\*(Aq, \*(Aq0000000\*(Aq ); # Writes 0 .Ve .PP You may add more than one handler in which case they will be called in the order that they were added. .PP Note, the \f(CW\*(C`add_write_handler()\*(C'\fR method is particularly suited for handling dates. .PP See the \f(CW\*(C`write_handler 1\-4\*(C'\fR programs in the \f(CW\*(C`examples\*(C'\fR directory for further examples. .ie n .SS "insert_image( $row, $col, $filename, $x, $y, $x_scale, $y_scale )" .el .SS "insert_image( \f(CW$row\fP, \f(CW$col\fP, \f(CW$filename\fP, \f(CW$x\fP, \f(CW$y\fP, \f(CW$x_scale\fP, \f(CW$y_scale\fP )" .IX Subsection "insert_image( $row, $col, $filename, $x, $y, $x_scale, $y_scale )" This method can be used to insert a image into a worksheet. The image can be in \s-1PNG\s0, \s-1JPEG\s0 or \s-1BMP\s0 format. The \f(CW$x\fR, \f(CW$y\fR, \f(CW$x_scale\fR and \f(CW$y_scale\fR parameters are optional. .PP .Vb 3 \& $worksheet1\->insert_image( \*(AqA1\*(Aq, \*(Aqperl.bmp\*(Aq ); \& $worksheet2\->insert_image( \*(AqA1\*(Aq, \*(Aq../images/perl.bmp\*(Aq ); \& $worksheet3\->insert_image( \*(AqA1\*(Aq, \*(Aq.c:\eimages\eperl.bmp\*(Aq ); .Ve .PP The parameters \f(CW$x\fR and \f(CW$y\fR can be used to specify an offset from the top left hand corner of the cell specified by \f(CW$row\fR and \f(CW$col\fR. The offset values are in pixels. .PP .Vb 1 \& $worksheet1\->insert_image(\*(AqA1\*(Aq, \*(Aqperl.bmp\*(Aq, 32, 10); .Ve .PP The offsets can be greater than the width or height of the underlying cell. This can be occasionally useful if you wish to align two or more images relative to the same cell. .PP The parameters \f(CW$x_scale\fR and \f(CW$y_scale\fR can be used to scale the inserted image horizontally and vertically: .PP .Vb 2 \& # Scale the inserted image: width x 2.0, height x 0.8 \& $worksheet\->insert_image( \*(AqA1\*(Aq, \*(Aqperl.bmp\*(Aq, 0, 0, 2, 0.8 ); .Ve .PP Note: you must call \f(CW\*(C`set_row()\*(C'\fR or \f(CW\*(C`set_column()\*(C'\fR before \f(CW\*(C`insert_image()\*(C'\fR if you wish to change the default dimensions of any of the rows or columns that the image occupies. The height of a row can also change if you use a font that is larger than the default. This in turn will affect the scaling of your image. To avoid this you should explicitly set the height of the row using \f(CW\*(C`set_row()\*(C'\fR if it contains a font size that will change the row height. .PP \&\s-1BMP\s0 images must be 24 bit, true colour, bitmaps. In general it is best to avoid \s-1BMP\s0 images since they aren't compressed. .ie n .SS "insert_chart( $row, $col, $chart, $x, $y, $x_scale, $y_scale )" .el .SS "insert_chart( \f(CW$row\fP, \f(CW$col\fP, \f(CW$chart\fP, \f(CW$x\fP, \f(CW$y\fP, \f(CW$x_scale\fP, \f(CW$y_scale\fP )" .IX Subsection "insert_chart( $row, $col, $chart, $x, $y, $x_scale, $y_scale )" This method can be used to insert a Chart object into a worksheet. The Chart must be created by the \f(CW\*(C`add_chart()\*(C'\fR Workbook method and it must have the \f(CW\*(C`embedded\*(C'\fR option set. .PP .Vb 1 \& my $chart = $workbook\->add_chart( type => \*(Aqline\*(Aq, embedded => 1 ); \& \& # Configure the chart. \& ... \& \& # Insert the chart into the a worksheet. \& $worksheet\->insert_chart( \*(AqE2\*(Aq, $chart ); .Ve .PP See \f(CW\*(C`add_chart()\*(C'\fR for details on how to create the Chart object and Excel::Writer::XLSX::Chart for details on how to configure it. See also the \f(CW\*(C`chart_*.pl\*(C'\fR programs in the examples directory of the distro. .PP The \f(CW$x\fR, \f(CW$y\fR, \f(CW$x_scale\fR and \f(CW$y_scale\fR parameters are optional. .PP The parameters \f(CW$x\fR and \f(CW$y\fR can be used to specify an offset from the top left hand corner of the cell specified by \f(CW$row\fR and \f(CW$col\fR. The offset values are in pixels. .PP .Vb 1 \& $worksheet1\->insert_chart( \*(AqE2\*(Aq, $chart, 3, 3 ); .Ve .PP The parameters \f(CW$x_scale\fR and \f(CW$y_scale\fR can be used to scale the inserted chart horizontally and vertically: .PP .Vb 2 \& # Scale the width by 120% and the height by 150% \& $worksheet\->insert_chart( \*(AqE2\*(Aq, $chart, 0, 0, 1.2, 1.5 ); .Ve .ie n .SS "insert_shape( $row, $col, $shape, $x, $y, $x_scale, $y_scale )" .el .SS "insert_shape( \f(CW$row\fP, \f(CW$col\fP, \f(CW$shape\fP, \f(CW$x\fP, \f(CW$y\fP, \f(CW$x_scale\fP, \f(CW$y_scale\fP )" .IX Subsection "insert_shape( $row, $col, $shape, $x, $y, $x_scale, $y_scale )" This method can be used to insert a Shape object into a worksheet. The Shape must be created by the \f(CW\*(C`add_shape()\*(C'\fR Workbook method. .PP .Vb 1 \& my $shape = $workbook\->add_shape( name => \*(AqMy Shape\*(Aq, type => \*(Aqplus\*(Aq ); \& \& # Configure the shape. \& $shape\->set_text(\*(Aqfoo\*(Aq); \& ... \& \& # Insert the shape into the a worksheet. \& $worksheet\->insert_shape( \*(AqE2\*(Aq, $shape ); .Ve .PP See \f(CW\*(C`add_shape()\*(C'\fR for details on how to create the Shape object and Excel::Writer::XLSX::Shape for details on how to configure it. .PP The \f(CW$x\fR, \f(CW$y\fR, \f(CW$x_scale\fR and \f(CW$y_scale\fR parameters are optional. .PP The parameters \f(CW$x\fR and \f(CW$y\fR can be used to specify an offset from the top left hand corner of the cell specified by \f(CW$row\fR and \f(CW$col\fR. The offset values are in pixels. .PP .Vb 1 \& $worksheet1\->insert_shape( \*(AqE2\*(Aq, $chart, 3, 3 ); .Ve .PP The parameters \f(CW$x_scale\fR and \f(CW$y_scale\fR can be used to scale the inserted shape horizontally and vertically: .PP .Vb 2 \& # Scale the width by 120% and the height by 150% \& $worksheet\->insert_shape( \*(AqE2\*(Aq, $shape, 0, 0, 1.2, 1.5 ); .Ve .PP See also the \f(CW\*(C`shape*.pl\*(C'\fR programs in the examples directory of the distro. .ie n .SS "insert_button( $row, $col, { %properties })" .el .SS "insert_button( \f(CW$row\fP, \f(CW$col\fP, { \f(CW%properties\fP })" .IX Subsection "insert_button( $row, $col, { %properties })" The \f(CW\*(C`insert_button()\*(C'\fR method can be used to insert an Excel form button into a worksheet. .PP This method is generally only useful when used in conjunction with the Workbook \f(CW\*(C`add_vba_project()\*(C'\fR method to tie the button to a macro from an embedded \s-1VBA\s0 project: .PP .Vb 3 \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqfile.xlsm\*(Aq ); \& ... \& $workbook\->add_vba_project( \*(Aq./vbaProject.bin\*(Aq ); \& \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq } ); .Ve .PP The properties of the button that can be set are: .PP .Vb 8 \& macro \& caption \& width \& height \& x_scale \& y_scale \& x_offset \& y_offset .Ve .IP "Option: macro" 4 .IX Item "Option: macro" This option is used to set the macro that the button will invoke when the user clicks on it. The macro should be included using the Workbook \f(CW\*(C`add_vba_project()\*(C'\fR method shown above. .Sp .Vb 1 \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq } ); .Ve .Sp The default macro is \f(CW\*(C`ButtonX_Click\*(C'\fR where X is the button number. .IP "Option: caption" 4 .IX Item "Option: caption" This option is used to set the caption on the button. The default is \f(CW\*(C`Button X\*(C'\fR where X is the button number. .Sp .Vb 1 \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq, caption => \*(AqHello\*(Aq } ); .Ve .IP "Option: width" 4 .IX Item "Option: width" This option is used to set the width of the button in pixels. .Sp .Vb 1 \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq, width => 128 } ); .Ve .Sp The default button width is 64 pixels which is the width of a default cell. .IP "Option: height" 4 .IX Item "Option: height" This option is used to set the height of the button in pixels. .Sp .Vb 1 \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq, height => 40 } ); .Ve .Sp The default button height is 20 pixels which is the height of a default cell. .IP "Option: x_scale" 4 .IX Item "Option: x_scale" This option is used to set the width of the button as a factor of the default width. .Sp .Vb 1 \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq, x_scale => 2.0 ); .Ve .IP "Option: y_scale" 4 .IX Item "Option: y_scale" This option is used to set the height of the button as a factor of the default height. .Sp .Vb 1 \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq, y_scale => 2.0 ); .Ve .IP "Option: x_offset" 4 .IX Item "Option: x_offset" This option is used to change the x offset, in pixels, of a button within a cell: .Sp .Vb 1 \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq, x_offset => 2 ); .Ve .IP "Option: y_offset" 4 .IX Item "Option: y_offset" This option is used to change the y offset, in pixels, of a comment within a cell. .PP Note: Button is the only Excel form element that is available in Excel::Writer::XLSX. Form elements represent a lot of work to implement and the underlying \s-1VML\s0 syntax isn't very much fun. .SS "\fIdata_validation()\fP" .IX Subsection "data_validation()" The \f(CW\*(C`data_validation()\*(C'\fR method is used to construct an Excel data validation or to limit the user input to a dropdown list of values. .PP .Vb 6 \& $worksheet\->data_validation(\*(AqB3\*(Aq, \& { \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 100, \& }); \& \& $worksheet\->data_validation(\*(AqB5:B9\*(Aq, \& { \& validate => \*(Aqlist\*(Aq, \& value => [\*(Aqopen\*(Aq, \*(Aqhigh\*(Aq, \*(Aqclose\*(Aq], \& }); .Ve .PP This method contains a lot of parameters and is described in detail in a separate section \*(L"\s-1DATA\s0 \s-1VALIDATION\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". .PP See also the \f(CW\*(C`data_validate.pl\*(C'\fR program in the examples directory of the distro .SS "\fIconditional_formatting()\fP" .IX Subsection "conditional_formatting()" The \f(CW\*(C`conditional_formatting()\*(C'\fR method is used to add formatting to a cell or range of cells based on user defined criteria. .PP .Vb 8 \& $worksheet\->conditional_formatting( \*(AqA1:J10\*(Aq, \& { \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aq>=\*(Aq, \& value => 50, \& format => $format1, \& } \& ); .Ve .PP This method contains a lot of parameters and is described in detail in a separate section \*(L"\s-1CONDITIONAL\s0 \s-1FORMATTING\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". .PP See also the \f(CW\*(C`conditional_format.pl\*(C'\fR program in the examples directory of the distro .SS "\fIadd_sparkline()\fP" .IX Subsection "add_sparkline()" The \f(CW\*(C`add_sparkline()\*(C'\fR worksheet method is used to add sparklines to a cell or a range of cells. .PP .Vb 8 \& $worksheet\->add_sparkline( \& { \& location => \*(AqF2\*(Aq, \& range => \*(AqSheet1!A2:E2\*(Aq, \& type => \*(Aqcolumn\*(Aq, \& style => 12, \& } \& ); .Ve .PP This method contains a lot of parameters and is described in detail in a separate section \*(L"\s-1SPARKLINES\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". .PP See also the \f(CW\*(C`sparklines1.pl\*(C'\fR and \f(CW\*(C`sparklines2.pl\*(C'\fR example programs in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .PP \&\fBNote:\fR Sparklines are a feature of Excel 2010+ only. You can write them to an \s-1XLSX\s0 file that can be read by Excel 2007 but they won't be displayed. .SS "\fIadd_table()\fP" .IX Subsection "add_table()" The \f(CW\*(C`add_table()\*(C'\fR method is used to group a range of cells into an Excel Table. .PP .Vb 1 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { ... } ); .Ve .PP This method contains a lot of parameters and is described in detail in a separate section \*(L"\s-1TABLES\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". .PP See also the \f(CW\*(C`tables.pl\*(C'\fR program in the examples directory of the distro .SS "\fIget_name()\fP" .IX Subsection "get_name()" The \f(CW\*(C`get_name()\*(C'\fR method is used to retrieve the name of a worksheet. For example: .PP .Vb 3 \& for my $sheet ( $workbook\->sheets() ) { \& print $sheet\->get_name(); \& } .Ve .PP For reasons related to the design of Excel::Writer::XLSX and to the internals of Excel there is no \f(CW\*(C`set_name()\*(C'\fR method. The only way to set the worksheet name is via the \f(CW\*(C`add_worksheet()\*(C'\fR method. .SS "\fIactivate()\fP" .IX Subsection "activate()" The \f(CW\*(C`activate()\*(C'\fR method is used to specify which worksheet is initially visible in a multi-sheet workbook: .PP .Vb 3 \& $worksheet1 = $workbook\->add_worksheet( \*(AqTo\*(Aq ); \& $worksheet2 = $workbook\->add_worksheet( \*(Aqthe\*(Aq ); \& $worksheet3 = $workbook\->add_worksheet( \*(Aqwind\*(Aq ); \& \& $worksheet3\->activate(); .Ve .PP This is similar to the Excel \s-1VBA\s0 activate method. More than one worksheet can be selected via the \f(CW\*(C`select()\*(C'\fR method, see below, however only one worksheet can be active. .PP The default active worksheet is the first worksheet. .SS "\fIselect()\fP" .IX Subsection "select()" The \f(CW\*(C`select()\*(C'\fR method is used to indicate that a worksheet is selected in a multi-sheet workbook: .PP .Vb 3 \& $worksheet1\->activate(); \& $worksheet2\->select(); \& $worksheet3\->select(); .Ve .PP A selected worksheet has its tab highlighted. Selecting worksheets is a way of grouping them together so that, for example, several worksheets could be printed in one go. A worksheet that has been activated via the \f(CW\*(C`activate()\*(C'\fR method will also appear as selected. .SS "\fIhide()\fP" .IX Subsection "hide()" The \f(CW\*(C`hide()\*(C'\fR method is used to hide a worksheet: .PP .Vb 1 \& $worksheet2\->hide(); .Ve .PP You may wish to hide a worksheet in order to avoid confusing a user with intermediate data or calculations. .PP A hidden worksheet can not be activated or selected so this method is mutually exclusive with the \f(CW\*(C`activate()\*(C'\fR and \f(CW\*(C`select()\*(C'\fR methods. In addition, since the first worksheet will default to being the active worksheet, you cannot hide the first worksheet without activating another sheet: .PP .Vb 2 \& $worksheet2\->activate(); \& $worksheet1\->hide(); .Ve .SS "\fIset_first_sheet()\fP" .IX Subsection "set_first_sheet()" The \f(CW\*(C`activate()\*(C'\fR method determines which worksheet is initially selected. However, if there are a large number of worksheets the selected worksheet may not appear on the screen. To avoid this you can select which is the leftmost visible worksheet using \f(CW\*(C`set_first_sheet()\*(C'\fR: .PP .Vb 3 \& for ( 1 .. 20 ) { \& $workbook\->add_worksheet; \& } \& \& $worksheet21 = $workbook\->add_worksheet(); \& $worksheet22 = $workbook\->add_worksheet(); \& \& $worksheet21\->set_first_sheet(); \& $worksheet22\->activate(); .Ve .PP This method is not required very often. The default value is the first worksheet. .ie n .SS "protect( $password, \e%options )" .el .SS "protect( \f(CW$password\fP, \e%options )" .IX Subsection "protect( $password, %options )" The \f(CW\*(C`protect()\*(C'\fR method is used to protect a worksheet from modification: .PP .Vb 1 \& $worksheet\->protect(); .Ve .PP The \f(CW\*(C`protect()\*(C'\fR method also has the effect of enabling a cell's \f(CW\*(C`locked\*(C'\fR and \f(CW\*(C`hidden\*(C'\fR properties if they have been set. A \fIlocked\fR cell cannot be edited and this property is on by default for all cells. A \fIhidden\fR cell will display the results of a formula but not the formula itself. .PP See the \f(CW\*(C`protection.pl\*(C'\fR program in the examples directory of the distro for an illustrative example and the \f(CW\*(C`set_locked\*(C'\fR and \f(CW\*(C`set_hidden\*(C'\fR format methods in \*(L"\s-1CELL\s0 \s-1FORMATTING\s0\*(R". .PP You can optionally add a password to the worksheet protection: .PP .Vb 1 \& $worksheet\->protect( \*(Aqdrowssap\*(Aq ); .Ve .PP Passing the empty string \f(CW\*(Aq\*(Aq\fR is the same as turning on protection without a password. .PP Note, the worksheet level password in Excel provides very weak protection. It does not encrypt your data and is very easy to deactivate. Full workbook encryption is not supported by \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR since it requires a completely different file format and would take several man months to implement. .PP You can specify which worksheet elements you wish to protect by passing a hash_ref with any or all of the following keys: .PP .Vb 10 \& # Default shown. \& %options = ( \& objects => 0, \& scenarios => 0, \& format_cells => 0, \& format_columns => 0, \& format_rows => 0, \& insert_columns => 0, \& insert_rows => 0, \& insert_hyperlinks => 0, \& delete_columns => 0, \& delete_rows => 0, \& select_locked_cells => 1, \& sort => 0, \& autofilter => 0, \& pivot_tables => 0, \& select_unlocked_cells => 1, \& ); .Ve .PP The default boolean values are shown above. Individual elements can be protected as follows: .PP .Vb 1 \& $worksheet\->protect( \*(Aqdrowssap\*(Aq, { insert_rows => 1 } ); .Ve .ie n .SS "set_selection( $first_row, $first_col, $last_row, $last_col )" .el .SS "set_selection( \f(CW$first_row\fP, \f(CW$first_col\fP, \f(CW$last_row\fP, \f(CW$last_col\fP )" .IX Subsection "set_selection( $first_row, $first_col, $last_row, $last_col )" This method can be used to specify which cell or cells are selected in a worksheet. The most common requirement is to select a single cell, in which case \f(CW$last_row\fR and \f(CW$last_col\fR can be omitted. The active cell within a selected range is determined by the order in which \f(CW$first\fR and \f(CW$last\fR are specified. It is also possible to specify a cell or a range using A1 notation. See the note about \*(L"Cell notation\*(R". .PP Examples: .PP .Vb 6 \& $worksheet1\->set_selection( 3, 3 ); # 1. Cell D4. \& $worksheet2\->set_selection( 3, 3, 6, 6 ); # 2. Cells D4 to G7. \& $worksheet3\->set_selection( 6, 6, 3, 3 ); # 3. Cells G7 to D4. \& $worksheet4\->set_selection( \*(AqD4\*(Aq ); # Same as 1. \& $worksheet5\->set_selection( \*(AqD4:G7\*(Aq ); # Same as 2. \& $worksheet6\->set_selection( \*(AqG7:D4\*(Aq ); # Same as 3. .Ve .PP The default cell selections is (0, 0), 'A1'. .ie n .SS "set_row( $row, $height, $format, $hidden, $level, $collapsed )" .el .SS "set_row( \f(CW$row\fP, \f(CW$height\fP, \f(CW$format\fP, \f(CW$hidden\fP, \f(CW$level\fP, \f(CW$collapsed\fP )" .IX Subsection "set_row( $row, $height, $format, $hidden, $level, $collapsed )" This method can be used to change the default properties of a row. All parameters apart from \f(CW$row\fR are optional. .PP The most common use for this method is to change the height of a row: .PP .Vb 1 \& $worksheet\->set_row( 0, 20 ); # Row 1 height set to 20 .Ve .PP If you wish to set the format without changing the height you can pass \f(CW\*(C`undef\*(C'\fR as the height parameter: .PP .Vb 1 \& $worksheet\->set_row( 0, undef, $format ); .Ve .PP The \f(CW$format\fR parameter will be applied to any cells in the row that don't have a format. For example .PP .Vb 3 \& $worksheet\->set_row( 0, undef, $format1 ); # Set the format for row 1 \& $worksheet\->write( \*(AqA1\*(Aq, \*(AqHello\*(Aq ); # Defaults to $format1 \& $worksheet\->write( \*(AqB1\*(Aq, \*(AqHello\*(Aq, $format2 ); # Keeps $format2 .Ve .PP If you wish to define a row format in this way you should call the method before any calls to \f(CW\*(C`write()\*(C'\fR. Calling it afterwards will overwrite any format that was previously specified. .PP The \f(CW$hidden\fR parameter should be set to 1 if you wish to hide a row. This can be used, for example, to hide intermediary steps in a complicated calculation: .PP .Vb 2 \& $worksheet\->set_row( 0, 20, $format, 1 ); \& $worksheet\->set_row( 1, undef, undef, 1 ); .Ve .PP The \f(CW$level\fR parameter is used to set the outline level of the row. Outlines are described in \*(L"\s-1OUTLINES\s0 \s-1AND\s0 \s-1GROUPING\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". Adjacent rows with the same outline level are grouped together into a single outline. .PP The following example sets an outline level of 1 for rows 1 and 2 (zero-indexed): .PP .Vb 2 \& $worksheet\->set_row( 1, undef, undef, 0, 1 ); \& $worksheet\->set_row( 2, undef, undef, 0, 1 ); .Ve .PP The \f(CW$hidden\fR parameter can also be used to hide collapsed outlined rows when used in conjunction with the \f(CW$level\fR parameter. .PP .Vb 2 \& $worksheet\->set_row( 1, undef, undef, 1, 1 ); \& $worksheet\->set_row( 2, undef, undef, 1, 1 ); .Ve .PP For collapsed outlines you should also indicate which row has the collapsed \f(CW\*(C`+\*(C'\fR symbol using the optional \f(CW$collapsed\fR parameter. .PP .Vb 1 \& $worksheet\->set_row( 3, undef, undef, 0, 0, 1 ); .Ve .PP For a more complete example see the \f(CW\*(C`outline.pl\*(C'\fR and \f(CW\*(C`outline_collapsed.pl\*(C'\fR programs in the examples directory of the distro. .PP Excel allows up to 7 outline levels. Therefore the \f(CW$level\fR parameter should be in the range \f(CW\*(C`0 <= $level <= 7\*(C'\fR. .ie n .SS "set_column( $first_col, $last_col, $width, $format, $hidden, $level, $collapsed )" .el .SS "set_column( \f(CW$first_col\fP, \f(CW$last_col\fP, \f(CW$width\fP, \f(CW$format\fP, \f(CW$hidden\fP, \f(CW$level\fP, \f(CW$collapsed\fP )" .IX Subsection "set_column( $first_col, $last_col, $width, $format, $hidden, $level, $collapsed )" This method can be used to change the default properties of a single column or a range of columns. All parameters apart from \f(CW$first_col\fR and \f(CW$last_col\fR are optional. .PP If \f(CW\*(C`set_column()\*(C'\fR is applied to a single column the value of \f(CW$first_col\fR and \f(CW$last_col\fR should be the same. In the case where \f(CW$last_col\fR is zero it is set to the same value as \f(CW$first_col\fR. .PP It is also possible, and generally clearer, to specify a column range using the form of A1 notation used for columns. See the note about \*(L"Cell notation\*(R". .PP Examples: .PP .Vb 4 \& $worksheet\->set_column( 0, 0, 20 ); # Column A width set to 20 \& $worksheet\->set_column( 1, 3, 30 ); # Columns B\-D width set to 30 \& $worksheet\->set_column( \*(AqE:E\*(Aq, 20 ); # Column E width set to 20 \& $worksheet\->set_column( \*(AqF:H\*(Aq, 30 ); # Columns F\-H width set to 30 .Ve .PP The width corresponds to the column width value that is specified in Excel. It is approximately equal to the length of a string in the default font of Calibri 11. Unfortunately, there is no way to specify \*(L"AutoFit\*(R" for a column in the Excel file format. This feature is only available at runtime from within Excel. .PP As usual the \f(CW$format\fR parameter is optional, for additional information, see \*(L"\s-1CELL\s0 \s-1FORMATTING\s0\*(R". If you wish to set the format without changing the width you can pass \f(CW\*(C`undef\*(C'\fR as the width parameter: .PP .Vb 1 \& $worksheet\->set_column( 0, 0, undef, $format ); .Ve .PP The \f(CW$format\fR parameter will be applied to any cells in the column that don't have a format. For example .PP .Vb 3 \& $worksheet\->set_column( \*(AqA:A\*(Aq, undef, $format1 ); # Set format for col 1 \& $worksheet\->write( \*(AqA1\*(Aq, \*(AqHello\*(Aq ); # Defaults to $format1 \& $worksheet\->write( \*(AqA2\*(Aq, \*(AqHello\*(Aq, $format2 ); # Keeps $format2 .Ve .PP If you wish to define a column format in this way you should call the method before any calls to \f(CW\*(C`write()\*(C'\fR. If you call it afterwards it won't have any effect. .PP A default row format takes precedence over a default column format .PP .Vb 4 \& $worksheet\->set_row( 0, undef, $format1 ); # Set format for row 1 \& $worksheet\->set_column( \*(AqA:A\*(Aq, undef, $format2 ); # Set format for col 1 \& $worksheet\->write( \*(AqA1\*(Aq, \*(AqHello\*(Aq ); # Defaults to $format1 \& $worksheet\->write( \*(AqA2\*(Aq, \*(AqHello\*(Aq ); # Defaults to $format2 .Ve .PP The \f(CW$hidden\fR parameter should be set to 1 if you wish to hide a column. This can be used, for example, to hide intermediary steps in a complicated calculation: .PP .Vb 2 \& $worksheet\->set_column( \*(AqD:D\*(Aq, 20, $format, 1 ); \& $worksheet\->set_column( \*(AqE:E\*(Aq, undef, undef, 1 ); .Ve .PP The \f(CW$level\fR parameter is used to set the outline level of the column. Outlines are described in \*(L"\s-1OUTLINES\s0 \s-1AND\s0 \s-1GROUPING\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". Adjacent columns with the same outline level are grouped together into a single outline. .PP The following example sets an outline level of 1 for columns B to G: .PP .Vb 1 \& $worksheet\->set_column( \*(AqB:G\*(Aq, undef, undef, 0, 1 ); .Ve .PP The \f(CW$hidden\fR parameter can also be used to hide collapsed outlined columns when used in conjunction with the \f(CW$level\fR parameter. .PP .Vb 1 \& $worksheet\->set_column( \*(AqB:G\*(Aq, undef, undef, 1, 1 ); .Ve .PP For collapsed outlines you should also indicate which row has the collapsed \f(CW\*(C`+\*(C'\fR symbol using the optional \f(CW$collapsed\fR parameter. .PP .Vb 1 \& $worksheet\->set_column( \*(AqH:H\*(Aq, undef, undef, 0, 0, 1 ); .Ve .PP For a more complete example see the \f(CW\*(C`outline.pl\*(C'\fR and \f(CW\*(C`outline_collapsed.pl\*(C'\fR programs in the examples directory of the distro. .PP Excel allows up to 7 outline levels. Therefore the \f(CW$level\fR parameter should be in the range \f(CW\*(C`0 <= $level <= 7\*(C'\fR. .ie n .SS "set_default_row( $height, $hide_unused_rows )" .el .SS "set_default_row( \f(CW$height\fP, \f(CW$hide_unused_rows\fP )" .IX Subsection "set_default_row( $height, $hide_unused_rows )" The \f(CW\*(C`set_default_row()\*(C'\fR method is used to set the limited number of default row properties allowed by Excel. These are the default height and the option to hide unused rows. .PP .Vb 1 \& $worksheet\->set_default_row( 24 ); # Set the default row height to 24. .Ve .PP The option to hide unused rows is used by Excel as an optimisation so that the user can hide a large number of rows without generating a very large file with an entry for each hidden row. .PP .Vb 1 \& $worksheet\->set_default_row( undef, 1 ); .Ve .PP See the \f(CW\*(C`hide_row_col.pl\*(C'\fR example program. .ie n .SS "outline_settings( $visible, $symbols_below, $symbols_right, $auto_style )" .el .SS "outline_settings( \f(CW$visible\fP, \f(CW$symbols_below\fP, \f(CW$symbols_right\fP, \f(CW$auto_style\fP )" .IX Subsection "outline_settings( $visible, $symbols_below, $symbols_right, $auto_style )" The \f(CW\*(C`outline_settings()\*(C'\fR method is used to control the appearance of outlines in Excel. Outlines are described in \*(L"\s-1OUTLINES\s0 \s-1AND\s0 \s-1GROUPING\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". .PP The \f(CW$visible\fR parameter is used to control whether or not outlines are visible. Setting this parameter to 0 will cause all outlines on the worksheet to be hidden. They can be unhidden in Excel by means of the \*(L"Show Outline Symbols\*(R" command button. The default setting is 1 for visible outlines. .PP .Vb 1 \& $worksheet\->outline_settings( 0 ); .Ve .PP The \f(CW$symbols_below\fR parameter is used to control whether the row outline symbol will appear above or below the outline level bar. The default setting is 1 for symbols to appear below the outline level bar. .PP The \f(CW$symbols_right\fR parameter is used to control whether the column outline symbol will appear to the left or the right of the outline level bar. The default setting is 1 for symbols to appear to the right of the outline level bar. .PP The \f(CW$auto_style\fR parameter is used to control whether the automatic outline generator in Excel uses automatic styles when creating an outline. This has no effect on a file generated by \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR but it does have an effect on how the worksheet behaves after it is created. The default setting is 0 for \*(L"Automatic Styles\*(R" to be turned off. .PP The default settings for all of these parameters correspond to Excel's default parameters. .PP The worksheet parameters controlled by \f(CW\*(C`outline_settings()\*(C'\fR are rarely used. .ie n .SS "freeze_panes( $row, $col, $top_row, $left_col )" .el .SS "freeze_panes( \f(CW$row\fP, \f(CW$col\fP, \f(CW$top_row\fP, \f(CW$left_col\fP )" .IX Subsection "freeze_panes( $row, $col, $top_row, $left_col )" This method can be used to divide a worksheet into horizontal or vertical regions known as panes and to also \*(L"freeze\*(R" these panes so that the splitter bars are not visible. This is the same as the \f(CW\*(C`Window\->Freeze Panes\*(C'\fR menu command in Excel .PP The parameters \f(CW$row\fR and \f(CW$col\fR are used to specify the location of the split. It should be noted that the split is specified at the top or left of a cell and that the method uses zero based indexing. Therefore to freeze the first row of a worksheet it is necessary to specify the split at row 2 (which is 1 as the zero-based index). This might lead you to think that you are using a 1 based index but this is not the case. .PP You can set one of the \f(CW$row\fR and \f(CW$col\fR parameters as zero if you do not want either a vertical or horizontal split. .PP Examples: .PP .Vb 6 \& $worksheet\->freeze_panes( 1, 0 ); # Freeze the first row \& $worksheet\->freeze_panes( \*(AqA2\*(Aq ); # Same using A1 notation \& $worksheet\->freeze_panes( 0, 1 ); # Freeze the first column \& $worksheet\->freeze_panes( \*(AqB1\*(Aq ); # Same using A1 notation \& $worksheet\->freeze_panes( 1, 2 ); # Freeze first row and first 2 columns \& $worksheet\->freeze_panes( \*(AqC2\*(Aq ); # Same using A1 notation .Ve .PP The parameters \f(CW$top_row\fR and \f(CW$left_col\fR are optional. They are used to specify the top-most or left-most visible row or column in the scrolling region of the panes. For example to freeze the first row and to have the scrolling region begin at row twenty: .PP .Vb 1 \& $worksheet\->freeze_panes( 1, 0, 20, 0 ); .Ve .PP You cannot use A1 notation for the \f(CW$top_row\fR and \f(CW$left_col\fR parameters. .PP See also the \f(CW\*(C`panes.pl\*(C'\fR program in the \f(CW\*(C`examples\*(C'\fR directory of the distribution. .ie n .SS "split_panes( $y, $x, $top_row, $left_col )" .el .SS "split_panes( \f(CW$y\fP, \f(CW$x\fP, \f(CW$top_row\fP, \f(CW$left_col\fP )" .IX Subsection "split_panes( $y, $x, $top_row, $left_col )" This method can be used to divide a worksheet into horizontal or vertical regions known as panes. This method is different from the \f(CW\*(C`freeze_panes()\*(C'\fR method in that the splits between the panes will be visible to the user and each pane will have its own scroll bars. .PP The parameters \f(CW$y\fR and \f(CW$x\fR are used to specify the vertical and horizontal position of the split. The units for \f(CW$y\fR and \f(CW$x\fR are the same as those used by Excel to specify row height and column width. However, the vertical and horizontal units are different from each other. Therefore you must specify the \f(CW$y\fR and \f(CW$x\fR parameters in terms of the row heights and column widths that you have set or the default values which are \f(CW15\fR for a row and \f(CW8.43\fR for a column. .PP You can set one of the \f(CW$y\fR and \f(CW$x\fR parameters as zero if you do not want either a vertical or horizontal split. The parameters \f(CW$top_row\fR and \f(CW$left_col\fR are optional. They are used to specify the top-most or left-most visible row or column in the bottom-right pane. .PP Example: .PP .Vb 3 \& $worksheet\->split_panes( 15, 0, ); # First row \& $worksheet\->split_panes( 0, 8.43 ); # First column \& $worksheet\->split_panes( 15, 8.43 ); # First row and column .Ve .PP You cannot use A1 notation with this method. .PP See also the \f(CW\*(C`freeze_panes()\*(C'\fR method and the \f(CW\*(C`panes.pl\*(C'\fR program in the \f(CW\*(C`examples\*(C'\fR directory of the distribution. .ie n .SS "merge_range( $first_row, $first_col, $last_row, $last_col, $token, $format )" .el .SS "merge_range( \f(CW$first_row\fP, \f(CW$first_col\fP, \f(CW$last_row\fP, \f(CW$last_col\fP, \f(CW$token\fP, \f(CW$format\fP )" .IX Subsection "merge_range( $first_row, $first_col, $last_row, $last_col, $token, $format )" The \f(CW\*(C`merge_range()\*(C'\fR method allows you to merge cells that contain other types of alignment in addition to the merging: .PP .Vb 5 \& my $format = $workbook\->add_format( \& border => 6, \& valign => \*(Aqvcenter\*(Aq, \& align => \*(Aqcenter\*(Aq, \& ); \& \& $worksheet\->merge_range( \*(AqB3:D4\*(Aq, \*(AqVertical and horizontal\*(Aq, $format ); .Ve .PP \&\f(CW\*(C`merge_range()\*(C'\fR writes its \f(CW$token\fR argument using the worksheet \f(CW\*(C`write()\*(C'\fR method. Therefore it will handle numbers, strings, formulas or urls as required. If you need to specify the required \f(CW\*(C`write_*()\*(C'\fR method use the \f(CW\*(C`merge_range_type()\*(C'\fR method, see below. .PP The full possibilities of this method are shown in the \f(CW\*(C`merge3.pl\*(C'\fR to \f(CW\*(C`merge6.pl\*(C'\fR programs in the \f(CW\*(C`examples\*(C'\fR directory of the distribution. .ie n .SS "merge_range_type( $type, $first_row, $first_col, $last_row, $last_col, ... )" .el .SS "merge_range_type( \f(CW$type\fP, \f(CW$first_row\fP, \f(CW$first_col\fP, \f(CW$last_row\fP, \f(CW$last_col\fP, ... )" .IX Subsection "merge_range_type( $type, $first_row, $first_col, $last_row, $last_col, ... )" The \f(CW\*(C`merge_range()\*(C'\fR method, see above, uses \f(CW\*(C`write()\*(C'\fR to insert the required data into to a merged range. However, there may be times where this isn't what you require so as an alternative the \f(CW\*(C`merge_range_type ()\*(C'\fR method allows you to specify the type of data you wish to write. For example: .PP .Vb 3 \& $worksheet\->merge_range_type( \*(Aqnumber\*(Aq, \*(AqB2:C2\*(Aq, 123, $format1 ); \& $worksheet\->merge_range_type( \*(Aqstring\*(Aq, \*(AqB4:C4\*(Aq, \*(Aqfoo\*(Aq, $format2 ); \& $worksheet\->merge_range_type( \*(Aqformula\*(Aq, \*(AqB6:C6\*(Aq, \*(Aq=1+2\*(Aq, $format3 ); .Ve .PP The \f(CW$type\fR must be one of the following, which corresponds to a \f(CW\*(C`write_*()\*(C'\fR method: .PP .Vb 8 \& \*(Aqnumber\*(Aq \& \*(Aqstring\*(Aq \& \*(Aqformula\*(Aq \& \*(Aqarray_formula\*(Aq \& \*(Aqblank\*(Aq \& \*(Aqrich_string\*(Aq \& \*(Aqdate_time\*(Aq \& \*(Aqurl\*(Aq .Ve .PP Any arguments after the range should be whatever the appropriate method accepts: .PP .Vb 2 \& $worksheet\->merge_range_type( \*(Aqrich_string\*(Aq, \*(AqB8:C8\*(Aq, \& \*(AqThis is \*(Aq, $bold, \*(Aqbold\*(Aq, $format4 ); .Ve .PP Note, you must always pass a \f(CW$format\fR object as an argument, even if it is a default format. .ie n .SS "set_zoom( $scale )" .el .SS "set_zoom( \f(CW$scale\fP )" .IX Subsection "set_zoom( $scale )" Set the worksheet zoom factor in the range \f(CW\*(C`10 <= $scale <= 400\*(C'\fR: .PP .Vb 4 \& $worksheet1\->set_zoom( 50 ); \& $worksheet2\->set_zoom( 75 ); \& $worksheet3\->set_zoom( 300 ); \& $worksheet4\->set_zoom( 400 ); .Ve .PP The default zoom factor is 100. You cannot zoom to \*(L"Selection\*(R" because it is calculated by Excel at run-time. .PP Note, \f(CW\*(C`set_zoom()\*(C'\fR does not affect the scale of the printed page. For that you should use \f(CW\*(C`set_print_scale()\*(C'\fR. .SS "\fIright_to_left()\fP" .IX Subsection "right_to_left()" The \f(CW\*(C`right_to_left()\*(C'\fR method is used to change the default direction of the worksheet from left-to-right, with the A1 cell in the top left, to right-to-left, with the A1 cell in the top right. .PP .Vb 1 \& $worksheet\->right_to_left(); .Ve .PP This is useful when creating Arabic, Hebrew or other near or far eastern worksheets that use right-to-left as the default direction. .SS "\fIhide_zero()\fP" .IX Subsection "hide_zero()" The \f(CW\*(C`hide_zero()\*(C'\fR method is used to hide any zero values that appear in cells. .PP .Vb 1 \& $worksheet\->hide_zero(); .Ve .PP In Excel this option is found under Tools\->Options\->View. .SS "\fIset_tab_color()\fP" .IX Subsection "set_tab_color()" The \f(CW\*(C`set_tab_color()\*(C'\fR method is used to change the colour of the worksheet tab. You can use one of the standard colour names provided by the Format object or a colour index. See \*(L"\s-1COLOURS\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R" and the \f(CW\*(C`set_custom_color()\*(C'\fR method. .PP .Vb 2 \& $worksheet1\->set_tab_color( \*(Aqred\*(Aq ); \& $worksheet2\->set_tab_color( 0x0C ); .Ve .PP See the \f(CW\*(C`tab_colors.pl\*(C'\fR program in the examples directory of the distro. .ie n .SS "autofilter( $first_row, $first_col, $last_row, $last_col )" .el .SS "autofilter( \f(CW$first_row\fP, \f(CW$first_col\fP, \f(CW$last_row\fP, \f(CW$last_col\fP )" .IX Subsection "autofilter( $first_row, $first_col, $last_row, $last_col )" This method allows an autofilter to be added to a worksheet. An autofilter is a way of adding drop down lists to the headers of a 2D range of worksheet data. This allows users to filter the data based on simple criteria so that some data is shown and some is hidden. .PP To add an autofilter to a worksheet: .PP .Vb 2 \& $worksheet\->autofilter( 0, 0, 10, 3 ); \& $worksheet\->autofilter( \*(AqA1:D11\*(Aq ); # Same as above in A1 notation. .Ve .PP Filter conditions can be applied using the \f(CW\*(C`filter_column()\*(C'\fR or \f(CW\*(C`filter_column_list()\*(C'\fR method. .PP See the \f(CW\*(C`autofilter.pl\*(C'\fR program in the examples directory of the distro for a more detailed example. .ie n .SS "filter_column( $column, $expression )" .el .SS "filter_column( \f(CW$column\fP, \f(CW$expression\fP )" .IX Subsection "filter_column( $column, $expression )" The \f(CW\*(C`filter_column\*(C'\fR method can be used to filter columns in a autofilter range based on simple conditions. .PP \&\fB\s-1NOTE:\s0\fR It isn't sufficient to just specify the filter condition. You must also hide any rows that don't match the filter condition. Rows are hidden using the \f(CW\*(C`set_row()\*(C'\fR \f(CW\*(C`visible\*(C'\fR parameter. \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR cannot do this automatically since it isn't part of the file format. See the \f(CW\*(C`autofilter.pl\*(C'\fR program in the examples directory of the distro for an example. .PP The conditions for the filter are specified using simple expressions: .PP .Vb 2 \& $worksheet\->filter_column( \*(AqA\*(Aq, \*(Aqx > 2000\*(Aq ); \& $worksheet\->filter_column( \*(AqB\*(Aq, \*(Aqx > 2000 and x < 5000\*(Aq ); .Ve .PP The \f(CW$column\fR parameter can either be a zero indexed column number or a string column name. .PP The following operators are available: .PP .Vb 7 \& Operator Synonyms \& == = eq =~ \& != <> ne != \& > \& < \& >= \& <= \& \& and && \& or || .Ve .PP The operator synonyms are just syntactic sugar to make you more comfortable using the expressions. It is important to remember that the expressions will be interpreted by Excel and not by perl. .PP An expression can comprise a single statement or two statements separated by the \f(CW\*(C`and\*(C'\fR and \f(CW\*(C`or\*(C'\fR operators. For example: .PP .Vb 5 \& \*(Aqx < 2000\*(Aq \& \*(Aqx > 2000\*(Aq \& \*(Aqx == 2000\*(Aq \& \*(Aqx > 2000 and x < 5000\*(Aq \& \*(Aqx == 2000 or x == 5000\*(Aq .Ve .PP Filtering of blank or non-blank data can be achieved by using a value of \f(CW\*(C`Blanks\*(C'\fR or \f(CW\*(C`NonBlanks\*(C'\fR in the expression: .PP .Vb 2 \& \*(Aqx == Blanks\*(Aq \& \*(Aqx == NonBlanks\*(Aq .Ve .PP Excel also allows some simple string matching operations: .PP .Vb 6 \& \*(Aqx =~ b*\*(Aq # begins with b \& \*(Aqx !~ b*\*(Aq # doesn\*(Aqt begin with b \& \*(Aqx =~ *b\*(Aq # ends with b \& \*(Aqx !~ *b\*(Aq # doesn\*(Aqt end with b \& \*(Aqx =~ *b*\*(Aq # contains b \& \*(Aqx !~ *b*\*(Aq # doesn\*(Aqt contains b .Ve .PP You can also use \f(CW\*(C`*\*(C'\fR to match any character or number and \f(CW\*(C`?\*(C'\fR to match any single character or number. No other regular expression quantifier is supported by Excel's filters. Excel's regular expression characters can be escaped using \f(CW\*(C`~\*(C'\fR. .PP The placeholder variable \f(CW\*(C`x\*(C'\fR in the above examples can be replaced by any simple string. The actual placeholder name is ignored internally so the following are all equivalent: .PP .Vb 3 \& \*(Aqx < 2000\*(Aq \& \*(Aqcol < 2000\*(Aq \& \*(AqPrice < 2000\*(Aq .Ve .PP Also, note that a filter condition can only be applied to a column in a range specified by the \f(CW\*(C`autofilter()\*(C'\fR Worksheet method. .PP See the \f(CW\*(C`autofilter.pl\*(C'\fR program in the examples directory of the distro for a more detailed example. .PP \&\fBNote\fR Spreadsheet::WriteExcel supports Top 10 style filters. These aren't currently supported by Excel::Writer::XLSX but may be added later. .ie n .SS "filter_column_list( $column, @matches )" .el .SS "filter_column_list( \f(CW$column\fP, \f(CW@matches\fP )" .IX Subsection "filter_column_list( $column, @matches )" Prior to Excel 2007 it was only possible to have either 1 or 2 filter conditions such as the ones shown above in the \f(CW\*(C`filter_column\*(C'\fR method. .PP Excel 2007 introduced a new list style filter where it is possible to specify 1 or more 'or' style criteria. For example if your column contained data for the first six months the initial data would be displayed as all selected as shown on the left. Then if you selected 'March', 'April' and 'May' they would be displayed as shown on the right. .PP .Vb 1 \& No criteria selected Some criteria selected. \& \& [/] (Select all) [X] (Select all) \& [/] January [ ] January \& [/] February [ ] February \& [/] March [/] March \& [/] April [/] April \& [/] May [/] May \& [/] June [ ] June .Ve .PP The \f(CW\*(C`filter_column_list()\*(C'\fR method can be used to represent these types of filters: .PP .Vb 1 \& $worksheet\->filter_column_list( \*(AqA\*(Aq, \*(AqMarch\*(Aq, \*(AqApril\*(Aq, \*(AqMay\*(Aq ); .Ve .PP The \f(CW$column\fR parameter can either be a zero indexed column number or a string column name. .PP One or more criteria can be selected: .PP .Vb 2 \& $worksheet\->filter_column_list( 0, \*(AqMarch\*(Aq ); \& $worksheet\->filter_column_list( 1, 100, 110, 120, 130 ); .Ve .PP \&\fB\s-1NOTE:\s0\fR It isn't sufficient to just specify the filter condition. You must also hide any rows that don't match the filter condition. Rows are hidden using the \f(CW\*(C`set_row()\*(C'\fR \f(CW\*(C`visible\*(C'\fR parameter. \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR cannot do this automatically since it isn't part of the file format. See the \f(CW\*(C`autofilter.pl\*(C'\fR program in the examples directory of the distro for an example. .ie n .SS "convert_date_time( $date_string )" .el .SS "convert_date_time( \f(CW$date_string\fP )" .IX Subsection "convert_date_time( $date_string )" The \f(CW\*(C`convert_date_time()\*(C'\fR method is used internally by the \f(CW\*(C`write_date_time()\*(C'\fR method to convert date strings to a number that represents an Excel date and time. .PP It is exposed as a public method for utility purposes. .PP The \f(CW$date_string\fR format is detailed in the \f(CW\*(C`write_date_time()\*(C'\fR method. .SS "Worksheet \fIset_vba_name()\fP" .IX Subsection "Worksheet set_vba_name()" The Worksheet \f(CW\*(C`set_vba_name()\*(C'\fR method can be used to set the \s-1VBA\s0 codename for the worksheet (there is a similar method for the workbook \s-1VBA\s0 name). This is sometimes required when a \f(CW\*(C`vbaProject\*(C'\fR macro included via \f(CW\*(C`add_vba_project()\*(C'\fR refers to the worksheet. The default Excel \s-1VBA\s0 name of \f(CW\*(C`Sheet1\*(C'\fR, etc., is used if a user defined name isn't specified. .PP See also \*(L"\s-1WORKING\s0 \s-1WITH\s0 \s-1VBA\s0 \s-1MACROS\s0\*(R". .SH "PAGE SET-UP METHODS" .IX Header "PAGE SET-UP METHODS" Page set-up methods affect the way that a worksheet looks when it is printed. They control features such as page headers and footers and margins. These methods are really just standard worksheet methods. They are documented here in a separate section for the sake of clarity. .PP The following methods are available for page set-up: .PP .Vb 10 \& set_landscape() \& set_portrait() \& set_page_view() \& set_paper() \& center_horizontally() \& center_vertically() \& set_margins() \& set_header() \& set_footer() \& repeat_rows() \& repeat_columns() \& hide_gridlines() \& print_row_col_headers() \& print_area() \& print_across() \& fit_to_pages() \& set_start_page() \& set_print_scale() \& print_black_and_white() \& set_h_pagebreaks() \& set_v_pagebreaks() .Ve .PP A common requirement when working with Excel::Writer::XLSX is to apply the same page set-up features to all of the worksheets in a workbook. To do this you can use the \f(CW\*(C`sheets()\*(C'\fR method of the \f(CW\*(C`workbook\*(C'\fR class to access the array of worksheets in a workbook: .PP .Vb 3 \& for $worksheet ( $workbook\->sheets() ) { \& $worksheet\->set_landscape(); \& } .Ve .SS "\fIset_landscape()\fP" .IX Subsection "set_landscape()" This method is used to set the orientation of a worksheet's printed page to landscape: .PP .Vb 1 \& $worksheet\->set_landscape(); # Landscape mode .Ve .SS "\fIset_portrait()\fP" .IX Subsection "set_portrait()" This method is used to set the orientation of a worksheet's printed page to portrait. The default worksheet orientation is portrait, so you won't generally need to call this method. .PP .Vb 1 \& $worksheet\->set_portrait(); # Portrait mode .Ve .SS "\fIset_page_view()\fP" .IX Subsection "set_page_view()" This method is used to display the worksheet in \*(L"Page View/Layout\*(R" mode. .PP .Vb 1 \& $worksheet\->set_page_view(); .Ve .ie n .SS "set_paper( $index )" .el .SS "set_paper( \f(CW$index\fP )" .IX Subsection "set_paper( $index )" This method is used to set the paper format for the printed output of a worksheet. The following paper styles are available: .PP .Vb 10 \& Index Paper format Paper size \& ===== ============ ========== \& 0 Printer default \- \& 1 Letter 8 1/2 x 11 in \& 2 Letter Small 8 1/2 x 11 in \& 3 Tabloid 11 x 17 in \& 4 Ledger 17 x 11 in \& 5 Legal 8 1/2 x 14 in \& 6 Statement 5 1/2 x 8 1/2 in \& 7 Executive 7 1/4 x 10 1/2 in \& 8 A3 297 x 420 mm \& 9 A4 210 x 297 mm \& 10 A4 Small 210 x 297 mm \& 11 A5 148 x 210 mm \& 12 B4 250 x 354 mm \& 13 B5 182 x 257 mm \& 14 Folio 8 1/2 x 13 in \& 15 Quarto 215 x 275 mm \& 16 \- 10x14 in \& 17 \- 11x17 in \& 18 Note 8 1/2 x 11 in \& 19 Envelope 9 3 7/8 x 8 7/8 \& 20 Envelope 10 4 1/8 x 9 1/2 \& 21 Envelope 11 4 1/2 x 10 3/8 \& 22 Envelope 12 4 3/4 x 11 \& 23 Envelope 14 5 x 11 1/2 \& 24 C size sheet \- \& 25 D size sheet \- \& 26 E size sheet \- \& 27 Envelope DL 110 x 220 mm \& 28 Envelope C3 324 x 458 mm \& 29 Envelope C4 229 x 324 mm \& 30 Envelope C5 162 x 229 mm \& 31 Envelope C6 114 x 162 mm \& 32 Envelope C65 114 x 229 mm \& 33 Envelope B4 250 x 353 mm \& 34 Envelope B5 176 x 250 mm \& 35 Envelope B6 176 x 125 mm \& 36 Envelope 110 x 230 mm \& 37 Monarch 3.875 x 7.5 in \& 38 Envelope 3 5/8 x 6 1/2 in \& 39 Fanfold 14 7/8 x 11 in \& 40 German Std Fanfold 8 1/2 x 12 in \& 41 German Legal Fanfold 8 1/2 x 13 in .Ve .PP Note, it is likely that not all of these paper types will be available to the end user since it will depend on the paper formats that the user's printer supports. Therefore, it is best to stick to standard paper types. .PP .Vb 2 \& $worksheet\->set_paper( 1 ); # US Letter \& $worksheet\->set_paper( 9 ); # A4 .Ve .PP If you do not specify a paper type the worksheet will print using the printer's default paper. .SS "\fIcenter_horizontally()\fP" .IX Subsection "center_horizontally()" Center the worksheet data horizontally between the margins on the printed page: .PP .Vb 1 \& $worksheet\->center_horizontally(); .Ve .SS "\fIcenter_vertically()\fP" .IX Subsection "center_vertically()" Center the worksheet data vertically between the margins on the printed page: .PP .Vb 1 \& $worksheet\->center_vertically(); .Ve .ie n .SS "set_margins( $inches )" .el .SS "set_margins( \f(CW$inches\fP )" .IX Subsection "set_margins( $inches )" There are several methods available for setting the worksheet margins on the printed page: .PP .Vb 7 \& set_margins() # Set all margins to the same value \& set_margins_LR() # Set left and right margins to the same value \& set_margins_TB() # Set top and bottom margins to the same value \& set_margin_left(); # Set left margin \& set_margin_right(); # Set right margin \& set_margin_top(); # Set top margin \& set_margin_bottom(); # Set bottom margin .Ve .PP All of these methods take a distance in inches as a parameter. Note: 1 inch = 25.4mm. \f(CW\*(C`;\-)\*(C'\fR The default left and right margin is 0.7 inch. The default top and bottom margin is 0.75 inch. Note, these defaults are different from the defaults used in the binary file format by Spreadsheet::WriteExcel. .ie n .SS "set_header( $string, $margin )" .el .SS "set_header( \f(CW$string\fP, \f(CW$margin\fP )" .IX Subsection "set_header( $string, $margin )" Headers and footers are generated using a \f(CW$string\fR which is a combination of plain text and control characters. The \f(CW$margin\fR parameter is optional. .PP The available control character are: .PP .Vb 5 \& Control Category Description \& ======= ======== =========== \& &L Justification Left \& &C Center \& &R Right \& \& &P Information Page number \& &N Total number of pages \& &D Date \& &T Time \& &F File name \& &A Worksheet name \& &Z Workbook path \& \& &fontsize Font Font size \& &"font,style" Font name and style \& &U Single underline \& &E Double underline \& &S Strikethrough \& &X Superscript \& &Y Subscript \& \& &[Picture] Images Image placeholder \& &G Same as &[Picture] \& \& && Miscellaneous Literal ampersand & .Ve .PP Text in headers and footers can be justified (aligned) to the left, center and right by prefixing the text with the control characters \f(CW&L\fR, \f(CW&C\fR and \f(CW&R\fR. .PP For example (with \s-1ASCII\s0 art representation of the results): .PP .Vb 1 \& $worksheet\->set_header(\*(Aq&LHello\*(Aq); \& \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | \& | Hello | \& | | \& \& \& $worksheet\->set_header(\*(Aq&CHello\*(Aq); \& \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | \& | Hello | \& | | \& \& \& $worksheet\->set_header(\*(Aq&RHello\*(Aq); \& \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | \& | Hello | \& | | .Ve .PP For simple text, if you do not specify any justification the text will be centred. However, you must prefix the text with \f(CW&C\fR if you specify a font name or any other formatting: .PP .Vb 1 \& $worksheet\->set_header(\*(AqHello\*(Aq); \& \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | \& | Hello | \& | | .Ve .PP You can have text in each of the justification regions: .PP .Vb 1 \& $worksheet\->set_header(\*(Aq&LCiao&CBello&RCielo\*(Aq); \& \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | \& | Ciao Bello Cielo | \& | | .Ve .PP The information control characters act as variables that Excel will update as the workbook or worksheet changes. Times and dates are in the users default format: .PP .Vb 1 \& $worksheet\->set_header(\*(Aq&CPage &P of &N\*(Aq); \& \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | \& | Page 1 of 6 | \& | | \& \& \& $worksheet\->set_header(\*(Aq&CUpdated at &T\*(Aq); \& \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | \& | Updated at 12:30 PM | \& | | .Ve .PP Images can be inserted using the options shown below. Each image must have a placeholder in header string using the \f(CW\*(C`&[Picture]\*(C'\fR or \f(CW&G\fR control characters: .PP .Vb 1 \& $worksheet\->set_header( \*(Aq&L&G\*(Aq, 0.3, { image_left => \*(Aqlogo.jpg\*(Aq }); .Ve .PP You can specify the font size of a section of the text by prefixing it with the control character \f(CW&n\fR where \f(CW\*(C`n\*(C'\fR is the font size: .PP .Vb 2 \& $worksheet1\->set_header( \*(Aq&C&30Hello Big\*(Aq ); \& $worksheet2\->set_header( \*(Aq&C&10Hello Small\*(Aq ); .Ve .PP You can specify the font of a section of the text by prefixing it with the control sequence \f(CW\*(C`&"font,style"\*(C'\fR where \f(CW\*(C`fontname\*(C'\fR is a font name such as \*(L"Courier New\*(R" or \*(L"Times New Roman\*(R" and \f(CW\*(C`style\*(C'\fR is one of the standard Windows font descriptions: \*(L"Regular\*(R", \*(L"Italic\*(R", \*(L"Bold\*(R" or \*(L"Bold Italic\*(R": .PP .Vb 3 \& $worksheet1\->set_header( \*(Aq&C&"Courier New,Italic"Hello\*(Aq ); \& $worksheet2\->set_header( \*(Aq&C&"Courier New,Bold Italic"Hello\*(Aq ); \& $worksheet3\->set_header( \*(Aq&C&"Times New Roman,Regular"Hello\*(Aq ); .Ve .PP It is possible to combine all of these features together to create sophisticated headers and footers. As an aid to setting up complicated headers and footers you can record a page set-up as a macro in Excel and look at the format strings that \s-1VBA\s0 produces. Remember however that \s-1VBA\s0 uses two double quotes \f(CW""\fR to indicate a single double quote. For the last example above the equivalent \s-1VBA\s0 code looks like this: .PP .Vb 3 \& .LeftHeader = "" \& .CenterHeader = "&""Times New Roman,Regular""Hello" \& .RightHeader = "" .Ve .PP To include a single literal ampersand \f(CW\*(C`&\*(C'\fR in a header or footer you should use a double ampersand \f(CW\*(C`&&\*(C'\fR: .PP .Vb 1 \& $worksheet1\->set_header(\*(Aq&CCuriouser && Curiouser \- Attorneys at Law\*(Aq); .Ve .PP As stated above the margin parameter is optional. As with the other margins the value should be in inches. The default header and footer margin is 0.3 inch. Note, the default margin is different from the default used in the binary file format by Spreadsheet::WriteExcel. The header and footer margin size can be set as follows: .PP .Vb 1 \& $worksheet\->set_header( \*(Aq&CHello\*(Aq, 0.75 ); .Ve .PP The header and footer margins are independent of the top and bottom margins. .PP The available optons are: .IP "\(bu" 4 \&\f(CW\*(C`image_left\*(C'\fR The path to the image. Requires a \f(CW&G\fR or \f(CW\*(C`&[Picture]\*(C'\fR placeholder. .IP "\(bu" 4 \&\f(CW\*(C`image_center\*(C'\fR Same as above. .IP "\(bu" 4 \&\f(CW\*(C`image_right\*(C'\fR Same as above. .IP "\(bu" 4 \&\f(CW\*(C`scale_with_doc\*(C'\fR Scale header with document. Defaults to true. .IP "\(bu" 4 \&\f(CW\*(C`align_with_margins\*(C'\fR Align header to margins. Defaults to true. .PP The image options must have an accompanying \f(CW\*(C`&[Picture]\*(C'\fR or \f(CW&G\fR control character in the header string: .PP .Vb 9 \& $worksheet\->set_header( \& \*(Aq&L&[Picture]&C&[Picture]&R&[Picture]\*(Aq, \& undef, # If you don\*(Aqt want to change the margin. \& { \& image_left => \*(Aqred.jpg\*(Aq, \& image_center => \*(Aqblue.jpg\*(Aq, \& image_right => \*(Aqyellow.jpg\*(Aq \& } \& ); .Ve .PP Note, the header or footer string must be less than 255 characters. Strings longer than this will not be written and a warning will be generated. .PP The \f(CW\*(C`set_header()\*(C'\fR method can also handle Unicode strings in \f(CW\*(C`UTF\-8\*(C'\fR format. .PP .Vb 1 \& $worksheet\->set_header( "&C\ex{263a}" ) .Ve .PP See, also the \f(CW\*(C`headers.pl\*(C'\fR program in the \f(CW\*(C`examples\*(C'\fR directory of the distribution. .ie n .SS "set_footer( $string, $margin )" .el .SS "set_footer( \f(CW$string\fP, \f(CW$margin\fP )" .IX Subsection "set_footer( $string, $margin )" The syntax of the \f(CW\*(C`set_footer()\*(C'\fR method is the same as \f(CW\*(C`set_header()\*(C'\fR, see above. .ie n .SS "repeat_rows( $first_row, $last_row )" .el .SS "repeat_rows( \f(CW$first_row\fP, \f(CW$last_row\fP )" .IX Subsection "repeat_rows( $first_row, $last_row )" Set the number of rows to repeat at the top of each printed page. .PP For large Excel documents it is often desirable to have the first row or rows of the worksheet print out at the top of each page. This can be achieved by using the \f(CW\*(C`repeat_rows()\*(C'\fR method. The parameters \f(CW$first_row\fR and \f(CW$last_row\fR are zero based. The \f(CW$last_row\fR parameter is optional if you only wish to specify one row: .PP .Vb 2 \& $worksheet1\->repeat_rows( 0 ); # Repeat the first row \& $worksheet2\->repeat_rows( 0, 1 ); # Repeat the first two rows .Ve .ie n .SS "repeat_columns( $first_col, $last_col )" .el .SS "repeat_columns( \f(CW$first_col\fP, \f(CW$last_col\fP )" .IX Subsection "repeat_columns( $first_col, $last_col )" Set the columns to repeat at the left hand side of each printed page. .PP For large Excel documents it is often desirable to have the first column or columns of the worksheet print out at the left hand side of each page. This can be achieved by using the \f(CW\*(C`repeat_columns()\*(C'\fR method. The parameters \f(CW$first_column\fR and \f(CW$last_column\fR are zero based. The \f(CW$last_column\fR parameter is optional if you only wish to specify one column. You can also specify the columns using A1 column notation, see the note about \*(L"Cell notation\*(R". .PP .Vb 4 \& $worksheet1\->repeat_columns( 0 ); # Repeat the first column \& $worksheet2\->repeat_columns( 0, 1 ); # Repeat the first two columns \& $worksheet3\->repeat_columns( \*(AqA:A\*(Aq ); # Repeat the first column \& $worksheet4\->repeat_columns( \*(AqA:B\*(Aq ); # Repeat the first two columns .Ve .ie n .SS "hide_gridlines( $option )" .el .SS "hide_gridlines( \f(CW$option\fP )" .IX Subsection "hide_gridlines( $option )" This method is used to hide the gridlines on the screen and printed page. Gridlines are the lines that divide the cells on a worksheet. Screen and printed gridlines are turned on by default in an Excel worksheet. If you have defined your own cell borders you may wish to hide the default gridlines. .PP .Vb 1 \& $worksheet\->hide_gridlines(); .Ve .PP The following values of \f(CW$option\fR are valid: .PP .Vb 3 \& 0 : Don\*(Aqt hide gridlines \& 1 : Hide printed gridlines only \& 2 : Hide screen and printed gridlines .Ve .PP If you don't supply an argument or use \f(CW\*(C`undef\*(C'\fR the default option is 1, i.e. only the printed gridlines are hidden. .SS "\fIprint_row_col_headers()\fP" .IX Subsection "print_row_col_headers()" Set the option to print the row and column headers on the printed page. .PP An Excel worksheet looks something like the following; .PP .Vb 8 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | | A | B | C | D | ... \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | 1 | | | | | ... \& | 2 | | | | | ... \& | 3 | | | | | ... \& | 4 | | | | | ... \& |...| ... | ... | ... | ... | ... .Ve .PP The headers are the letters and numbers at the top and the left of the worksheet. Since these headers serve mainly as a indication of position on the worksheet they generally do not appear on the printed page. If you wish to have them printed you can use the \f(CW\*(C`print_row_col_headers()\*(C'\fR method : .PP .Vb 1 \& $worksheet\->print_row_col_headers(); .Ve .PP Do not confuse these headers with page headers as described in the \f(CW\*(C`set_header()\*(C'\fR section above. .ie n .SS "print_area( $first_row, $first_col, $last_row, $last_col )" .el .SS "print_area( \f(CW$first_row\fP, \f(CW$first_col\fP, \f(CW$last_row\fP, \f(CW$last_col\fP )" .IX Subsection "print_area( $first_row, $first_col, $last_row, $last_col )" This method is used to specify the area of the worksheet that will be printed. All four parameters must be specified. You can also use A1 notation, see the note about \*(L"Cell notation\*(R". .PP .Vb 3 \& $worksheet1\->print_area( \*(AqA1:H20\*(Aq ); # Cells A1 to H20 \& $worksheet2\->print_area( 0, 0, 19, 7 ); # The same \& $worksheet2\->print_area( \*(AqA:H\*(Aq ); # Columns A to H if rows have data .Ve .SS "\fIprint_across()\fP" .IX Subsection "print_across()" The \f(CW\*(C`print_across\*(C'\fR method is used to change the default print direction. This is referred to by Excel as the sheet \*(L"page order\*(R". .PP .Vb 1 \& $worksheet\->print_across(); .Ve .PP The default page order is shown below for a worksheet that extends over 4 pages. The order is called \*(L"down then across\*(R": .PP .Vb 2 \& [1] [3] \& [2] [4] .Ve .PP However, by using the \f(CW\*(C`print_across\*(C'\fR method the print order will be changed to \*(L"across then down\*(R": .PP .Vb 2 \& [1] [2] \& [3] [4] .Ve .ie n .SS "fit_to_pages( $width, $height )" .el .SS "fit_to_pages( \f(CW$width\fP, \f(CW$height\fP )" .IX Subsection "fit_to_pages( $width, $height )" The \f(CW\*(C`fit_to_pages()\*(C'\fR method is used to fit the printed area to a specific number of pages both vertically and horizontally. If the printed area exceeds the specified number of pages it will be scaled down to fit. This guarantees that the printed area will always appear on the specified number of pages even if the page size or margins change. .PP .Vb 3 \& $worksheet1\->fit_to_pages( 1, 1 ); # Fit to 1x1 pages \& $worksheet2\->fit_to_pages( 2, 1 ); # Fit to 2x1 pages \& $worksheet3\->fit_to_pages( 1, 2 ); # Fit to 1x2 pages .Ve .PP The print area can be defined using the \f(CW\*(C`print_area()\*(C'\fR method as described above. .PP A common requirement is to fit the printed output to \fIn\fR pages wide but have the height be as long as necessary. To achieve this set the \f(CW$height\fR to zero: .PP .Vb 1 \& $worksheet1\->fit_to_pages( 1, 0 ); # 1 page wide and as long as necessary .Ve .PP Note that although it is valid to use both \f(CW\*(C`fit_to_pages()\*(C'\fR and \f(CW\*(C`set_print_scale()\*(C'\fR on the same worksheet only one of these options can be active at a time. The last method call made will set the active option. .PP Note that \f(CW\*(C`fit_to_pages()\*(C'\fR will override any manual page breaks that are defined in the worksheet. .PP Note: When using \f(CW\*(C`fit_to_pages()\*(C'\fR it may also be required to set the printer paper size using \f(CW\*(C`set_paper()\*(C'\fR or else Excel will default to \*(L"\s-1US\s0 Letter\*(R". .ie n .SS "set_start_page( $start_page )" .el .SS "set_start_page( \f(CW$start_page\fP )" .IX Subsection "set_start_page( $start_page )" The \f(CW\*(C`set_start_page()\*(C'\fR method is used to set the number of the starting page when the worksheet is printed out. The default value is 1. .PP .Vb 1 \& $worksheet\->set_start_page( 2 ); .Ve .ie n .SS "set_print_scale( $scale )" .el .SS "set_print_scale( \f(CW$scale\fP )" .IX Subsection "set_print_scale( $scale )" Set the scale factor of the printed page. Scale factors in the range \f(CW\*(C`10 <= $scale <= 400\*(C'\fR are valid: .PP .Vb 4 \& $worksheet1\->set_print_scale( 50 ); \& $worksheet2\->set_print_scale( 75 ); \& $worksheet3\->set_print_scale( 300 ); \& $worksheet4\->set_print_scale( 400 ); .Ve .PP The default scale factor is 100. Note, \f(CW\*(C`set_print_scale()\*(C'\fR does not affect the scale of the visible page in Excel. For that you should use \f(CW\*(C`set_zoom()\*(C'\fR. .PP Note also that although it is valid to use both \f(CW\*(C`fit_to_pages()\*(C'\fR and \f(CW\*(C`set_print_scale()\*(C'\fR on the same worksheet only one of these options can be active at a time. The last method call made will set the active option. .SS "\fIprint_black_and_white()\fP" .IX Subsection "print_black_and_white()" Set the option to print the worksheet in black and white: .PP .Vb 1 \& $worksheet\->print_black_and_white(); .Ve .ie n .SS "set_h_pagebreaks( @breaks )" .el .SS "set_h_pagebreaks( \f(CW@breaks\fP )" .IX Subsection "set_h_pagebreaks( @breaks )" Add horizontal page breaks to a worksheet. A page break causes all the data that follows it to be printed on the next page. Horizontal page breaks act between rows. To create a page break between rows 20 and 21 you must specify the break at row 21. However in zero index notation this is actually row 20. So you can pretend for a small while that you are using 1 index notation: .PP .Vb 1 \& $worksheet1\->set_h_pagebreaks( 20 ); # Break between row 20 and 21 .Ve .PP The \f(CW\*(C`set_h_pagebreaks()\*(C'\fR method will accept a list of page breaks and you can call it more than once: .PP .Vb 2 \& $worksheet2\->set_h_pagebreaks( 20, 40, 60, 80, 100 ); # Add breaks \& $worksheet2\->set_h_pagebreaks( 120, 140, 160, 180, 200 ); # Add some more .Ve .PP Note: If you specify the \*(L"fit to page\*(R" option via the \f(CW\*(C`fit_to_pages()\*(C'\fR method it will override all manual page breaks. .PP There is a silent limitation of about 1000 horizontal page breaks per worksheet in line with an Excel internal limitation. .ie n .SS "set_v_pagebreaks( @breaks )" .el .SS "set_v_pagebreaks( \f(CW@breaks\fP )" .IX Subsection "set_v_pagebreaks( @breaks )" Add vertical page breaks to a worksheet. A page break causes all the data that follows it to be printed on the next page. Vertical page breaks act between columns. To create a page break between columns 20 and 21 you must specify the break at column 21. However in zero index notation this is actually column 20. So you can pretend for a small while that you are using 1 index notation: .PP .Vb 1 \& $worksheet1\->set_v_pagebreaks(20); # Break between column 20 and 21 .Ve .PP The \f(CW\*(C`set_v_pagebreaks()\*(C'\fR method will accept a list of page breaks and you can call it more than once: .PP .Vb 2 \& $worksheet2\->set_v_pagebreaks( 20, 40, 60, 80, 100 ); # Add breaks \& $worksheet2\->set_v_pagebreaks( 120, 140, 160, 180, 200 ); # Add some more .Ve .PP Note: If you specify the \*(L"fit to page\*(R" option via the \f(CW\*(C`fit_to_pages()\*(C'\fR method it will override all manual page breaks. .SH "CELL FORMATTING" .IX Header "CELL FORMATTING" This section describes the methods and properties that are available for formatting cells in Excel. The properties of a cell that can be formatted include: fonts, colours, patterns, borders, alignment and number formatting. .SS "Creating and using a Format object" .IX Subsection "Creating and using a Format object" Cell formatting is defined through a Format object. Format objects are created by calling the workbook \f(CW\*(C`add_format()\*(C'\fR method as follows: .PP .Vb 2 \& my $format1 = $workbook\->add_format(); # Set properties later \& my $format2 = $workbook\->add_format( %props ); # Set at creation .Ve .PP The format object holds all the formatting properties that can be applied to a cell, a row or a column. The process of setting these properties is discussed in the next section. .PP Once a Format object has been constructed and its properties have been set it can be passed as an argument to the worksheet \f(CW\*(C`write\*(C'\fR methods as follows: .PP .Vb 4 \& $worksheet\->write( 0, 0, \*(AqOne\*(Aq, $format ); \& $worksheet\->write_string( 1, 0, \*(AqTwo\*(Aq, $format ); \& $worksheet\->write_number( 2, 0, 3, $format ); \& $worksheet\->write_blank( 3, 0, $format ); .Ve .PP Formats can also be passed to the worksheet \f(CW\*(C`set_row()\*(C'\fR and \f(CW\*(C`set_column()\*(C'\fR methods to define the default property for a row or column. .PP .Vb 2 \& $worksheet\->set_row( 0, 15, $format ); \& $worksheet\->set_column( 0, 0, 15, $format ); .Ve .SS "Format methods and Format properties" .IX Subsection "Format methods and Format properties" The following table shows the Excel format categories, the formatting properties that can be applied and the equivalent object method: .PP .Vb 12 \& Category Description Property Method Name \& \-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\- \& Font Font type font set_font() \& Font size size set_size() \& Font color color set_color() \& Bold bold set_bold() \& Italic italic set_italic() \& Underline underline set_underline() \& Strikeout font_strikeout set_font_strikeout() \& Super/Subscript font_script set_font_script() \& Outline font_outline set_font_outline() \& Shadow font_shadow set_font_shadow() \& \& Number Numeric format num_format set_num_format() \& \& Protection Lock cells locked set_locked() \& Hide formulas hidden set_hidden() \& \& Alignment Horizontal align align set_align() \& Vertical align valign set_align() \& Rotation rotation set_rotation() \& Text wrap text_wrap set_text_wrap() \& Justify last text_justlast set_text_justlast() \& Center across center_across set_center_across() \& Indentation indent set_indent() \& Shrink to fit shrink set_shrink() \& \& Pattern Cell pattern pattern set_pattern() \& Background color bg_color set_bg_color() \& Foreground color fg_color set_fg_color() \& \& Border Cell border border set_border() \& Bottom border bottom set_bottom() \& Top border top set_top() \& Left border left set_left() \& Right border right set_right() \& Border color border_color set_border_color() \& Bottom color bottom_color set_bottom_color() \& Top color top_color set_top_color() \& Left color left_color set_left_color() \& Right color right_color set_right_color() \& Diagional type diag_type set_diag_type() \& Diagional border diag_border set_diag_border() \& Diagional color diag_color set_diag_color() .Ve .PP There are two ways of setting Format properties: by using the object method interface or by setting the property directly. For example, a typical use of the method interface would be as follows: .PP .Vb 3 \& my $format = $workbook\->add_format(); \& $format\->set_bold(); \& $format\->set_color( \*(Aqred\*(Aq ); .Ve .PP By comparison the properties can be set directly by passing a hash of properties to the Format constructor: .PP .Vb 1 \& my $format = $workbook\->add_format( bold => 1, color => \*(Aqred\*(Aq ); .Ve .PP or after the Format has been constructed by means of the \f(CW\*(C`set_format_properties()\*(C'\fR method as follows: .PP .Vb 2 \& my $format = $workbook\->add_format(); \& $format\->set_format_properties( bold => 1, color => \*(Aqred\*(Aq ); .Ve .PP You can also store the properties in one or more named hashes and pass them to the required method: .PP .Vb 6 \& my %font = ( \& font => \*(AqCalibri\*(Aq, \& size => 12, \& color => \*(Aqblue\*(Aq, \& bold => 1, \& ); \& \& my %shading = ( \& bg_color => \*(Aqgreen\*(Aq, \& pattern => 1, \& ); \& \& \& my $format1 = $workbook\->add_format( %font ); # Font only \& my $format2 = $workbook\->add_format( %font, %shading ); # Font and shading .Ve .PP The provision of two ways of setting properties might lead you to wonder which is the best way. The method mechanism may be better if you prefer setting properties via method calls (which the author did when the code was first written) otherwise passing properties to the constructor has proved to be a little more flexible and self documenting in practice. An additional advantage of working with property hashes is that it allows you to share formatting between workbook objects as shown in the example above. .PP The Perl/Tk style of adding properties is also supported: .PP .Vb 6 \& my %font = ( \& \-font => \*(AqCalibri\*(Aq, \& \-size => 12, \& \-color => \*(Aqblue\*(Aq, \& \-bold => 1, \& ); .Ve .SS "Working with formats" .IX Subsection "Working with formats" The default format is Calibri 11 with all other properties off. .PP Each unique format in Excel::Writer::XLSX must have a corresponding Format object. It isn't possible to use a Format with a \fIwrite()\fR method and then redefine the Format for use at a later stage. This is because a Format is applied to a cell not in its current state but in its final state. Consider the following example: .PP .Vb 6 \& my $format = $workbook\->add_format(); \& $format\->set_bold(); \& $format\->set_color( \*(Aqred\*(Aq ); \& $worksheet\->write( \*(AqA1\*(Aq, \*(AqCell A1\*(Aq, $format ); \& $format\->set_color( \*(Aqgreen\*(Aq ); \& $worksheet\->write( \*(AqB1\*(Aq, \*(AqCell B1\*(Aq, $format ); .Ve .PP Cell A1 is assigned the Format \f(CW$format\fR which is initially set to the colour red. However, the colour is subsequently set to green. When Excel displays Cell A1 it will display the final state of the Format which in this case will be the colour green. .PP In general a method call without an argument will turn a property on, for example: .PP .Vb 4 \& my $format1 = $workbook\->add_format(); \& $format1\->set_bold(); # Turns bold on \& $format1\->set_bold( 1 ); # Also turns bold on \& $format1\->set_bold( 0 ); # Turns bold off .Ve .SH "FORMAT METHODS" .IX Header "FORMAT METHODS" The Format object methods are described in more detail in the following sections. In addition, there is a Perl program called \f(CW\*(C`formats.pl\*(C'\fR in the \f(CW\*(C`examples\*(C'\fR directory of the WriteExcel distribution. This program creates an Excel workbook called \f(CW\*(C`formats.xlsx\*(C'\fR which contains examples of almost all the format types. .PP The following Format methods are available: .PP .Vb 10 \& set_font() \& set_size() \& set_color() \& set_bold() \& set_italic() \& set_underline() \& set_font_strikeout() \& set_font_script() \& set_font_outline() \& set_font_shadow() \& set_num_format() \& set_locked() \& set_hidden() \& set_align() \& set_rotation() \& set_text_wrap() \& set_text_justlast() \& set_center_across() \& set_indent() \& set_shrink() \& set_pattern() \& set_bg_color() \& set_fg_color() \& set_border() \& set_bottom() \& set_top() \& set_left() \& set_right() \& set_border_color() \& set_bottom_color() \& set_top_color() \& set_left_color() \& set_right_color() \& set_diag_type() \& set_diag_border() \& set_diag_color() .Ve .PP The above methods can also be applied directly as properties. For example \f(CW\*(C`$format\->set_bold()\*(C'\fR is equivalent to \f(CW\*(C`$workbook\->add_format(bold => 1)\*(C'\fR. .ie n .SS "set_format_properties( %properties )" .el .SS "set_format_properties( \f(CW%properties\fP )" .IX Subsection "set_format_properties( %properties )" The properties of an existing Format object can be also be set by means of \f(CW\*(C`set_format_properties()\*(C'\fR: .PP .Vb 2 \& my $format = $workbook\->add_format(); \& $format\->set_format_properties( bold => 1, color => \*(Aqred\*(Aq ); .Ve .PP However, this method is here mainly for legacy reasons. It is preferable to set the properties in the format constructor: .PP .Vb 1 \& my $format = $workbook\->add_format( bold => 1, color => \*(Aqred\*(Aq ); .Ve .ie n .SS "set_font( $fontname )" .el .SS "set_font( \f(CW$fontname\fP )" .IX Subsection "set_font( $fontname )" .Vb 3 \& Default state: Font is Calibri \& Default action: None \& Valid args: Any valid font name .Ve .PP Specify the font used: .PP .Vb 1 \& $format\->set_font(\*(AqTimes New Roman\*(Aq); .Ve .PP Excel can only display fonts that are installed on the system that it is running on. Therefore it is best to use the fonts that come as standard such as 'Calibri', 'Times New Roman' and 'Courier New'. See also the Fonts worksheet created by formats.pl .SS "\fIset_size()\fP" .IX Subsection "set_size()" .Vb 3 \& Default state: Font size is 10 \& Default action: Set font size to 1 \& Valid args: Integer values from 1 to as big as your screen. .Ve .PP Set the font size. Excel adjusts the height of a row to accommodate the largest font size in the row. You can also explicitly specify the height of a row using the \fIset_row()\fR worksheet method. .PP .Vb 2 \& my $format = $workbook\->add_format(); \& $format\->set_size( 30 ); .Ve .SS "\fIset_color()\fP" .IX Subsection "set_color()" .Vb 10 \& Default state: Excels default color, usually black \& Default action: Set the default color \& Valid args: Integers from 8..63 or the following strings: \& \*(Aqblack\*(Aq \& \*(Aqblue\*(Aq \& \*(Aqbrown\*(Aq \& \*(Aqcyan\*(Aq \& \*(Aqgray\*(Aq \& \*(Aqgreen\*(Aq \& \*(Aqlime\*(Aq \& \*(Aqmagenta\*(Aq \& \*(Aqnavy\*(Aq \& \*(Aqorange\*(Aq \& \*(Aqpink\*(Aq \& \*(Aqpurple\*(Aq \& \*(Aqred\*(Aq \& \*(Aqsilver\*(Aq \& \*(Aqwhite\*(Aq \& \*(Aqyellow\*(Aq .Ve .PP Set the font colour. The \f(CW\*(C`set_color()\*(C'\fR method is used as follows: .PP .Vb 3 \& my $format = $workbook\->add_format(); \& $format\->set_color( \*(Aqred\*(Aq ); \& $worksheet\->write( 0, 0, \*(Aqwheelbarrow\*(Aq, $format ); .Ve .PP Note: The \f(CW\*(C`set_color()\*(C'\fR method is used to set the colour of the font in a cell. To set the colour of a cell use the \f(CW\*(C`set_bg_color()\*(C'\fR and \f(CW\*(C`set_pattern()\*(C'\fR methods. .PP For additional examples see the 'Named colors' and 'Standard colors' worksheets created by formats.pl in the examples directory. .PP See also \*(L"\s-1COLOURS\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". .SS "\fIset_bold()\fP" .IX Subsection "set_bold()" .Vb 3 \& Default state: bold is off \& Default action: Turn bold on \& Valid args: 0, 1 .Ve .PP Set the bold property of the font: .PP .Vb 1 \& $format\->set_bold(); # Turn bold on .Ve .SS "\fIset_italic()\fP" .IX Subsection "set_italic()" .Vb 3 \& Default state: Italic is off \& Default action: Turn italic on \& Valid args: 0, 1 .Ve .PP Set the italic property of the font: .PP .Vb 1 \& $format\->set_italic(); # Turn italic on .Ve .SS "\fIset_underline()\fP" .IX Subsection "set_underline()" .Vb 7 \& Default state: Underline is off \& Default action: Turn on single underline \& Valid args: 0 = No underline \& 1 = Single underline \& 2 = Double underline \& 33 = Single accounting underline \& 34 = Double accounting underline .Ve .PP Set the underline property of the font. .PP .Vb 1 \& $format\->set_underline(); # Single underline .Ve .SS "\fIset_font_strikeout()\fP" .IX Subsection "set_font_strikeout()" .Vb 3 \& Default state: Strikeout is off \& Default action: Turn strikeout on \& Valid args: 0, 1 .Ve .PP Set the strikeout property of the font. .SS "\fIset_font_script()\fP" .IX Subsection "set_font_script()" .Vb 5 \& Default state: Super/Subscript is off \& Default action: Turn Superscript on \& Valid args: 0 = Normal \& 1 = Superscript \& 2 = Subscript .Ve .PP Set the superscript/subscript property of the font. .SS "\fIset_font_outline()\fP" .IX Subsection "set_font_outline()" .Vb 3 \& Default state: Outline is off \& Default action: Turn outline on \& Valid args: 0, 1 .Ve .PP Macintosh only. .SS "\fIset_font_shadow()\fP" .IX Subsection "set_font_shadow()" .Vb 3 \& Default state: Shadow is off \& Default action: Turn shadow on \& Valid args: 0, 1 .Ve .PP Macintosh only. .SS "\fIset_num_format()\fP" .IX Subsection "set_num_format()" .Vb 3 \& Default state: General format \& Default action: Format index 1 \& Valid args: See the following table .Ve .PP This method is used to define the numerical format of a number in Excel. It controls whether a number is displayed as an integer, a floating point number, a date, a currency value or some other user defined format. .PP The numerical format of a cell can be specified by using a format string or an index to one of Excel's built-in formats: .PP .Vb 4 \& my $format1 = $workbook\->add_format(); \& my $format2 = $workbook\->add_format(); \& $format1\->set_num_format( \*(Aqd mmm yyyy\*(Aq ); # Format string \& $format2\->set_num_format( 0x0f ); # Format index \& \& $worksheet\->write( 0, 0, 36892.521, $format1 ); # 1 Jan 2001 \& $worksheet\->write( 0, 0, 36892.521, $format2 ); # 1\-Jan\-01 .Ve .PP Using format strings you can define very sophisticated formatting of numbers. .PP .Vb 2 \& $format01\->set_num_format( \*(Aq0.000\*(Aq ); \& $worksheet\->write( 0, 0, 3.1415926, $format01 ); # 3.142 \& \& $format02\->set_num_format( \*(Aq#,##0\*(Aq ); \& $worksheet\->write( 1, 0, 1234.56, $format02 ); # 1,235 \& \& $format03\->set_num_format( \*(Aq#,##0.00\*(Aq ); \& $worksheet\->write( 2, 0, 1234.56, $format03 ); # 1,234.56 \& \& $format04\->set_num_format( \*(Aq$0.00\*(Aq ); \& $worksheet\->write( 3, 0, 49.99, $format04 ); # $49.99 \& \& # Note you can use other currency symbols such as the pound or yen as well. \& # Other currencies may require the use of Unicode. \& \& $format07\->set_num_format( \*(Aqmm/dd/yy\*(Aq ); \& $worksheet\->write( 6, 0, 36892.521, $format07 ); # 01/01/01 \& \& $format08\->set_num_format( \*(Aqmmm d yyyy\*(Aq ); \& $worksheet\->write( 7, 0, 36892.521, $format08 ); # Jan 1 2001 \& \& $format09\->set_num_format( \*(Aqd mmmm yyyy\*(Aq ); \& $worksheet\->write( 8, 0, 36892.521, $format09 ); # 1 January 2001 \& \& $format10\->set_num_format( \*(Aqdd/mm/yyyy hh:mm AM/PM\*(Aq ); \& $worksheet\->write( 9, 0, 36892.521, $format10 ); # 01/01/2001 12:30 AM \& \& $format11\->set_num_format( \*(Aq0 "dollar and" .00 "cents"\*(Aq ); \& $worksheet\->write( 10, 0, 1.87, $format11 ); # 1 dollar and .87 cents \& \& # Conditional numerical formatting. \& $format12\->set_num_format( \*(Aq[Green]General;[Red]\-General;General\*(Aq ); \& $worksheet\->write( 11, 0, 123, $format12 ); # > 0 Green \& $worksheet\->write( 12, 0, \-45, $format12 ); # < 0 Red \& $worksheet\->write( 13, 0, 0, $format12 ); # = 0 Default colour \& \& # Zip code \& $format13\->set_num_format( \*(Aq00000\*(Aq ); \& $worksheet\->write( 14, 0, \*(Aq01209\*(Aq, $format13 ); .Ve .PP The number system used for dates is described in \*(L"\s-1DATES\s0 \s-1AND\s0 \s-1TIME\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R". .PP The colour format should have one of the following values: .PP .Vb 1 \& [Black] [Blue] [Cyan] [Green] [Magenta] [Red] [White] [Yellow] .Ve .PP Alternatively you can specify the colour based on a colour index as follows: \f(CW\*(C`[Color n]\*(C'\fR, where n is a standard Excel colour index \- 7. See the 'Standard colors' worksheet created by formats.pl. .PP For more information refer to the documentation on formatting in the \f(CW\*(C`docs\*(C'\fR directory of the Excel::Writer::XLSX distro, the Excel on-line help or http://office.microsoft.com/en\-gb/assistance/HP051995001033.aspx . .PP You should ensure that the format string is valid in Excel prior to using it in WriteExcel. .PP Excel's built-in formats are shown in the following table: .PP .Vb 10 \& Index Index Format String \& 0 0x00 General \& 1 0x01 0 \& 2 0x02 0.00 \& 3 0x03 #,##0 \& 4 0x04 #,##0.00 \& 5 0x05 ($#,##0_);($#,##0) \& 6 0x06 ($#,##0_);[Red]($#,##0) \& 7 0x07 ($#,##0.00_);($#,##0.00) \& 8 0x08 ($#,##0.00_);[Red]($#,##0.00) \& 9 0x09 0% \& 10 0x0a 0.00% \& 11 0x0b 0.00E+00 \& 12 0x0c # ?/? \& 13 0x0d # ??/?? \& 14 0x0e m/d/yy \& 15 0x0f d\-mmm\-yy \& 16 0x10 d\-mmm \& 17 0x11 mmm\-yy \& 18 0x12 h:mm AM/PM \& 19 0x13 h:mm:ss AM/PM \& 20 0x14 h:mm \& 21 0x15 h:mm:ss \& 22 0x16 m/d/yy h:mm \& .. .... ........... \& 37 0x25 (#,##0_);(#,##0) \& 38 0x26 (#,##0_);[Red](#,##0) \& 39 0x27 (#,##0.00_);(#,##0.00) \& 40 0x28 (#,##0.00_);[Red](#,##0.00) \& 41 0x29 _(* #,##0_);_(* (#,##0);_(* "\-"_);_(@_) \& 42 0x2a _($* #,##0_);_($* (#,##0);_($* "\-"_);_(@_) \& 43 0x2b _(* #,##0.00_);_(* (#,##0.00);_(* "\-"??_);_(@_) \& 44 0x2c _($* #,##0.00_);_($* (#,##0.00);_($* "\-"??_);_(@_) \& 45 0x2d mm:ss \& 46 0x2e [h]:mm:ss \& 47 0x2f mm:ss.0 \& 48 0x30 ##0.0E+0 \& 49 0x31 @ .Ve .PP For examples of these formatting codes see the 'Numerical formats' worksheet created by formats.pl. See also the number_formats1.html and the number_formats2.html documents in the \f(CW\*(C`docs\*(C'\fR directory of the distro. .PP Note 1. Numeric formats 23 to 36 are not documented by Microsoft and may differ in international versions. .PP Note 2. The dollar sign appears as the defined local currency symbol. .SS "\fIset_locked()\fP" .IX Subsection "set_locked()" .Vb 3 \& Default state: Cell locking is on \& Default action: Turn locking on \& Valid args: 0, 1 .Ve .PP This property can be used to prevent modification of a cells contents. Following Excel's convention, cell locking is turned on by default. However, it only has an effect if the worksheet has been protected, see the worksheet \f(CW\*(C`protect()\*(C'\fR method. .PP .Vb 2 \& my $locked = $workbook\->add_format(); \& $locked\->set_locked( 1 ); # A non\-op \& \& my $unlocked = $workbook\->add_format(); \& $locked\->set_locked( 0 ); \& \& # Enable worksheet protection \& $worksheet\->protect(); \& \& # This cell cannot be edited. \& $worksheet\->write( \*(AqA1\*(Aq, \*(Aq=1+2\*(Aq, $locked ); \& \& # This cell can be edited. \& $worksheet\->write( \*(AqA2\*(Aq, \*(Aq=1+2\*(Aq, $unlocked ); .Ve .PP Note: This offers weak protection even with a password, see the note in relation to the \f(CW\*(C`protect()\*(C'\fR method. .SS "\fIset_hidden()\fP" .IX Subsection "set_hidden()" .Vb 3 \& Default state: Formula hiding is off \& Default action: Turn hiding on \& Valid args: 0, 1 .Ve .PP This property is used to hide a formula while still displaying its result. This is generally used to hide complex calculations from end users who are only interested in the result. It only has an effect if the worksheet has been protected, see the worksheet \f(CW\*(C`protect()\*(C'\fR method. .PP .Vb 2 \& my $hidden = $workbook\->add_format(); \& $hidden\->set_hidden(); \& \& # Enable worksheet protection \& $worksheet\->protect(); \& \& # The formula in this cell isn\*(Aqt visible \& $worksheet\->write( \*(AqA1\*(Aq, \*(Aq=1+2\*(Aq, $hidden ); .Ve .PP Note: This offers weak protection even with a password, see the note in relation to the \f(CW\*(C`protect()\*(C'\fR method. .SS "\fIset_align()\fP" .IX Subsection "set_align()" .Vb 8 \& Default state: Alignment is off \& Default action: Left alignment \& Valid args: \*(Aqleft\*(Aq Horizontal \& \*(Aqcenter\*(Aq \& \*(Aqright\*(Aq \& \*(Aqfill\*(Aq \& \*(Aqjustify\*(Aq \& \*(Aqcenter_across\*(Aq \& \& \*(Aqtop\*(Aq Vertical \& \*(Aqvcenter\*(Aq \& \*(Aqbottom\*(Aq \& \*(Aqvjustify\*(Aq .Ve .PP This method is used to set the horizontal and vertical text alignment within a cell. Vertical and horizontal alignments can be combined. The method is used as follows: .PP .Vb 5 \& my $format = $workbook\->add_format(); \& $format\->set_align( \*(Aqcenter\*(Aq ); \& $format\->set_align( \*(Aqvcenter\*(Aq ); \& $worksheet\->set_row( 0, 30 ); \& $worksheet\->write( 0, 0, \*(AqX\*(Aq, $format ); .Ve .PP Text can be aligned across two or more adjacent cells using the \f(CW\*(C`center_across\*(C'\fR property. However, for genuine merged cells it is better to use the \f(CW\*(C`merge_range()\*(C'\fR worksheet method. .PP The \f(CW\*(C`vjustify\*(C'\fR (vertical justify) option can be used to provide automatic text wrapping in a cell. The height of the cell will be adjusted to accommodate the wrapped text. To specify where the text wraps use the \f(CW\*(C`set_text_wrap()\*(C'\fR method. .PP For further examples see the 'Alignment' worksheet created by formats.pl. .SS "\fIset_center_across()\fP" .IX Subsection "set_center_across()" .Vb 3 \& Default state: Center across selection is off \& Default action: Turn center across on \& Valid args: 1 .Ve .PP Text can be aligned across two or more adjacent cells using the \f(CW\*(C`set_center_across()\*(C'\fR method. This is an alias for the \f(CW\*(C`set_align(\*(Aqcenter_across\*(Aq)\*(C'\fR method call. .PP Only one cell should contain the text, the other cells should be blank: .PP .Vb 2 \& my $format = $workbook\->add_format(); \& $format\->set_center_across(); \& \& $worksheet\->write( 1, 1, \*(AqCenter across selection\*(Aq, $format ); \& $worksheet\->write_blank( 1, 2, $format ); .Ve .PP See also the \f(CW\*(C`merge1.pl\*(C'\fR to \f(CW\*(C`merge6.pl\*(C'\fR programs in the \f(CW\*(C`examples\*(C'\fR directory and the \f(CW\*(C`merge_range()\*(C'\fR method. .SS "\fIset_text_wrap()\fP" .IX Subsection "set_text_wrap()" .Vb 3 \& Default state: Text wrap is off \& Default action: Turn text wrap on \& Valid args: 0, 1 .Ve .PP Here is an example using the text wrap property, the escape character \f(CW\*(C`\en\*(C'\fR is used to indicate the end of line: .PP .Vb 3 \& my $format = $workbook\->add_format(); \& $format\->set_text_wrap(); \& $worksheet\->write( 0, 0, "It\*(Aqs\ena bum\enwrap", $format ); .Ve .PP Excel will adjust the height of the row to accommodate the wrapped text. A similar effect can be obtained without newlines using the \f(CW\*(C`set_align(\*(Aqvjustify\*(Aq)\*(C'\fR method. See the \f(CW\*(C`textwrap.pl\*(C'\fR program in the \f(CW\*(C`examples\*(C'\fR directory. .SS "\fIset_rotation()\fP" .IX Subsection "set_rotation()" .Vb 3 \& Default state: Text rotation is off \& Default action: None \& Valid args: Integers in the range \-90 to 90 and 270 .Ve .PP Set the rotation of the text in a cell. The rotation can be any angle in the range \-90 to 90 degrees. .PP .Vb 3 \& my $format = $workbook\->add_format(); \& $format\->set_rotation( 30 ); \& $worksheet\->write( 0, 0, \*(AqThis text is rotated\*(Aq, $format ); .Ve .PP The angle 270 is also supported. This indicates text where the letters run from top to bottom. .SS "\fIset_indent()\fP" .IX Subsection "set_indent()" .Vb 3 \& Default state: Text indentation is off \& Default action: Indent text 1 level \& Valid args: Positive integers .Ve .PP This method can be used to indent text. The argument, which should be an integer, is taken as the level of indentation: .PP .Vb 3 \& my $format = $workbook\->add_format(); \& $format\->set_indent( 2 ); \& $worksheet\->write( 0, 0, \*(AqThis text is indented\*(Aq, $format ); .Ve .PP Indentation is a horizontal alignment property. It will override any other horizontal properties but it can be used in conjunction with vertical properties. .SS "\fIset_shrink()\fP" .IX Subsection "set_shrink()" .Vb 3 \& Default state: Text shrinking is off \& Default action: Turn "shrink to fit" on \& Valid args: 1 .Ve .PP This method can be used to shrink text so that it fits in a cell. .PP .Vb 3 \& my $format = $workbook\->add_format(); \& $format\->set_shrink(); \& $worksheet\->write( 0, 0, \*(AqHoney, I shrunk the text!\*(Aq, $format ); .Ve .SS "\fIset_text_justlast()\fP" .IX Subsection "set_text_justlast()" .Vb 3 \& Default state: Justify last is off \& Default action: Turn justify last on \& Valid args: 0, 1 .Ve .PP Only applies to Far Eastern versions of Excel. .SS "\fIset_pattern()\fP" .IX Subsection "set_pattern()" .Vb 3 \& Default state: Pattern is off \& Default action: Solid fill is on \& Valid args: 0 .. 18 .Ve .PP Set the background pattern of a cell. .PP Examples of the available patterns are shown in the 'Patterns' worksheet created by formats.pl. However, it is unlikely that you will ever need anything other than Pattern 1 which is a solid fill of the background color. .SS "\fIset_bg_color()\fP" .IX Subsection "set_bg_color()" .Vb 3 \& Default state: Color is off \& Default action: Solid fill. \& Valid args: See set_color() .Ve .PP The \f(CW\*(C`set_bg_color()\*(C'\fR method can be used to set the background colour of a pattern. Patterns are defined via the \f(CW\*(C`set_pattern()\*(C'\fR method. If a pattern hasn't been defined then a solid fill pattern is used as the default. .PP Here is an example of how to set up a solid fill in a cell: .PP .Vb 1 \& my $format = $workbook\->add_format(); \& \& $format\->set_pattern(); # This is optional when using a solid fill \& \& $format\->set_bg_color( \*(Aqgreen\*(Aq ); \& $worksheet\->write( \*(AqA1\*(Aq, \*(AqRay\*(Aq, $format ); .Ve .PP For further examples see the 'Patterns' worksheet created by formats.pl. .SS "\fIset_fg_color()\fP" .IX Subsection "set_fg_color()" .Vb 3 \& Default state: Color is off \& Default action: Solid fill. \& Valid args: See set_color() .Ve .PP The \f(CW\*(C`set_fg_color()\*(C'\fR method can be used to set the foreground colour of a pattern. .PP For further examples see the 'Patterns' worksheet created by formats.pl. .SS "\fIset_border()\fP" .IX Subsection "set_border()" .Vb 4 \& Also applies to: set_bottom() \& set_top() \& set_left() \& set_right() \& \& Default state: Border is off \& Default action: Set border type 1 \& Valid args: 0\-13, See below. .Ve .PP A cell border is comprised of a border on the bottom, top, left and right. These can be set to the same value using \f(CW\*(C`set_border()\*(C'\fR or individually using the relevant method calls shown above. .PP The following shows the border styles sorted by Excel::Writer::XLSX index number: .PP .Vb 10 \& Index Name Weight Style \& ===== ============= ====== =========== \& 0 None 0 \& 1 Continuous 1 \-\-\-\-\-\-\-\-\-\-\- \& 2 Continuous 2 \-\-\-\-\-\-\-\-\-\-\- \& 3 Dash 1 \- \- \- \- \- \- \& 4 Dot 1 . . . . . . \& 5 Continuous 3 \-\-\-\-\-\-\-\-\-\-\- \& 6 Double 3 =========== \& 7 Continuous 0 \-\-\-\-\-\-\-\-\-\-\- \& 8 Dash 2 \- \- \- \- \- \- \& 9 Dash Dot 1 \- . \- . \- . \& 10 Dash Dot 2 \- . \- . \- . \& 11 Dash Dot Dot 1 \- . . \- . . \& 12 Dash Dot Dot 2 \- . . \- . . \& 13 SlantDash Dot 2 / \- . / \- . .Ve .PP The following shows the borders sorted by style: .PP .Vb 10 \& Name Weight Style Index \& ============= ====== =========== ===== \& Continuous 0 \-\-\-\-\-\-\-\-\-\-\- 7 \& Continuous 1 \-\-\-\-\-\-\-\-\-\-\- 1 \& Continuous 2 \-\-\-\-\-\-\-\-\-\-\- 2 \& Continuous 3 \-\-\-\-\-\-\-\-\-\-\- 5 \& Dash 1 \- \- \- \- \- \- 3 \& Dash 2 \- \- \- \- \- \- 8 \& Dash Dot 1 \- . \- . \- . 9 \& Dash Dot 2 \- . \- . \- . 10 \& Dash Dot Dot 1 \- . . \- . . 11 \& Dash Dot Dot 2 \- . . \- . . 12 \& Dot 1 . . . . . . 4 \& Double 3 =========== 6 \& None 0 0 \& SlantDash Dot 2 / \- . / \- . 13 .Ve .PP The following shows the borders in the order shown in the Excel Dialog. .PP .Vb 9 \& Index Style Index Style \& ===== ===== ===== ===== \& 0 None 12 \- . . \- . . \& 7 \-\-\-\-\-\-\-\-\-\-\- 13 / \- . / \- . \& 4 . . . . . . 10 \- . \- . \- . \& 11 \- . . \- . . 8 \- \- \- \- \- \- \& 9 \- . \- . \- . 2 \-\-\-\-\-\-\-\-\-\-\- \& 3 \- \- \- \- \- \- 5 \-\-\-\-\-\-\-\-\-\-\- \& 1 \-\-\-\-\-\-\-\-\-\-\- 6 =========== .Ve .PP Examples of the available border styles are shown in the 'Borders' worksheet created by formats.pl. .SS "\fIset_border_color()\fP" .IX Subsection "set_border_color()" .Vb 4 \& Also applies to: set_bottom_color() \& set_top_color() \& set_left_color() \& set_right_color() \& \& Default state: Color is off \& Default action: Undefined \& Valid args: See set_color() .Ve .PP Set the colour of the cell borders. A cell border is comprised of a border on the bottom, top, left and right. These can be set to the same colour using \f(CW\*(C`set_border_color()\*(C'\fR or individually using the relevant method calls shown above. Examples of the border styles and colours are shown in the 'Borders' worksheet created by formats.pl. .SS "\fIset_diag_type()\fP" .IX Subsection "set_diag_type()" .Vb 3 \& Default state: Diagonal border is off. \& Default action: None. \& Valid args: 1\-3, See below. .Ve .PP Set the diagonal border type for the cell. Three types of diagonal borders are available in Excel: .PP .Vb 3 \& 1: From bottom left to top right. \& 2: From top left to bottom right. \& 3: Same as 1 and 2 combined. .Ve .PP For example: .PP .Vb 1 \& $format\->set_diag_type( 3 ); .Ve .SS "\fIset_diag_border()\fP" .IX Subsection "set_diag_border()" .Vb 3 \& Default state: Border is off \& Default action: Set border type 1 \& Valid args: 0\-13, See below. .Ve .PP Set the diagonal border style. Same as the parmater to \f(CW\*(C`set_border()\*(C'\fR above. .SS "\fIset_diag_color()\fP" .IX Subsection "set_diag_color()" .Vb 3 \& Default state: Color is off \& Default action: Undefined \& Valid args: See set_color() .Ve .PP Set the colour of the diagonal cell border: .PP .Vb 3 \& $format\->set_diag_type( 3 ); \& $format\->set_diag_border( 7 ); \& $format\->set_diag_color( \*(Aqred\*(Aq ); .Ve .ie n .SS "copy( $format )" .el .SS "copy( \f(CW$format\fP )" .IX Subsection "copy( $format )" This method is used to copy all of the properties from one Format object to another: .PP .Vb 4 \& my $lorry1 = $workbook\->add_format(); \& $lorry1\->set_bold(); \& $lorry1\->set_italic(); \& $lorry1\->set_color( \*(Aqred\*(Aq ); # lorry1 is bold, italic and red \& \& my $lorry2 = $workbook\->add_format(); \& $lorry2\->copy( $lorry1 ); \& $lorry2\->set_color( \*(Aqyellow\*(Aq ); # lorry2 is bold, italic and yellow .Ve .PP The \f(CW\*(C`copy()\*(C'\fR method is only useful if you are using the method interface to Format properties. It generally isn't required if you are setting Format properties directly using hashes. .PP Note: this is not a copy constructor, both objects must exist prior to copying. .SH "UNICODE IN EXCEL" .IX Header "UNICODE IN EXCEL" The following is a brief introduction to handling Unicode in \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR. .PP \&\fIFor a more general introduction to Unicode handling in Perl see\fR perlunitut and perluniintro. .PP Excel::Writer::XLSX writer differs from Spreadsheet::WriteExcel in that it only handles Unicode data in \f(CW\*(C`UTF\-8\*(C'\fR format and doesn't try to handle legacy \s-1UTF\-16\s0 Excel formats. .PP If the data is in \f(CW\*(C`UTF\-8\*(C'\fR format then Excel::Writer::XLSX will handle it automatically. .PP If you are dealing with non-ASCII characters that aren't in \f(CW\*(C`UTF\-8\*(C'\fR then perl provides useful tools in the guise of the \f(CW\*(C`Encode\*(C'\fR module to help you to convert to the required format. For example: .PP .Vb 1 \& use Encode \*(Aqdecode\*(Aq; \& \& my $string = \*(Aqsome string with koi8\-r characters\*(Aq; \& $string = decode(\*(Aqkoi8\-r\*(Aq, $string); # koi8\-r to utf8 .Ve .PP Alternatively you can read data from an encoded file and convert it to \f(CW\*(C`UTF\-8\*(C'\fR as you read it in: .PP .Vb 2 \& my $file = \*(Aqunicode_koi8r.txt\*(Aq; \& open FH, \*(Aq<:encoding(koi8\-r)\*(Aq, $file or die "Couldn\*(Aqt open $file: $!\en"; \& \& my $row = 0; \& while ( ) { \& # Data read in is now in utf8 format. \& chomp; \& $worksheet\->write( $row++, 0, $_ ); \& } .Ve .PP These methodologies are explained in more detail in perlunitut, perluniintro and perlunicode. .PP See also the \f(CW\*(C`unicode_*.pl\*(C'\fR programs in the examples directory of the distro. .SH "COLOURS IN EXCEL" .IX Header "COLOURS IN EXCEL" Excel provides a colour palette of 56 colours. In Excel::Writer::XLSX these colours are accessed via their palette index in the range 8..63. This index is used to set the colour of fonts, cell patterns and cell borders. For example: .PP .Vb 6 \& my $format = $workbook\->add_format( \& color => 12, # index for blue \& font => \*(AqCalibri\*(Aq, \& size => 12, \& bold => 1, \& ); .Ve .PP The most commonly used colours can also be accessed by name. The name acts as a simple alias for the colour index: .PP .Vb 10 \& black => 8 \& blue => 12 \& brown => 16 \& cyan => 15 \& gray => 23 \& green => 17 \& lime => 11 \& magenta => 14 \& navy => 18 \& orange => 53 \& pink => 33 \& purple => 20 \& red => 10 \& silver => 22 \& white => 9 \& yellow => 13 .Ve .PP For example: .PP .Vb 1 \& my $font = $workbook\->add_format( color => \*(Aqred\*(Aq ); .Ve .PP Users of \s-1VBA\s0 in Excel should note that the equivalent colour indices are in the range 1..56 instead of 8..63. .PP If the default palette does not provide a required colour you can override one of the built-in values. This is achieved by using the \f(CW\*(C`set_custom_color()\*(C'\fR workbook method to adjust the \s-1RGB\s0 (red green blue) components of the colour: .PP .Vb 1 \& my $ferrari = $workbook\->set_custom_color( 40, 216, 12, 12 ); \& \& my $format = $workbook\->add_format( \& bg_color => $ferrari, \& pattern => 1, \& border => 1 \& ); \& \& $worksheet\->write_blank( \*(AqA1\*(Aq, $format ); .Ve .PP You can generate and example of the Excel palette using \f(CW\*(C`colors.pl\*(C'\fR in the \f(CW\*(C`examples\*(C'\fR directory. .SH "DATES AND TIME IN EXCEL" .IX Header "DATES AND TIME IN EXCEL" There are two important things to understand about dates and times in Excel: .IP "1 A date/time in Excel is a real number plus an Excel number format." 4 .IX Item "1 A date/time in Excel is a real number plus an Excel number format." .PD 0 .ie n .IP "2 Excel::Writer::XLSX doesn't automatically convert date/time strings in ""write()"" to an Excel date/time." 4 .el .IP "2 Excel::Writer::XLSX doesn't automatically convert date/time strings in \f(CWwrite()\fR to an Excel date/time." 4 .IX Item "2 Excel::Writer::XLSX doesn't automatically convert date/time strings in write() to an Excel date/time." .PD .PP These two points are explained in more detail below along with some suggestions on how to convert times and dates to the required format. .SS "An Excel date/time is a number plus a format" .IX Subsection "An Excel date/time is a number plus a format" If you write a date string with \f(CW\*(C`write()\*(C'\fR then all you will get is a string: .PP .Vb 1 \& $worksheet\->write( \*(AqA1\*(Aq, \*(Aq02/03/04\*(Aq ); # !! Writes a string not a date. !! .Ve .PP Dates and times in Excel are represented by real numbers, for example \*(L"Jan 1 2001 12:30 \s-1AM\s0\*(R" is represented by the number 36892.521. .PP The integer part of the number stores the number of days since the epoch and the fractional part stores the percentage of the day. .PP A date or time in Excel is just like any other number. To have the number display as a date you must apply an Excel number format to it. Here are some examples. .PP .Vb 1 \& #!/usr/bin/perl \-w \& \& use strict; \& use Excel::Writer::XLSX; \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqdate_examples.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& \& $worksheet\->set_column( \*(AqA:A\*(Aq, 30 ); # For extra visibility. \& \& my $number = 39506.5; \& \& $worksheet\->write( \*(AqA1\*(Aq, $number ); # 39506.5 \& \& my $format2 = $workbook\->add_format( num_format => \*(Aqdd/mm/yy\*(Aq ); \& $worksheet\->write( \*(AqA2\*(Aq, $number, $format2 ); # 28/02/08 \& \& my $format3 = $workbook\->add_format( num_format => \*(Aqmm/dd/yy\*(Aq ); \& $worksheet\->write( \*(AqA3\*(Aq, $number, $format3 ); # 02/28/08 \& \& my $format4 = $workbook\->add_format( num_format => \*(Aqd\-m\-yyyy\*(Aq ); \& $worksheet\->write( \*(AqA4\*(Aq, $number, $format4 ); # 28\-2\-2008 \& \& my $format5 = $workbook\->add_format( num_format => \*(Aqdd/mm/yy hh:mm\*(Aq ); \& $worksheet\->write( \*(AqA5\*(Aq, $number, $format5 ); # 28/02/08 12:00 \& \& my $format6 = $workbook\->add_format( num_format => \*(Aqd mmm yyyy\*(Aq ); \& $worksheet\->write( \*(AqA6\*(Aq, $number, $format6 ); # 28 Feb 2008 \& \& my $format7 = $workbook\->add_format( num_format => \*(Aqmmm d yyyy hh:mm AM/PM\*(Aq ); \& $worksheet\->write(\*(AqA7\*(Aq, $number , $format7); # Feb 28 2008 12:00 PM .Ve .SS "Excel::Writer::XLSX doesn't automatically convert date/time strings" .IX Subsection "Excel::Writer::XLSX doesn't automatically convert date/time strings" Excel::Writer::XLSX doesn't automatically convert input date strings into Excel's formatted date numbers due to the large number of possible date formats and also due to the possibility of misinterpretation. .PP For example, does \f(CW\*(C`02/03/04\*(C'\fR mean March 2 2004, February 3 2004 or even March 4 2002. .PP Therefore, in order to handle dates you will have to convert them to numbers and apply an Excel format. Some methods for converting dates are listed in the next section. .PP The most direct way is to convert your dates to the \s-1ISO8601\s0 \f(CW\*(C`yyyy\-mm\-ddThh:mm:ss.sss\*(C'\fR date format and use the \f(CW\*(C`write_date_time()\*(C'\fR worksheet method: .PP .Vb 1 \& $worksheet\->write_date_time( \*(AqA2\*(Aq, \*(Aq2001\-01\-01T12:20\*(Aq, $format ); .Ve .PP See the \f(CW\*(C`write_date_time()\*(C'\fR section of the documentation for more details. .PP A general methodology for handling date strings with \f(CW\*(C`write_date_time()\*(C'\fR is: .PP .Vb 4 \& 1. Identify incoming date/time strings with a regex. \& 2. Extract the component parts of the date/time using the same regex. \& 3. Convert the date/time to the ISO8601 format. \& 4. Write the date/time using write_date_time() and a number format. .Ve .PP Here is an example: .PP .Vb 1 \& #!/usr/bin/perl \-w \& \& use strict; \& use Excel::Writer::XLSX; \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqexample.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& \& # Set the default format for dates. \& my $date_format = $workbook\->add_format( num_format => \*(Aqmmm d yyyy\*(Aq ); \& \& # Increase column width to improve visibility of data. \& $worksheet\->set_column( \*(AqA:C\*(Aq, 20 ); \& \& # Simulate reading from a data source. \& my $row = 0; \& \& while ( ) { \& chomp; \& \& my $col = 0; \& my @data = split \*(Aq \*(Aq; \& \& for my $item ( @data ) { \& \& # Match dates in the following formats: d/m/yy, d/m/yyyy \& if ( $item =~ qr[^(\ed{1,2})/(\ed{1,2})/(\ed{4})$] ) { \& \& # Change to the date format required by write_date_time(). \& my $date = sprintf "%4d\-%02d\-%02dT", $3, $2, $1; \& \& $worksheet\->write_date_time( $row, $col++, $date, \& $date_format ); \& } \& else { \& \& # Just plain data \& $worksheet\->write( $row, $col++, $item ); \& } \& } \& $row++; \& } \& \& _\|_DATA_\|_ \& Item Cost Date \& Book 10 1/9/2007 \& Beer 4 12/9/2007 \& Bed 500 5/10/2007 .Ve .PP For a slightly more advanced solution you can modify the \f(CW\*(C`write()\*(C'\fR method to handle date formats of your choice via the \f(CW\*(C`add_write_handler()\*(C'\fR method. See the \f(CW\*(C`add_write_handler()\*(C'\fR section of the docs and the write_handler3.pl and write_handler4.pl programs in the examples directory of the distro. .SS "Converting dates and times to an Excel date or time" .IX Subsection "Converting dates and times to an Excel date or time" The \f(CW\*(C`write_date_time()\*(C'\fR method above is just one way of handling dates and times. .PP You can also use the \f(CW\*(C`convert_date_time()\*(C'\fR worksheet method to convert from an \s-1ISO8601\s0 style date string to an Excel date and time number. .PP The Excel::Writer::XLSX::Utility module which is included in the distro has date/time handling functions: .PP .Vb 1 \& use Excel::Writer::XLSX::Utility; \& \& $date = xl_date_list(2002, 1, 1); # 37257 \& $date = xl_parse_date("11 July 1997"); # 35622 \& $time = xl_parse_time(\*(Aq3:21:36 PM\*(Aq); # 0.64 \& $date = xl_decode_date_EU("13 May 2002"); # 37389 .Ve .PP Note: some of these functions require additional \s-1CPAN\s0 modules. .PP For date conversions using the \s-1CPAN\s0 \f(CW\*(C`DateTime\*(C'\fR framework see DateTime::Format::Excel http://search.cpan.org/search?dist=DateTime\-Format\-Excel . .SH "OUTLINES AND GROUPING IN EXCEL" .IX Header "OUTLINES AND GROUPING IN EXCEL" Excel allows you to group rows or columns so that they can be hidden or displayed with a single mouse click. This feature is referred to as outlines. .PP Outlines can reduce complex data down to a few salient sub-totals or summaries. .PP This feature is best viewed in Excel but the following is an \s-1ASCII\s0 representation of what a worksheet with three outlines might look like. Rows 3\-4 and rows 7\-8 are grouped at level 2. Rows 2\-9 are grouped at level 1. The lines at the left hand side are called outline level bars. .PP .Vb 10 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& 1 2 3 | | A | B | C | D | ... \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& _ | 1 | A | | | | ... \& | _ | 2 | B | | | | ... \& | | | 3 | (C) | | | | ... \& | | | 4 | (D) | | | | ... \& | \- | 5 | E | | | | ... \& | _ | 6 | F | | | | ... \& | | | 7 | (G) | | | | ... \& | | | 8 | (H) | | | | ... \& | \- | 9 | I | | | | ... \& \- | . | ... | ... | ... | ... | ... .Ve .PP Clicking the minus sign on each of the level 2 outlines will collapse and hide the data as shown in the next figure. The minus sign changes to a plus sign to indicate that the data in the outline is hidden. .PP .Vb 9 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& 1 2 3 | | A | B | C | D | ... \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& _ | 1 | A | | | | ... \& | | 2 | B | | | | ... \& | + | 5 | E | | | | ... \& | | 6 | F | | | | ... \& | + | 9 | I | | | | ... \& \- | . | ... | ... | ... | ... | ... .Ve .PP Clicking on the minus sign on the level 1 outline will collapse the remaining rows as follows: .PP .Vb 5 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& 1 2 3 | | A | B | C | D | ... \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& | 1 | A | | | | ... \& + | . | ... | ... | ... | ... | ... .Ve .PP Grouping in \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR is achieved by setting the outline level via the \f(CW\*(C`set_row()\*(C'\fR and \f(CW\*(C`set_column()\*(C'\fR worksheet methods: .PP .Vb 2 \& set_row( $row, $height, $format, $hidden, $level, $collapsed ) \& set_column( $first_col, $last_col, $width, $format, $hidden, $level, $collapsed ) .Ve .PP The following example sets an outline level of 1 for rows 1 and 2 (zero-indexed) and columns B to G. The parameters \f(CW$height\fR and \f(CW$XF\fR are assigned default values since they are undefined: .PP .Vb 3 \& $worksheet\->set_row( 1, undef, undef, 0, 1 ); \& $worksheet\->set_row( 2, undef, undef, 0, 1 ); \& $worksheet\->set_column( \*(AqB:G\*(Aq, undef, undef, 0, 1 ); .Ve .PP Excel allows up to 7 outline levels. Therefore the \f(CW$level\fR parameter should be in the range \f(CW\*(C`0 <= $level <= 7\*(C'\fR. .PP Rows and columns can be collapsed by setting the \f(CW$hidden\fR flag for the hidden rows/columns and setting the \f(CW$collapsed\fR flag for the row/column that has the collapsed \f(CW\*(C`+\*(C'\fR symbol: .PP .Vb 3 \& $worksheet\->set_row( 1, undef, undef, 1, 1 ); \& $worksheet\->set_row( 2, undef, undef, 1, 1 ); \& $worksheet\->set_row( 3, undef, undef, 0, 0, 1 ); # Collapsed flag. \& \& $worksheet\->set_column( \*(AqB:G\*(Aq, undef, undef, 1, 1 ); \& $worksheet\->set_column( \*(AqH:H\*(Aq, undef, undef, 0, 0, 1 ); # Collapsed flag. .Ve .PP Note: Setting the \f(CW$collapsed\fR flag is particularly important for compatibility with OpenOffice.org and Gnumeric. .PP For a more complete example see the \f(CW\*(C`outline.pl\*(C'\fR and \f(CW\*(C`outline_collapsed.pl\*(C'\fR programs in the examples directory of the distro. .PP Some additional outline properties can be set via the \f(CW\*(C`outline_settings()\*(C'\fR worksheet method, see above. .SH "DATA VALIDATION IN EXCEL" .IX Header "DATA VALIDATION IN EXCEL" Data validation is a feature of Excel which allows you to restrict the data that a users enters in a cell and to display help and warning messages. It also allows you to restrict input to values in a drop down list. .PP A typical use case might be to restrict data in a cell to integer values in a certain range, to provide a help message to indicate the required value and to issue a warning if the input data doesn't meet the stated criteria. In Excel::Writer::XLSX we could do that as follows: .PP .Vb 10 \& $worksheet\->data_validation(\*(AqB3\*(Aq, \& { \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => 1, \& maximum => 100, \& input_title => \*(AqInput an integer:\*(Aq, \& input_message => \*(AqBetween 1 and 100\*(Aq, \& error_message => \*(AqSorry, try again.\*(Aq, \& }); .Ve .PP For more information on data validation see the following Microsoft support article \*(L"Description and examples of data validation in Excel\*(R": . .PP The following sections describe how to use the \f(CW\*(C`data_validation()\*(C'\fR method and its various options. .ie n .SS "data_validation( $row, $col, { parameter => 'value', ... } )" .el .SS "data_validation( \f(CW$row\fP, \f(CW$col\fP, { parameter => 'value', ... } )" .IX Subsection "data_validation( $row, $col, { parameter => 'value', ... } )" The \f(CW\*(C`data_validation()\*(C'\fR method is used to construct an Excel data validation. .PP It can be applied to a single cell or a range of cells. You can pass 3 parameters such as \f(CW\*(C`($row, $col, {...})\*(C'\fR or 5 parameters such as \f(CW\*(C`($first_row, $first_col, $last_row, $last_col, {...})\*(C'\fR. You can also use \f(CW\*(C`A1\*(C'\fR style notation. For example: .PP .Vb 2 \& $worksheet\->data_validation( 0, 0, {...} ); \& $worksheet\->data_validation( 0, 0, 4, 1, {...} ); \& \& # Which are the same as: \& \& $worksheet\->data_validation( \*(AqA1\*(Aq, {...} ); \& $worksheet\->data_validation( \*(AqA1:B5\*(Aq, {...} ); .Ve .PP See also the note about \*(L"Cell notation\*(R" for more information. .PP The last parameter in \f(CW\*(C`data_validation()\*(C'\fR must be a hash ref containing the parameters that describe the type and style of the data validation. The allowable parameters are: .PP .Vb 6 \& validate \& criteria \& value | minimum | source \& maximum \& ignore_blank \& dropdown \& \& input_title \& input_message \& show_input \& \& error_title \& error_message \& error_type \& show_error .Ve .PP These parameters are explained in the following sections. Most of the parameters are optional, however, you will generally require the three main options \f(CW\*(C`validate\*(C'\fR, \f(CW\*(C`criteria\*(C'\fR and \f(CW\*(C`value\*(C'\fR. .PP .Vb 6 \& $worksheet\->data_validation(\*(AqB3\*(Aq, \& { \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 100, \& }); .Ve .PP The \f(CW\*(C`data_validation\*(C'\fR method returns: .PP .Vb 4 \& 0 for success. \& \-1 for insufficient number of arguments. \& \-2 for row or column out of bounds. \& \-3 for incorrect parameter or value. .Ve .SS "validate" .IX Subsection "validate" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`validate\*(C'\fR parameter is used to set the type of data that you wish to validate. It is always required and it has no default value. Allowable values are: .PP .Vb 8 \& any \& integer \& decimal \& list \& date \& time \& length \& custom .Ve .IP "\(bu" 4 \&\fBany\fR is used to specify that the type of data is unrestricted. This is the same as not applying a data validation. It is only provided for completeness and isn't used very often in the context of Excel::Writer::XLSX. .IP "\(bu" 4 \&\fBinteger\fR restricts the cell to integer values. Excel refers to this as 'whole number'. .Sp .Vb 3 \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 100, .Ve .IP "\(bu" 4 \&\fBdecimal\fR restricts the cell to decimal values. .Sp .Vb 3 \& validate => \*(Aqdecimal\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 38.6, .Ve .IP "\(bu" 4 \&\fBlist\fR restricts the cell to a set of user specified values. These can be passed in an array ref or as a cell range (named ranges aren't currently supported): .Sp .Vb 4 \& validate => \*(Aqlist\*(Aq, \& value => [\*(Aqopen\*(Aq, \*(Aqhigh\*(Aq, \*(Aqclose\*(Aq], \& # Or like this: \& value => \*(AqB1:B3\*(Aq, .Ve .Sp Excel requires that range references are only to cells on the same worksheet. .IP "\(bu" 4 \&\fBdate\fR restricts the cell to date values. Dates in Excel are expressed as integer values but you can also pass an \s-1ISO8601\s0 style string as used in \f(CW\*(C`write_date_time()\*(C'\fR. See also \*(L"\s-1DATES\s0 \s-1AND\s0 \s-1TIME\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R" for more information about working with Excel's dates. .Sp .Vb 5 \& validate => \*(Aqdate\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 39653, # 24 July 2008 \& # Or like this: \& value => \*(Aq2008\-07\-24T\*(Aq, .Ve .IP "\(bu" 4 \&\fBtime\fR restricts the cell to time values. Times in Excel are expressed as decimal values but you can also pass an \s-1ISO8601\s0 style string as used in \f(CW\*(C`write_date_time()\*(C'\fR. See also \*(L"\s-1DATES\s0 \s-1AND\s0 \s-1TIME\s0 \s-1IN\s0 \s-1EXCEL\s0\*(R" for more information about working with Excel's times. .Sp .Vb 5 \& validate => \*(Aqtime\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 0.5, # Noon \& # Or like this: \& value => \*(AqT12:00:00\*(Aq, .Ve .IP "\(bu" 4 \&\fBlength\fR restricts the cell data based on an integer string length. Excel refers to this as 'Text length'. .Sp .Vb 3 \& validate => \*(Aqlength\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 10, .Ve .IP "\(bu" 4 \&\fBcustom\fR restricts the cell based on an external Excel formula that returns a \f(CW\*(C`TRUE/FALSE\*(C'\fR value. .Sp .Vb 2 \& validate => \*(Aqcustom\*(Aq, \& value => \*(Aq=IF(A10>B10,TRUE,FALSE)\*(Aq, .Ve .SS "criteria" .IX Subsection "criteria" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`criteria\*(C'\fR parameter is used to set the criteria by which the data in the cell is validated. It is almost always required except for the \f(CW\*(C`list\*(C'\fR and \f(CW\*(C`custom\*(C'\fR validate options. It has no default value. Allowable values are: .PP .Vb 8 \& \*(Aqbetween\*(Aq \& \*(Aqnot between\*(Aq \& \*(Aqequal to\*(Aq | \*(Aq==\*(Aq | \*(Aq=\*(Aq \& \*(Aqnot equal to\*(Aq | \*(Aq!=\*(Aq | \*(Aq<>\*(Aq \& \*(Aqgreater than\*(Aq | \*(Aq>\*(Aq \& \*(Aqless than\*(Aq | \*(Aq<\*(Aq \& \*(Aqgreater than or equal to\*(Aq | \*(Aq>=\*(Aq \& \*(Aqless than or equal to\*(Aq | \*(Aq<=\*(Aq .Ve .PP You can either use Excel's textual description strings, in the first column above, or the more common symbolic alternatives. The following are equivalent: .PP .Vb 3 \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aqgreater than\*(Aq, \& value => 100, \& \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 100, .Ve .PP The \f(CW\*(C`list\*(C'\fR and \f(CW\*(C`custom\*(C'\fR validate options don't require a \f(CW\*(C`criteria\*(C'\fR. If you specify one it will be ignored. .PP .Vb 2 \& validate => \*(Aqlist\*(Aq, \& value => [\*(Aqopen\*(Aq, \*(Aqhigh\*(Aq, \*(Aqclose\*(Aq], \& \& validate => \*(Aqcustom\*(Aq, \& value => \*(Aq=IF(A10>B10,TRUE,FALSE)\*(Aq, .Ve .SS "value | minimum | source" .IX Subsection "value | minimum | source" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`value\*(C'\fR parameter is used to set the limiting value to which the \f(CW\*(C`criteria\*(C'\fR is applied. It is always required and it has no default value. You can also use the synonyms \f(CW\*(C`minimum\*(C'\fR or \f(CW\*(C`source\*(C'\fR to make the validation a little clearer and closer to Excel's description of the parameter: .PP .Vb 4 \& # Use \*(Aqvalue\*(Aq \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 100, \& \& # Use \*(Aqminimum\*(Aq \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => 1, \& maximum => 100, \& \& # Use \*(Aqsource\*(Aq \& validate => \*(Aqlist\*(Aq, \& source => \*(Aq$B$1:$B$3\*(Aq, .Ve .SS "maximum" .IX Subsection "maximum" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`maximum\*(C'\fR parameter is used to set the upper limiting value when the \f(CW\*(C`criteria\*(C'\fR is either \f(CW\*(Aqbetween\*(Aq\fR or \f(CW\*(Aqnot between\*(Aq\fR: .PP .Vb 4 \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => 1, \& maximum => 100, .Ve .SS "ignore_blank" .IX Subsection "ignore_blank" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`ignore_blank\*(C'\fR parameter is used to toggle on and off the 'Ignore blank' option in the Excel data validation dialog. When the option is on the data validation is not applied to blank data in the cell. It is on by default. .PP .Vb 1 \& ignore_blank => 0, # Turn the option off .Ve .SS "dropdown" .IX Subsection "dropdown" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`dropdown\*(C'\fR parameter is used to toggle on and off the 'In\-cell dropdown' option in the Excel data validation dialog. When the option is on a dropdown list will be shown for \f(CW\*(C`list\*(C'\fR validations. It is on by default. .PP .Vb 1 \& dropdown => 0, # Turn the option off .Ve .SS "input_title" .IX Subsection "input_title" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`input_title\*(C'\fR parameter is used to set the title of the input message that is displayed when a cell is entered. It has no default value and is only displayed if the input message is displayed. See the \f(CW\*(C`input_message\*(C'\fR parameter below. .PP .Vb 1 \& input_title => \*(AqThis is the input title\*(Aq, .Ve .PP The maximum title length is 32 characters. .SS "input_message" .IX Subsection "input_message" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`input_message\*(C'\fR parameter is used to set the input message that is displayed when a cell is entered. It has no default value. .PP .Vb 6 \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => 1, \& maximum => 100, \& input_title => \*(AqEnter the applied discount:\*(Aq, \& input_message => \*(Aqbetween 1 and 100\*(Aq, .Ve .PP The message can be split over several lines using newlines, \f(CW"\en"\fR in double quoted strings. .PP .Vb 1 \& input_message => "This is\ena test.", .Ve .PP The maximum message length is 255 characters. .SS "show_input" .IX Subsection "show_input" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`show_input\*(C'\fR parameter is used to toggle on and off the 'Show input message when cell is selected' option in the Excel data validation dialog. When the option is off an input message is not displayed even if it has been set using \f(CW\*(C`input_message\*(C'\fR. It is on by default. .PP .Vb 1 \& show_input => 0, # Turn the option off .Ve .SS "error_title" .IX Subsection "error_title" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`error_title\*(C'\fR parameter is used to set the title of the error message that is displayed when the data validation criteria is not met. The default error title is 'Microsoft Excel'. .PP .Vb 1 \& error_title => \*(AqInput value is not valid\*(Aq, .Ve .PP The maximum title length is 32 characters. .SS "error_message" .IX Subsection "error_message" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`error_message\*(C'\fR parameter is used to set the error message that is displayed when a cell is entered. The default error message is \*(L"The value you entered is not valid.\enA user has restricted values that can be entered into the cell.\*(R". .PP .Vb 6 \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => 1, \& maximum => 100, \& error_title => \*(AqInput value is not valid\*(Aq, \& error_message => \*(AqIt should be an integer between 1 and 100\*(Aq, .Ve .PP The message can be split over several lines using newlines, \f(CW"\en"\fR in double quoted strings. .PP .Vb 1 \& input_message => "This is\ena test.", .Ve .PP The maximum message length is 255 characters. .SS "error_type" .IX Subsection "error_type" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`error_type\*(C'\fR parameter is used to specify the type of error dialog that is displayed. There are 3 options: .PP .Vb 3 \& \*(Aqstop\*(Aq \& \*(Aqwarning\*(Aq \& \*(Aqinformation\*(Aq .Ve .PP The default is \f(CW\*(Aqstop\*(Aq\fR. .SS "show_error" .IX Subsection "show_error" This parameter is passed in a hash ref to \f(CW\*(C`data_validation()\*(C'\fR. .PP The \f(CW\*(C`show_error\*(C'\fR parameter is used to toggle on and off the 'Show error alert after invalid data is entered' option in the Excel data validation dialog. When the option is off an error message is not displayed even if it has been set using \f(CW\*(C`error_message\*(C'\fR. It is on by default. .PP .Vb 1 \& show_error => 0, # Turn the option off .Ve .SS "Data Validation Examples" .IX Subsection "Data Validation Examples" Example 1. Limiting input to an integer greater than a fixed value. .PP .Vb 6 \& $worksheet\->data_validation(\*(AqA1\*(Aq, \& { \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 0, \& }); .Ve .PP Example 2. Limiting input to an integer greater than a fixed value where the value is referenced from a cell. .PP .Vb 6 \& $worksheet\->data_validation(\*(AqA2\*(Aq, \& { \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => \*(Aq=E3\*(Aq, \& }); .Ve .PP Example 3. Limiting input to a decimal in a fixed range. .PP .Vb 7 \& $worksheet\->data_validation(\*(AqA3\*(Aq, \& { \& validate => \*(Aqdecimal\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => 0.1, \& maximum => 0.5, \& }); .Ve .PP Example 4. Limiting input to a value in a dropdown list. .PP .Vb 5 \& $worksheet\->data_validation(\*(AqA4\*(Aq, \& { \& validate => \*(Aqlist\*(Aq, \& source => [\*(Aqopen\*(Aq, \*(Aqhigh\*(Aq, \*(Aqclose\*(Aq], \& }); .Ve .PP Example 5. Limiting input to a value in a dropdown list where the list is specified as a cell range. .PP .Vb 5 \& $worksheet\->data_validation(\*(AqA5\*(Aq, \& { \& validate => \*(Aqlist\*(Aq, \& source => \*(Aq=$E$4:$G$4\*(Aq, \& }); .Ve .PP Example 6. Limiting input to a date in a fixed range. .PP .Vb 7 \& $worksheet\->data_validation(\*(AqA6\*(Aq, \& { \& validate => \*(Aqdate\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => \*(Aq2008\-01\-01T\*(Aq, \& maximum => \*(Aq2008\-12\-12T\*(Aq, \& }); .Ve .PP Example 7. Displaying a message when the cell is selected. .PP .Vb 9 \& $worksheet\->data_validation(\*(AqA7\*(Aq, \& { \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => 1, \& maximum => 100, \& input_title => \*(AqEnter an integer:\*(Aq, \& input_message => \*(Aqbetween 1 and 100\*(Aq, \& }); .Ve .PP See also the \f(CW\*(C`data_validate.pl\*(C'\fR program in the examples directory of the distro. .SH "CONDITIONAL FORMATTING IN EXCEL" .IX Header "CONDITIONAL FORMATTING IN EXCEL" Conditional formatting is a feature of Excel which allows you to apply a format to a cell or a range of cells based on a certain criteria. .PP For example the following criteria is used to highlight cells >= 50 in red in the \f(CW\*(C`conditional_format.pl\*(C'\fR example from the distro: .PP .Vb 9 \& # Write a conditional format over a range. \& $worksheet\->conditional_formatting( \*(AqB3:K12\*(Aq, \& { \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aq>=\*(Aq, \& value => 50, \& format => $format1, \& } \& ); .Ve .ie n .SS "conditional_formatting( $row, $col, { parameter => 'value', ... } )" .el .SS "conditional_formatting( \f(CW$row\fP, \f(CW$col\fP, { parameter => 'value', ... } )" .IX Subsection "conditional_formatting( $row, $col, { parameter => 'value', ... } )" The \f(CW\*(C`conditional_formatting()\*(C'\fR method is used to apply formatting based on user defined criteria to an Excel::Writer::XLSX file. .PP It can be applied to a single cell or a range of cells. You can pass 3 parameters such as \f(CW\*(C`($row, $col, {...})\*(C'\fR or 5 parameters such as \f(CW\*(C`($first_row, $first_col, $last_row, $last_col, {...})\*(C'\fR. You can also use \f(CW\*(C`A1\*(C'\fR style notation. For example: .PP .Vb 2 \& $worksheet\->conditional_formatting( 0, 0, {...} ); \& $worksheet\->conditional_formatting( 0, 0, 4, 1, {...} ); \& \& # Which are the same as: \& \& $worksheet\->conditional_formatting( \*(AqA1\*(Aq, {...} ); \& $worksheet\->conditional_formatting( \*(AqA1:B5\*(Aq, {...} ); .Ve .PP See also the note about \*(L"Cell notation\*(R" for more information. .PP Using \f(CW\*(C`A1\*(C'\fR style notation is also possible to specify non-contiguous ranges, separated by a comma. For example: .PP .Vb 1 \& $worksheet\->conditional_formatting( \*(AqA1:D5,A8:D12\*(Aq, {...} ); .Ve .PP The last parameter in \f(CW\*(C`conditional_formatting()\*(C'\fR must be a hash ref containing the parameters that describe the type and style of the data validation. The main parameters are: .PP .Vb 6 \& type \& format \& criteria \& value \& minimum \& maximum .Ve .PP Other, less commonly used parameters are: .PP .Vb 10 \& min_type \& mid_type \& max_type \& min_value \& mid_value \& max_value \& min_color \& mid_color \& max_color \& bar_color .Ve .PP Additional parameters which are used for specific conditional format types are shown in the relevant sections below. .SS "type" .IX Subsection "type" This parameter is passed in a hash ref to \f(CW\*(C`conditional_formatting()\*(C'\fR. .PP The \f(CW\*(C`type\*(C'\fR parameter is used to set the type of conditional formatting that you wish to apply. It is always required and it has no default value. Allowable \f(CW\*(C`type\*(C'\fR values and their associated parameters are: .PP .Vb 6 \& Type Parameters \& ==== ========== \& cell criteria \& value \& minimum \& maximum \& \& date criteria \& value \& minimum \& maximum \& \& time_period criteria \& \& text criteria \& value \& \& average criteria \& \& duplicate (none) \& \& unique (none) \& \& top criteria \& value \& \& bottom criteria \& value \& \& blanks (none) \& \& no_blanks (none) \& \& errors (none) \& \& no_errors (none) \& \& 2_color_scale (none) \& \& 3_color_scale (none) \& \& data_bar (none) \& \& formula criteria .Ve .PP All conditional formatting types have a \f(CW\*(C`format\*(C'\fR parameter, see below. Other types and parameters such as icon sets will be added in time. .SS "type => 'cell'" .IX Subsection "type => 'cell'" This is the most common conditional formatting type. It is used when a format is applied to a cell based on a simple criterion. For example: .PP .Vb 8 \& $worksheet\->conditional_formatting( \*(AqA1\*(Aq, \& { \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aqgreater than\*(Aq, \& value => 5, \& format => $red_format, \& } \& ); .Ve .PP Or, using the \f(CW\*(C`between\*(C'\fR criteria: .PP .Vb 9 \& $worksheet\->conditional_formatting( \*(AqC1:C4\*(Aq, \& { \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => 20, \& maximum => 30, \& format => $green_format, \& } \& ); .Ve .SS "criteria" .IX Subsection "criteria" The \f(CW\*(C`criteria\*(C'\fR parameter is used to set the criteria by which the cell data will be evaluated. It has no default value. The most common criteria as applied to \f(CW\*(C`{ type => \*(Aqcell\*(Aq }\*(C'\fR are: .PP .Vb 8 \& \*(Aqbetween\*(Aq \& \*(Aqnot between\*(Aq \& \*(Aqequal to\*(Aq | \*(Aq==\*(Aq | \*(Aq=\*(Aq \& \*(Aqnot equal to\*(Aq | \*(Aq!=\*(Aq | \*(Aq<>\*(Aq \& \*(Aqgreater than\*(Aq | \*(Aq>\*(Aq \& \*(Aqless than\*(Aq | \*(Aq<\*(Aq \& \*(Aqgreater than or equal to\*(Aq | \*(Aq>=\*(Aq \& \*(Aqless than or equal to\*(Aq | \*(Aq<=\*(Aq .Ve .PP You can either use Excel's textual description strings, in the first column above, or the more common symbolic alternatives. .PP Additional criteria which are specific to other conditional format types are shown in the relevant sections below. .SS "value" .IX Subsection "value" The \f(CW\*(C`value\*(C'\fR is generally used along with the \f(CW\*(C`criteria\*(C'\fR parameter to set the rule by which the cell data will be evaluated. .PP .Vb 4 \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 5 \& format => $format, .Ve .PP The \f(CW\*(C`value\*(C'\fR property can also be an cell reference. .PP .Vb 4 \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => \*(Aq$C$1\*(Aq, \& format => $format, .Ve .SS "format" .IX Subsection "format" The \f(CW\*(C`format\*(C'\fR parameter is used to specify the format that will be applied to the cell when the conditional formatting criterion is met. The format is created using the \f(CW\*(C`add_format()\*(C'\fR method in the same way as cell formats: .PP .Vb 1 \& $format = $workbook\->add_format( bold => 1, italic => 1 ); \& \& $worksheet\->conditional_formatting( \*(AqA1\*(Aq, \& { \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aq>\*(Aq, \& value => 5 \& format => $format, \& } \& ); .Ve .PP The conditional format follows the same rules as in Excel: it is superimposed over the existing cell format and not all font and border properties can be modified. Font properties that can't be modified are font name, font size, superscript and subscript. The border property that cannot be modified is diagonal borders. .PP Excel specifies some default formats to be used with conditional formatting. You can replicate them using the following Excel::Writer::XLSX formats: .PP .Vb 1 \& # Light red fill with dark red text. \& \& my $format1 = $workbook\->add_format( \& bg_color => \*(Aq#FFC7CE\*(Aq, \& color => \*(Aq#9C0006\*(Aq, \& ); \& \& # Light yellow fill with dark yellow text. \& \& my $format2 = $workbook\->add_format( \& bg_color => \*(Aq#FFEB9C\*(Aq, \& color => \*(Aq#9C6500\*(Aq, \& ); \& \& # Green fill with dark green text. \& \& my $format3 = $workbook\->add_format( \& bg_color => \*(Aq#C6EFCE\*(Aq, \& color => \*(Aq#006100\*(Aq, \& ); .Ve .SS "minimum" .IX Subsection "minimum" The \f(CW\*(C`minimum\*(C'\fR parameter is used to set the lower limiting value when the \f(CW\*(C`criteria\*(C'\fR is either \f(CW\*(Aqbetween\*(Aq\fR or \f(CW\*(Aqnot between\*(Aq\fR: .PP .Vb 4 \& validate => \*(Aqinteger\*(Aq, \& criteria => \*(Aqbetween\*(Aq, \& minimum => 1, \& maximum => 100, .Ve .SS "maximum" .IX Subsection "maximum" The \f(CW\*(C`maximum\*(C'\fR parameter is used to set the upper limiting value when the \f(CW\*(C`criteria\*(C'\fR is either \f(CW\*(Aqbetween\*(Aq\fR or \f(CW\*(Aqnot between\*(Aq\fR. See the previous example. .SS "type => 'date'" .IX Subsection "type => 'date'" The \f(CW\*(C`date\*(C'\fR type is the same as the \f(CW\*(C`cell\*(C'\fR type and uses the same criteria and values. However it allows the \f(CW\*(C`value\*(C'\fR, \f(CW\*(C`minimum\*(C'\fR and \f(CW\*(C`maximum\*(C'\fR properties to be specified in the \s-1ISO8601\s0 \f(CW\*(C`yyyy\-mm\-ddThh:mm:ss.sss\*(C'\fR date format which is detailed in the \f(CW\*(C`write_date_time()\*(C'\fR method. .PP .Vb 8 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqdate\*(Aq, \& criteria => \*(Aqgreater than\*(Aq, \& value => \*(Aq2011\-01\-01T\*(Aq, \& format => $format, \& } \& ); .Ve .SS "type => 'time_period'" .IX Subsection "type => 'time_period'" The \f(CW\*(C`time_period\*(C'\fR type is used to specify Excel's \*(L"Dates Occurring\*(R" style conditional format. .PP .Vb 7 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqtime_period\*(Aq, \& criteria => \*(Aqyesterday\*(Aq, \& format => $format, \& } \& ); .Ve .PP The period is set in the \f(CW\*(C`criteria\*(C'\fR and can have one of the following values: .PP .Vb 9 \& criteria => \*(Aqyesterday\*(Aq, \& criteria => \*(Aqtoday\*(Aq, \& criteria => \*(Aqlast 7 days\*(Aq, \& criteria => \*(Aqlast week\*(Aq, \& criteria => \*(Aqthis week\*(Aq, \& criteria => \*(Aqnext week\*(Aq, \& criteria => \*(Aqlast month\*(Aq, \& criteria => \*(Aqthis month\*(Aq, \& criteria => \*(Aqnext month\*(Aq .Ve .SS "type => 'text'" .IX Subsection "type => 'text'" The \f(CW\*(C`text\*(C'\fR type is used to specify Excel's \*(L"Specific Text\*(R" style conditional format. It is used to do simple string matching using the \f(CW\*(C`criteria\*(C'\fR and \f(CW\*(C`value\*(C'\fR parameters: .PP .Vb 8 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqtext\*(Aq, \& criteria => \*(Aqcontaining\*(Aq, \& value => \*(Aqfoo\*(Aq, \& format => $format, \& } \& ); .Ve .PP The \f(CW\*(C`criteria\*(C'\fR can have one of the following values: .PP .Vb 4 \& criteria => \*(Aqcontaining\*(Aq, \& criteria => \*(Aqnot containing\*(Aq, \& criteria => \*(Aqbegins with\*(Aq, \& criteria => \*(Aqends with\*(Aq, .Ve .PP The \f(CW\*(C`value\*(C'\fR parameter should be a string or single character. .SS "type => 'average'" .IX Subsection "type => 'average'" The \f(CW\*(C`average\*(C'\fR type is used to specify Excel's \*(L"Average\*(R" style conditional format. .PP .Vb 7 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqaverage\*(Aq, \& criteria => \*(Aqabove\*(Aq, \& format => $format, \& } \& ); .Ve .PP The type of average for the conditional format range is specified by the \f(CW\*(C`criteria\*(C'\fR: .PP .Vb 10 \& criteria => \*(Aqabove\*(Aq, \& criteria => \*(Aqbelow\*(Aq, \& criteria => \*(Aqequal or above\*(Aq, \& criteria => \*(Aqequal or below\*(Aq, \& criteria => \*(Aq1 std dev above\*(Aq, \& criteria => \*(Aq1 std dev below\*(Aq, \& criteria => \*(Aq2 std dev above\*(Aq, \& criteria => \*(Aq2 std dev below\*(Aq, \& criteria => \*(Aq3 std dev above\*(Aq, \& criteria => \*(Aq3 std dev below\*(Aq, .Ve .SS "type => 'duplicate'" .IX Subsection "type => 'duplicate'" The \f(CW\*(C`duplicate\*(C'\fR type is used to highlight duplicate cells in a range: .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqduplicate\*(Aq, \& format => $format, \& } \& ); .Ve .SS "type => 'unique'" .IX Subsection "type => 'unique'" The \f(CW\*(C`unique\*(C'\fR type is used to highlight unique cells in a range: .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqunique\*(Aq, \& format => $format, \& } \& ); .Ve .SS "type => 'top'" .IX Subsection "type => 'top'" The \f(CW\*(C`top\*(C'\fR type is used to specify the top \f(CW\*(C`n\*(C'\fR values by number or percentage in a range: .PP .Vb 7 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqtop\*(Aq, \& value => 10, \& format => $format, \& } \& ); .Ve .PP The \f(CW\*(C`criteria\*(C'\fR can be used to indicate that a percentage condition is required: .PP .Vb 8 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqtop\*(Aq, \& value => 10, \& criteria => \*(Aq%\*(Aq, \& format => $format, \& } \& ); .Ve .SS "type => 'bottom'" .IX Subsection "type => 'bottom'" The \f(CW\*(C`bottom\*(C'\fR type is used to specify the bottom \f(CW\*(C`n\*(C'\fR values by number or percentage in a range. .PP It takes the same parameters as \f(CW\*(C`top\*(C'\fR, see above. .SS "type => 'blanks'" .IX Subsection "type => 'blanks'" The \f(CW\*(C`blanks\*(C'\fR type is used to highlight blank cells in a range: .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqblanks\*(Aq, \& format => $format, \& } \& ); .Ve .SS "type => 'no_blanks'" .IX Subsection "type => 'no_blanks'" The \f(CW\*(C`no_blanks\*(C'\fR type is used to highlight non blank cells in a range: .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqno_blanks\*(Aq, \& format => $format, \& } \& ); .Ve .SS "type => 'errors'" .IX Subsection "type => 'errors'" The \f(CW\*(C`errors\*(C'\fR type is used to highlight error cells in a range: .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqerrors\*(Aq, \& format => $format, \& } \& ); .Ve .SS "type => 'no_errors'" .IX Subsection "type => 'no_errors'" The \f(CW\*(C`no_errors\*(C'\fR type is used to highlight non error cells in a range: .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqno_errors\*(Aq, \& format => $format, \& } \& ); .Ve .SS "type => '2_color_scale'" .IX Subsection "type => '2_color_scale'" The \f(CW\*(C`2_color_scale\*(C'\fR type is used to specify Excel's \*(L"2 Color Scale\*(R" style conditional format. .PP .Vb 5 \& $worksheet\->conditional_formatting( \*(AqA1:A12\*(Aq, \& { \& type => \*(Aq2_color_scale\*(Aq, \& } \& ); .Ve .PP This conditional type can be modified with \f(CW\*(C`min_type\*(C'\fR, \f(CW\*(C`max_type\*(C'\fR, \f(CW\*(C`min_value\*(C'\fR, \f(CW\*(C`max_value\*(C'\fR, \f(CW\*(C`min_color\*(C'\fR and \f(CW\*(C`max_color\*(C'\fR, see below. .SS "type => '3_color_scale'" .IX Subsection "type => '3_color_scale'" The \f(CW\*(C`3_color_scale\*(C'\fR type is used to specify Excel's \*(L"3 Color Scale\*(R" style conditional format. .PP .Vb 5 \& $worksheet\->conditional_formatting( \*(AqA1:A12\*(Aq, \& { \& type => \*(Aq3_color_scale\*(Aq, \& } \& ); .Ve .PP This conditional type can be modified with \f(CW\*(C`min_type\*(C'\fR, \f(CW\*(C`mid_type\*(C'\fR, \f(CW\*(C`max_type\*(C'\fR, \f(CW\*(C`min_value\*(C'\fR, \f(CW\*(C`mid_value\*(C'\fR, \f(CW\*(C`max_value\*(C'\fR, \f(CW\*(C`min_color\*(C'\fR, \f(CW\*(C`mid_color\*(C'\fR and \f(CW\*(C`max_color\*(C'\fR, see below. .SS "type => 'data_bar'" .IX Subsection "type => 'data_bar'" The \f(CW\*(C`data_bar\*(C'\fR type is used to specify Excel's \*(L"Data Bar\*(R" style conditional format. .PP .Vb 5 \& $worksheet\->conditional_formatting( \*(AqA1:A12\*(Aq, \& { \& type => \*(Aqdata_bar\*(Aq, \& } \& ); .Ve .PP This conditional type can be modified with \f(CW\*(C`min_type\*(C'\fR, \f(CW\*(C`max_type\*(C'\fR, \f(CW\*(C`min_value\*(C'\fR, \f(CW\*(C`max_value\*(C'\fR and \f(CW\*(C`bar_color\*(C'\fR, see below. .SS "type => 'formula'" .IX Subsection "type => 'formula'" The \f(CW\*(C`formula\*(C'\fR type is used to specify a conditional format based on a user defined formula: .PP .Vb 7 \& $worksheet\->conditional_formatting( \*(AqA1:A4\*(Aq, \& { \& type => \*(Aqformula\*(Aq, \& criteria => \*(Aq=$A$1 > 5\*(Aq, \& format => $format, \& } \& ); .Ve .PP The formula is specified in the \f(CW\*(C`criteria\*(C'\fR. .SS "min_type, mid_type, max_type" .IX Subsection "min_type, mid_type, max_type" The \f(CW\*(C`min_type\*(C'\fR and \f(CW\*(C`max_type\*(C'\fR properties are available when the conditional formatting type is \f(CW\*(C`2_color_scale\*(C'\fR, \f(CW\*(C`3_color_scale\*(C'\fR or \f(CW\*(C`data_bar\*(C'\fR. The \f(CW\*(C`mid_type\*(C'\fR is available for \f(CW\*(C`3_color_scale\*(C'\fR. The properties are used as follows: .PP .Vb 7 \& $worksheet\->conditional_formatting( \*(AqA1:A12\*(Aq, \& { \& type => \*(Aq2_color_scale\*(Aq, \& min_type => \*(Aqpercent\*(Aq, \& max_type => \*(Aqpercent\*(Aq, \& } \& ); .Ve .PP The available min/mid/max types are: .PP .Vb 4 \& num \& percent \& percentile \& formula .Ve .SS "min_value, mid_value, max_value" .IX Subsection "min_value, mid_value, max_value" The \f(CW\*(C`min_value\*(C'\fR and \f(CW\*(C`max_value\*(C'\fR properties are available when the conditional formatting type is \f(CW\*(C`2_color_scale\*(C'\fR, \f(CW\*(C`3_color_scale\*(C'\fR or \f(CW\*(C`data_bar\*(C'\fR. The \f(CW\*(C`mid_value\*(C'\fR is available for \f(CW\*(C`3_color_scale\*(C'\fR. The properties are used as follows: .PP .Vb 7 \& $worksheet\->conditional_formatting( \*(AqA1:A12\*(Aq, \& { \& type => \*(Aq2_color_scale\*(Aq, \& min_value => 10, \& max_value => 90, \& } \& ); .Ve .SS "min_color, mid_color, max_color, bar_color" .IX Subsection "min_color, mid_color, max_color, bar_color" The \f(CW\*(C`min_color\*(C'\fR and \f(CW\*(C`max_color\*(C'\fR properties are available when the conditional formatting type is \f(CW\*(C`2_color_scale\*(C'\fR, \f(CW\*(C`3_color_scale\*(C'\fR or \f(CW\*(C`data_bar\*(C'\fR. The \f(CW\*(C`mid_color\*(C'\fR is available for \f(CW\*(C`3_color_scale\*(C'\fR. The properties are used as follows: .PP .Vb 7 \& $worksheet\->conditional_formatting( \*(AqA1:A12\*(Aq, \& { \& type => \*(Aq2_color_scale\*(Aq, \& min_color => "#C5D9F1", \& max_color => "#538ED5", \& } \& ); .Ve .PP The color can be specifies as an Excel::Writer::XLSX color index or, more usefully, as a \s-1HTML\s0 style \s-1RGB\s0 hex number, as shown above. .SS "Conditional Formatting Examples" .IX Subsection "Conditional Formatting Examples" Example 1. Highlight cells greater than an integer value. .PP .Vb 8 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aqgreater than\*(Aq, \& value => 5, \& format => $format, \& } \& ); .Ve .PP Example 2. Highlight cells greater than a value in a reference cell. .PP .Vb 8 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aqgreater than\*(Aq, \& value => \*(Aq$H$1\*(Aq, \& format => $format, \& } \& ); .Ve .PP Example 3. Highlight cells greater than a certain date: .PP .Vb 8 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqdate\*(Aq, \& criteria => \*(Aqgreater than\*(Aq, \& value => \*(Aq2011\-01\-01T\*(Aq, \& format => $format, \& } \& ); .Ve .PP Example 4. Highlight cells with a date in the last seven days: .PP .Vb 7 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqtime_period\*(Aq, \& criteria => \*(Aqlast 7 days\*(Aq, \& format => $format, \& } \& ); .Ve .PP Example 5. Highlight cells with strings starting with the letter \f(CW\*(C`b\*(C'\fR: .PP .Vb 8 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqtext\*(Aq, \& criteria => \*(Aqbegins with\*(Aq, \& value => \*(Aqb\*(Aq, \& format => $format, \& } \& ); .Ve .PP Example 6. Highlight cells that are 1 std deviation above the average for the range: .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqaverage\*(Aq, \& format => $format, \& } \& ); .Ve .PP Example 7. Highlight duplicate cells in a range: .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqduplicate\*(Aq, \& format => $format, \& } \& ); .Ve .PP Example 8. Highlight unique cells in a range. .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqunique\*(Aq, \& format => $format, \& } \& ); .Ve .PP Example 9. Highlight the top 10 cells. .PP .Vb 7 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqtop\*(Aq, \& value => 10, \& format => $format, \& } \& ); .Ve .PP Example 10. Highlight blank cells. .PP .Vb 6 \& $worksheet\->conditional_formatting( \*(AqA1:F10\*(Aq, \& { \& type => \*(Aqblanks\*(Aq, \& format => $format, \& } \& ); .Ve .PP See also the \f(CW\*(C`conditional_format.pl\*(C'\fR example program in \f(CW\*(C`EXAMPLES\*(C'\fR. .SH "SPARKLINES IN EXCEL" .IX Header "SPARKLINES IN EXCEL" Sparklines are a feature of Excel 2010+ which allows you to add small charts to worksheet cells. These are useful for showing visual trends in data in a compact format. .PP In Excel::Writer::XLSX Sparklines can be added to cells using the \f(CW\*(C`add_sparkline()\*(C'\fR worksheet method: .PP .Vb 8 \& $worksheet\->add_sparkline( \& { \& location => \*(AqF2\*(Aq, \& range => \*(AqSheet1!A2:E2\*(Aq, \& type => \*(Aqcolumn\*(Aq, \& style => 12, \& } \& ); .Ve .PP \&\fBNote:\fR Sparklines are a feature of Excel 2010+ only. You can write them to an \s-1XLSX\s0 file that can be read by Excel 2007 but they won't be displayed. .SS "add_sparkline( { parameter => 'value', ... } )" .IX Subsection "add_sparkline( { parameter => 'value', ... } )" The \f(CW\*(C`add_sparkline()\*(C'\fR worksheet method is used to add sparklines to a cell or a range of cells. .PP The parameters to \f(CW\*(C`add_sparkline()\*(C'\fR must be passed in a hash ref. The main sparkline parameters are: .PP .Vb 4 \& location (required) \& range (required) \& type \& style \& \& markers \& negative_points \& axis \& reverse .Ve .PP Other, less commonly used parameters are: .PP .Vb 10 \& high_point \& low_point \& first_point \& last_point \& max \& min \& empty_cells \& show_hidden \& date_axis \& weight \& \& series_color \& negative_color \& markers_color \& first_color \& last_color \& high_color \& low_color .Ve .PP These parameters are explained in the sections below: .SS "location" .IX Subsection "location" This is the cell where the sparkline will be displayed: .PP .Vb 1 \& location => \*(AqF1\*(Aq .Ve .PP The \f(CW\*(C`location\*(C'\fR should be a single cell. (For multiple cells see \*(L"Grouped Sparklines\*(R" below). .PP To specify the location in row-column notation use the \f(CW\*(C`xl_rowcol_to_cell()\*(C'\fR function from the Excel::Writer::XLSX::Utility module. .PP .Vb 3 \& use Excel::Writer::XLSX::Utility \*(Aq:rowcol\*(Aq; \& ... \& location => xl_rowcol_to_cell( 0, 5 ), # F1 .Ve .SS "range" .IX Subsection "range" This specifies the cell data range that the sparkline will plot: .PP .Vb 6 \& $worksheet\->add_sparkline( \& { \& location => \*(AqF1\*(Aq, \& range => \*(AqA1:E1\*(Aq, \& } \& ); .Ve .PP The \f(CW\*(C`range\*(C'\fR should be a 2D array. (For 3D arrays of cells see \*(L"Grouped Sparklines\*(R" below). .PP If \f(CW\*(C`range\*(C'\fR is not on the same worksheet you can specify its location using the usual Excel notation: .PP .Vb 1 \& range => \*(AqSheet1!A1:E1\*(Aq, .Ve .PP If the worksheet contains spaces or special characters you should quote the worksheet name in the same way that Excel does: .PP .Vb 1 \& range => q(\*(AqMonthly Data\*(Aq!A1:E1), .Ve .PP To specify the location in row-column notation use the \f(CW\*(C`xl_range()\*(C'\fR or \f(CW\*(C`xl_range_formula()\*(C'\fR functions from the Excel::Writer::XLSX::Utility module. .PP .Vb 4 \& use Excel::Writer::XLSX::Utility \*(Aq:rowcol\*(Aq; \& ... \& range => xl_range( 1, 1, 0, 4 ), # \*(AqA1:E1\*(Aq \& range => xl_range_formula( \*(AqSheet1\*(Aq, 0, 0, 0, 4 ), # \*(AqSheet1!A2:E2\*(Aq .Ve .SS "type" .IX Subsection "type" Specifies the type of sparkline. There are 3 available sparkline types: .PP .Vb 3 \& line (default) \& column \& win_loss .Ve .PP For example: .PP .Vb 5 \& { \& location => \*(AqF1\*(Aq, \& range => \*(AqA1:E1\*(Aq, \& type => \*(Aqcolumn\*(Aq, \& } .Ve .SS "style" .IX Subsection "style" Excel provides 36 built-in Sparkline styles in 6 groups of 6. The \f(CW\*(C`style\*(C'\fR parameter can be used to replicate these and should be a corresponding number from 1 .. 36. .PP .Vb 5 \& { \& location => \*(AqA14\*(Aq, \& range => \*(AqSheet2!A2:J2\*(Aq, \& style => 3, \& } .Ve .PP The style number starts in the top left of the style grid and runs left to right. The default style is 1. It is possible to override colour elements of the sparklines using the \f(CW*_color\fR parameters below. .SS "markers" .IX Subsection "markers" Turn on the markers for \f(CW\*(C`line\*(C'\fR style sparklines. .PP .Vb 5 \& { \& location => \*(AqA6\*(Aq, \& range => \*(AqSheet2!A1:J1\*(Aq, \& markers => 1, \& } .Ve .PP Markers aren't shown in Excel for \f(CW\*(C`column\*(C'\fR and \f(CW\*(C`win_loss\*(C'\fR sparklines. .SS "negative_points" .IX Subsection "negative_points" Highlight negative values in a sparkline range. This is usually required with \f(CW\*(C`win_loss\*(C'\fR sparklines. .PP .Vb 6 \& { \& location => \*(AqA21\*(Aq, \& range => \*(AqSheet2!A3:J3\*(Aq, \& type => \*(Aqwin_loss\*(Aq, \& negative_points => 1, \& } .Ve .SS "axis" .IX Subsection "axis" Display a horizontal axis in the sparkline: .PP .Vb 5 \& { \& location => \*(AqA10\*(Aq, \& range => \*(AqSheet2!A1:J1\*(Aq, \& axis => 1, \& } .Ve .SS "reverse" .IX Subsection "reverse" Plot the data from right-to-left instead of the default left-to-right: .PP .Vb 6 \& { \& location => \*(AqA24\*(Aq, \& range => \*(AqSheet2!A4:J4\*(Aq, \& type => \*(Aqcolumn\*(Aq, \& reverse => 1, \& } .Ve .SS "weight" .IX Subsection "weight" Adjust the default line weight (thickness) for \f(CW\*(C`line\*(C'\fR style sparklines. .PP .Vb 1 \& weight => 0.25, .Ve .PP The weight value should be one of the following values allowed by Excel: .PP .Vb 6 \& 0.25 0.5 0.75 \& 1 1.25 \& 2.25 \& 3 \& 4.25 \& 6 .Ve .SS "high_point, low_point, first_point, last_point" .IX Subsection "high_point, low_point, first_point, last_point" Highlight points in a sparkline range. .PP .Vb 4 \& high_point => 1, \& low_point => 1, \& first_point => 1, \& last_point => 1, .Ve .SS "max, min" .IX Subsection "max, min" Specify the maximum and minimum vertical axis values: .PP .Vb 2 \& max => 0.5, \& min => \-0.5, .Ve .PP As a special case you can set the maximum and minimum to be for a group of sparklines rather than one: .PP .Vb 1 \& max => \*(Aqgroup\*(Aq, .Ve .PP See \*(L"Grouped Sparklines\*(R" below. .SS "empty_cells" .IX Subsection "empty_cells" Define how empty cells are handled in a sparkline. .PP .Vb 1 \& empty_cells => \*(Aqzero\*(Aq, .Ve .PP The available options are: .PP .Vb 3 \& gaps : show empty cells as gaps (the default). \& zero : plot empty cells as 0. \& connect: Connect points with a line ("line" type sparklines only). .Ve .SS "show_hidden" .IX Subsection "show_hidden" Plot data in hidden rows and columns: .PP .Vb 1 \& show_hidden => 1, .Ve .PP Note, this option is off by default. .SS "date_axis" .IX Subsection "date_axis" Specify an alternative date axis for the sparkline. This is useful if the data being plotted isn't at fixed width intervals: .PP .Vb 5 \& { \& location => \*(AqF3\*(Aq, \& range => \*(AqA3:E3\*(Aq, \& date_axis => \*(AqA4:E4\*(Aq, \& } .Ve .PP The number of cells in the date range should correspond to the number of cells in the data range. .SS "series_color" .IX Subsection "series_color" It is possible to override the colour of a sparkline style using the following parameters: .PP .Vb 7 \& series_color \& negative_color \& markers_color \& first_color \& last_color \& high_color \& low_color .Ve .PP The color should be specified as a \s-1HTML\s0 style \f(CW\*(C`#rrggbb\*(C'\fR hex value: .PP .Vb 6 \& { \& location => \*(AqA18\*(Aq, \& range => \*(AqSheet2!A2:J2\*(Aq, \& type => \*(Aqcolumn\*(Aq, \& series_color => \*(Aq#E965E0\*(Aq, \& } .Ve .SS "Grouped Sparklines" .IX Subsection "Grouped Sparklines" The \f(CW\*(C`add_sparkline()\*(C'\fR worksheet method can be used multiple times to write as many sparklines as are required in a worksheet. .PP However, it is sometimes necessary to group contiguous sparklines so that changes that are applied to one are applied to all. In Excel this is achieved by selecting a 3D range of cells for the data \f(CW\*(C`range\*(C'\fR and a 2D range of cells for the \f(CW\*(C`location\*(C'\fR. .PP In Excel::Writer::XLSX, you can simulate this by passing an array refs of values to \f(CW\*(C`location\*(C'\fR and \f(CW\*(C`range\*(C'\fR: .PP .Vb 5 \& { \& location => [ \*(AqA27\*(Aq, \*(AqA28\*(Aq, \*(AqA29\*(Aq ], \& range => [ \*(AqSheet2!A5:J5\*(Aq, \*(AqSheet2!A6:J6\*(Aq, \*(AqSheet2!A7:J7\*(Aq ], \& markers => 1, \& } .Ve .SS "Sparkline examples" .IX Subsection "Sparkline examples" See the \f(CW\*(C`sparklines1.pl\*(C'\fR and \f(CW\*(C`sparklines2.pl\*(C'\fR example programs in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .SH "TABLES IN EXCEL" .IX Header "TABLES IN EXCEL" Tables in Excel are a way of grouping a range of cells into a single entity that has common formatting or that can be referenced from formulas. Tables can have column headers, autofilters, total rows, column formulas and default formatting. .PP For more information see \*(L"An Overview of Excel Tables\*(R" http://office.microsoft.com/en\-us/excel\-help/overview\-of\-excel\-tables\-HA010048546.aspx . .PP Note, tables don't work in Excel::Writer::XLSX when \f(CW\*(C`set_optimization()\*(C'\fR mode in on. .ie n .SS "add_table( $row1, $col1, $row2, $col2, { parameter => 'value', ... })" .el .SS "add_table( \f(CW$row1\fP, \f(CW$col1\fP, \f(CW$row2\fP, \f(CW$col2\fP, { parameter => 'value', ... })" .IX Subsection "add_table( $row1, $col1, $row2, $col2, { parameter => 'value', ... })" Tables are added to a worksheet using the \f(CW\*(C`add_table()\*(C'\fR method: .PP .Vb 1 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { %parameters } ); .Ve .PP The data range can be specified in 'A1' or 'row/col' notation (see also the note about \*(L"Cell notation\*(R" for more information): .PP .Vb 3 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq ); \& # Same as: \& $worksheet\->add_table( 2, 1, 6, 5 ); .Ve .PP The last parameter in \f(CW\*(C`add_table()\*(C'\fR should be a hash ref containing the parameters that describe the table options and data. The available parameters are: .PP .Vb 11 \& data \& autofilter \& header_row \& banded_columns \& banded_rows \& first_column \& last_column \& style \& total_row \& columns \& name .Ve .PP The table parameters are detailed below. There are no required parameters and the hash ref isn't required if no options are specified. .SS "data" .IX Subsection "data" The \f(CW\*(C`data\*(C'\fR parameter can be used to specify the data in the cells of the table. .PP .Vb 5 \& my $data = [ \& [ \*(AqApples\*(Aq, 10000, 5000, 8000, 6000 ], \& [ \*(AqPears\*(Aq, 2000, 3000, 4000, 5000 ], \& [ \*(AqBananas\*(Aq, 6000, 6000, 6500, 6000 ], \& [ \*(AqOranges\*(Aq, 500, 300, 200, 700 ], \& \& ]; \& \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { data => $data } ); .Ve .PP Table data can also be written separately, as an array or individual cells. .PP .Vb 3 \& # These two statements are the same as the single statement above. \& $worksheet\->add_table( \*(AqB3:F7\*(Aq ); \& $worksheet\->write_col( \*(AqB4\*(Aq, $data ); .Ve .PP Writing the cell data separately is occasionally required when you need to control the \f(CW\*(C`write_*()\*(C'\fR method used to populate the cells or if you wish to tweak the cell formatting. .PP The \f(CW\*(C`data\*(C'\fR structure should be an array ref of array refs holding row data as shown above. .SS "header_row" .IX Subsection "header_row" The \f(CW\*(C`header_row\*(C'\fR parameter can be used to turn on or off the header row in the table. It is on by default. .PP .Vb 1 \& $worksheet\->add_table( \*(AqB4:F7\*(Aq, { header_row => 0 } ); # Turn header off. .Ve .PP The header row will contain default captions such as \f(CW\*(C`Column 1\*(C'\fR, \f(CW\*(C`Column 2\*(C'\fR, etc. These captions can be overridden using the \f(CW\*(C`columns\*(C'\fR parameter below. .SS "autofilter" .IX Subsection "autofilter" The \f(CW\*(C`autofilter\*(C'\fR parameter can be used to turn on or off the autofilter in the header row. It is on by default. .PP .Vb 1 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { autofilter => 0 } ); # Turn autofilter off. .Ve .PP The \f(CW\*(C`autofilter\*(C'\fR is only shown if the \f(CW\*(C`header_row\*(C'\fR is on. Filters within the table are not supported. .SS "banded_rows" .IX Subsection "banded_rows" The \f(CW\*(C`banded_rows\*(C'\fR parameter can be used to used to create rows of alternating colour in the table. It is on by default. .PP .Vb 1 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { banded_rows => 0 } ); .Ve .SS "banded_columns" .IX Subsection "banded_columns" The \f(CW\*(C`banded_columns\*(C'\fR parameter can be used to used to create columns of alternating colour in the table. It is off by default. .PP .Vb 1 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { banded_columns => 1 } ); .Ve .SS "first_column" .IX Subsection "first_column" The \f(CW\*(C`first_column\*(C'\fR parameter can be used to highlight the first column of the table. The type of highlighting will depend on the \f(CW\*(C`style\*(C'\fR of the table. It may be bold text or a different colour. It is off by default. .PP .Vb 1 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { first_column => 1 } ); .Ve .SS "last_column" .IX Subsection "last_column" The \f(CW\*(C`last_column\*(C'\fR parameter can be used to highlight the last column of the table. The type of highlighting will depend on the \f(CW\*(C`style\*(C'\fR of the table. It may be bold text or a different colour. It is off by default. .PP .Vb 1 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { last_column => 1 } ); .Ve .SS "style" .IX Subsection "style" The \f(CW\*(C`style\*(C'\fR parameter can be used to set the style of the table. Standard Excel table format names should be used (with matching capitalisation): .PP .Vb 7 \& $worksheet11\->add_table( \& \*(AqB3:F7\*(Aq, \& { \& data => $data, \& style => \*(AqTable Style Light 11\*(Aq, \& } \& ); .Ve .PP The default table style is 'Table Style Medium 9'. .SS "name" .IX Subsection "name" The \f(CW\*(C`name\*(C'\fR parameter can be used to set the name of the table. .PP By default tables are named \f(CW\*(C`Table1\*(C'\fR, \f(CW\*(C`Table2\*(C'\fR, etc. If you override the table name you must ensure that it doesn't clash with an existing table name and that it follows Excel's requirements for table names. .PP .Vb 1 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { name => \*(AqSalesData\*(Aq } ); .Ve .PP If you need to know the name of the table, for example to use it in a formula, you can get it as follows: .PP .Vb 2 \& my $table = $worksheet2\->add_table( \*(AqB3:F7\*(Aq ); \& my $table_name = $table\->{_name}; .Ve .SS "total_row" .IX Subsection "total_row" The \f(CW\*(C`total_row\*(C'\fR parameter can be used to turn on the total row in the last row of a table. It is distinguished from the other rows by a different formatting and also with dropdown \f(CW\*(C`SUBTOTAL\*(C'\fR functions. .PP .Vb 1 \& $worksheet\->add_table( \*(AqB3:F7\*(Aq, { total_row => 1 } ); .Ve .PP The default total row doesn't have any captions or functions. These must by specified via the \f(CW\*(C`columns\*(C'\fR parameter below. .SS "columns" .IX Subsection "columns" The \f(CW\*(C`columns\*(C'\fR parameter can be used to set properties for columns within the table. .PP The sub-properties that can be set are: .PP .Vb 6 \& header \& formula \& total_string \& total_function \& total_value \& format .Ve .PP The column data must be specified as an array ref of hash refs. For example to override the default 'Column n' style table headers: .PP .Vb 10 \& $worksheet\->add_table( \& \*(AqB3:F7\*(Aq, \& { \& data => $data, \& columns => [ \& { header => \*(AqProduct\*(Aq }, \& { header => \*(AqQuarter 1\*(Aq }, \& { header => \*(AqQuarter 2\*(Aq }, \& { header => \*(AqQuarter 3\*(Aq }, \& { header => \*(AqQuarter 4\*(Aq }, \& ] \& } \& ); .Ve .PP If you don't wish to specify properties for a specific column you pass an empty hash ref and the defaults will be applied: .PP .Vb 9 \& ... \& columns => [ \& { header => \*(AqProduct\*(Aq }, \& { header => \*(AqQuarter 1\*(Aq }, \& { }, # Defaults to \*(AqColumn 3\*(Aq. \& { header => \*(AqQuarter 3\*(Aq }, \& { header => \*(AqQuarter 4\*(Aq }, \& ] \& ... .Ve .PP Column formulas can by applied using the \f(CW\*(C`formula\*(C'\fR column property: .PP .Vb 10 \& $worksheet8\->add_table( \& \*(AqB3:G7\*(Aq, \& { \& data => $data, \& columns => [ \& { header => \*(AqProduct\*(Aq }, \& { header => \*(AqQuarter 1\*(Aq }, \& { header => \*(AqQuarter 2\*(Aq }, \& { header => \*(AqQuarter 3\*(Aq }, \& { header => \*(AqQuarter 4\*(Aq }, \& { \& header => \*(AqYear\*(Aq, \& formula => \*(Aq=SUM(Table8[@[Quarter 1]:[Quarter 4]])\*(Aq \& }, \& ] \& } \& ); .Ve .PP The Excel 2007 \f(CW\*(C`[#This Row]\*(C'\fR and Excel 2010 \f(CW\*(C`@\*(C'\fR structural references are supported within the formula. .PP As stated above the \f(CW\*(C`total_row\*(C'\fR table parameter turns on the \*(L"Total\*(R" row in the table but it doesn't populate it with any defaults. Total captions and functions must be specified via the \f(CW\*(C`columns\*(C'\fR property and the \f(CW\*(C`total_string\*(C'\fR, \f(CW\*(C`total_function\*(C'\fR and \f(CW\*(C`total_value\*(C'\fR sub properties: .PP .Vb 10 \& $worksheet10\->add_table( \& \*(AqB3:F8\*(Aq, \& { \& data => $data, \& total_row => 1, \& columns => [ \& { header => \*(AqProduct\*(Aq, total_string => \*(AqTotals\*(Aq }, \& { header => \*(AqQuarter 1\*(Aq, total_function => \*(Aqsum\*(Aq }, \& { header => \*(AqQuarter 2\*(Aq, total_function => \*(Aqsum\*(Aq }, \& { header => \*(AqQuarter 3\*(Aq, total_function => \*(Aqsum\*(Aq }, \& { header => \*(AqQuarter 4\*(Aq, total_function => \*(Aqsum\*(Aq }, \& ] \& } \& ); .Ve .PP The supported totals row \f(CW\*(C`SUBTOTAL\*(C'\fR functions are: .PP .Vb 8 \& average \& count_nums \& count \& max \& min \& std_dev \& sum \& var .Ve .PP User defined functions or formulas aren't supported. .PP It is also possible to set a calculated value for the \f(CW\*(C`total_function\*(C'\fR using the \f(CW\*(C`total_value\*(C'\fR sub property. This is only necessary when creating workbooks for applications that cannot calculate the value of formulas automatically. This is similar to setting the \f(CW\*(C`value\*(C'\fR optional property in \f(CW\*(C`write_formula()\*(C'\fR: .PP .Vb 10 \& $worksheet10\->add_table( \& \*(AqB3:F8\*(Aq, \& { \& data => $data, \& total_row => 1, \& columns => [ \& { total_string => \*(AqTotals\*(Aq }, \& { total_function => \*(Aqsum\*(Aq, total_value => 100 }, \& { total_function => \*(Aqsum\*(Aq, total_value => 200 }, \& { total_function => \*(Aqsum\*(Aq, total_value => 100 }, \& { total_function => \*(Aqsum\*(Aq, total_value => 400 }, \& ] \& } \& ); .Ve .PP Format can also be applied to columns: .PP .Vb 1 \& my $currency_format = $workbook\->add_format( num_format => \*(Aq$#,##0\*(Aq ); \& \& $worksheet\->add_table( \& \*(AqB3:D8\*(Aq, \& { \& data => $data, \& total_row => 1, \& columns => [ \& { header => \*(AqProduct\*(Aq, total_string => \*(AqTotals\*(Aq }, \& { \& header => \*(AqQuarter 1\*(Aq, \& total_function => \*(Aqsum\*(Aq, \& format => $currency_format, \& }, \& { \& header => \*(AqQuarter 2\*(Aq, \& total_function => \*(Aqsum\*(Aq, \& format => $currency_format, \& }, \& ] \& } \& ); .Ve .PP Standard Excel::Writer::XLSX format objects can be used. However, they should be limited to numerical formats. Overriding other table formatting may produce inconsistent results. .SH "FORMULAS AND FUNCTIONS IN EXCEL" .IX Header "FORMULAS AND FUNCTIONS IN EXCEL" .SS "Introduction" .IX Subsection "Introduction" The following is a brief introduction to formulas and functions in Excel and Excel::Writer::XLSX. .PP A formula is a string that begins with an equals sign: .PP .Vb 2 \& \*(Aq=A1+B1\*(Aq \& \*(Aq=AVERAGE(1, 2, 3)\*(Aq .Ve .PP The formula can contain numbers, strings, boolean values, cell references, cell ranges and functions. Named ranges are not supported. Formulas should be written as they appear in Excel, that is cells and functions must be in uppercase. .PP Cells in Excel are referenced using the A1 notation system where the column is designated by a letter and the row by a number. Columns range from A to \s-1XFD\s0 i.e. 0 to 16384, rows range from 1 to 1048576. The \f(CW\*(C`Excel::Writer::XLSX::Utility\*(C'\fR module that is included in the distro contains helper functions for dealing with A1 notation, for example: .PP .Vb 1 \& use Excel::Writer::XLSX::Utility; \& \& ( $row, $col ) = xl_cell_to_rowcol( \*(AqC2\*(Aq ); # (1, 2) \& $str = xl_rowcol_to_cell( 1, 2 ); # C2 .Ve .PP The Excel \f(CW\*(C`$\*(C'\fR notation in cell references is also supported. This allows you to specify whether a row or column is relative or absolute. This only has an effect if the cell is copied. The following examples show relative and absolute values. .PP .Vb 4 \& \*(Aq=A1\*(Aq # Column and row are relative \& \*(Aq=$A1\*(Aq # Column is absolute and row is relative \& \*(Aq=A$1\*(Aq # Column is relative and row is absolute \& \*(Aq=$A$1\*(Aq # Column and row are absolute .Ve .PP Formulas can also refer to cells in other worksheets of the current workbook. For example: .PP .Vb 6 \& \*(Aq=Sheet2!A1\*(Aq \& \*(Aq=Sheet2!A1:A5\*(Aq \& \*(Aq=Sheet2:Sheet3!A1\*(Aq \& \*(Aq=Sheet2:Sheet3!A1:A5\*(Aq \& q{=\*(AqTest Data\*(Aq!A1} \& q{=\*(AqTest Data1:Test Data2\*(Aq!A1} .Ve .PP The sheet reference and the cell reference are separated by \f(CW\*(C`!\*(C'\fR the exclamation mark symbol. If worksheet names contain spaces, commas or parentheses then Excel requires that the name is enclosed in single quotes as shown in the last two examples above. In order to avoid using a lot of escape characters you can use the quote operator \f(CW\*(C`q{}\*(C'\fR to protect the quotes. See \f(CW\*(C`perlop\*(C'\fR in the main Perl documentation. Only valid sheet names that have been added using the \f(CW\*(C`add_worksheet()\*(C'\fR method can be used in formulas. You cannot reference external workbooks. .PP The following table lists the operators that are available in Excel's formulas. The majority of the operators are the same as Perl's, differences are indicated: .PP .Vb 10 \& Arithmetic operators: \& ===================== \& Operator Meaning Example \& + Addition 1+2 \& \- Subtraction 2\-1 \& * Multiplication 2*3 \& / Division 1/4 \& ^ Exponentiation 2^3 # Equivalent to ** \& \- Unary minus \-(1+2) \& % Percent (Not modulus) 13% \& \& \& Comparison operators: \& ===================== \& Operator Meaning Example \& = Equal to A1 = B1 # Equivalent to == \& <> Not equal to A1 <> B1 # Equivalent to != \& > Greater than A1 > B1 \& < Less than A1 < B1 \& >= Greater than or equal to A1 >= B1 \& <= Less than or equal to A1 <= B1 \& \& \& String operator: \& ================ \& Operator Meaning Example \& & Concatenation "Hello " & "World!" # [1] \& \& \& Reference operators: \& ==================== \& Operator Meaning Example \& : Range operator A1:A4 # [2] \& , Union operator SUM(1, 2+2, B3) # [3] \& \& \& Notes: \& [1]: Equivalent to "Hello " . "World!" in Perl. \& [2]: This range is equivalent to cells A1, A2, A3 and A4. \& [3]: The comma behaves like the list separator in Perl. .Ve .PP The range and comma operators can have different symbols in non-English versions of Excel. These may be supported in a later version of Excel::Writer::XLSX. In the meantime European users of Excel take note: .PP .Vb 2 \& $worksheet\->write(\*(AqA1\*(Aq, \*(Aq=SUM(1; 2; 3)\*(Aq); # Wrong!! \& $worksheet\->write(\*(AqA1\*(Aq, \*(Aq=SUM(1, 2, 3)\*(Aq); # Okay .Ve .PP For a general introduction to Excel's formulas and an explanation of the syntax of the function refer to the Excel help files or the following: http://office.microsoft.com/en\-us/assistance/CH062528031033.aspx . .PP If your formula doesn't work in Excel::Writer::XLSX try the following: .PP .Vb 7 \& 1. Verify that the formula works in Excel. \& 2. Ensure that cell references and formula names are in uppercase. \& 3. Ensure that you are using \*(Aq:\*(Aq as the range operator, A1:A4. \& 4. Ensure that you are using \*(Aq,\*(Aq as the union operator, SUM(1,2,3). \& 5. If you verify that the formula works in Gnumeric, OpenOffice.org \& or LibreOffice, make sure to note items 2\-4 above, since these \& applications are more flexible than Excel with formula syntax. .Ve .SH "WORKING WITH VBA MACROS" .IX Header "WORKING WITH VBA MACROS" An Excel \f(CW\*(C`xlsm\*(C'\fR file is exactly the same as a \f(CW\*(C`xlsx\*(C'\fR file except that is includes an additional \f(CW\*(C`vbaProject.bin\*(C'\fR file which contains functions and/or macros. Excel uses a different extension to differentiate between the two file formats since files containing macros are usually subject to additional security checks. .PP The \f(CW\*(C`vbaProject.bin\*(C'\fR file is a binary \s-1OLE\s0 \s-1COM\s0 container. This was the format used in older \f(CW\*(C`xls\*(C'\fR versions of Excel prior to Excel 2007. Unlike all of the other components of an xlsx/xlsm file the data isn't stored in \s-1XML\s0 format. Instead the functions and macros as stored as pre-parsed binary format. As such it wouldn't be feasible to define macros and create a \f(CW\*(C`vbaProject.bin\*(C'\fR file from scratch (at least not in the remaining lifespan and interest levels of the author). .PP Instead a workaround is used to extract \f(CW\*(C`vbaProject.bin\*(C'\fR files from existing xlsm files and then add these to Excel::Writer::XLSX files. .SS "The extract_vba utility" .IX Subsection "The extract_vba utility" The \f(CW\*(C`extract_vba\*(C'\fR utility is used to extract the \f(CW\*(C`vbaProject.bin\*(C'\fR binary from an Excel 2007+ xlsm file. The utility is included in the Excel::Writer::XLSX bin directory and is also installed as a standalone executable file: .PP .Vb 2 \& $ extract_vba macro_file.xlsm \& Extracted: vbaProject.bin .Ve .SS "Adding the \s-1VBA\s0 macros to a Excel::Writer::XLSX file" .IX Subsection "Adding the VBA macros to a Excel::Writer::XLSX file" Once the \f(CW\*(C`vbaProject.bin\*(C'\fR file has been extracted it can be added to the Excel::Writer::XLSX workbook using the \f(CW\*(C`add_vba_project()\*(C'\fR method: .PP .Vb 1 \& $workbook\->add_vba_project( \*(Aq./vbaProject.bin\*(Aq ); .Ve .PP If the \s-1VBA\s0 file contains functions you can then refer to them in calculations using \f(CW\*(C`write_formula\*(C'\fR: .PP .Vb 1 \& $worksheet\->write_formula( \*(AqA1\*(Aq, \*(Aq=MyMortgageCalc(200000, 25)\*(Aq ); .Ve .PP Excel files that contain functions and macros should use an \f(CW\*(C`xlsm\*(C'\fR extension or else Excel will complain and possibly not open the file: .PP .Vb 1 \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqfile.xlsm\*(Aq ); .Ve .PP It is also possible to assign a macro to a button that is inserted into a worksheet using the \f(CW\*(C`insert_button()\*(C'\fR method: .PP .Vb 3 \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqfile.xlsm\*(Aq ); \& ... \& $workbook\->add_vba_project( \*(Aq./vbaProject.bin\*(Aq ); \& \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(Aqmy_macro\*(Aq } ); .Ve .PP It may be necessary to specify a more explicit macro name prefixed by the workbook \s-1VBA\s0 name as follows: .PP .Vb 1 \& $worksheet\->insert_button( \*(AqC2\*(Aq, { macro => \*(AqThisWorkbook.my_macro\*(Aq } ); .Ve .PP See the \f(CW\*(C`macros.pl\*(C'\fR from the examples directory for a working example. .PP Note: Button is the only \s-1VBA\s0 Control supported by Excel::Writer::XLSX. Due to the large effort in implementation (1+ man months) it is unlikely that any other form elements will be added in the future. .SS "Setting the \s-1VBA\s0 codenames" .IX Subsection "Setting the VBA codenames" \&\s-1VBA\s0 macros generally refer to workbook and worksheet objects. If the \s-1VBA\s0 codenames aren't specified then Excel::Writer::XLSX will use the Excel defaults of \f(CW\*(C`ThisWorkbook\*(C'\fR and \f(CW\*(C`Sheet1\*(C'\fR, \f(CW\*(C`Sheet2\*(C'\fR etc. .PP If the macro uses other codenames you can set them using the workbook and worksheet \f(CW\*(C`set_vba_name()\*(C'\fR methods as follows: .PP .Vb 2 \& $workbook\->set_vba_name( \*(AqMyWorkbook\*(Aq ); \& $worksheet\->set_vba_name( \*(AqMySheet\*(Aq ); .Ve .PP You can find the names that are used in the \s-1VBA\s0 editor or by unzipping the \f(CW\*(C`xlsm\*(C'\fR file and grepping the files. The following shows how to do that using libxml's xmllint to format the \s-1XML\s0 for clarity: .PP .Vb 2 \& $ unzip myfile.xlsm \-d myfile \& $ xmllint \-\-format \`find myfile \-name "*.xml" | xargs\` | grep "Pr.*codeName" \& \& \& .Ve .PP Note: This step is particularly important for macros created with non-English versions of Excel. .SS "What to do if it doesn't work" .IX Subsection "What to do if it doesn't work" This feature should be considered experimental and there is no guarantee that it will work in all cases. Some effort may be required and some knowledge of \s-1VBA\s0 will certainly help. If things don't work out here are some things to try: .IP "\(bu" 4 Start with a simple macro file, ensure that it works and then add complexity. .IP "\(bu" 4 Try to extract the macros from an Excel 2007 file. The method should work with macros from later versions (it was also tested with Excel 2010 macros). However there may be features in the macro files of more recent version of Excel that aren't backward compatible. .IP "\(bu" 4 Check the code names that macros use to refer to the workbook and worksheets (see the previous section above). In general \s-1VBA\s0 uses a code name of \f(CW\*(C`ThisWorkbook\*(C'\fR to refer to the current workbook and the sheet name (such as \f(CW\*(C`Sheet1\*(C'\fR) to refer to the worksheets. These are the defaults used by Excel::Writer::XLSX. If the macro uses other names then you can specify these using the workbook and worksheet \f(CW\*(C`set_vba_name()\*(C'\fR methods: .Sp .Vb 2 \& $workbook>set_vba_name( \*(AqMyWorkbook\*(Aq ); \& $worksheet\->set_vba_name( \*(AqMySheet\*(Aq ); .Ve .SH "EXAMPLES" .IX Header "EXAMPLES" See Excel::Writer::XLSX::Examples for a full list of examples. .SS "Example 1" .IX Subsection "Example 1" The following example shows some of the basic features of Excel::Writer::XLSX. .PP .Vb 1 \& #!/usr/bin/perl \-w \& \& use strict; \& use Excel::Writer::XLSX; \& \& # Create a new workbook called simple.xlsx and add a worksheet \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqsimple.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& \& # The general syntax is write($row, $column, $token). Note that row and \& # column are zero indexed \& \& # Write some text \& $worksheet\->write( 0, 0, \*(AqHi Excel!\*(Aq ); \& \& \& # Write some numbers \& $worksheet\->write( 2, 0, 3 ); \& $worksheet\->write( 3, 0, 3.00000 ); \& $worksheet\->write( 4, 0, 3.00001 ); \& $worksheet\->write( 5, 0, 3.14159 ); \& \& \& # Write some formulas \& $worksheet\->write( 7, 0, \*(Aq=A3 + A6\*(Aq ); \& $worksheet\->write( 8, 0, \*(Aq=IF(A5>3,"Yes", "No")\*(Aq ); \& \& \& # Write a hyperlink \& my $hyperlink_format = $workbook\->add_format( \& color => \*(Aqblue\*(Aq, \& underline => 1, \& ); \& \& $worksheet\->write( 10, 0, \*(Aqhttp://www.perl.com/\*(Aq, $hyperlink_format ); .Ve .SS "Example 2" .IX Subsection "Example 2" The following is a general example which demonstrates some features of working with multiple worksheets. .PP .Vb 1 \& #!/usr/bin/perl \-w \& \& use strict; \& use Excel::Writer::XLSX; \& \& # Create a new Excel workbook \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqregions.xlsx\*(Aq ); \& \& # Add some worksheets \& my $north = $workbook\->add_worksheet( \*(AqNorth\*(Aq ); \& my $south = $workbook\->add_worksheet( \*(AqSouth\*(Aq ); \& my $east = $workbook\->add_worksheet( \*(AqEast\*(Aq ); \& my $west = $workbook\->add_worksheet( \*(AqWest\*(Aq ); \& \& # Add a Format \& my $format = $workbook\->add_format(); \& $format\->set_bold(); \& $format\->set_color( \*(Aqblue\*(Aq ); \& \& # Add a caption to each worksheet \& for my $worksheet ( $workbook\->sheets() ) { \& $worksheet\->write( 0, 0, \*(AqSales\*(Aq, $format ); \& } \& \& # Write some data \& $north\->write( 0, 1, 200000 ); \& $south\->write( 0, 1, 100000 ); \& $east\->write( 0, 1, 150000 ); \& $west\->write( 0, 1, 100000 ); \& \& # Set the active worksheet \& $south\->activate(); \& \& # Set the width of the first column \& $south\->set_column( 0, 0, 20 ); \& \& # Set the active cell \& $south\->set_selection( 0, 1 ); .Ve .SS "Example 3" .IX Subsection "Example 3" Example of how to add conditional formatting to an Excel::Writer::XLSX file. The example below highlights cells that have a value greater than or equal to 50 in red and cells below that value in green. .PP .Vb 1 \& #!/usr/bin/perl \& \& use strict; \& use warnings; \& use Excel::Writer::XLSX; \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqconditional_format.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& \& \& # This example below highlights cells that have a value greater than or \& # equal to 50 in red and cells below that value in green. \& \& # Light red fill with dark red text. \& my $format1 = $workbook\->add_format( \& bg_color => \*(Aq#FFC7CE\*(Aq, \& color => \*(Aq#9C0006\*(Aq, \& \& ); \& \& # Green fill with dark green text. \& my $format2 = $workbook\->add_format( \& bg_color => \*(Aq#C6EFCE\*(Aq, \& color => \*(Aq#006100\*(Aq, \& \& ); \& \& # Some sample data to run the conditional formatting against. \& my $data = [ \& [ 34, 72, 38, 30, 75, 48, 75, 66, 84, 86 ], \& [ 6, 24, 1, 84, 54, 62, 60, 3, 26, 59 ], \& [ 28, 79, 97, 13, 85, 93, 93, 22, 5, 14 ], \& [ 27, 71, 40, 17, 18, 79, 90, 93, 29, 47 ], \& [ 88, 25, 33, 23, 67, 1, 59, 79, 47, 36 ], \& [ 24, 100, 20, 88, 29, 33, 38, 54, 54, 88 ], \& [ 6, 57, 88, 28, 10, 26, 37, 7, 41, 48 ], \& [ 52, 78, 1, 96, 26, 45, 47, 33, 96, 36 ], \& [ 60, 54, 81, 66, 81, 90, 80, 93, 12, 55 ], \& [ 70, 5, 46, 14, 71, 19, 66, 36, 41, 21 ], \& ]; \& \& my $caption = \*(AqCells with values >= 50 are in light red. \*(Aq \& . \*(AqValues < 50 are in light green\*(Aq; \& \& # Write the data. \& $worksheet\->write( \*(AqA1\*(Aq, $caption ); \& $worksheet\->write_col( \*(AqB3\*(Aq, $data ); \& \& # Write a conditional format over a range. \& $worksheet\->conditional_formatting( \*(AqB3:K12\*(Aq, \& { \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aq>=\*(Aq, \& value => 50, \& format => $format1, \& } \& ); \& \& # Write another conditional format over the same range. \& $worksheet\->conditional_formatting( \*(AqB3:K12\*(Aq, \& { \& type => \*(Aqcell\*(Aq, \& criteria => \*(Aq<\*(Aq, \& value => 50, \& format => $format2, \& } \& ); .Ve .SS "Example 4" .IX Subsection "Example 4" The following is a simple example of using functions. .PP .Vb 1 \& #!/usr/bin/perl \-w \& \& use strict; \& use Excel::Writer::XLSX; \& \& # Create a new workbook and add a worksheet \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqstats.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet( \*(AqTest data\*(Aq ); \& \& # Set the column width for columns 1 \& $worksheet\->set_column( 0, 0, 20 ); \& \& \& # Create a format for the headings \& my $format = $workbook\->add_format(); \& $format\->set_bold(); \& \& \& # Write the sample data \& $worksheet\->write( 0, 0, \*(AqSample\*(Aq, $format ); \& $worksheet\->write( 0, 1, 1 ); \& $worksheet\->write( 0, 2, 2 ); \& $worksheet\->write( 0, 3, 3 ); \& $worksheet\->write( 0, 4, 4 ); \& $worksheet\->write( 0, 5, 5 ); \& $worksheet\->write( 0, 6, 6 ); \& $worksheet\->write( 0, 7, 7 ); \& $worksheet\->write( 0, 8, 8 ); \& \& $worksheet\->write( 1, 0, \*(AqLength\*(Aq, $format ); \& $worksheet\->write( 1, 1, 25.4 ); \& $worksheet\->write( 1, 2, 25.4 ); \& $worksheet\->write( 1, 3, 24.8 ); \& $worksheet\->write( 1, 4, 25.0 ); \& $worksheet\->write( 1, 5, 25.3 ); \& $worksheet\->write( 1, 6, 24.9 ); \& $worksheet\->write( 1, 7, 25.2 ); \& $worksheet\->write( 1, 8, 24.8 ); \& \& # Write some statistical functions \& $worksheet\->write( 4, 0, \*(AqCount\*(Aq, $format ); \& $worksheet\->write( 4, 1, \*(Aq=COUNT(B1:I1)\*(Aq ); \& \& $worksheet\->write( 5, 0, \*(AqSum\*(Aq, $format ); \& $worksheet\->write( 5, 1, \*(Aq=SUM(B2:I2)\*(Aq ); \& \& $worksheet\->write( 6, 0, \*(AqAverage\*(Aq, $format ); \& $worksheet\->write( 6, 1, \*(Aq=AVERAGE(B2:I2)\*(Aq ); \& \& $worksheet\->write( 7, 0, \*(AqMin\*(Aq, $format ); \& $worksheet\->write( 7, 1, \*(Aq=MIN(B2:I2)\*(Aq ); \& \& $worksheet\->write( 8, 0, \*(AqMax\*(Aq, $format ); \& $worksheet\->write( 8, 1, \*(Aq=MAX(B2:I2)\*(Aq ); \& \& $worksheet\->write( 9, 0, \*(AqStandard Deviation\*(Aq, $format ); \& $worksheet\->write( 9, 1, \*(Aq=STDEV(B2:I2)\*(Aq ); \& \& $worksheet\->write( 10, 0, \*(AqKurtosis\*(Aq, $format ); \& $worksheet\->write( 10, 1, \*(Aq=KURT(B2:I2)\*(Aq ); .Ve .SS "Example 5" .IX Subsection "Example 5" The following example converts a tab separated file called \f(CW\*(C`tab.txt\*(C'\fR into an Excel file called \f(CW\*(C`tab.xlsx\*(C'\fR. .PP .Vb 1 \& #!/usr/bin/perl \-w \& \& use strict; \& use Excel::Writer::XLSX; \& \& open( TABFILE, \*(Aqtab.txt\*(Aq ) or die "tab.txt: $!"; \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqtab.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& \& # Row and column are zero indexed \& my $row = 0; \& \& while ( ) { \& chomp; \& \& # Split on single tab \& my @fields = split( \*(Aq\et\*(Aq, $_ ); \& \& my $col = 0; \& for my $token ( @fields ) { \& $worksheet\->write( $row, $col, $token ); \& $col++; \& } \& $row++; \& } .Ve .PP \&\s-1NOTE:\s0 This is a simple conversion program for illustrative purposes only. For converting a \s-1CSV\s0 or Tab separated or any other type of delimited text file to Excel I recommend the more rigorous csv2xls program that is part of H.Merijn Brand's Text::CSV_XS module distro. .PP See the examples/csv2xls link here: http://search.cpan.org/~hmbrand/Text\-CSV_XS/MANIFEST . .SS "Additional Examples" .IX Subsection "Additional Examples" The following is a description of the example files that are provided in the standard Excel::Writer::XLSX distribution. They demonstrate the different features and options of the module. See Excel::Writer::XLSX::Examples for more details. .PP .Vb 8 \& Getting started \& =============== \& a_simple.pl A simple demo of some of the features. \& bug_report.pl A template for submitting bug reports. \& demo.pl A demo of some of the available features. \& formats.pl All the available formatting on several worksheets. \& regions.pl A simple example of multiple worksheets. \& stats.pl Basic formulas and functions. \& \& \& Intermediate \& ============ \& autofilter.pl Examples of worksheet autofilters. \& array_formula.pl Examples of how to write array formulas. \& cgi.pl A simple CGI program. \& chart_area.pl A demo of area style charts. \& chart_bar.pl A demo of bar (vertical histogram) style charts. \& chart_column.pl A demo of column (histogram) style charts. \& chart_line.pl A demo of line style charts. \& chart_pie.pl A demo of pie style charts. \& chart_doughnut.pl A demo of dougnut style charts. \& chart_radar.pl A demo of radar style charts. \& chart_scatter.pl A demo of scatter style charts. \& chart_secondary_axis.pl A demo of a line chart with a secondary axis. \& chart_combined.pl A demo of a combined column and line chart. \& chart_pareto.pl A demo of a combined Pareto chart. \& chart_stock.pl A demo of stock style charts. \& chart_data_table.pl A demo of a chart with a data table on the axis. \& chart_data_tools.pl A demo of charts with data highlighting options. \& chart_clustered.pl A demo of a chart with a clustered axis. \& chart_styles.pl A demo of the available chart styles. \& colors.pl A demo of the colour palette and named colours. \& comments1.pl Add comments to worksheet cells. \& comments2.pl Add comments with advanced options. \& conditional_format.pl Add conditional formats to a range of cells. \& data_validate.pl An example of data validation and dropdown lists. \& date_time.pl Write dates and times with write_date_time(). \& defined_name.pl Example of how to create defined names. \& diag_border.pl A simple example of diagonal cell borders. \& filehandle.pl Examples of working with filehandles. \& headers.pl Examples of worksheet headers and footers. \& hide_row_col.pl Example of hiding rows and columns. \& hide_sheet.pl Simple example of hiding a worksheet. \& hyperlink1.pl Shows how to create web hyperlinks. \& hyperlink2.pl Examples of internal and external hyperlinks. \& indent.pl An example of cell indentation. \& macros.pl An example of adding macros from an existing file. \& merge1.pl A simple example of cell merging. \& merge2.pl A simple example of cell merging with formatting. \& merge3.pl Add hyperlinks to merged cells. \& merge4.pl An advanced example of merging with formatting. \& merge5.pl An advanced example of merging with formatting. \& merge6.pl An example of merging with Unicode strings. \& mod_perl1.pl A simple mod_perl 1 program. \& mod_perl2.pl A simple mod_perl 2 program. \& panes.pl An examples of how to create panes. \& outline.pl An example of outlines and grouping. \& outline_collapsed.pl An example of collapsed outlines. \& protection.pl Example of cell locking and formula hiding. \& rich_strings.pl Example of strings with multiple formats. \& right_to_left.pl Change default sheet direction to right to left. \& sales.pl An example of a simple sales spreadsheet. \& shape1.pl Insert shapes in worksheet. \& shape2.pl Insert shapes in worksheet. With properties. \& shape3.pl Insert shapes in worksheet. Scaled. \& shape4.pl Insert shapes in worksheet. With modification. \& shape5.pl Insert shapes in worksheet. With connections. \& shape6.pl Insert shapes in worksheet. With connections. \& shape7.pl Insert shapes in worksheet. One to many connections. \& shape8.pl Insert shapes in worksheet. One to many connections. \& shape_all.pl Demo of all the available shape and connector types. \& sparklines1.pl Simple sparklines demo. \& sparklines2.pl Sparklines demo showing formatting options. \& stats_ext.pl Same as stats.pl with external references. \& stocks.pl Demonstrates conditional formatting. \& tab_colors.pl Example of how to set worksheet tab colours. \& tables.pl Add Excel tables to a worksheet. \& write_handler1.pl Example of extending the write() method. Step 1. \& write_handler2.pl Example of extending the write() method. Step 2. \& write_handler3.pl Example of extending the write() method. Step 3. \& write_handler4.pl Example of extending the write() method. Step 4. \& write_to_scalar.pl Example of writing an Excel file to a Perl scalar. \& \& Unicode \& ======= \& unicode_2022_jp.pl Japanese: ISO\-2022\-JP. \& unicode_8859_11.pl Thai: ISO\-8859_11. \& unicode_8859_7.pl Greek: ISO\-8859_7. \& unicode_big5.pl Chinese: BIG5. \& unicode_cp1251.pl Russian: CP1251. \& unicode_cp1256.pl Arabic: CP1256. \& unicode_cyrillic.pl Russian: Cyrillic. \& unicode_koi8r.pl Russian: KOI8\-R. \& unicode_polish_utf8.pl Polish : UTF8. \& unicode_shift_jis.pl Japanese: Shift JIS. .Ve .SH "LIMITATIONS" .IX Header "LIMITATIONS" The following limits are imposed by Excel 2007+: .PP .Vb 7 \& Description Limit \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\- \& Maximum number of chars in a string 32,767 \& Maximum number of columns 16,384 \& Maximum number of rows 1,048,576 \& Maximum chars in a sheet name 31 \& Maximum chars in a header/footer 254 \& \& Maximum characters in hyperlink 255 \& Maximum number of unique hyperlinks* 65,530 .Ve .PP * Per worksheet. Excel allows a greater number of non-unique hyperlinks if they are contiguous and can be grouped into a single range. This will be supported in a later version of Excel::Writer::XLSX if possible. .SH "Compatibility with Spreadsheet::WriteExcel" .IX Header "Compatibility with Spreadsheet::WriteExcel" The \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR module is a drop-in replacement for \f(CW\*(C`Spreadsheet::WriteExcel\*(C'\fR. .PP It supports all of the features of Spreadsheet::WriteExcel with some minor differences noted below. .PP .Vb 10 \& Workbook Methods Support \& ================ ====== \& new() Yes \& add_worksheet() Yes \& add_format() Yes \& add_chart() Yes \& add_shape() Yes. Not in Spreadsheet::WriteExcel. \& add_vba_project() Yes. Not in Spreadsheet::WriteExcel. \& close() Yes \& set_properties() Yes \& define_name() Yes \& set_tempdir() Yes \& set_custom_color() Yes \& sheets() Yes \& set_1904() Yes \& set_optimization() Yes. Not required in Spreadsheet::WriteExcel. \& add_chart_ext() Not supported. Not required in Excel::Writer::XLSX. \& compatibility_mode() Deprecated. Not required in Excel::Writer::XLSX. \& set_codepage() Deprecated. Not required in Excel::Writer::XLSX. \& \& \& Worksheet Methods Support \& ================= ======= \& write() Yes \& write_number() Yes \& write_string() Yes \& write_rich_string() Yes. Not in Spreadsheet::WriteExcel. \& write_blank() Yes \& write_row() Yes \& write_col() Yes \& write_date_time() Yes \& write_url() Yes \& write_formula() Yes \& write_array_formula() Yes. Not in Spreadsheet::WriteExcel. \& keep_leading_zeros() Yes \& write_comment() Yes \& show_comments() Yes \& set_comments_author() Yes \& add_write_handler() Yes \& insert_image() Yes. \& insert_chart() Yes \& insert_shape() Yes. Not in Spreadsheet::WriteExcel. \& insert_button() Yes. Not in Spreadsheet::WriteExcel. \& data_validation() Yes \& conditional_formatting() Yes. Not in Spreadsheet::WriteExcel. \& add_sparkline() Yes. Not in Spreadsheet::WriteExcel. \& add_table() Yes. Not in Spreadsheet::WriteExcel. \& get_name() Yes \& activate() Yes \& select() Yes \& hide() Yes \& set_first_sheet() Yes \& protect() Yes \& set_selection() Yes \& set_row() Yes. \& set_column() Yes. \& set_default_row() Yes. Not in Spreadsheet::WriteExcel. \& outline_settings() Yes \& freeze_panes() Yes \& split_panes() Yes \& merge_range() Yes \& merge_range_type() Yes. Not in Spreadsheet::WriteExcel. \& set_zoom() Yes \& right_to_left() Yes \& hide_zero() Yes \& set_tab_color() Yes \& autofilter() Yes \& filter_column() Yes \& filter_column_list() Yes. Not in Spreadsheet::WriteExcel. \& write_utf16be_string() Deprecated. Use Perl utf8 strings instead. \& write_utf16le_string() Deprecated. Use Perl utf8 strings instead. \& store_formula() Deprecated. See docs. \& repeat_formula() Deprecated. See docs. \& write_url_range() Not supported. Not required in Excel::Writer::XLSX. \& \& Page Set\-up Methods Support \& =================== ======= \& set_landscape() Yes \& set_portrait() Yes \& set_page_view() Yes \& set_paper() Yes \& center_horizontally() Yes \& center_vertically() Yes \& set_margins() Yes \& set_header() Yes \& set_footer() Yes \& repeat_rows() Yes \& repeat_columns() Yes \& hide_gridlines() Yes \& print_row_col_headers() Yes \& print_area() Yes \& print_across() Yes \& fit_to_pages() Yes \& set_start_page() Yes \& set_print_scale() Yes \& set_h_pagebreaks() Yes \& set_v_pagebreaks() Yes \& \& Format Methods Support \& ============== ======= \& set_font() Yes \& set_size() Yes \& set_color() Yes \& set_bold() Yes \& set_italic() Yes \& set_underline() Yes \& set_font_strikeout() Yes \& set_font_script() Yes \& set_font_outline() Yes \& set_font_shadow() Yes \& set_num_format() Yes \& set_locked() Yes \& set_hidden() Yes \& set_align() Yes \& set_rotation() Yes \& set_text_wrap() Yes \& set_text_justlast() Yes \& set_center_across() Yes \& set_indent() Yes \& set_shrink() Yes \& set_pattern() Yes \& set_bg_color() Yes \& set_fg_color() Yes \& set_border() Yes \& set_bottom() Yes \& set_top() Yes \& set_left() Yes \& set_right() Yes \& set_border_color() Yes \& set_bottom_color() Yes \& set_top_color() Yes \& set_left_color() Yes \& set_right_color() Yes .Ve .SH "REQUIREMENTS" .IX Header "REQUIREMENTS" http://search.cpan.org/search?dist=Archive\-Zip/ . .PP Perl 5.8.2. .SH "SPEED AND MEMORY USAGE" .IX Header "SPEED AND MEMORY USAGE" \&\f(CW\*(C`Spreadsheet::WriteExcel\*(C'\fR was written to optimise speed and reduce memory usage. However, these design goals meant that it wasn't easy to implement features that many users requested such as writing formatting and data separately. .PP As a result \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR takes a different design approach and holds a lot more data in memory so that it is functionally more flexible. .PP The effect of this is that Excel::Writer::XLSX is about 30% slower than Spreadsheet::WriteExcel and uses 5 times more memory. .PP In addition the extended row and column ranges in Excel 2007+ mean that it is possible to run out of memory creating large files. This was almost never an issue with Spreadsheet::WriteExcel. .PP This memory usage can be reduced almost completely by using the Workbook \f(CW\*(C`set_optimization()\*(C'\fR method: .PP .Vb 1 \& $workbook\->set_optimization(); .Ve .PP This also gives an increase in performance to within 1\-10% of Spreadsheet::WriteExcel, see below. .PP The trade-off is that you won't be able to take advantage of any new features that manipulate cell data after it is written. One such feature is Tables. .SS "Performance figures" .IX Subsection "Performance figures" The performance figures below show execution speed and memory usage for 60 columns x N rows for a 50/50 mixture of strings and numbers. Percentage speeds are relative to Spreadsheet::WriteExcel. .PP .Vb 10 \& Excel::Writer::XLSX \& Rows Time (s) Memory (bytes) Rel. Time \& 400 0.66 6,586,254 129% \& 800 1.26 13,099,422 125% \& 1600 2.55 26,126,361 123% \& 3200 5.16 52,211,284 125% \& 6400 10.47 104,401,428 128% \& 12800 21.48 208,784,519 131% \& 25600 43.90 417,700,746 126% \& 51200 88.52 835,900,298 126% \& \& Excel::Writer::XLSX + set_optimisation() \& Rows Time (s) Memory (bytes) Rel. Time \& 400 0.70 63,059 135% \& 800 1.10 63,059 110% \& 1600 2.30 63,062 111% \& 3200 4.44 63,062 107% \& 6400 8.91 63,062 109% \& 12800 17.69 63,065 108% \& 25600 35.15 63,065 101% \& 51200 70.67 63,065 101% \& \& Spreadsheet::WriteExcel \& Rows Time (s) Memory (bytes) \& 400 0.51 1,265,583 \& 800 1.01 2,424,855 \& 1600 2.07 4,743,400 \& 3200 4.14 9,411,139 \& 6400 8.20 18,766,915 \& 12800 16.39 37,478,468 \& 25600 34.72 75,044,423 \& 51200 70.21 150,543,431 .Ve .SH "DOWNLOADING" .IX Header "DOWNLOADING" The latest version of this module is always available at: http://search.cpan.org/search?dist=Excel\-Writer\-XLSX/ . .SH "INSTALLATION" .IX Header "INSTALLATION" The module can be installed using the standard Perl procedure: .PP .Vb 4 \& perl Makefile.PL \& make \& make test \& make install # You may need to be sudo/root .Ve .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" .IP "Filename required by Excel::Writer::XLSX\->\fInew()\fR" 4 .IX Item "Filename required by Excel::Writer::XLSX->new()" A filename must be given in the constructor. .IP "Can't open filename. It may be in use or protected." 4 .IX Item "Can't open filename. It may be in use or protected." The file cannot be opened for writing. The directory that you are writing to may be protected or the file may be in use by another program. .ie n .IP "Can't call method ""\s-1XXX\s0"" on an undefined value at someprogram.pl." 4 .el .IP "Can't call method ``\s-1XXX\s0'' on an undefined value at someprogram.pl." 4 .IX Item "Can't call method XXX on an undefined value at someprogram.pl." On Windows this is usually caused by the file that you are trying to create clashing with a version that is already open and locked by Excel. .IP "The file you are trying to open 'file.xls' is in a different format than specified by the file extension." 4 .IX Item "The file you are trying to open 'file.xls' is in a different format than specified by the file extension." This warning occurs when you create an \s-1XLSX\s0 file but give it an xls extension. .SH "WRITING EXCEL FILES" .IX Header "WRITING EXCEL FILES" Depending on your requirements, background and general sensibilities you may prefer one of the following methods of getting data into Excel: .IP "\(bu" 4 Spreadsheet::WriteExcel .Sp This module is the precursor to Excel::Writer::XLSX and uses the same interface. It produces files in the Excel Biff xls format that was used in Excel versions 97\-2003. These files can still be read by Excel 2007 but have some limitations in relation to the number of rows and columns that the format supports. .Sp Spreadsheet::WriteExcel. .IP "\(bu" 4 Win32::OLE module and office automation .Sp This requires a Windows platform and an installed copy of Excel. This is the most powerful and complete method for interfacing with Excel. .Sp Win32::OLE .IP "\(bu" 4 \&\s-1CSV\s0, comma separated variables or text .Sp Excel will open and automatically convert files with a \f(CW\*(C`csv\*(C'\fR extension. .Sp To create \s-1CSV\s0 files refer to the Text::CSV_XS module. .IP "\(bu" 4 \&\s-1DBI\s0 with \s-1DBD::ADO\s0 or \s-1DBD::ODBC\s0 .Sp Excel files contain an internal index table that allows them to act like a database file. Using one of the standard Perl database modules you can connect to an Excel file as a database. .PP For other Perl-Excel modules try the following search: . .SH "READING EXCEL FILES" .IX Header "READING EXCEL FILES" To read data from Excel files try: .IP "\(bu" 4 Spreadsheet::XLSX .Sp A module for reading formatted or unformatted data form \s-1XLSX\s0 files. .Sp Spreadsheet::XLSX .IP "\(bu" 4 SimpleXlsx .Sp A lightweight module for reading data from \s-1XLSX\s0 files. .Sp SimpleXlsx .IP "\(bu" 4 Spreadsheet::ParseExcel .Sp This module can read data from an Excel \s-1XLS\s0 file but it doesn't support the \s-1XLSX\s0 format. .Sp Spreadsheet::ParseExcel .IP "\(bu" 4 Win32::OLE module and office automation (reading) .Sp See above. .IP "\(bu" 4 \&\s-1DBI\s0 with \s-1DBD::ADO\s0 or \s-1DBD::ODBC\s0. .Sp See above. .PP For other Perl-Excel modules try the following search: . .SH "BUGS" .IX Header "BUGS" .IP "\(bu" 4 Memory usage is very high for large worksheets. .Sp If you run out of memory creating large worksheets use the \f(CW\*(C`set_optimization()\*(C'\fR method. See \*(L"\s-1SPEED\s0 \s-1AND\s0 \s-1MEMORY\s0 \s-1USAGE\s0\*(R" for more information. .IP "\(bu" 4 Perl packaging programs can't find chart modules. .Sp When using Excel::Writer::XLSX charts with Perl packagers such as \s-1PAR\s0 or Cava you should explicitly include the chart that you are trying to create in your \f(CW\*(C`use\*(C'\fR statements. This isn't a bug as such but it might help someone from banging their head off a wall: .Sp .Vb 4 \& ... \& use Excel::Writer::XLSX; \& use Excel::Writer::XLSX::Chart::Column; \& ... .Ve .PP If you wish to submit a bug report run the \f(CW\*(C`bug_report.pl\*(C'\fR program in the \f(CW\*(C`examples\*(C'\fR directory of the distro. .PP The bug tracker is on Github: https://github.com/jmcnamara/excel\-writer\-xlsx/issues . .SH "TO DO" .IX Header "TO DO" The roadmap is as follows: .IP "\(bu" 4 New separated data/formatting \s-1API\s0 to allow cells to be formatted after data is added. .IP "\(bu" 4 More charting features. .IP "\(bu" 4 Excel::Reader::XLSX and Excel::Rewriter::XLSX. Hopefully. .IP "\(bu" 4 Pivot tables, maybe. .SH "REPOSITORY" .IX Header "REPOSITORY" The Excel::Writer::XLSX source code in host on github: http://github.com/jmcnamara/excel\-writer\-xlsx . .SH "MAILING LIST" .IX Header "MAILING LIST" There is a Google group for discussing and asking questions about Excel::Writer::XLSX. This is a good place to search to see if your question has been asked before: http://groups.google.com/group/spreadsheet\-writeexcel . .SH "DONATIONS and SPONSORSHIP" .IX Header "DONATIONS and SPONSORSHIP" If you'd care to donate to the Excel::Writer::XLSX project or sponsor a new feature, you can do so via PayPal: . .SH "SEE ALSO" .IX Header "SEE ALSO" Spreadsheet::WriteExcel: http://search.cpan.org/dist/Spreadsheet\-WriteExcel . .PP Spreadsheet::ParseExcel: http://search.cpan.org/dist/Spreadsheet\-ParseExcel . .PP Spreadsheet::XLSX: http://search.cpan.org/dist/Spreadsheet\-XLSX . .SH "ACKNOWLEDGMENTS" .IX Header "ACKNOWLEDGMENTS" The following people contributed to the debugging, testing or enhancement of Excel::Writer::XLSX: .PP Rob Messer of IntelliSurvey gave me the initial prompt to port Spreadsheet::WriteExcel to the \s-1XLSX\s0 format. IntelliSurvey () also sponsored large files optimisations and the charting feature. .PP Bariatric Advantage () sponsored work on chart formatting. .PP Eric Johnson provided the ability to use secondary axes with charts. Thanks to Foxtons () for sponsoring this work. .PP BuildFax () sponsored the Tables feature and the Chart point formatting feature. .SH "DISCLAIMER OF WARRANTY" .IX Header "DISCLAIMER OF WARRANTY" Because this software is licensed free of charge, there is no warranty for the software, to the extent permitted by applicable law. Except when otherwise stated in writing the copyright holders and/or other parties provide the software \*(L"as is\*(R" without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the software is with you. Should the software prove defective, you assume the cost of all necessary servicing, repair, or correction. .PP In no event unless required by applicable law or agreed to in writing will any copyright holder, or any other party who may modify and/or redistribute the software as permitted by the above licence, be liable to you for damages, including any general, special, incidental, or consequential damages arising out of the use or inability to use the software (including but not limited to loss of data or data being rendered inaccurate or losses sustained by you or third parties or a failure of the software to operate with any other software), even if such holder or other party has been advised of the possibility of such damages. .SH "LICENSE" .IX Header "LICENSE" Either the Perl Artistic Licence or the \s-1GPL\s0 http://www.opensource.org/licenses/gpl\-license.php . .SH "AUTHOR" .IX Header "AUTHOR" John McNamara jmcnamara@cpan.org .PP .Vb 4 \& Wilderness for miles, eyes so mild and wise \& Oasis child, born and so wild \& Don\*(Aqt I know you better than the rest \& All deception, all deception from you \& \& Any way you run, you run before us \& Black and white horse arching among us \& Any way you run, you run before us \& Black and white horse arching among us \& \& \-\- Beach House .Ve .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright MM-MMXV, John McNamara. .PP All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.