The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<HTML>
<HEAD>
<TITLE>Spreadsheet::WriteExcel - Write to a cross-platform Excel binary file.</TITLE>
<LINK REV="made" HREF="mailto:">
</HEAD>

<style type="text/css">   



   <!--
   
   pre  {
        font-family : courier new, sans-serif;
        font-size : 10pt;
        color : #0066cc;
   }

   CODE  {
        font-family : courier new, sans-serif;
        font-size : 10pt;
        color : #0066cc;
   }
   
         
   -->
</style>


<BODY>

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A></LI>
	<LI><A HREF="#VERSION">VERSION</A></LI>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A></LI>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A></LI>
	<LI><A HREF="#QUICK_START">QUICK START</A></LI>
	<LI><A HREF="#WORKBOOK_METHODS">WORKBOOK METHODS</A></LI>
	<UL>

        <code><LI><A HREF="#new_">new()</A></LI>
        <LI><A HREF="#close_">close()</A></LI>
        <LI><A HREF="#set_tempdir_">set_tempdir()</A></LI>
        <LI><A HREF="#addworksheet_sheetname_">addworksheet($sheetname)</A></LI>
        <LI><A HREF="#addformat_properties_">addformat(%properties)</A></LI>
        <LI><A HREF="#set_custom_color_index_red_">set_custom_color($index, $red, $green, $blue)</A></LI>
        <LI><A HREF="#set_palette_xl5_">set_palette_xl5()</A></LI>
        <LI><A HREF="#sheets_">sheets()</A></LI>
        <LI><A HREF="#set_1904_">set_1904()</A></LI>
        <LI><A HREF="#set_codepage_codepage_">set_codepage($codepage)</A></LI></code>
	</UL>

	<LI><A HREF="#WORKSHEET_METHODS">WORKSHEET METHODS</A></LI>
	<UL>

        <code><LI><A HREF="#Cell_notation">Cell notation</A></LI>
        <LI><A HREF="#write_row_column_token_fo">write($row, $column, $token, $format)</A></LI>
        <LI><A HREF="#write_number_row_column_num">write_number($row, $column, $number, $format)</A></LI>
        <LI><A HREF="#write_string_row_column_str">write_string($row, $column, $string, $format)</A></LI>
        <LI><A HREF="#keep_leading_zeros_">keep_leading_zeros()</A></LI>
        <LI><A HREF="#write_blank_row_column_form">write_blank($row, $column, $format)</A></LI>
        <LI><A HREF="#write_row_row_column_array_">write_row($row, $column, $array_ref, $format)</A></LI>
        <LI><A HREF="#write_col_row_column_array_">write_col($row, $column, $array_ref, $format)</A></LI>
        <LI><A HREF="#write_url_row_col_url_str">write_url($row, $col, $url, $string, $format)</A></LI>
        <LI><A HREF="#write_url_range_row1_col1_r">write_url_range($row1, $col1, $row2, $col2, $url, $string, $format)</A></LI>
        <LI><A HREF="#write_formula_row_column_fo">write_formula($row, $column, $formula, $format)</A></LI>
        <LI><A HREF="#store_formula_formula_">store_formula($formula)</A></LI>
        <LI><A HREF="#repeat_formula_row_col_form">repeat_formula($row, $col, $formula, $format, ($pattern =&gt; $replace, ...))</A></LI>
        <LI><A HREF="#insert_bitmap_row_col_filen">insert_bitmap($row, $col, $filename, $x, $y, $scale_x, $scale_y)</A></LI>
        <LI><A HREF="#get_name_">get_name()</A></LI>
        <LI><A HREF="#activate_">activate()</A></LI>
        <LI><A HREF="#select_">select()</A></LI>
        <LI><A HREF="#set_first_sheet_">set_first_sheet()</A></LI>
        <LI><A HREF="#protect_password_">protect($password)</A></LI>
        <LI><A HREF="#set_selection_first_row_first">set_selection($first_row, $first_col, $last_row, $last_col)</A></LI>
        <LI><A HREF="#set_row_row_height_format_">set_row($row, $height, $format, $hidden)</A></LI>
        <LI><A HREF="#set_column_first_col_last_col">set_column($first_col, $last_col, $width, $format, $hidden)</A></LI>
        <LI><A HREF="#freeze_panes_row_col_top_ro">freeze_panes($row, $col, $top_row, $left_col)</A></LI>
        <LI><A HREF="#thaw_panes_y_x_top_row_le">thaw_panes($y, $x, $top_row, $left_col)</A></LI>
        <LI><A HREF="#merge_range_first_row_first_c">merge_range($first_row, $first_col, $last_row, $last_col, $token, $format)</A></LI>
        <LI><A HREF="#set_zoom_scale_">set_zoom($scale)</A></LI></code>
	</UL>

	<LI><A HREF="#PAGE_SET_UP_METHODS">PAGE SET-UP METHODS</A></LI>
	<UL>

        <code><LI><A HREF="#set_landscape_">set_landscape()</A></LI>
        <LI><A HREF="#set_portrait_">set_portrait()</A></LI>
        <LI><A HREF="#set_paper_index_">set_paper($index)</A></LI>
        <LI><A HREF="#center_horizontally_">center_horizontally()</A></LI>
        <LI><A HREF="#center_vertically_">center_vertically()</A></LI>
        <LI><A HREF="#set_margins_inches_">set_margins($inches)</A></LI>
        <LI><A HREF="#set_header_string_margin_">set_header($string, $margin)</A></LI>
        <LI><A HREF="#set_footer_">set_footer()</A></LI>
        <LI><A HREF="#repeat_rows_first_row_last_ro">repeat_rows($first_row, $last_row)</A></LI>
        <LI><A HREF="#repeat_columns_first_col_last">repeat_columns($first_col, $last_col)</A></LI>
        <LI><A HREF="#hide_gridlines_option_">hide_gridlines($option)</A></LI>
        <LI><A HREF="#print_row_col_headers_">print_row_col_headers()</A></LI>
        <LI><A HREF="#print_area_first_row_first_co">print_area($first_row, $first_col, $last_row, $last_col)</A></LI>
        <LI><A HREF="#fit_to_pages_width_height_">fit_to_pages($width, $height)</A></LI>
        <LI><A HREF="#set_print_scale_scale_">set_print_scale($scale)</A></LI>
        <LI><A HREF="#set_h_pagebreaks_breaks_">set_h_pagebreaks(@breaks)</A></LI>
        <LI><A HREF="#set_v_pagebreaks_breaks_">set_v_pagebreaks(@breaks)</A></LI></code>
	</UL>

	<LI><A HREF="#CELL_FORMATTING">CELL FORMATTING</A></LI>
	<UL>

		<LI><A HREF="#Creating_and_using_a_Format_obje">Creating and using a Format object</A></LI>
		<LI><A HREF="#Format_methods_and_Format_proper">Format methods and Format properties</A></LI>
		<LI><A HREF="#Working_with_formats">Working with formats</A></LI>
	</UL>

	<LI><A HREF="#FORMAT_METHODS">FORMAT METHODS</A></LI>
	<UL>

        <code><LI><A HREF="#set_properties_properties_">set_properties(%properties)</A></LI>
        <LI><A HREF="#set_font_fontname_">set_font($fontname)</A></LI>
        <LI><A HREF="#set_size_">set_size()</A></LI>
        <LI><A HREF="#set_color_">set_color()</A></LI>
        <LI><A HREF="#set_bold_">set_bold()</A></LI>
        <LI><A HREF="#set_italic_">set_italic()</A></LI>
        <LI><A HREF="#set_underline_">set_underline()</A></LI>
        <LI><A HREF="#set_strikeout_">set_strikeout()</A></LI>
        <LI><A HREF="#set_script_">set_script()</A></LI>
        <LI><A HREF="#set_outline_">set_outline()</A></LI>
        <LI><A HREF="#set_shadow_">set_shadow()</A></LI>
        <LI><A HREF="#set_num_format_">set_num_format()</A></LI>
        <LI><A HREF="#set_locked_">set_locked()</A></LI>
        <LI><A HREF="#set_hidden_">set_hidden()</A></LI>
        <LI><A HREF="#set_align_">set_align()</A></LI>
        <LI><A HREF="#set_merge_">set_merge()</A></LI>
        <LI><A HREF="#set_text_wrap_">set_text_wrap()</A></LI>
        <LI><A HREF="#set_rotation_">set_rotation()</A></LI>
        <LI><A HREF="#set_text_justlast_">set_text_justlast()</A></LI>
        <LI><A HREF="#set_pattern_">set_pattern()</A></LI>
        <LI><A HREF="#set_bg_color_">set_bg_color()</A></LI>
        <LI><A HREF="#set_fg_color_">set_fg_color()</A></LI>
        <LI><A HREF="#set_border_">set_border()</A></LI>
        <LI><A HREF="#set_border_color_">set_border_color()</A></LI>
        <LI><A HREF="#copy_format_">copy($format)</A></LI></code>
	</UL>

	<LI><A HREF="#COLOURS_IN_EXCEL">COLOURS IN EXCEL</A></LI>
	<LI><A HREF="#DATES_IN_EXCEL">DATES IN EXCEL</A></LI>
	<LI><A HREF="#FORMULAS_AND_FUNCTIONS_IN_EXCEL">FORMULAS AND FUNCTIONS IN EXCEL</A></LI>
	<UL>

		<LI><A HREF="#Caveats">Caveats</A></LI>
		<LI><A HREF="#Introduction">Introduction</A></LI>
		<LI><A HREF="#Improving_performance_when_worki">Improving performance when working with formulas</A></LI>
	</UL>

	<LI><A HREF="#EXAMPLES">EXAMPLES</A></LI>
	<UL>

        <code><LI><A HREF="#Example_1">Example 1</A></LI>
        <LI><A HREF="#Example_2">Example 2</A></LI>
        <LI><A HREF="#Example_3">Example 3</A></LI>
        <LI><A HREF="#Example_4">Example 4</A></LI>
        <LI><A HREF="#Example_5">Example 5</A></LI>
        <LI><A HREF="#Additional_Examples">Additional Examples</A></LI></code>
	</UL>

	<LI><A HREF="#LIMITATIONS">LIMITATIONS</A></LI>
	<LI><A HREF="#REQUIREMENTS">REQUIREMENTS</A></LI>
	<LI><A HREF="#INSTALLATION">INSTALLATION</A></LI>
	<LI><A HREF="#PORTABILITY">PORTABILITY</A></LI>
	<LI><A HREF="#DIAGNOSTICS">DIAGNOSTICS</A></LI>
	<LI><A HREF="#THE_EXCEL_BINARY_FORMAT">THE EXCEL BINARY FORMAT</A></LI>
	<LI><A HREF="#WRITING_EXCEL_FILES">WRITING EXCEL FILES</A></LI>
	<LI><A HREF="#READING_EXCEL_FILES">READING EXCEL FILES</A></LI>
	<LI><A HREF="#WORKING_WITH_XML">WORKING WITH XML</A></LI>
	<LI><A HREF="#BUGS">BUGS</A></LI>
	<LI><A HREF="#TO_DO">TO DO</A></LI>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A></LI>
	<LI><A HREF="#ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</A></LI>
	<LI><A HREF="#AUTHOR">AUTHOR</A></LI>
	<LI><A HREF="#COPYRIGHT">COPYRIGHT</A></LI>
</UL>
<!-- INDEX END -->

<HR>
<P>
<H1><A NAME="NAME">NAME</A></H1>
<P>
Spreadsheet::WriteExcel - Write to a cross-platform Excel binary file.

</P>
<P>
<HR>
<H1><A NAME="VERSION">VERSION</A></H1>
<P>
This document refers to version 0.40 of Spreadsheet::WriteExcel, released
December 20, 2002.

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<P>
To write a string, a formatted string, a number and a formula to the first
worksheet in an Excel workbook called perl.xls:

</P>
<P>
<PRE>
    use Spreadsheet::WriteExcel;
</PRE>
</P>
<P>
<PRE>
    # Create a new Excel workbook
    my $workbook = Spreadsheet::WriteExcel-&gt;new(&quot;perl.xls&quot;);
</PRE>
</P>
<P>
<PRE>
    # Add a worksheet
    $worksheet = $workbook-&gt;addworksheet();
</PRE>
</P>
<P>
<PRE>
    #  Add and define a format
    $format = $workbook-&gt;addformat(); # Add a format
    $format-&gt;set_bold();
    $format-&gt;set_color('red');
    $format-&gt;set_align('center');
</PRE>
</P>
<P>
<PRE>
    # Write a formatted and unformatted string, row and column notation.
    $col = $row = 0;
    $worksheet-&gt;write($row, $col, &quot;Hi Excel!&quot;, $format);
    $worksheet-&gt;write(1,    $col, &quot;Hi Excel!&quot;);
</PRE>
</P>
<P>
<PRE>
    # Write a number and a formula using A1 notation
    $worksheet-&gt;write('A3', 1.2345);
    $worksheet-&gt;write('A4', '=SIN(PI()/4)');
</PRE>
</P>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
The Spreadsheet::WriteExcel module can be used to create a cross-platform
Excel binary file. Multiple worksheets can be added to a workbook and
formatting can be applied to cells. Text, numbers, formulas, hyperlinks and
images can be written to the cells.

</P>
<P>
The Excel file produced by this module is compatible with Excel 5, 95, 97,
2000 and 2002.

</P>
<P>
The module will work on the majority of Windows, UNIX and Macintosh
platforms. Generated files are also compatible with the Linux/UNIX
spreadsheet applications Gnumeric and OpenOffice.

</P>
<P>
This module cannot be used to write to an existing Excel file.

</P>
<P>
<HR>
<H1><A NAME="QUICK_START">QUICK START</A></H1>
<P>
Spreadsheet::WriteExcel 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:

</P>
<P>
1. Create a new Excel <EM>workbook</EM> (i.e. file) using <CODE>new()</CODE>.

</P>
<P>
2. Add a <EM>worksheet</EM> to the new workbook using <CODE>addworksheet()</CODE>.

</P>
<P>
3. Write to the worksheet using <CODE>write()</CODE>.

</P>
<P>
Like this:

</P>
<P>
<PRE>
    use Spreadsheet::WriteExcel;                             # Step 0
</PRE>
</P>
<P>
<PRE>
    my $workbook = Spreadsheet::WriteExcel-&gt;new(&quot;perl.xls&quot;); # Step 1
    $worksheet   = $workbook-&gt;addworksheet();                # Step 2
    $worksheet-&gt;write('A1', &quot;Hi Excel!&quot;);                    # Step 3
</PRE>
</P>
<P>
This will create an Excel file called <CODE>perl.xls</CODE> with a single worksheet and the text <CODE>&quot;Hi Excel!&quot;</CODE> in the relevant cell. And that's it. Okay, so there is actually a zeroth
step as well, but <CODE>use module</CODE> goes without saying. There are also more than 40 examples that come with
the distribution and which you can use to get you started. See <A HREF="#EXAMPLES">EXAMPLES</A>.

</P>
<P>
Those of you who read the instructions first and assemble the furniture
afterwards will know how to proceed. ;-)

</P>
<P>
<HR>
<H1><A NAME="WORKBOOK_METHODS">WORKBOOK METHODS</A></H1>
<P>
The Spreadsheet::WriteExcel module provides an object oriented interface to
a new Excel workbook. The following methods are available through a new
workbook.

</P>
<P>
<PRE>
    new()
    close()
    set_tempdir()
    addworksheet()
    addformat()
    set_custom_color()
    set_palette_xl5()
    sheets()
    set_1904()
    set_codepage()
</PRE>
</P>
<P>
If you are unfamiliar with object oriented interfaces or the way that they
are implemented in Perl have a look at <CODE>perlobj</CODE> and <CODE>perltoot</CODE> in the main Perl documentation.

</P>
<P>
<HR>
<H2><A NAME="new_">new()</A></H2>
<P>
A new Excel workbook is created using the <CODE>new()</CODE> constructor which accepts either a filename or a filehandle as a parameter.
The following example creates a new Excel file based on a filename:

</P>
<P>
<PRE>
    my $workbook  = Spreadsheet::WriteExcel-&gt;new('filename.xls');
    my $worksheet = $workbook-&gt;addworksheet();
    $worksheet-&gt;write(0, 0, &quot;Hi Excel!&quot;);
</PRE>
</P>
<P>
Here are some other examples of using <CODE>new()</CODE> with filenames:

</P>
<P>
<PRE>
    my $workbook1 = Spreadsheet::WriteExcel-&gt;new($filename);
    my $workbook2 = Spreadsheet::WriteExcel-&gt;new(&quot;/tmp/filename.xls&quot;);
    my $workbook3 = Spreadsheet::WriteExcel-&gt;new(&quot;c:\\tmp\\filename.xls&quot;);
    my $workbook4 = Spreadsheet::WriteExcel-&gt;new('c:\tmp\filename.xls');
</PRE>
</P>
<P>
The last two examples demonstrates how to create a file on DOS or Windows
where it is necessary to either escape the directory separator <CODE>\</CODE> or to use single quotes to ensure that it isn't interpolated. For more
information see <CODE>perlfaq5: Why can't I use &quot;C:\temp\foo&quot; in DOS paths?</CODE>.

</P>
<P>
The <CODE>new()</CODE> constructor returns a Spreadsheet::WriteExcel object that you can use to
add worksheets and store data. It should be noted that although <CODE>my</CODE> 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 <CODE>close()</CODE> method.

</P>
<P>
If the file cannot be created, due to file permissions or some other
reason,  <CODE>new</CODE> will return <CODE>undef</CODE>. Therefore, it is good practice to check the return value of <CODE>new</CODE> before proceeding. As usual the Perl variable <CODE>$!</CODE> will be set if there is a file creation error. You will also see one of the
warning messages detailed in <A HREF="#DIAGNOSTICS">DIAGNOSTICS</A>:

</P>
<P>
<PRE>
    my $workbook  = Spreadsheet::WriteExcel-&gt;new('protected.xls');
    die &quot;Problems creating new Excel file: $!&quot; unless defined $workbook;
</PRE>
</P>
<P>
You can also pass a valid filehandle to the <CODE>new()</CODE> constructor. For example in a CGI program you could do something like this:

</P>
<P>
<PRE>
    binmode(STDOUT);
    my $workbook  = Spreadsheet::WriteExcel-&gt;new(\*STDOUT);
</PRE>
</P>
<P>
The requirement for <CODE>binmode()</CODE> is explained below.

</P>
<P>
For CGI programs you can also use the special Perl filename <CODE>'-'</CODE> which will redirect the output to STDOUT:

</P>
<P>
<PRE>
    my $workbook  = Spreadsheet::WriteExcel-&gt;new('-');
</PRE>
</P>
<P>
See also, the <CODE>cgi.pl</CODE> program in the <CODE>examples</CODE> directory of the distro.

</P>
<P>
However, this special case will not work in <CODE>mod_perl</CODE> programs where you will have to do something like the following:

</P>
<P>
<PRE>
    tie *XLS, 'Apache';
    binmode(XLS);
    my $workbook  = Spreadsheet::WriteExcel-&gt;new(\*XLS);
</PRE>
</P>
<P>
See also, the <CODE>mod_perl.pl</CODE> program in the <CODE>examples</CODE> directory of the distro.

</P>
<P>
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 tied scalar. For some
examples of using filehandles with Spreadsheet::WriteExcel see the <CODE>filehandle.pl</CODE> program in the <CODE>examples</CODE> directory of the distro.

</P>
<P>
Note about the requirement for <CODE>binmode()</CODE>: An Excel file is comprised of binary data. Therefore, if you are using a
filehandle you should ensure that you <CODE>binmode()</CODE> it prior to passing it to <CODE>new()</CODE>.You can safely do this regardless of whether your platform requires it or
not. For more information about <CODE>binmode()</CODE> see <CODE>perlfunc</CODE> and <CODE>perlopentut</CODE> in the main Perl documentation. It is equally important to note that you do
not need to <CODE>binmode()</CODE> a filename. In fact it would cause an error. Spreadsheet::WriteExcel
performs the <CODE>binmode()</CODE> internally when it converts the filename to a filehandle.

</P>
<P>
<HR>
<H2><A NAME="close_">close()</A></H2>
<P>
The <CODE>close()</CODE> method can be used to explicitly close an Excel file.

</P>
<P>
<PRE>
    $workbook-&gt;close();
</PRE>
</P>
<P>
An explicit <CODE>close()</CODE> 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.

</P>
<P>
In addition, <CODE>close()</CODE> may be required if the scope of the Workbook, Worksheet or Format objects
cannot be determined by perl. Situations where this can occur are:

</P>
<UL>
<LI>
<P>
If <CODE>my()</CODE> was not used to declare the scope of a workbook variable created using <CODE>new()</CODE>.

</P>
<LI>
<P>
If the <CODE>new()</CODE>, <CODE>addworksheet()</CODE> or <CODE>addformat()</CODE> methods are called in subroutines.

</P>
</UL>
<P>
The reason for this is that Spreadsheet::WriteExcel relies on Perl's <CODE>DESTROY</CODE> mechanism to trigger destructor methods in a specific sequence. This will
not happen if the scope of the variables cannot be determined.

</P>
<P>
In general, if you create a file with a size of 0 bytes or you fail to
create a file you need to call <CODE>close()</CODE>.

</P>
<P>
The return value of <CODE>close()</CODE> is the same as that returned by perl when it closes the file created by <CODE>new()</CODE>. This allows you to handle error conditions in the usual way:

</P>
<P>
<PRE>
    $workbook-&gt;close() or die &quot;Error closing file: $!&quot;;
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_tempdir_">set_tempdir()</A></H2>
<P>
For speed and efficiency <CODE>Spreadsheet::WriteExcel</CODE> stores worksheet data in temporary files prior to assembling the final
workbook.

</P>
<P>
If Spreadsheet::WriteExcel is unable to create these temporary files it
will store the required data in memory. This can be slow for large files.
To avoid this problem the <CODE>set_tempdir()</CODE> method can be used to specify a directory that is accessible for the
creation of temporary files.

</P>
<P>
To check if this might be a problem on a particular system you can run a
simple test program with <CODE>-w</CODE> or <CODE>use warnings</CODE>. This will generate a warning if the module cannot create the required
temporary files:

</P>
<P>
<PRE>
    #!/usr/bin/perl -w
</PRE>
</P>
<P>
<PRE>
    use Spreadsheet::WriteExcel;
</PRE>
</P>
<P>
<PRE>
    my $workbook  = Spreadsheet::WriteExcel-&gt;new(&quot;test.xls&quot;);
    my $worksheet = $workbook-&gt;addworksheet();
</PRE>
</P>
<P>
However, this is not a common problem. The only reported instances of this
were with certain IIS configurations on Windows. Also, as of version 0.37
the mechanism for creating temporary files has changed and it should now
work without intervention even on IIS.

</P>
<P>
The <CODE>File::Temp</CODE> module is used to create the temporary files. File::Temp uses <CODE>File::Spec</CODE> to determine an appropriate location for these files such as <CODE>/tmp</CODE> or <CODE>c:\windows\temp</CODE>. You can find out which directory is used on your system as follows:

</P>
<P>
<PRE>
    perl -MFile::Spec -le 'print File::Spec-&gt;tmpdir'
</PRE>
</P>
<P>
Even if the default temporary file directory is accessible you may wish to
specify an alternative location for security reasons:

</P>
<P>
<PRE>
    $workbook-&gt;set_tempdir('/tmp/writeexcel');
    $workbook-&gt;set_tempdir('c:\windows\temp\writeexcel');
</PRE>
</P>
<P>
The directory for the temporary file must exist, <CODE>set_tempdir()</CODE> will not create a new directory.

</P>
<P>
Note: This method must be called before calling <CODE>addworksheet()</CODE>.

</P>
<P>
<HR>
<H2><A NAME="addworksheet_sheetname_">addworksheet($sheetname)</A></H2>
<P>
At least one worksheet should be added to a new workbook. A worksheet is
used to write data into cells:

</P>
<P>
<PRE>
    $worksheet1 = $workbook-&gt;addworksheet();          # Sheet1
    $worksheet2 = $workbook-&gt;addworksheet('Foglio2'); # Foglio2
    $worksheet3 = $workbook-&gt;addworksheet('Data');    # Data
    $worksheet4 = $workbook-&gt;addworksheet();          # Sheet4
</PRE>
</P>
<P>
If <CODE>$sheetname</CODE> is not specified the default Excel convention will be followed, i.e.
Sheet1, Sheet2, etc.

</P>
<P>
The worksheet name must be a valid Excel worksheet name, i.e. it cannot
contain any of the following characters, <CODE>: * ? / \</CODE> and it must be less than 32 characters. In addition, you cannot use the
same <CODE>$sheetname</CODE> for more than one worksheet.

</P>
<P>
<HR>
<H2><A NAME="addformat_properties_">addformat(%properties)</A></H2>
<P>
The <CODE>addformat()</CODE> 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.

</P>
<P>
<PRE>
    $format1 = $workbook-&gt;addformat(%props); # Set properties at creation
    $format2 = $workbook-&gt;addformat();       # Set properties later
</PRE>
</P>
<P>
See the <A HREF="#CELL_FORMATTING">CELL FORMATTING</A> section for more details about Format properties and how to set them.

</P>
<P>
<HR>
<H2><A NAME="set_custom_color_index_red_">set_custom_color($index, $red, $green, $blue)</A></H2>
<P>
The <CODE>set_custom_color()</CODE> method can be used to override one of the built-in palette values with a
more suitable colour.

</P>
<P>
The value for <CODE>$index</CODE> should be in the range 8..63, see <A HREF="#COLOURS_IN_EXCEL">COLOURS IN EXCEL</A>.

</P>
<P>
The default named colours use the following indices:

</P>
<P>
<PRE>
     8   =&gt;   black
     9   =&gt;   white
    10   =&gt;   red
    11   =&gt;   lime
    12   =&gt;   blue
    13   =&gt;   yellow
    14   =&gt;   magenta
    15   =&gt;   cyan
    16   =&gt;   brown
    17   =&gt;   green
    18   =&gt;   navy
    20   =&gt;   purple
    22   =&gt;   silver
    23   =&gt;   gray
    53   =&gt;   orange
</PRE>
</P>
<P>
A new colour is set using its RGB (red green blue) components. The <CODE>$red</CODE>, <CODE>$green</CODE> and <CODE>$blue</CODE> values must be in the range 0..255. You can determine the required values
in Excel using the <CODE>Tools-&gt;Options-&gt;Colors-&gt;Modify</CODE> dialog.

</P>
<P>
The <CODE>set_custom_color()</CODE> workbook method can also be used with a HTML style <CODE>#rrggbb</CODE> hex value:

</P>
<P>
<PRE>
    $workbook-&gt;set_custom_color(40, 255,  102,  0   ); # Orange
    $workbook-&gt;set_custom_color(40, 0xFF, 0x66, 0x00); # Same thing
    $workbook-&gt;set_custom_color(40, '#FF6600'       ); # Same thing
</PRE>
</P>
<P>
<PRE>
    my $font = $workbook-&gt;addformat(color =&gt; 40); # Use the modified colour
</PRE>
</P>
<P>
The return value from <CODE>set_custom_color()</CODE> is the index of the colour that was changed:

</P>
<P>
<PRE>
    my $ferrari = $workbook-&gt;set_custom_color(40, 216, 12, 12);
</PRE>
</P>
<P>
<PRE>
    my $format  = $workbook-&gt;addformat(
                                        bg_color =&gt; $ferrari,
                                        pattern  =&gt; 1,
                                        border   =&gt; 1
                                      );
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_palette_xl5_">set_palette_xl5()</A></H2>
<P>
Prior to version 0.36, Spreadsheet::WriteExcel used the Excel 5 default
colour palette. It was changed to the Excel 97+ palette for forward
compatibility.

</P>
<P>
However, if you have programs that rely on the colours and indices of the
Excel 5 palette you can revert to the previous default by using the <CODE>set_palette_xl5()</CODE> method:

</P>
<P>
<PRE>
    $workbook-&gt;set_palette_xl5();
</PRE>
</P>
<P>
A comparison of the colour components in the Excel 5 and Excel 97+ colour
palettes is shown in <CODE>rgb5-97.txt</CODE> in the <CODE>doc</CODE> directory of the distro.

</P>
<P>
See also <A HREF="#COLOURS_IN_EXCEL">COLOURS IN EXCEL</A>.

</P>
<P>
<HR>
<H2><A NAME="sheets_">sheets()</A></H2>
<P>
The <CODE>sheets()</CODE> method returns a list of the worksheets in a workbook. This can be useful
if you want to repeat an operation on each worksheet in a workbook or if
you wish to refer to a worksheet by its index:

</P>
<P>
<PRE>
    foreach $worksheet ($workbook-&gt;sheets()) {
       print $worksheet-&gt;get_name();
    }
</PRE>
</P>
<P>
<PRE>
    # or:
</PRE>
</P>
<P>
<PRE>
    ($workbook-&gt;sheets())[5]-&gt;write('A1', &quot;Hello&quot;);
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_1904_">set_1904()</A></H2>
<P>
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.

</P>
<P>
Spreadsheet::WriteExcel stores dates in the 1900 format by default. If you
wish to change this you can call the <CODE>set_1904()</CODE> workbook method. You can query the current value by calling the <CODE>get_1904()</CODE> workbook method. This returns 0 for 1900 and 1 for 1904.

</P>
<P>
See also <A HREF="#Dates_in_Excel">Dates in Excel</A> for more information about working with Excel's date system.

</P>
<P>
In general you probably won't need to use <CODE>set_1904()</CODE>.

</P>
<P>
<HR>
<H2><A NAME="set_codepage_codepage_">set_codepage($codepage)</A></H2>
<P>
The default code page or character set used by Spreadsheet::WriteExcel is
ANSI. This is also the default used by Excel for Windows. Occasionally
however it may be necessary to change the code page via the <CODE>set_codepage()</CODE> method.

</P>
<P>
Changing the code page may be required if your are using
Spreadsheet::WriteExcel on the Macintosh and you are using characters
outside the ASCII 128 character set:

</P>
<P>
<PRE>
    $workbook-&gt;set_codepage(1); # ANSI, MS Windows
    $workbook-&gt;set_codepage(2); # Apple Macintosh
</PRE>
</P>
<P>
The <CODE>set_codepage()</CODE> method is rarely required.

</P>
<P>
<HR>
<H1><A NAME="WORKSHEET_METHODS">WORKSHEET METHODS</A></H1>
<P>
A new worksheet is created by calling the <CODE>addworksheet()</CODE> method from a workbook object:

</P>
<P>
<PRE>
    $worksheet1 = $workbook-&gt;addworksheet();
    $worksheet2 = $workbook-&gt;addworksheet();
</PRE>
</P>
<P>
The following methods are available through a new worksheet:

</P>
<P>
<PRE>
    write()
    write_number()
    write_string()
    keep_leading_zeros()
    write_blank()
    write_row()
    write_col()
    write_url()
    write_url_range()
    write_formula()
    store_formula()
    repeat_formula()
    insert_bitmap()
    get_name()
    activate()
    select()
    set_first_sheet()
    protect()
    set_selection()
    set_row()
    set_column()
    freeze_panes()
    thaw_panes()
    merge_range()
    set_zoom()
</PRE>
</P>
<P>
<HR>
<H2><A NAME="Cell_notation">Cell notation</A></H2>
<P>
Spreadsheet::WriteExcel supports two forms of notation to designate the
position of cells: Row-column notation and A1 notation.

</P>
<P>
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:

</P>
<P>
<PRE>
    (0, 0)      # The top left cell in row-column notation.
    ('A1')      # The top left cell in A1 notation.
</PRE>
</P>
<P>
<PRE>
    (1999, 29)  # Row-column notation.
    ('AD2000')  # The same cell in A1 notation.
</PRE>
</P>
<P>
Row-column notation is useful if you are referring to cells
programmatically:

</P>
<P>
<PRE>
    for my $i (0 .. 9) {
        $worksheet-&gt;write($i, 0, 'Hello'); # Cells A1 to A10
    }
</PRE>
</P>
<P>
A1 notation is useful for setting up a worksheet manually and for working
with formulas:

</P>
<P>
<PRE>
    $worksheet-&gt;write('H1', 200);
    $worksheet-&gt;write('H2', '=H1+1');
</PRE>
</P>
<P>
In formulas and applicable methods you can also use the <CODE>A:A</CODE> column notation:

</P>
<P>
<PRE>
    $worksheet-&gt;write('A1', '=SUM(B:B)');
</PRE>
</P>
<P>
The <CODE>Spreadsheet::WriteExcel::Utility</CODE> module that is included in the distro contains helper functions for dealing
with A1 notation, for example:

</P>
<P>
<PRE>
    use Spreadsheet::WriteExcel::Utility;
</PRE>
</P>
<P>
<PRE>
    ($row, $col)    = xl_cell_to_rowcol('C2');  # (1, 2)
    $str            = xl_rowcol_to_cell(1, 2);  # C2
</PRE>
</P>
<P>
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.

</P>
<P>
Note: in Excel it is also possible to use a R1C1 notation. This is not
supported by Spreadsheet::WriteExcel.

</P>
<P>
<HR>
<H2><A NAME="write_row_column_token_fo">write($row, $column, $token, $format)</A></H2>
<P>
Excel makes a distinction between data types such as strings, numbers,
blanks, formulas and hyperlinks. To simplify the process of writing data
the <CODE>write()</CODE> method acts as a general alias for several more specific methods:

</P>
<P>
<PRE>
    write_string()
    write_number()
    write_blank()
    write_formula()
    write_url()
    write_row()
    write_col()
</PRE>
</P>
<P>
The general rule is that if the data looks like a <EM>something</EM> then a <EM>something</EM> is written. Here are some examples in both row-column and A1 notation:

</P>
<P>
<PRE>
                                                      # Same as:
    $worksheet-&gt;write(0, 0, &quot;Hello&quot;                ); # write_string()
    $worksheet-&gt;write(1, 0, 'One'                  ); # write_string()
    $worksheet-&gt;write(2, 0,  2                     ); # write_number()
    $worksheet-&gt;write(3, 0,  3.00001               ); # write_number()
    $worksheet-&gt;write(4, 0,  &quot;&quot;                    ); # write_blank()
    $worksheet-&gt;write(5, 0,  ''                    ); # write_blank()
    $worksheet-&gt;write(6, 0,  undef                 ); # write_blank()
    $worksheet-&gt;write(7, 0                         ); # write_blank()
    $worksheet-&gt;write(8, 0,  'http://www.perl.com/'); # write_url()
    $worksheet-&gt;write('A9',  'ftp://ftp.cpan.org/<' ); # write_url()
    $worksheet-&gt;write('A10', 'internal:Sheet1!A1'  ); # write_url()
    $worksheet-&gt;write('A11', 'external:c:\foo.xls' ); # write_url()
    $worksheet-&gt;write('A12', '=A3 + 3*A4'          ); # write_formula()
    $worksheet-&gt;write('A13', '=SIN(PI()/4)'        ); # write_formula()
    $worksheet-&gt;write('A14', \@array               ); # write_row()
    $worksheet-&gt;write('A15', [\@array]             ); # write_col()
</PRE>
</P>
<P>
<PRE>
    # And if the keep_leading_zeros property is set:
    $worksheet-&gt;write('A16,  2                     ); # write_number()
    $worksheet-&gt;write('A17,  02                    ); # write_string()
    $worksheet-&gt;write('A18,  00002                 ); # write_string()
</PRE>
</P>
<P>
The &quot;looks like&quot; rule is defined by regular expressions:

</P>
<P>
<CODE>write_number()</CODE> if <CODE>$token</CODE> is a number based on the following regex: <CODE>$token =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/</CODE>.

</P>
<P>
<CODE>write_string()</CODE> if <CODE>keep_leading_zeros()</CODE> is set and <CODE>$token</CODE> is an integer with leading zeros based on the following regex: <CODE>$token =~ /^0\d+$/</CODE>.

</P>
<P>
<CODE>write_blank()</CODE> if <CODE>$token</CODE> is undef or a blank string: <CODE>undef</CODE>, <CODE>&quot;&quot;</CODE> or <CODE>''</CODE>.

</P>
<P>
<CODE>write_url()</CODE> if <CODE>$token</CODE> is a http, https, ftp or mailto URL based on the following regexes: <CODE>$token =~ m|^[fh]tt?ps?://|</CODE> or  <CODE>$token =~ m|^mailto:|</CODE>.

</P>
<P>
<CODE>write_url()</CODE> if <CODE>$token</CODE> is an internal or external sheet reference based on the following regex: <CODE>$token =~ m[^(in|ex)ternal:]</CODE>.

</P>
<P>
<CODE>write_formula()</CODE> if the first character of <CODE>$token</CODE> is <CODE>&quot;=&quot;</CODE>.

</P>
<P>
<CODE>write_row()</CODE> if <CODE>$token</CODE> is an array ref.

</P>
<P>
<CODE>write_col()</CODE> if <CODE>$token</CODE> is an array ref of array refs.

</P>
<P>
<CODE>write_string()</CODE> if none of the previous conditions apply.

</P>
<P>
The <CODE>$format</CODE> parameter is optional. It should be a valid Format object, see <A HREF="#CELL_FORMATTING">CELL FORMATTING</A>:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_bold();
    $format-&gt;set_color('red');
    $format-&gt;set_align('center');
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(4, 0, &quot;Hello&quot;, $format ); # Formatted string
</PRE>
</P>
<P>
The <CODE>write()</CODE> method will ignore empty strings or <CODE>undef</CODE> tokens unless a format is also supplied. As such you needn't worry about
special handling for empty or <CODE>undef</CODE> values in your data. See also the the <CODE>write_blank()</CODE> method.

</P>
<P>
One problem with the <CODE>write()</CODE> method is that occasionally data looks like a number but you don't want it
treated as a number. For example, zip codes or ID numbers often start with
a leading zero. If you write this data as a number then the leading
<CODE>zero(s)</CODE> will be stripped. You can change this default
behaviour by using the <CODE>keep_leading_zeros()</CODE> 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 <CODE>keep_leading_zeros()</CODE> section for a full discussion of this issue.

</P>
<P>
The <CODE>write</CODE> methods return:

</P>
<P>
<PRE>
    0 for success.
   -1 for insufficient number of arguments.
   -2 for row or column out of bounds.
   -3 for string too long.
</PRE>
</P>
<P>
<HR>
<H2><A NAME="write_number_row_column_num">write_number($row, $column, $number, $format)</A></H2>
<P>
Write an integer or a float to the cell specified by <CODE>$row</CODE> and <CODE>$column</CODE>:

</P>
<P>
<PRE>
    $worksheet-&gt;write_number(0, 0,  123456);
    $worksheet-&gt;write_number('A2',  2.3451);
</PRE>
</P>
<P>
See the note about <A HREF="#Cell_notation">Cell notation</A>. The <CODE>$format</CODE> parameter is optional.

</P>
<P>
In general it is sufficient to use the <CODE>write()</CODE> method.

</P>
<P>
<HR>
<H2><A NAME="write_string_row_column_str">write_string($row, $column, $string, $format)</A></H2>
<P>
Write a string to the cell specified by <CODE>$row</CODE> and <CODE>$column</CODE>:

</P>
<P>
<PRE>
    $worksheet-&gt;write_string(0, 0, &quot;Your text here&quot; );
    $worksheet-&gt;write_string('A2', &quot;or here&quot; );
</PRE>
</P>
<P>
The maximum string size is 255 characters. The <CODE>$format</CODE> parameter is optional.

</P>
<P>
In general it is sufficient to use the <CODE>write()</CODE> method. However, you may sometimes wish to use the <CODE>write_string()</CODE> 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:

</P>
<P>
<PRE>
    # Write as a plain string
    $worksheet-&gt;write_string('A1', '01209');
</PRE>
</P>
<P>
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 <CODE>@</CODE>:

</P>
<P>
<PRE>
    # Format as a string. Doesn't change to a number when edited
    my $format1 = $workbook-&gt;addformat(num_format =&gt; '@');
    $worksheet-&gt;write_string('A2', '01209', $format1);
</PRE>
</P>
<P>
See also the note about <A HREF="#Cell_notation">Cell notation</A>.

</P>
<P>
The 255 character limit will be removed when the module moves to the Excel
97+ format. In the meantime, you can work around this limit using a
formula. See the <CODE>long_string.pl</CODE> program in the <CODE>examples</CODE> directory of the distro. See also  <A HREF="#TO_DO">TO DO</A> for information about the Excel97 pre-release version of this module.

</P>
<P>
<HR>
<H2><A NAME="keep_leading_zeros_">keep_leading_zeros()</A></H2>
<P>
This method changes the default handling of integers with leading zeros
when using the <CODE>write()</CODE> method.

</P>
<P>
The <CODE>write()</CODE> 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 <CODE>write_number()</CODE>. One problem with this approach is that occasionally data looks like a
number but you don't want it treated as a number.

</P>
<P>
For example, zip codes or ID numbers often start with a leading zero. If
you write this data as a number then the leading <CODE>zero(s)</CODE> will
be stripped. This is the also the default behaviour when you enter data
manually in Excel.

</P>
<P>
To get around this you can either write a formatted number, write the
number as a string or use the <CODE>keep_leading_zeros()</CODE> method to change the default behaviour of <CODE>write()</CODE>:

</P>
<P>
<PRE>
    # Write implicitly as a number, the leading zero is removed: 1209
    $worksheet-&gt;write('A1', '01209');
</PRE>
</P>
<P>
<PRE>
    # Write a zero padded number using a format: 01209
    my $format1 = $workbook-&gt;addformat(num_format =&gt; '00000');
    $worksheet-&gt;write('A2', '01209', $format1);
</PRE>
</P>
<P>
<PRE>
    # Write explicitly as a string: 01209
    $worksheet-&gt;write_string('A3', '01209');
</PRE>
</P>
<P>
<PRE>
    # Write implicitly as a string: 01209
    $worksheet-&gt;keep_leading_zeros();
    $worksheet-&gt;write('A4', '01209');
</PRE>
</P>
<P>
The above code would generate a worksheet that looked like the following:

</P>
<P>
<PRE>
     -----------------------------------------------------------
    |   |     A     |     B     |     C     |     D     | ...
     -----------------------------------------------------------
    | 1 |      1209 |           |           |           | ...
    | 2 |     01209 |           |           |           | ...
    | 3 | 01209     |           |           |           | ...
    | 4 | 01209     |           |           |           | ...
</PRE>
</P>
<P>
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 <A HREF="#CELL_FORMATTING">CELL FORMATTING</A>.

</P>
<P>
It should be noted that if the user edits the data in examples <CODE>A3</CODE> and <CODE>A4</CODE> the strings will revert back to numbers. Again this is Excel's default
behaviour. To avoid this you can use the text format <CODE>@</CODE>:

</P>
<P>
<PRE>
    # Format as a string (01209)
    my $format2 = $workbook-&gt;addformat(num_format =&gt; '@');
    $worksheet-&gt;write_string('A5', '01209', $format2);
</PRE>
</P>
<P>
The <CODE>keep_leading_zeros()</CODE> property is off by default. The <CODE>keep_leading_zeros()</CODE> method takes 0 or 1 as an argument. It defaults to 1 if an argument isn't
specified:

</P>
<P>
<PRE>
    $worksheet-&gt;keep_leading_zeros();  # Set on
    $worksheet-&gt;keep_leading_zeros(1); # Set on
    $worksheet-&gt;keep_leading_zeros(0); # Set off
</PRE>
</P>
<P>
<HR>
<H2><A NAME="write_blank_row_column_form">write_blank($row, $column, $format)</A></H2>
<P>
Write a blank cell specified by <CODE>$row</CODE> and <CODE>$column</CODE>:

</P>
<P>
<PRE>
    $worksheet-&gt;write_blank(0, 0, $format);
</PRE>
</P>
<P>
This method is used to add formatting to a cell which doesn't contain a
string or number value.

</P>
<P>
Excel differentiates between an &quot;Empty&quot; cell and a
&quot;Blank&quot; cell. An &quot;Empty&quot; cell is a cell which doesn't
contain data whilst a &quot;Blank&quot; cell is a cell which doesn't
contain data but does contain formatting. Excel stores &quot;Blank&quot;
cells but ignores &quot;Empty&quot; cells.

</P>
<P>
As such, if you write an empty cell without formatting it is ignored:

</P>
<P>
<PRE>
    $worksheet-&gt;write('A1',  undef, $format); # write_blank()
    $worksheet-&gt;write('A2',  undef         ); # Ignored
</PRE>
</P>
<P>
This seemingly uninteresting fact means that you can write arrays of data
without special treatment for undef or empty string values.

</P>
<P>
See the note about <A HREF="#Cell_notation">Cell notation</A>.

</P>
<P>
<HR>
<H2><A NAME="write_row_row_column_array_">write_row($row, $column, $array_ref, $format)</A></H2>
<P>
The <CODE>write_row()</CODE> method can be used to write a 1D or 2D array or 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 <CODE>write()</CODE> method is then called for each element of the data. For example:

</P>
<P>
<PRE>
    @array      = ('awk', 'gawk', 'mawk');
    $array_ref  = \@array;
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write_row(0, 0, $array_ref);
</PRE>
</P>
<P>
<PRE>
    # The above example is equivalent to:
    $worksheet-&gt;write(0, 0, $array[0]);
    $worksheet-&gt;write(0, 1, $array[1]);
    $worksheet-&gt;write(0, 2, $array[2]);
</PRE>
</P>
<P>
Note: For convenience the <CODE>write()</CODE> method behaves in the same way as <CODE>write_row()</CODE> if it is passed an array reference. Therefore the following two method
calls are equivalent:

</P>
<P>
<PRE>
    $worksheet-&gt;write_row('A1', $array_ref); # Write a row of data
    $worksheet-&gt;write(    'A1', $array_ref); # Same thing
</PRE>
</P>
<P>
As with all of the write methods the <CODE>$format</CODE> parameter is optional. If a format is specified it is applied to all the
elements of the data array.

</P>
<P>
Array references within the data will be treated as columns. This allows
you to write 2D arrays of data in one go. For example:

</P>
<P>
<PRE>
    @eec =  (
                ['maggie', 'milly', 'molly', 'may'  ],
                [13,       14,      15,      16     ],
                ['shell',  'star',  'crab',  'stone']
            );
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write_row('A1', \@eec);
</PRE>
</P>
<P>
Would produce a worksheet as follows:

</P>
<P>
<PRE>
     -----------------------------------------------------------
    |   |    A    |    B    |    C    |    D    |    E    | ...
     -----------------------------------------------------------
    | 1 | maggie  | 13      | shell   | ...     |  ...    | ...
    | 2 | milly   | 14      | star    | ...     |  ...    | ...
    | 3 | molly   | 15      | crab    | ...     |  ...    | ...
    | 4 | may     | 16      | stone   | ...     |  ...    | ...
    | 5 | ...     | ...     | ...     | ...     |  ...    | ...
    | 6 | ...     | ...     | ...     | ...     |  ...    | ...
</PRE>
</P>
<P>
To write the data in a row-column order refer to the <CODE>write_col()</CODE> method below.

</P>
<P>
Any <CODE>undef</CODE> 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.

</P>
<P>
To find out more about array references refer to <CODE>perlref</CODE> and <CODE>perlreftut</CODE> in the main Perl documentation. To find out more about 2D arrays or
&quot;lists of lists&quot; refer to <CODE>perllol</CODE>.

</P>
<P>
The <CODE>write_row()</CODE> 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 <CODE>write()</CODE> method above.

</P>
<P>
See also the <CODE>write_arrays.pl</CODE> program in the <CODE>examples</CODE> directory of the distro.

</P>
<P>
The <CODE>write_row()</CODE> method allows the following idiomatic conversion of a text file to an Excel
file:

</P>
<P>
<PRE>
    #!/usr/bin/perl -w
</PRE>
</P>
<P>
<PRE>
    use strict;
    use Spreadsheet::WriteExcel;
</PRE>
</P>
<P>
<PRE>
    my $workbook  = Spreadsheet::WriteExcel-&gt;new('file.xls');
    my $worksheet = $workbook-&gt;addworksheet();
</PRE>
</P>
<P>
<PRE>
    open INPUT, &quot;file.txt&quot; or die &quot;Couldn't open file: $!&quot;;
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write($.-1, 0, [split]) while &lt;INPUT&gt;;
</PRE>
</P>
<P>
<HR>
<H2><A NAME="write_col_row_column_array_">write_col($row, $column, $array_ref, $format)</A></H2>
<P>
The <CODE>write_col()</CODE> method can be used to write a 1D or 2D array or 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 <CODE>write()</CODE> method is then called for each element of the data. For example:

</P>
<P>
<PRE>
    @array      = ('awk', 'gawk', 'mawk');
    $array_ref  = \@array;
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write_col(0, 0, $array_ref);
</PRE>
</P>
<P>
<PRE>
    # The above example is equivalent to:
    $worksheet-&gt;write(0, 0, $array[0]);
    $worksheet-&gt;write(1, 0, $array[1]);
    $worksheet-&gt;write(2, 0, $array[2]);
</PRE>
</P>
<P>
As with all of the write methods the <CODE>$format</CODE> parameter is optional. If a format is specified it is applied to all the
elements of the data array.

</P>
<P>
Array references within the data will be treated as rows. This allows you
to write 2D arrays of data in one go. For example:

</P>
<P>
<PRE>
    @eec =  (
                ['maggie', 'milly', 'molly', 'may'  ],
                [13,       14,      15,      16     ],
                ['shell',  'star',  'crab',  'stone']
            );
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write_col('A1', \@eec);
</PRE>
</P>
<P>
Would produce a worksheet as follows:

</P>
<P>
<PRE>
     -----------------------------------------------------------
    |   |    A    |    B    |    C    |    D    |    E    | ...
     -----------------------------------------------------------
    | 1 | maggie  | milly   | molly   | may     |  ...    | ...
    | 2 | 13      | 14      | 15      | 16      |  ...    | ...
    | 3 | shell   | star    | crab    | stone   |  ...    | ...
    | 4 | ...     | ...     | ...     | ...     |  ...    | ...
    | 5 | ...     | ...     | ...     | ...     |  ...    | ...
    | 6 | ...     | ...     | ...     | ...     |  ...    | ...
</PRE>
</P>
<P>
To write the data in a column-row order refer to the <CODE>write_row()</CODE> method above.

</P>
<P>
Any <CODE>undef</CODE> 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.

</P>
<P>
As noted above the <CODE>write()</CODE> method can be used as a synonym for <CODE>write_row()</CODE> and <CODE>write_row()</CODE> handles nested array refs as columns. Therefore, the following two method
calls are equivalent although the more explicit call to <CODE>write_col()</CODE> would be preferable for maintainability:

</P>
<P>
<PRE>
    $worksheet-&gt;write_col('A1', $array_ref    ); # Write a column of data
    $worksheet-&gt;write(    'A1', [ $array_ref ]); # Same thing
</PRE>
</P>
<P>
To find out more about array references refer to <CODE>perlref</CODE> and <CODE>perlreftut</CODE> in the main Perl documentation. To find out more about 2D arrays or
&quot;lists of lists&quot; refer to <CODE>perllol</CODE>.

</P>
<P>
The <CODE>write_col()</CODE> 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 <CODE>write()</CODE> method above.

</P>
<P>
See also the <CODE>write_arrays.pl</CODE> program in the <CODE>examples</CODE> directory of the distro.

</P>
<P>
<HR>
<H2><A NAME="write_url_row_col_url_str">write_url($row, $col, $url, $string, $format)</A></H2>
<P>
Write a hyperlink to a URL in the cell specified by <CODE>$row</CODE> and <CODE>$column</CODE>. 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 string is specified. The parameters <CODE>$string</CODE> and the <CODE>$format</CODE> are optional and their position is interchangeable.

</P>
<P>
The label is written using the <CODE>write_string()</CODE> method. Therefore the 255 characters string limit applies to the label: the
URL can be any length.

</P>
<P>
There are four web style URI's supported: <CODE>http://</CODE>, <CODE>https://</CODE>, <CODE>ftp://</CODE> and  <CODE>mailto:</CODE>:

</P>
<P>
<PRE>
    $worksheet-&gt;write_url(0, 0,  'ftp://www.perl.org/'                  );
    $worksheet-&gt;write_url(1, 0,  'http://www.perl.com/', 'Perl home'    );
    $worksheet-&gt;write_url('A3',  'http://www.perl.com/', $format        );
    $worksheet-&gt;write_url('A4',  'http://www.perl.com/', 'Perl', $format);
    $worksheet-&gt;write_url('A5',  'mailto:jmcnamara@cpan.org'            );
</PRE>
</P>
<P>
There are two local URIs supported: <CODE>internal:</CODE> and <CODE>external:</CODE>. These are used for hyperlinks to internal worksheet references or
external workbook and worksheet references:

</P>
<P>
<PRE>
    $worksheet-&gt;write_url('A6',  'internal:Sheet2!A1'                   );
    $worksheet-&gt;write_url('A7',  'internal:Sheet2!A1',   $format        );
    $worksheet-&gt;write_url('A8',  'internal:Sheet2!A1:B2'                );
    $worksheet-&gt;write_url('A9',  q{internal:'Sales Data'!A1}            );
    $worksheet-&gt;write_url('A10', 'external:c:\temp\foo.xls'             );
    $worksheet-&gt;write_url('A11', 'external:c:\temp\foo.xls#Sheet2!A1'   );
    $worksheet-&gt;write_url('A12', 'external:..\..\..\foo.xls'            );
    $worksheet-&gt;write_url('A13', 'external:..\..\..\foo.xls#Sheet2!A1'  );
    $worksheet-&gt;write_url('A13', 'external:\\\\NETWORK\share\foo.xls'   );
</PRE>
</P>
<P>
All of the these URI types are recognised by the <CODE>write()</CODE> method, see above.

</P>
<P>
Worksheet references are typically of the form <CODE>Sheet1!A1</CODE>. You can also refer to a worksheet range using the standard Excel
notation: <CODE>Sheet1!A1:B2</CODE>.

</P>
<P>
In external links the workbook and worksheet name must be separated by the <CODE>#</CODE> character: <CODE>external:Workbook.xls#Sheet1!A1'</CODE>.

</P>
<P>
You can also link to a named range in the target worksheet. For example say
you have a named range called <CODE>my_name</CODE> in the workbook <CODE>c:\temp\foo.xls</CODE> you could link to it as follows:

</P>
<P>
<PRE>
    $worksheet-&gt;write_url('A14', 'external:c:\temp\foo.xls#my_name');
</PRE>
</P>
<P>
Note, you cannot currently create named ranges with <CODE>Spreadsheet::WriteExcel</CODE>.

</P>
<P>
Excel requires that worksheet names containing spaces or non alphanumeric
characters are single quoted as follows <CODE>'Sales Data'!A1</CODE>. If you need to do this in a single quoted string then you can either
escape the single quotes <CODE>\'</CODE> or use the quote operator <CODE>q{}</CODE> as described in <CODE>perlop</CODE> in the main Perl documentation.

</P>
<P>
Links to network files are also supported. MS/Novell Network files normally
begin with two back slashes as follows <CODE>\\NETWORK\etc</CODE>. In order to generate this in a single or double quoted string you will
have to escape the backslashes,  <CODE>'\\\\NETWORK\etc'</CODE>.

</P>
<P>
If you are using double quote strings then you should be careful to escape
anything that looks like a metacharacter. For more information see <CODE>perlfaq5: Why can't I use &quot;C:\temp\foo&quot; in DOS paths?</CODE>.

</P>
<P>
Finally, you can avoid most of these quoting problems by using forward
slashes. These are translated internally to backslashes:

</P>
<P>
<PRE>
    $worksheet-&gt;write_url('A14', &quot;external:c:/temp/foo.xls&quot;             );
    $worksheet-&gt;write_url('A15', 'external://NETWORK/share/foo.xls'     );
</PRE>
</P>
<P>
Note: Hyperlinks are not available in Excel 5. They will appear as a string
only.

</P>
<P>
See also, the note about <A HREF="#Cell_notation">Cell notation</A>.

</P>
<P>
<HR>
<H2><A NAME="write_url_range_row1_col1_r">write_url_range($row1, $col1, $row2, $col2, $url, $string, $format)</A></H2>
<P>
This method is essentially the same as the <CODE>write_url()</CODE> method described above. The main difference is that you can specify a link
for a range of cells:

</P>
<P>
<PRE>
    $worksheet-&gt;write_url(0, 0, 0, 3, 'ftp://www.perl.org/'              );
    $worksheet-&gt;write_url(1, 0, 0, 3, 'http://www.perl.com/', 'Perl home');
    $worksheet-&gt;write_url('A3:D3',    'internal:Sheet2!A1'               );
    $worksheet-&gt;write_url('A4:D4',    'external:c:\temp\foo.xls'         );
</PRE>
</P>
<P>
This method is generally only required when used in conjunction with merged
cells. See the <CODE>merge_range()</CODE> method and the <CODE>merge</CODE> property of a Format object, <A HREF="#CELL_FORMATTING">CELL FORMATTING</A>.

</P>
<P>
There is no way to force this behaviour through the <CODE>write()</CODE> method.

</P>
<P>
The parameters <CODE>$string</CODE> and the <CODE>$format</CODE> are optional and their position is interchangeable. However, they are
applied only to the first cell in the range.

</P>
<P>
Note: Hyperlinks are not available in Excel 5. They will appear as a string
only.

</P>
<P>
See also, the note about <A HREF="#Cell_notation">Cell notation</A>.

</P>
<P>
<HR>
<H2><A NAME="write_formula_row_column_fo">write_formula($row, $column, $formula, $format)</A></H2>
<P>
Write a formula or function to the cell specified by <CODE>$row</CODE> and <CODE>$column</CODE>:

</P>
<P>
<PRE>
    $worksheet-&gt;write_formula(0, 0, '=$B$3 + B4'  );
    $worksheet-&gt;write_formula(1, 0, '=SIN(PI()/4)');
    $worksheet-&gt;write_formula(2, 0, '=SUM(B1:B5)' );
    $worksheet-&gt;write_formula('A4', '=IF(A3&gt;1,&quot;Yes&quot;, &quot;No&quot;)'   );
    $worksheet-&gt;write_formula('A5', '=AVERAGE(1, 2, 3, 4)'    );
    $worksheet-&gt;write_formula('A6', '=DATEVALUE(&quot;1-Jan-2001&quot;)');
</PRE>
</P>
<P>
See the note about <A HREF="#Cell_notation">Cell notation</A>. For more information about writing Excel formulas see <A HREF="#FORMULAS_AND_FUNCTIONS_IN_EXCEL">FORMULAS AND FUNCTIONS IN EXCEL</A>



</P>
<P>
See also the section &quot;Improving performance when working with
formulas&quot; and the <CODE>store_formula()</CODE> and <CODE>repeat_formula()</CODE> methods.

</P>
<P>
<HR>
<H2><A NAME="store_formula_formula_">store_formula($formula)</A></H2>
<P>
The <CODE>store_formula()</CODE> method is used in conjunction with <CODE>repeat_formula()</CODE> to speed up the generation of repeated formulas. See &quot;Improving
performance when working with formulas&quot; in <A HREF="#FORMULAS_AND_FUNCTIONS_IN_EXCEL">FORMULAS AND FUNCTIONS IN EXCEL</A>.

</P>
<P>
The <CODE>store_formula()</CODE> method pre-parses a textual representation of a formula and stores it for
use at a later stage by the <CODE>repeat_formula()</CODE> method.

</P>
<P>
<CODE>store_formula()</CODE> carries the same speed penalty as <CODE>write_formula()</CODE>. However, in practice it will be used less frequently.

</P>
<P>
The return value of this method is a scalar that can be thought of as a
reference to a formula.

</P>
<P>
<PRE>
    my $sin = $worksheet-&gt;store_formula('=SIN(A1)');
    my $cos = $worksheet-&gt;store_formula('=COS(A1)');
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;repeat_formula('B1', $sin, $format, 'A1', 'A2');
    $worksheet-&gt;repeat_formula('C1', $cos, $format, 'A1', 'A2');
</PRE>
</P>
<P>
Although <CODE>store_formula()</CODE> is a worksheet method the return value can be used in any worksheet:

</P>
<P>
<PRE>
    my $now = $worksheet-&gt;store_formula('=NOW()');
</PRE>
</P>
<P>
<PRE>
    $worksheet1-&gt;repeat_formula('B1', $now);
    $worksheet2-&gt;repeat_formula('B1', $now);
    $worksheet3-&gt;repeat_formula('B1', $now);
</PRE>
</P>
<P>
<HR>
<H2><A NAME="repeat_formula_row_col_form">repeat_formula($row, $col, $formula, $format, ($pattern =&gt; $replace, ...))</A></H2>
<P>
The <CODE>repeat_formula()</CODE> method is used in conjunction with <CODE>store_formula()</CODE> to speed up the generation of repeated formulas. See &quot;Improving
performance when working with formulas&quot; in <A HREF="#FORMULAS_AND_FUNCTIONS_IN_EXCEL">FORMULAS AND FUNCTIONS IN EXCEL</A>.

</P>
<P>
In many respects <CODE>repeat_formula()</CODE> behaves like <CODE>write_formula()</CODE> except that it is significantly faster.

</P>
<P>
The <CODE>repeat_formula()</CODE> method creates a new formula based on the pre-parsed tokens returned by <CODE>store_formula()</CODE>. The new formula is generated by substituting <CODE>$pattern</CODE>, <CODE>$replace</CODE> pairs in the stored formula:

</P>
<P>
<PRE>
    my $formula = $worksheet-&gt;store_formula('=A1 * 3 + 50');
</PRE>
</P>
<P>
<PRE>
    for my $row (0..99) {
        $worksheet-&gt;repeat_formula($row, 1, $formula, $format, 'A1', 'A'.($row +1));
    }
</PRE>
</P>
<P>
It should be noted that <CODE>repeat_formula()</CODE> doesn't modify the tokens. In the above example the substitution is always
made against the original token, <CODE>A1</CODE>, which doesn't change.

</P>
<P>
As usual, you can use <CODE>undef</CODE> if you don't wish to specify a <CODE>$format</CODE>:

</P>
<P>
<PRE>
    $worksheet-&gt;repeat_formula('B2', $formula, $format, 'A1', 'A2');
    $worksheet-&gt;repeat_formula('B3', $formula, undef,   'A1', 'A3');
</PRE>
</P>
<P>
The substitutions are made from left to right and you can use as many <CODE>$pattern</CODE>, <CODE>$replace</CODE> pairs as you need. However, each substitution is made only once:

</P>
<P>
<PRE>
    my $formula = $worksheet-&gt;store_formula('=A1 + A1');
</PRE>
</P>
<P>
<PRE>
    # Gives '=B1 + A1'
    $worksheet-&gt;repeat_formula('B1', $formula, undef, 'A1', 'B1');
</PRE>
</P>
<P>
<PRE>
    # Gives '=B1 + B1'
    $worksheet-&gt;repeat_formula('B2', $formula, undef, ('A1', 'B1') x 2);
</PRE>
</P>
<P>
Since the <CODE>$pattern</CODE> is interpolated each time that it is used it is worth using the <CODE>qr</CODE> operator to quote the pattern. The <CODE>qr</CODE> operator is explained in the <CODE>perlop</CODE> man page.

</P>
<P>
<PRE>
    $worksheet-&gt;repeat_formula('B1', $formula, $format, qr/A1/, 'A2');
</PRE>
</P>
<P>
Care should be taken with the values that are substituted. The formula
returned by <CODE>repeat_formula()</CODE> contains several other tokens in addition to those in the formula and these
might also match the pattern that you are trying to replace. In particular
you should avoid substituting a single 0, 1, 2 or 3. Either substitute an
explicit token such as <CODE>A1</CODE> or else use a number that won't give a false match. For example, say you
wanted to change <CODE>SIN(A1)</CODE> to <CODE>SIN(A2)</CODE>:

</P>
<P>
<PRE>
    my $formula = $worksheet-&gt;store_formula('=SIN(A1)');
</PRE>
</P>
<P>
<PRE>
    # 1. This is explicit
    $worksheet-&gt;repeat_formula('B1', $formula, undef, 'A1', 'A2');
</PRE>
</P>
<P>
<PRE>
    # 2. May be wrong. Avoid matching simple matches against 0, 1, 2 or 3
    $worksheet-&gt;repeat_formula('B2', $formula, undef, 1, 2);
</PRE>
</P>
<P>
<PRE>
    # 3. Unlikely to give false match, easier to generate programmatically
    $worksheet-&gt;repeat_formula('B3', $formula, undef, 99, 2);
</PRE>
</P>
<P>
You don't have to be overly paranoid about this. It is just something to be
aware of. You can check the tokens that you are substituting against as
follows.

</P>
<P>
<PRE>
    my $formula = $worksheet-&gt;store_formula('=A1*5+4');
    print &quot;@$formula\n&quot;;
</PRE>
</P>
<P>
See also the <CODE>repeat.pl</CODE> program in the <CODE>examples</CODE> directory of the distro.

</P>
<P>
<HR>
<H2><A NAME="insert_bitmap_row_col_filen">insert_bitmap($row, $col, $filename, $x, $y, $scale_x, $scale_y)</A></H2>
<P>
This method can be used to insert a bitmap into a worksheet. The bitmap
must be a 24 bit, true colour, bitmap. No other format is supported. The <CODE>$x</CODE>, <CODE>$y</CODE>, <CODE>$scale_x</CODE> and <CODE>$scale_y</CODE> parameters are optional.

</P>
<P>
<PRE>
    $worksheet1-&gt;insert_bitmap('A1', 'perl.bmp');
    $worksheet2-&gt;insert_bitmap('A1', '../images/perl.bmp');
    $worksheet3-&gt;insert_bitmap('A1', '.c:\images\perl.bmp');
</PRE>
</P>
<P>
Note: you must call <CODE>set_row()</CODE> or <CODE>set_column()</CODE> before <CODE>insert_bitmap()</CODE> if you wish to change the default dimensions of any of the rows or columns
that the images occupies. Also, if you use large fonts then the height of
the row that they occupy may change automatically. This in turn could
affect the scaling of your image. To avoid this you should explicitly set
the height of the row using <CODE>set_row()</CODE>.

</P>
<P>
The parameters <CODE>$x</CODE> and <CODE>$y</CODE> can be used to specify an offset from the top left hand corner of the the
cell specified by <CODE>$row</CODE> and <CODE>$col</CODE>. The offset values are in pixels.

</P>
<P>
<PRE>
    $worksheet1-&gt;insert_bitmap('A1', 'perl.bmp', 32, 10);
</PRE>
</P>
<P>
The default width of a cell is 63 pixels. The default height of a cell is
17 pixels. The offsets are ignored if they are greater than the width or
height of the underlying cell.

</P>
<P>
The pixels offsets can be calculated using the following relationships:

</P>
<P>
<PRE>
    Wp = 7We +5
    Hp = 4/3He
</PRE>
</P>
<P>
<PRE>
    where:
    We is the cell width in Excels units
    Wp is width in pixels
    He is the cell height in Excels units
    Hp is height in pixels
</PRE>
</P>
<P>
The parameters <CODE>$scale_x</CODE> and <CODE>$scale_y</CODE> can be used to scale the inserted image horizontally and vertically:

</P>
<P>
<PRE>
    # Scale the inserted image: width x 2.0, height x 0.8
    $worksheet-&gt;insert_bitmap('A1', 'perl.bmp', 0, 0, 2, 0.8);
</PRE>
</P>
<P>
Note: although Excel allows you to import several graphics formats such as
gif, jpeg, png and eps these are converted internally into a proprietary
format. One of the few non-proprietary formats that Excel supports is 24
bit, true colour, bitmaps. Therefore if you wish to use images in any other
format you must first use an external application such as the ImageMagick <EM>convert</EM> utility to convert them to 24 bit bitmaps.

</P>
<P>
<PRE>
    convert test.png test.bmp
</PRE>
</P>
<P>
A later release will support the use of file handles and pre-encoded bitmap
strings.

</P>
<P>
See also the <CODE>images.pl</CODE> program in the <CODE>examples</CODE> directory of the distro.

</P>
<P>
<HR>
<H2><A NAME="get_name_">get_name()</A></H2>
<P>
The <CODE>get_name()</CODE> method is used to retrieve the name of a worksheet. For example:

</P>
<P>
<PRE>
    foreach my $sheet ($workbook-&gt;sheets()) {
        print $sheet-&gt;get_name();
    }
</PRE>
</P>
<P>
<HR>
<H2><A NAME="activate_">activate()</A></H2>
<P>
The <CODE>activate()</CODE> method is used to specify which worksheet is initially visible in a
multi-sheet workbook:

</P>
<P>
<PRE>
    $worksheet1 = $workbook-&gt;addworksheet('To');
    $worksheet2 = $workbook-&gt;addworksheet('the');
    $worksheet3 = $workbook-&gt;addworksheet('wind');
</PRE>
</P>
<P>
<PRE>
    $worksheet3-&gt;activate();
</PRE>
</P>
<P>
This is similar to the Excel VBA activate method. More than one worksheet
can be selected via the <CODE>select()</CODE> method, however only one worksheet can be active. The default value is the
first worksheet.

</P>
<P>
<HR>
<H2><A NAME="select_">select()</A></H2>
<P>
The <CODE>select()</CODE> method is used to indicate that a worksheet is selected in a multi-sheet
workbook:

</P>
<P>
<PRE>
    $worksheet1-&gt;activate();
    $worksheet2-&gt;select();
    $worksheet3-&gt;select();
</PRE>
</P>
<P>
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 <CODE>activate()</CODE> method will also appear as selected. You probably won't need to use the <CODE>select()</CODE> method very often.

</P>
<P>
<HR>
<H2><A NAME="set_first_sheet_">set_first_sheet()</A></H2>
<P>
The <CODE>activate()</CODE> 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 <CODE>set_first_sheet()</CODE>:

</P>
<P>
<PRE>
    for (1..20) {
        $workbook-&gt;addworksheet;
    }
</PRE>
</P>
<P>
<PRE>
    $worksheet21 = $workbook-&gt;addworksheet();
    $worksheet22 = $workbook-&gt;addworksheet();
</PRE>
</P>
<P>
<PRE>
    $worksheet21-&gt;set_first_sheet();
    $worksheet22-&gt;activate();
</PRE>
</P>
<P>
This method is not required very often. The default value is the first
worksheet.

</P>
<P>
<HR>
<H2><A NAME="protect_password_">protect($password)</A></H2>
<P>
The <CODE>protect()</CODE> method is used to protect a worksheet from modification:

</P>
<P>
<PRE>
    $worksheet-&gt;protect();
</PRE>
</P>
<P>
It can be turned off in Excel via the <CODE>Tools-&gt;Protection-&gt;Unprotect Sheet</CODE> menu command.

</P>
<P>
The <CODE>protect()</CODE> method also has the effect of enabling a cell's <CODE>locked</CODE> and <CODE>hidden</CODE> properties if they have been set. A &quot;locked&quot; cell cannot be
edited. A &quot;hidden&quot; cell will display the results of a formula but
not the formula itself. In Excel a cell's locked property is on by default.

</P>
<P>
<PRE>
    # Set some format properties
    my $unlocked  = $workbook-&gt;addformat(locked =&gt; 0);
    my $hidden    = $workbook-&gt;addformat(hidden =&gt; 1);
</PRE>
</P>
<P>
<PRE>
    # Enable worksheet protection
    $worksheet-&gt;protect();
</PRE>
</P>
<P>
<PRE>
    # This cell cannot be edited, it is locked by default
    $worksheet-&gt;write('A1', '=1+2');
</PRE>
</P>
<P>
<PRE>
    # This cell can be edited
    $worksheet-&gt;write('A2', '=1+2', $unlocked);
</PRE>
</P>
<P>
<PRE>
    # The formula in this cell isn't visible
    $worksheet-&gt;write('A3', '=1+2', $hidden);
</PRE>
</P>
<P>
See also the <CODE>set_locked</CODE> and <CODE>set_hidden</CODE> format methods in <A HREF="#CELL_FORMATTING">CELL FORMATTING</A>.

</P>
<P>
You can optionally add a password to the worksheet protection:

</P>
<P>
<PRE>
    $worksheet-&gt;protect('drowssap');
</PRE>
</P>
<P>
Note, the worksheet level password in Excel provides very weak protection.
It does not encrypt your data in any way and it is very easy to deactivate.
Therefore, do not use the above method if you wish to protect sensitive
data or calculations. However, before you get worried, Excel's own workbook
level password protection does provide strong encryption in Excel 97+. For
technical reasons this will never be supported by <CODE>Spreadsheet::WriteExcel</CODE>.

</P>
<P>
<HR>
<H2><A NAME="set_selection_first_row_first">set_selection($first_row, $first_col, $last_row, $last_col)</A></H2>
<P>
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 <CODE>$last_row</CODE> and <CODE>$last_col</CODE> can be omitted. The active cell within a selected range is determined by
the order in which <CODE>$first</CODE> and <CODE>$last</CODE> are specified. It is also possible to specify a cell or a range using A1
notation. See the note about <A HREF="#Cell_notation">Cell notation</A>.

</P>
<P>
Examples:

</P>
<P>
<PRE>
    $worksheet1-&gt;set_selection(3, 3);       # 1. Cell D4.
    $worksheet2-&gt;set_selection(3, 3, 6, 6); # 2. Cells D4 to G7.
    $worksheet3-&gt;set_selection(6, 6, 3, 3); # 3. Cells G7 to D4.
    $worksheet4-&gt;set_selection('D4');       # Same as 1.
    $worksheet5-&gt;set_selection('D4:G7');    # Same as 2.
    $worksheet6-&gt;set_selection('G7:D4');    # Same as 3.
</PRE>
</P>
<P>
The default cell selections is (0, 0), 'A1'.

</P>
<P>
<HR>
<H2><A NAME="set_row_row_height_format_">set_row($row, $height, $format, $hidden)</A></H2>
<P>
This method can be used to specify the height and format of a row. The <CODE>$format</CODE> parameter is optional, for additional information, see <A HREF="#CELL_FORMATTING">CELL FORMATTING</A>.

</P>
<P>
<PRE>
    $worksheet-&gt;set_row(0, 20); # Row 1 height set to 20
</PRE>
</P>
<P>
If you wish to set the format without changing the height you can pass <CODE>undef</CODE> as the height parameter:

</P>
<P>
<PRE>
    $worksheet-&gt;set_row(0, undef, $format);
</PRE>
</P>
<P>
The <CODE>$format</CODE> parameter will be applied to any cells in the row that don't have a format.
For example

</P>
<P>
<PRE>
    $worksheet-&gt;set_row(0, undef, $format1);    # Set the format for row 1
    $worksheet-&gt;write('A1', &quot;Hello&quot;);           # Defaults to $format1
    $worksheet-&gt;write('B1', &quot;Hello&quot;, $format2); # Keeps $format2
</PRE>
</P>
<P>
If you wish to define a row format in this way you should call the method
before any calls to <CODE>write()</CODE>. If you call it afterwards it will overwrite any format that was
previously specified.

</P>
<P>
The <CODE>$hidden</CODE> parameter is optional. It 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:

</P>
<P>
<PRE>
    $worksheet-&gt;set_row(0, 20,    $format, 1);
    $worksheet-&gt;set_row(1, undef, undef,   1);
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_column_first_col_last_col">set_column($first_col, $last_col, $width, $format, $hidden)</A></H2>
<P>
This method can be used to specify the width and format of a single column
or a range of columns. If the method is applied to a single column the
value of <CODE>$first_col</CODE> and <CODE>$last_col</CODE> should be the same. It is also possible to specify a column range using the
form of A1 notation used for columns. See the note about <A HREF="#Cell_notation">Cell notation</A>.

</P>
<P>
Examples:

</P>
<P>
<PRE>
    $worksheet-&gt;set_column(0, 0,  20); # Column  A   width set to 20
    $worksheet-&gt;set_column(1, 3,  30); # Columns B-D width set to 30
    $worksheet-&gt;set_column('E:E', 20); # Column  E   width set to 20
    $worksheet-&gt;set_column('F:H', 30); # Columns F-H width set to 30
</PRE>
</P>
<P>
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
Arial 10. Unfortunately, there is no way to specify &quot;AutoFit&quot; for
a column in the Excel file format. This feature is only available at
runtime from within Excel.

</P>
<P>
The <CODE>$format</CODE> parameter is optional, for additional information, see <A HREF="#CELL_FORMATTING">CELL FORMATTING</A>. If you wish to set the format without changing the width you can pass <CODE>undef</CODE> as the width parameter:

</P>
<P>
<PRE>
    $worksheet-&gt;set_column(0, 0, undef, $format);
</PRE>
</P>
<P>
The <CODE>$format</CODE> parameter will be applied to any cells in the column that don't have a
format. For example

</P>
<P>
<PRE>
    $worksheet-&gt;set_column('A:A', undef, $format1); # Set format for col 1
    $worksheet-&gt;write('A1', &quot;Hello&quot;);               # Defaults to $format1
    $worksheet-&gt;write('A2', &quot;Hello&quot;, $format2);     # Keeps $format2
</PRE>
</P>
<P>
If you wish to define a column format in this way you should call the
method before any calls to <CODE>write()</CODE>. If you call it afterwards it won't have any effect.

</P>
<P>
A default row format takes precedence over a default column format

</P>
<P>
<PRE>
    $worksheet-&gt;set_row(0, undef,        $format1); # Set format for row 1
    $worksheet-&gt;set_column('A:A', undef, $format2); # Set format for col 1
    $worksheet-&gt;write('A1', &quot;Hello&quot;);               # Defaults to $format1
    $worksheet-&gt;write('A2', &quot;Hello&quot;);               # Defaults to $format2
</PRE>
</P>
<P>
The <CODE>$hidden</CODE> parameter is optional. It 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:

</P>
<P>
<PRE>
    $worksheet-&gt;set_column('D:D', 20,    $format, 1);
    $worksheet-&gt;set_column('E:E', undef, undef,   1);
</PRE>
</P>
<P>
<HR>
<H2><A NAME="freeze_panes_row_col_top_ro">freeze_panes($row, $col, $top_row, $left_col)</A></H2>
<P>
This method can be used to divide a worksheet into horizontal or vertical
regions known as panes and to also &quot;freeze&quot; these panes so that
the splitter bars are not visible. This is the same as the <CODE>Window-&gt;Freeze Panes</CODE> menu command in Excel

</P>
<P>
The parameters <CODE>$row</CODE> and <CODE>$col</CODE> 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.

</P>
<P>
You can set one of the <CODE>$row</CODE> and <CODE>$col</CODE> parameters as zero if you do not want either a vertical or horizontal
split.

</P>
<P>
Examples:

</P>
<P>
<PRE>
    $worksheet-&gt;freeze_panes(1, 0); # Freeze the first row
    $worksheet-&gt;freeze_panes('A2'); # Same using A1 notation
    $worksheet-&gt;freeze_panes(0, 1); # Freeze the first column
    $worksheet-&gt;freeze_panes('B1'); # Same using A1 notation
    $worksheet-&gt;freeze_panes(1, 2); # Freeze first row and first 2 columns
    $worksheet-&gt;freeze_panes('C2'); # Same using A1 notation
</PRE>
</P>
<P>
The parameters <CODE>$top_row</CODE> and <CODE>$left_col</CODE> 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:

</P>
<P>
<PRE>
    $worksheet-&gt;freeze_panes(1, 0, 20, 0);
</PRE>
</P>
<P>
You cannot use A1 notation for the <CODE>$top_row</CODE> and <CODE>$left_col</CODE> parameters.

</P>
<P>
See also the <CODE>panes.pl</CODE> program in the <CODE>examples</CODE> directory of the distribution.

</P>
<P>
<HR>
<H2><A NAME="thaw_panes_y_x_top_row_le">thaw_panes($y, $x, $top_row, $left_col)</A></H2>
<P>
This method can be used to divide a worksheet into horizontal or vertical
regions known as panes. This method is different from the <CODE>freeze_panes()</CODE> method in that the splits between the panes will be visible to the user and
each pane will have its own scroll bars.

</P>
<P>
The parameters <CODE>$y</CODE> and <CODE>$x</CODE> are used to specify the vertical and horizontal position of the split. The
units for <CODE>$y</CODE> and <CODE>$x</CODE> 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 <CODE>$y</CODE> and <CODE>$x</CODE> parameters in terms of the row heights and column widths that you have set
or the default values which are <CODE>12.75</CODE> for a row and  <CODE>8.43</CODE> for a column.

</P>
<P>
You can set one of the <CODE>$y</CODE> and <CODE>$x</CODE> parameters as zero if you do not want either a vertical or horizontal
split. The parameters <CODE>$top_row</CODE> and <CODE>$left_col</CODE> are optional. They are used to specify the top-most or left-most visible
row or column in the bottom-right pane.

</P>
<P>
Example:

</P>
<P>
<PRE>
    $worksheet-&gt;thaw_panes(12.75, 0,    1, 0); # First row
    $worksheet-&gt;thaw_panes(0,     8.43, 0, 1); # First column
    $worksheet-&gt;thaw_panes(12.75, 8.43, 1, 1); # First row and column
</PRE>
</P>
<P>
You cannot use A1 notation with this method.

</P>
<P>
See also the <CODE>freeze_panes()</CODE> method and the <CODE>panes.pl</CODE> program in the <CODE>examples</CODE> directory of the distribution.

</P>
<P>
<HR>
<H2><A NAME="merge_range_first_row_first_c">merge_range($first_row, $first_col, $last_row, $last_col, $token, $format)</A></H2>
<P>
Note, the <CODE>merge_range()</CODE> method replaces the <CODE>merge_cells()</CODE> method as a simpler and safer way of generating a merged range. <CODE>merge_cells()</CODE> is still available but it is deprecated and no longer documented.

</P>
<P>
Merging cells is generally achieved by setting the <CODE>merge</CODE> property of a Format object, see <A HREF="#CELL_FORMATTING">CELL FORMATTING</A>. However, this only allows simple Excel5 style horizontal merging which
Excel refers to as &quot;center across selection&quot;.

</P>
<P>
The <CODE>merge_range()</CODE> method allows you to do Excel97+ style formatting where the cells can
contain other types of alignment in addition to the merging:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat(
                                        border  =&gt; 6,
                                        valign  =&gt; 'vcenter',
                                        align   =&gt; 'center',
                                      );
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;merge_range('B3:D4', 'Vertically and horizontal', $format);
</PRE>
</P>
<P>
The format object that is used with a <CODE>merge_range()</CODE> method call is marked internally as being associated with a merged range.
As such, it shouldn't be used for other formatting.

</P>
<P>
<CODE>merge_range()</CODE> writes its <CODE>$token</CODE> argument using the worksheet <CODE>write()</CODE> method. Therefore it will handle numbers, strings, formulas or urls as
required.

</P>
<P>
Setting the <CODE>merge</CODE> property of the format isn't required when you are using <CODE>merge_range()</CODE>. In fact using it will exclude the use of any other horizontal alignment
option.

</P>
<P>
The full possibilities of this method are shown in the <CODE>merge3.pl</CODE>, <CODE>merge4.pl</CODE> and <CODE>merge5.pl</CODE> programs in the <CODE>examples</CODE> directory of the distribution.

</P>
<P>
The <CODE>merge_range()</CODE> method doesn't work with Excel versions before Excel 97.

</P>
<P>
<HR>
<H2><A NAME="set_zoom_scale_">set_zoom($scale)</A></H2>
<P>
Set the worksheet zoom factor in the range <CODE>10 &lt;= $scale &lt;= 400</CODE>:

</P>
<P>
<PRE>
    $worksheet1-&gt;set_zoom(50);
    $worksheet2-&gt;set_zoom(75);
    $worksheet3-&gt;set_zoom(300);
    $worksheet4-&gt;set_zoom(400);
</PRE>
</P>
<P>
The default zoom factor is 100. You cannot zoom to &quot;Selection&quot;
because it is calculated by Excel at run-time.

</P>
<P>
Note, <CODE>set_zoom()</CODE> does not affect the scale of the printed page. For that you should use <CODE>set_print_scale()</CODE>.

</P>
<P>
<HR>
<H1><A NAME="PAGE_SET_UP_METHODS">PAGE SET-UP METHODS</A></H1>
<P>
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.

</P>
<P>
The following methods are available for page set-up:

</P>
<P>
<PRE>
    set_landscape()
    set_portrait()
    set_paper()
    center_horizontally()
    center_vertically()
    set_margins()
    set_header()
    set_footer()
    repeat_rows()
    repeat_columns()
    hide_gridlines()
    print_row_col_headers()
    print_area()
    fit_to_pages()
    set_print_scale()
    set_h_pagebreaks()
    set_v_pagebreaks()
</PRE>
</P>
<P>
A common requirement when working with Spreadsheet::WriteExcel is to apply
the same page set-up features to all of the worksheets in a workbook. To do
this you can use the <CODE>sheets()</CODE> method of the <CODE>workbook</CODE> class to access the array of worksheets in a workbook:

</P>
<P>
<PRE>
    foreach $worksheet ($workbook-&gt;sheets()) {
       $worksheet-&gt;set_landscape();
    }
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_landscape_">set_landscape()</A></H2>
<P>
This method is used to set the orientation of a worksheet's printed page to
landscape:

</P>
<P>
<PRE>
    $worksheet-&gt;set_landscape(); # Landscape mode
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_portrait_">set_portrait()</A></H2>
<P>
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.

</P>
<P>
<PRE>
    $worksheet-&gt;set_portrait(); # Portrait mode
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_paper_index_">set_paper($index)</A></H2>
<P>
This method is used to set the paper format for the printed output of a
worksheet. The following paper styles are available:

</P>
<P>
<PRE>
    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
</PRE>
</P>
<P>
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.

</P>
<P>
<PRE>
    $worksheet-&gt;set_paper(1); # US Letter
    $worksheet-&gt;set_paper(9); # A4
</PRE>
</P>
<P>
If you do not specify a paper type the worksheet will print using the
printer's default paper.

</P>
<P>
<HR>
<H2><A NAME="center_horizontally_">center_horizontally()</A></H2>
<P>
Center the worksheet data horizontally between the margins on the printed
page:

</P>
<P>
<PRE>
    $worksheet-&gt;center_horizontally();
</PRE>
</P>
<P>
<HR>
<H2><A NAME="center_vertically_">center_vertically()</A></H2>
<P>
Center the worksheet data vertically between the margins on the printed
page:

</P>
<P>
<PRE>
    $worksheet-&gt;center_vertically();
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_margins_inches_">set_margins($inches)</A></H2>
<P>
There are several methods available for setting the worksheet margins on
the printed page:

</P>
<P>
<PRE>
    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
</PRE>
</P>
<P>
All of these methods take a distance in inches as a parameter. Note: 1 inch
= 25.4mm. ;-) The default left and right margin is 0.75 inch. The default
top and bottom margin is 1.00 inch.

</P>
<P>
<HR>
<H2><A NAME="set_header_string_margin_">set_header($string, $margin)</A></H2>
<P>
Headers and footers are generated using a <CODE>$string</CODE> which is a combination of plain text and control characters. The <CODE>$margin</CODE> parameter is optional.

</P>
<P>
The available control character are:

</P>
<P>
<PRE>
    Control             Category            Description
    =======             ========            ===========
    &amp;L                  Justification       Left
    &amp;C                                      Center
    &amp;R                                      Right
</PRE>
</P>
<P>
<PRE>
    &amp;P                  Information         Page number
    &amp;N                                      Total number of pages
    &amp;D                                      Date
    &amp;T                                      Time
    &amp;F                                      File name
    &amp;A                                      Worksheet name
</PRE>
</P>
<P>
<PRE>
    &amp;fontsize           Font                Font size
    &amp;&quot;font,style&quot;                           Font name and style
    &amp;U                                      Single underline
    &amp;E                                      Double underline
    &amp;S                                      Strikethrough
    &amp;X                                      Superscript
    &amp;Y                                      Subscript
</PRE>
</P>
<P>
<PRE>
    &amp;&amp;                  Miscellaneous       Literal ampersand &amp;
</PRE>
</P>
<P>
Text in headers and footers can be justified (aligned) to the left, center
and right by prefixing the text with the control characters <CODE>&amp;L</CODE>, <CODE>&amp;C</CODE> and <CODE>&amp;R</CODE>.

</P>
<P>
For example (with ASCII art representation of the results):

</P>
<P>
<PRE>
    $worksheet-&gt;set_header('&amp;LHello');
</PRE>
</P>
<P>
<PRE>
     ---------------------------------------------------------------
    |                                                               |
    | Hello                                                         |
    |                                                               |
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;set_header('&amp;CHello');
</PRE>
</P>
<P>
<PRE>
     ---------------------------------------------------------------
    |                                                               |
    |                          Hello                                |
    |                                                               |
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;set_header('&amp;RHello');
</PRE>
</P>
<P>
<PRE>
     ---------------------------------------------------------------
    |                                                               |
    |                                                         Hello |
    |                                                               |
</PRE>
</P>
<P>
For simple text, if you do not specify any justification the text will be
centred. However, you must prefix the text with <CODE>&amp;C</CODE> if you specify a font name or any other formatting:

</P>
<P>
<PRE>
    $worksheet-&gt;set_header('Hello');
</PRE>
</P>
<P>
<PRE>
     ---------------------------------------------------------------
    |                                                               |
    |                          Hello                                |
    |                                                               |
</PRE>
</P>
<P>
You can have text in each of the justification regions:

</P>
<P>
<PRE>
    $worksheet-&gt;set_header('&amp;LCiao&amp;CBello&amp;RCielo');
</PRE>
</P>
<P>
<PRE>
     ---------------------------------------------------------------
    |                                                               |
    | Ciao                     Bello                          Cielo |
    |                                                               |
</PRE>
</P>
<P>
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:

</P>
<P>
<PRE>
    $worksheet-&gt;set_header('&amp;CPage &amp;P of &amp;N');
</PRE>
</P>
<P>
<PRE>
     ---------------------------------------------------------------
    |                                                               |
    |                        Page 1 of 6                            |
    |                                                               |
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;set_header('&amp;CUpdated at &amp;T');
</PRE>
</P>
<P>
<PRE>
     ---------------------------------------------------------------
    |                                                               |
    |                    Updated at 12:30 PM                        |
    |                                                               |
</PRE>
</P>
<P>
You can specify the font size of a section of the text by prefixing it with
the control character <CODE>&amp;n</CODE> where <CODE>n</CODE> is the font size:

</P>
<P>
<PRE>
    $worksheet1-&gt;set_header('&amp;C&amp;30Hello Big'  );
    $worksheet2-&gt;set_header('&amp;C&amp;10Hello Small');
</PRE>
</P>
<P>
You can specify the font of a section of the text by prefixing it with the
control sequence <CODE>&amp;&quot;font,style&quot;</CODE> where <CODE>fontname</CODE> is a font name such as &quot;Courier New&quot; or &quot;Times New
Roman&quot; and <CODE>style</CODE> is one of the standard Windows font descriptions: &quot;Regular&quot;,
&quot;Italic&quot;, &quot;Bold&quot; or &quot;Bold Italic&quot;:

</P>
<P>
<PRE>
    $worksheet1-&gt;set_header('&amp;C&amp;&quot;Courier New,Italic&quot;Hello');
    $worksheet2-&gt;set_header('&amp;C&amp;&quot;Courier New,Bold Italic&quot;Hello');
    $worksheet3-&gt;set_header('&amp;C&amp;&quot;Times New Roman,Regular&quot;Hello');
</PRE>
</P>
<P>
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 VBA produces. Remember however that VBA
uses two double quotes <CODE>&quot;&quot;</CODE> to indicate a single double quote. For the last example above the
equivalent VBA code looks like this:

</P>
<P>
<PRE>
    .LeftHeader   = &quot;&quot;
    .CenterHeader = &quot;&amp;&quot;&quot;Times New Roman,Regular&quot;&quot;Hello&quot;
    .RightHeader  = &quot;&quot;
</PRE>
</P>
<P>
To include a single literal ampersand <CODE>&amp;</CODE> in a header or footer you should use a double ampersand <CODE>&amp;&amp;</CODE>:

</P>
<P>
<PRE>
    $worksheet1-&gt;set_header('&amp;CCuriouser &amp;&amp; Curiouser - Attorneys at Law');
</PRE>
</P>
<P>
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.50
inch. The header and footer margin size can be set as follows:

</P>
<P>
<PRE>
    $worksheet-&gt;set_header('&amp;CHello', 0.75);
</PRE>
</P>
<P>
The header and footer margins are independent of the top and bottom
margins.

</P>
<P>
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.

</P>
<P>
See, also the <CODE>headers.pl</CODE> program in the <CODE>examples</CODE> directory of the distribution.

</P>
<P>
<HR>
<H2><A NAME="set_footer_">set_footer()</A></H2>
<P>
The syntax of the <CODE>set_footer()</CODE> method is the same as <CODE>set_header()</CODE>, see above.

</P>
<P>
<HR>
<H2><A NAME="repeat_rows_first_row_last_ro">repeat_rows($first_row, $last_row)</A></H2>
<P>
Set the number of rows to repeat at the top of each printed page.

</P>
<P>
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 <CODE>repeat_rows()</CODE> method. The parameters <CODE>$first_row</CODE> and <CODE>$last_row</CODE> are zero based. The <CODE>$last_row</CODE> parameter is optional if you only wish to specify one row:

</P>
<P>
<PRE>
    $worksheet1-&gt;repeat_rows(0);    # Repeat the first row
    $worksheet2-&gt;repeat_rows(0, 1); # Repeat the first two rows
</PRE>
</P>
<P>
<HR>
<H2><A NAME="repeat_columns_first_col_last">repeat_columns($first_col, $last_col)</A></H2>
<P>
Set the columns to repeat at the left hand side of each printed page.

</P>
<P>
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 <CODE>repeat_columns()</CODE> method. The parameters <CODE>$first_column</CODE> and <CODE>$last_column</CODE> are zero based. The <CODE>$last_column</CODE> 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 <A HREF="#Cell_notation">Cell notation</A>.

</P>
<P>
<PRE>
    $worksheet1-&gt;repeat_columns(0);     # Repeat the first column
    $worksheet2-&gt;repeat_columns(0, 1);  # Repeat the first two columns
    $worksheet3-&gt;repeat_columns('A:A'); # Repeat the first column
    $worksheet4-&gt;repeat_columns('A:B'); # Repeat the first two columns
</PRE>
</P>
<P>
<HR>
<H2><A NAME="hide_gridlines_option_">hide_gridlines($option)</A></H2>
<P>
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.

</P>
<P>
<PRE>
    $worksheet-&gt;hide_gridlines();
</PRE>
</P>
<P>
The following values of <CODE>$option</CODE> are valid:

</P>
<P>
<PRE>
    0 : Don't hide gridlines
    1 : Hide printed gridlines only
    2 : Hide screen and printed gridlines
</PRE>
</P>
<P>
If you don't supply an argument or use <CODE>undef</CODE> the default option is 1, i.e. only the printed gridlines are hidden.

</P>
<P>
<HR>
<H2><A NAME="print_row_col_headers_">print_row_col_headers()</A></H2>
<P>
Set the option to print the row and column headers on the printed page.

</P>
<P>
An Excel worksheet looks something like the following;

</P>
<P>
<PRE>
     ------------------------------------------
    |   |   A   |   B   |   C   |   D   |  ...
     ------------------------------------------
    | 1 |       |       |       |       |  ...
    | 2 |       |       |       |       |  ...
    | 3 |       |       |       |       |  ...
    | 4 |       |       |       |       |  ...
    |...|  ...  |  ...  |  ...  |  ...  |  ...
</PRE>
</P>
<P>
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 <CODE>print_row_col_headers()</CODE> method :

</P>
<P>
<PRE>
    $worksheet-&gt;print_row_col_headers()
</PRE>
</P>
<P>
Do not confuse these headers with page headers as described in the <CODE>set_header()</CODE> section above.

</P>
<P>
<HR>
<H2><A NAME="print_area_first_row_first_co">print_area($first_row, $first_col, $last_row, $last_col)</A></H2>
<P>
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 <A HREF="#Cell_notation">Cell notation</A>.

</P>
<P>
<PRE>
    $worksheet1-&gt;print_area(&quot;A1:H20&quot;);    # Cells A1 to H20
    $worksheet2-&gt;print_area(0, 0, 19, 7); # The same
    $worksheet2-&gt;print_area('A:H');       # Columns A to H if rows have data
</PRE>
</P>
<P>
<HR>
<H2><A NAME="fit_to_pages_width_height_">fit_to_pages($width, $height)</A></H2>
<P>
The <CODE>fit_to_pages()</CODE> 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.

</P>
<P>
<PRE>
    $worksheet1-&gt;fit_to_pages(1, 1); # Fit to 1x1 pages
    $worksheet2-&gt;fit_to_pages(2, 1); # Fit to 2x1 pages
    $worksheet3-&gt;fit_to_pages(1, 2); # Fit to 1x2 pages
</PRE>
</P>
<P>
The print area can be defined using the <CODE>print_area()</CODE> method as described above.

</P>
<P>
A common requirement is to fit the printed output to <EM>n</EM> pages wide but have the height be as long as necessary. To achieve this set
the <CODE>$height</CODE> to zero or leave it blank:

</P>
<P>
<PRE>
    $worksheet1-&gt;fit_to_pages(1, 0); # 1 page wide and as long as necessary
    $worksheet2-&gt;fit_to_pages(1);    # The same
</PRE>
</P>
<P>
Note that although it is valid to use both <CODE>fit_to_pages()</CODE> and <CODE>set_print_scale()</CODE> 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.

</P>
<P>
Note that <CODE>fit_to_pages()</CODE> will override any manual page breaks that are defined in the worksheet.

</P>
<P>
<HR>
<H2><A NAME="set_print_scale_scale_">set_print_scale($scale)</A></H2>
<P>
Set the scale factor of the printed page. Scale factors in the range <CODE>10 &lt;= $scale &lt;= 400</CODE> are valid:

</P>
<P>
<PRE>
    $worksheet1-&gt;set_print_scale(50);
    $worksheet2-&gt;set_print_scale(75);
    $worksheet3-&gt;set_print_scale(300);
    $worksheet4-&gt;set_print_scale(400);
</PRE>
</P>
<P>
The default scale factor is 100. Note, <CODE>set_print_scale()</CODE> does not affect the scale of the visible page in Excel. For that you should
use <CODE>set_zoom()</CODE>.

</P>
<P>
Note also that although it is valid to use both <CODE>fit_to_pages()</CODE> and <CODE>set_print_scale()</CODE> 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.

</P>
<P>
<HR>
<H2><A NAME="set_h_pagebreaks_breaks_">set_h_pagebreaks(@breaks)</A></H2>
<P>
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:

</P>
<P>
<PRE>
    $worksheet1-&gt;set_h_pagebreaks(20); # Break between row 20 and 21
</PRE>
</P>
<P>
The <CODE>set_h_pagebreaks()</CODE> method will accept a list of page breaks and you can call it more than
once:

</P>
<P>
<PRE>
    $worksheet2-&gt;set_h_pagebreaks( 20,  40,  60,  80, 100); # Add breaks
    $worksheet2-&gt;set_h_pagebreaks(120, 140, 160, 180, 200); # Add some more
</PRE>
</P>
<P>
Note: If you specify the &quot;fit to page&quot; option via the <CODE>fit_to_pages()</CODE> method it will override all manual page breaks.

</P>
<P>
There is a silent limitation of about 1000 horizontal page breaks per
worksheet in line with an Excel internal limitation.

</P>
<P>
<HR>
<H2><A NAME="set_v_pagebreaks_breaks_">set_v_pagebreaks(@breaks)</A></H2>
<P>
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:

</P>
<P>
<PRE>
    $worksheet1-&gt;set_v_pagebreaks(20); # Break between column 20 and 21
</PRE>
</P>
<P>
The <CODE>set_v_pagebreaks()</CODE> method will accept a list of page breaks and you can call it more than
once:

</P>
<P>
<PRE>
    $worksheet2-&gt;set_v_pagebreaks( 20,  40,  60,  80, 100); # Add breaks
    $worksheet2-&gt;set_v_pagebreaks(120, 140, 160, 180, 200); # Add some more
</PRE>
</P>
<P>
Note: If you specify the &quot;fit to page&quot; option via the <CODE>fit_to_pages()</CODE> method it will override all manual page breaks.

</P>
<P>
<HR>
<H1><A NAME="CELL_FORMATTING">CELL FORMATTING</A></H1>
<P>
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.

</P>
<P>
<HR>
<H2><A NAME="Creating_and_using_a_Format_obje">Creating and using a Format object</A></H2>
<P>
Cell formatting is defined through a Format object. Format objects are
created by calling the workbook <CODE>addformat()</CODE> method as follows:

</P>
<P>
<PRE>
    my $format1 = $workbook-&gt;addformat();       # Set properties later
    my $format2 = $workbook-&gt;addformat(%props); # Set properties at creation
</PRE>
</P>
<P>
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.

</P>
<P>
Once a Format object has been constructed and it properties have been set
it can be passed as an argument to the worksheet <CODE>write</CODE> methods as follows:

</P>
<P>
<PRE>
    $worksheet-&gt;write(0, 0, &quot;One&quot;, $format);
    $worksheet-&gt;write_string(1, 0, &quot;Two&quot;, $format);
    $worksheet-&gt;write_number(2, 0, 3, $format);
    $worksheet-&gt;write_blank(3, 0, $format);
</PRE>
</P>
<P>
Formats can also be passed to the worksheet <CODE>set_row()</CODE> and <CODE>set_column()</CODE> methods to define the default property for a row or column.

</P>
<P>
<PRE>
    $worksheet-&gt;set_row(0, 15, $format);
    $worksheet-&gt;set_column(0, 0, 15, $format);
</PRE>
</P>
<P>
<HR>
<H2><A NAME="Format_methods_and_Format_proper">Format methods and Format properties</A></H2>
<P>
The following table shows the Excel format categories, the formatting
properties that can be applied and the equivalent object method:

</P>
<P>
<PRE>
    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()
</PRE>
</P>
<P>
<PRE>
    Number     Numeric format    num_format      set_num_format()
</PRE>
</P>
<P>
<PRE>
    Protection Lock cells        locked          set_locked()
               Hide formulas     hidden          set_hidden()
</PRE>
</P>
<P>
<PRE>
    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()
               Merge             merge           set_merge()
</PRE>
</P>
<P>
<PRE>
    Pattern    Cell pattern      pattern         set_pattern()
               Background color  bg_color        set_bg_color()
               Foreground color  fg_color        set_fg_color()
</PRE>
</P>
<P>
<PRE>
    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()
</PRE>
</P>
<P>
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:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_bold();
    $format-&gt;set_color('red');
</PRE>
</P>
<P>
By comparison the properties can be set directly by passing a hash of
properties to the Format constructor:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat(bold =&gt; 1, color =&gt; 'red');
</PRE>
</P>
<P>
or after the Format has been constructed by means of the <CODE>set_properties()</CODE> method as follows:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_properties(bold =&gt; 1, color =&gt; 'red');
</PRE>
</P>
<P>
You can also store the properties in one or more named hashes and pass them
to the required method:

</P>
<P>
<PRE>
    my %font    = (
                    font  =&gt; 'Arial',
                    size  =&gt; 12,
                    color =&gt; 'blue',
                    bold  =&gt; 1,
                  );
</PRE>
</P>
<P>
<PRE>
    my %shading = (
                    bg_color =&gt; 'green',
                    pattern  =&gt; 1,
                  );
</PRE>
</P>
<P>
<PRE>
    my $format1 = $workbook-&gt;addformat(%font);            # Font only
    my $format2 = $workbook-&gt;addformat(%font, %shading);  # Font and shading
</PRE>
</P>
<P>
The provision of two ways of setting properties might lead you to wonder
which is the best way. The answer depends on the amount of formatting that
will be required in your program. Initially, Spreadsheet::WriteExcel only
allowed individual Format properties to be set via the appropriate method.
While this was sufficient for most circumstances it proved very cumbersome
in programs that required a large amount of formatting. In addition the
mechanism for reusing properties between Format objects was complicated.

</P>
<P>
As a result the Perl/Tk style of adding properties was added to, hopefully,
facilitate developers who need to define a lot of formatting. In fact the
Tk style of defining properties is also supported:

</P>
<P>
<PRE>
    my %font    = (
                    -font      =&gt; 'Arial',
                    -size      =&gt; 12,
                    -color     =&gt; 'blue',
                    -bold      =&gt; 1,
                  );
</PRE>
</P>
<P>
An additional advantage of working with hashes of properties is that it
allows you to share formatting between workbook objects

</P>
<P>
You can also create a format &quot;on the fly&quot; and pass it directly to
a write method as follows:

</P>
<P>
<PRE>
    $worksheet-&gt;write('A1', &quot;Title&quot;, $workbook-&gt;addformat(bold =&gt; 1));
</PRE>
</P>
<P>
This corresponds to an &quot;anonymous&quot; format in the Perl sense of
anonymous data or subs.

</P>
<P>
If you need to create an Excel file with a large amount of formatting you
can also use the <CODE>lecxe.pl</CODE> program in the <CODE>examples</CODE> directory of the distribution. <CODE>lecxe</CODE> is a Win32::OLE program written by Tomas Andersson which converts Excel
files to Spreadsheet::WriteExcel files. Therefore, you can use Excel to
define your formatting and have <CODE>lecxe</CODE> do the hard work for you.

</P>
<P>
<HR>
<H2><A NAME="Working_with_formats">Working with formats</A></H2>
<P>
The default format is Arial 10 with all other properties off.

</P>
<P>
Each unique format in Spreadsheet::WriteExcel must have a corresponding
Format object. It isn't possible to use a Format with a
<CODE>write()</CODE> 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:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_bold();
    $format-&gt;set_color('red');
    $worksheet-&gt;write('A1', &quot;Cell A1&quot;, $format);
    $format-&gt;set_color('green');
    $worksheet-&gt;write('B1', &quot;Cell B1&quot;, $format);
</PRE>
</P>
<P>
Cell A1 is assigned the Format <CODE>$format</CODE> 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.

</P>
<P>
In general a method call without an argument will turn a property on, for
example:

</P>
<P>
<PRE>
    my $format1 = $workbook-&gt;addformat();
    $format1-&gt;set_bold();  # Turns bold on
    $format1-&gt;set_bold(1); # Also turns bold on
    $format1-&gt;set_bold(0); # Turns bold off
</PRE>
</P>
<P>
<HR>
<H1><A NAME="FORMAT_METHODS">FORMAT METHODS</A></H1>
<P>
The Format object methods are described in more detail in the following
sections. In addition, there is a Perl program called <CODE>formats.pl</CODE> in the <CODE>examples</CODE> directory of the WriteExcel distribution. This program creates an Excel
workbook called <CODE>formats.xls</CODE> which contains examples of almost all the format types.

</P>
<P>
The following Format methods are available:

</P>
<P>
<PRE>
    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_align()
    set_rotation()
    set_text_wrap()
    set_text_justlast()
    set_merge()
    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()
</PRE>
</P>
<P>
The above methods can also be applied directly as properties. For example <CODE>$worksheet-&gt;set_bold()</CODE> is equivalent to <CODE>set_properties(bold =&gt; 1)</CODE>.

</P>
<P>
<HR>
<H2><A NAME="set_properties_properties_">set_properties(%properties)</A></H2>
<P>
The properties of an existing Format object can be set by means of <CODE>set_properties()</CODE>:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_properties(bold =&gt; 1, color =&gt; 'red');
</PRE>
</P>
<P>
You can also store the properties in one or more named hashes and pass them
to the <CODE>set_properties()</CODE> method:

</P>
<P>
<PRE>
    my %font    = (
                    font  =&gt; 'Arial',
                    size  =&gt; 12,
                    color =&gt; 'blue',
                    bold  =&gt; 1,
                  );
</PRE>
</P>
<P>
<PRE>
    my $format = $workbook-&gt;set_properties(%font);
</PRE>
</P>
<P>
This method can be used as an alternative to setting the properties with <CODE>addformat()</CODE> or the specific format methods that are detailed in the following sections.

</P>
<P>
<HR>
<H2><A NAME="set_font_fontname_">set_font($fontname)</A></H2>
<P>
<PRE>
    Default state:      Font is Arial
    Default action:     None
    Valid args:         Any valid font name
</PRE>
</P>
<P>
Specify the font used:

</P>
<P>
<PRE>
    $format-&gt;set_font('Times New Roman');
</PRE>
</P>
<P>
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 'Arial', 'Times New Roman' and 'Courier New'. See also the Fonts
worksheet created by formats.pl

</P>
<P>
<HR>
<H2><A NAME="set_size_">set_size()</A></H2>
<P>
<PRE>
    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.
</PRE>
</P>
<P>
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 <CODE>set_row()</CODE> worksheet method.

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_size(30);
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_color_">set_color()</A></H2>
<P>
<PRE>
    Default state:      Excels default color, usually black
    Default action:     Set the default color
    Valid args:         Integers from 8..63 or the following strings:
                        'black'
                        'blue'
                        'brown'
                        'cyan'
                        'gray'
                        'green'
                        'lime'
                        'magenta'
                        'navy'
                        'orange'
                        'purple'
                        'red'
                        'silver'
                        'white'
                        'yellow'
</PRE>
</P>
<P>
Set the font colour. The <CODE>set_color()</CODE> method is used as follows:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_color('red');
    $worksheet-&gt;write(0, 0, &quot;wheelbarrow&quot;, $format);
</PRE>
</P>
<P>
Note: The <CODE>set_color()</CODE> method is used to set the colour of the font in a cell. To set the colour
of a cell use the <CODE>set_bg_color()</CODE> and <CODE>set_pattern()</CODE> methods.

</P>
<P>
For additional examples see the 'Named colors' and 'Standard colors'
worksheets created by formats.pl in the examples directory.

</P>
<P>
See also <A HREF="#COLOURS_IN_EXCEL">COLOURS IN EXCEL</A>.

</P>
<P>
<HR>
<H2><A NAME="set_bold_">set_bold()</A></H2>
<P>
<PRE>
    Default state:      bold is off
    Default action:     Turn bold on
    Valid args:         0, 1 [1]
</PRE>
</P>
<P>
Set the bold property of the font:

</P>
<P>
<PRE>
    $format-&gt;set_bold();  # Turn bold on
</PRE>
</P>
<P>
[1] Actually, values in the range 100..1000 are also valid. 400 is normal,
700 is bold and 1000 is very bold indeed. It is probably best to set the
value to 1 and use normal bold.

</P>
<P>
<HR>
<H2><A NAME="set_italic_">set_italic()</A></H2>
<P>
<PRE>
    Default state:      Italic is off
    Default action:     Turn italic on
    Valid args:         0, 1
</PRE>
</P>
<P>
Set the italic property of the font:

</P>
<P>
<PRE>
    $format-&gt;set_italic();  # Turn italic on
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_underline_">set_underline()</A></H2>
<P>
<PRE>
    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
</PRE>
</P>
<P>
Set the underline property of the font.

</P>
<P>
<PRE>
    $format-&gt;set_underline();   # Single underline
</PRE>
</P>
<P>
<HR>
<H2><A NAME="set_strikeout_">set_strikeout()</A></H2>
<P>
<PRE>
    Default state:      Strikeout is off
    Default action:     Turn strikeout on
    Valid args:         0, 1
</PRE>
</P>
<P>
Set the strikeout property of the font.

</P>
<P>
<HR>
<H2><A NAME="set_script_">set_script()</A></H2>
<P>
<PRE>
    Default state:      Super/Subscript is off
    Default action:     Turn Superscript on
    Valid args:         0  = Normal
                        1  = Superscript
                        2  = Subscript
</PRE>
</P>
<P>
Set the superscript/subscript property of the font. This format is
currently not very useful.

</P>
<P>
<HR>
<H2><A NAME="set_outline_">set_outline()</A></H2>
<P>
<PRE>
    Default state:      Outline is off
    Default action:     Turn outline on
    Valid args:         0, 1
</PRE>
</P>
<P>
Macintosh only.

</P>
<P>
<HR>
<H2><A NAME="set_shadow_">set_shadow()</A></H2>
<P>
<PRE>
    Default state:      Shadow is off
    Default action:     Turn shadow on
    Valid args:         0, 1
</PRE>
</P>
<P>
Macintosh only.

</P>
<P>
<HR>
<H2><A NAME="set_num_format_">set_num_format()</A></H2>
<P>
<PRE>
    Default state:      General format
    Default action:     Format index 1
    Valid args:         See the following table
</PRE>
</P>
<P>
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.

</P>
<P>
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:

</P>
<P>
<PRE>
    my $format1 = $workbook-&gt;addformat();
    my $format2 = $workbook-&gt;addformat();
    $format1-&gt;set_num_format('d mmm yyyy'); # Format string
    $format2-&gt;set_num_format(0x0f);         # Format index
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(0, 0, 36892.521, $format1);      # 1 Jan 2001
    $worksheet-&gt;write(0, 0, 36892.521, $format2);      # 1-Jan-01
</PRE>
</P>
<P>
Using format strings you can define very sophisticated formatting of
numbers.

</P>
<P>
<PRE>
    $format01-&gt;set_num_format('0.000');
    $worksheet-&gt;write(0,  0, 3.1415926, $format01);    # 3.142
</PRE>
</P>
<P>
<PRE>
    $format02-&gt;set_num_format('#,##0');
    $worksheet-&gt;write(1,  0, 1234.56,   $format02);    # 1,235
</PRE>
</P>
<P>
<PRE>
    $format03-&gt;set_num_format('#,##0.00');
    $worksheet-&gt;write(2,  0, 1234.56,   $format03);    # 1,234.56
</PRE>
</P>
<P>
<PRE>
    $format04-&gt;set_num_format('$0.00');
    $worksheet-&gt;write(3,  0, 49.99,     $format04);    # $49.99
</PRE>
</P>
<P>
<PRE>
    $format05-&gt;set_num_format('£0.00');
    $worksheet-&gt;write(4,  0, 49.99,     $format05);    # £49.99
</PRE>
</P>
<P>
<PRE>
    $format06-&gt;set_num_format('¥0.00');
    $worksheet-&gt;write(5,  0, 49.99,     $format06);    # ¥49.99
</PRE>
</P>
<P>
<PRE>
    $format07-&gt;set_num_format('mm/dd/yy');
    $worksheet-&gt;write(6,  0, 36892.521, $format07);    # 01/01/01
</PRE>
</P>
<P>
<PRE>
    $format08-&gt;set_num_format('mmm d yyyy');
    $worksheet-&gt;write(7,  0, 36892.521, $format08);    # Jan 1 2001
</PRE>
</P>
<P>
<PRE>
    $format09-&gt;set_num_format('d mmmm yyyy');
    $worksheet-&gt;write(8,  0, 36892.521, $format09);    # 1 January 2001
</PRE>
</P>
<P>
<PRE>
    $format10-&gt;set_num_format('dd/mm/yyyy hh:mm AM/PM');
    $worksheet-&gt;write(9,  0, 36892.521, $format10);    # 01/01/2001 12:30 AM
</PRE>
</P>
<P>
<PRE>
    $format11-&gt;set_num_format('0 &quot;dollar and&quot; .00 &quot;cents&quot;');
    $worksheet-&gt;write(10, 0, 1.87,      $format11);    # 1 dollar and .87 cents
</PRE>
</P>
<P>
<PRE>
    # Conditional formatting
    $format12-&gt;set_num_format('[Green]General;[Red]-General;General');
    $worksheet-&gt;write(11, 0, 123,       $format12);    # &gt; 0 Green
    $worksheet-&gt;write(12, 0, -45,       $format12);    # &lt; 0 Red
    $worksheet-&gt;write(13, 0, 0,         $format12);    # = 0 Default colour
</PRE>
</P>
<P>
<PRE>
    # Zip code
    $format13-&gt;set_num_format('00000');
    $worksheet-&gt;write(14, 0, '01209',   $format13);
</PRE>
</P>
<P>
The number system used for dates is described in <A HREF="#Dates_in_Excel">Dates in Excel</A>.

</P>
<P>
The colour format should have one of the following values:

</P>
<P>
<PRE>
    [Black] [Blue] [Cyan] [Green] [Magenta] [Red] [White] [Yellow]
</PRE>
</P>
<P>
Alternatively you can specify the colour based on a colour index as
follows: <CODE>[Color n]</CODE>, where n is a standard Excel colour index - 7. See the 'Standard colors'
worksheet created by formats.pl.

</P>
<P>
For more information refer to the documentation on formatting in the <CODE>doc</CODE> directory of the Spreadsheet::WriteExcel distro, the Excel on-line help or
to the tutorial at: <A
HREF="http://support.microsoft.com/support/Excel/Content/Formats/default.asp">http://support.microsoft.com/support/Excel/Content/Formats/default.asp</A>
and <A
HREF="http://support.microsoft.com/support/Excel/Content/Formats/codes.asp">http://support.microsoft.com/support/Excel/Content/Formats/codes.asp</A>


</P>
<P>
You should ensure that the format string is valid in Excel prior to using
it in WriteExcel.

</P>
<P>
Excel's built-in formats are shown in the following table:

</P>
<P>
<PRE>
    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);_(* &quot;-&quot;_);_(@_)
    42      0x2a    _($* #,##0_);_($* (#,##0);_($* &quot;-&quot;_);_(@_)
    43      0x2b    _(* #,##0.00_);_(* (#,##0.00);_(* &quot;-&quot;??_);_(@_)
    44      0x2c    _($* #,##0.00_);_($* (#,##0.00);_($* &quot;-&quot;??_);_(@_)
    45      0x2d    mm:ss
    46      0x2e    [h]:mm:ss
    47      0x2f    mm:ss.0
    48      0x30    ##0.0E+0
    49      0x31    @
</PRE>
</P>
<P>
For examples of these formatting codes see the 'Numerical formats'
worksheet created by formats.pl.

</P>
<P>
Note 1. Numeric formats 23 to 36 are not documented by Microsoft and may
differ in international versions.

</P>
<P>
Note 2. In Excel 5 the dollar sign appears as a dollar sign. In Excel
97-2000 it appears as the defined local currency symbol.

</P>
<P>
Note 3. The red negative numeric formats display slightly differently in
Excel 5 and Excel 97-2000.

</P>
<P>
<HR>
<H2><A NAME="set_locked_">set_locked()</A></H2>
<P>
<PRE>
    Default state:      Cell locking is on
    Default action:     Turn locking on
    Valid args:         0, 1
</PRE>
</P>
<P>
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 <CODE>protect()</CODE> method.

</P>
<P>
<PRE>
    my $locked  = $workbook-&gt;addformat();
    $locked-&gt;set_locked(1); # A non-op
</PRE>
</P>
<P>
<PRE>
    my $unlocked = $workbook-&gt;addformat();
    $locked-&gt;set_locked(0);
</PRE>
</P>
<P>
<PRE>
    # Enable worksheet protection
    $worksheet-&gt;protect();
</PRE>
</P>
<P>
<PRE>
    # This cell cannot be edited.
    $worksheet-&gt;write('A1', '=1+2', $locked);
</PRE>
</P>
<P>
<PRE>
    # This cell can be edited.
    $worksheet-&gt;write('A2', '=1+2', $unlocked);
</PRE>
</P>
<P>
Note: This offers weak protection even with a password, see the note in
relation to the <CODE>protect()</CODE> method.

</P>
<P>
<HR>
<H2><A NAME="set_hidden_">set_hidden()</A></H2>
<P>
<PRE>
    Default state:      Formula hiding is off
    Default action:     Turn hiding on
    Valid args:         0, 1
</PRE>
</P>
<P>
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 <CODE>protect()</CODE> method.

</P>
<P>
<PRE>
    my $hidden = $workbook-&gt;addformat();
    $hidden-&gt;set_hidden();
</PRE>
</P>
<P>
<PRE>
    # Enable worksheet protection
    $worksheet-&gt;protect();
</PRE>
</P>
<P>
<PRE>
    # The formula in this cell isn't visible
    $worksheet-&gt;write('A1', '=1+2', $hidden);
</PRE>
</P>
<P>
Note: This offers weak protection even with a password, see the note in
relation to the <CODE>protect()</CODE> method.

</P>
<P>
<HR>
<H2><A NAME="set_align_">set_align()</A></H2>
<P>
<PRE>
    Default state:      Alignment is off
    Default action:     Left alignment
    Valid args:         'left'              Horizontal
                        'center'
                        'right'
                        'fill'
                        'justify'
                        'merge'
</PRE>
</P>
<P>
<PRE>
                        'top'               Vertical
                        'vcenter'
                        'bottom'
                        'vjustify'
</PRE>
</P>
<P>
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:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_align('center');
    $format-&gt;set_align('vcenter');
    $worksheet-&gt;set_row(0, 30);
    $worksheet-&gt;write(0, 0, &quot;X&quot;, $format);
</PRE>
</P>
<P>
Text can be aligned across two or more adjacent cells using the <CODE>merge</CODE> property. See also, the <CODE>set_merge()</CODE> method.

</P>
<P>
The <CODE>vjustify</CODE> (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 <CODE>set_text_wrap()</CODE> method.

</P>
<P>
For further examples see the 'Alignment' worksheet created by formats.pl.

</P>
<P>
<HR>
<H2><A NAME="set_merge_">set_merge()</A></H2>
<P>
<PRE>
    Default state:      Cell merging is off
    Default action:     Turn cell merging on
    Valid args:         1
</PRE>
</P>
<P>
Text can be aligned across two or more adjacent cells using the <CODE>set_merge()</CODE> method. This is an alias for the unintuitive <CODE>set_align('merge')</CODE> method call.

</P>
<P>
Only one cell should contain the text, the other cells should be blank:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_merge();
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(1, 1, 'Merged cells', $format);
    $worksheet-&gt;write_blank(1, 2, $format);
</PRE>
</P>
<P>
See also the <CODE>merge1.pl</CODE>, <CODE>merge2.pl</CODE> and <CODE>merge3.pl</CODE> programs in the <CODE>examples</CODE> directory and the <CODE>merge_range()</CODE> method.

</P>
<P>
<HR>
<H2><A NAME="set_text_wrap_">set_text_wrap()</A></H2>
<P>
<PRE>
    Default state:      Text wrap is off
    Default action:     Turn text wrap on
    Valid args:         0, 1
</PRE>
</P>
<P>
Here is an example using the text wrap property, the escape character <CODE>\n</CODE> is used to indicate the end of line:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_text_wrap();
    $worksheet-&gt;write(0, 0, &quot;It's\na bum\nwrap&quot;, $format);
</PRE>
</P>
<P>
Excel will adjust the height of the row to accommodate the wrapped text. A
similar effect can be obtained without newlines using the <CODE>set_align('vjustify')</CODE> method. See the <CODE>textwrap.pl</CODE> program in the <CODE>examples</CODE> directory.

</P>
<P>
<HR>
<H2><A NAME="set_rotation_">set_rotation()</A></H2>
<P>
<PRE>
    Default state:      Text rotation is off
    Default action:     Rotation style 1
    Valid args:         0 No rotation
                        1 Letters run from top to bottom
                        2 90° anticlockwise
                        3 90° clockwise
</PRE>
</P>
<P>
Set the rotation of the text in a cell. See the 'Alignment' worksheet
created by formats.pl. Note, fractional rotations aren't possible with the
Excel 5 format.

</P>
<P>
<HR>
<H2><A NAME="set_text_justlast_">set_text_justlast()</A></H2>
<P>
<PRE>
    Default state:      Justify last is off
    Default action:     Turn justify last on
    Valid args:         0, 1
</PRE>
</P>
<P>
Only applies to Far Eastern versions of Excel.

</P>
<P>
<HR>
<H2><A NAME="set_pattern_">set_pattern()</A></H2>
<P>
<PRE>
    Default state:      Pattern is off
    Default action:     Solid fill is on
    Valid args:         0 .. 18
</PRE>
</P>
<P>
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.

</P>
<P>
<HR>
<H2><A NAME="set_bg_color_">set_bg_color()</A></H2>
<P>
<PRE>
    Default state:      Color is off
    Default action:     Solid fill.
    Valid args:         See set_color()
</PRE>
</P>
<P>
The <CODE>set_bg_color()</CODE> method can be used to set the background colour of a pattern. Patterns are
defined via the <CODE>set_pattern()</CODE> method. If a pattern hasn't been defined then a solid fill pattern is used
as the default.

</P>
<P>
Here is an example of how to set up a solid fill in a cell:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat();
</PRE>
</P>
<P>
<PRE>
    $format-&gt;set_pattern(); # This is optional when using a solid fill
</PRE>
</P>
<P>
<PRE>
    $format-&gt;set_bg_color('green');
    $worksheet-&gt;write('A1', 'Ray', $format);
</PRE>
</P>
<P>
For further examples see the 'Patterns' worksheet created by formats.pl.

</P>
<P>
<HR>
<H2><A NAME="set_fg_color_">set_fg_color()</A></H2>
<P>
<PRE>
    Default state:      Color is off
    Default action:     Solid fill.
    Valid args:         See set_color()
</PRE>
</P>
<P>
The <CODE>set_fg_color()</CODE> method can be used to set the foreground colour of a pattern.

</P>
<P>
Note, in older versions of Spreadsheet::WriteExcel it was recommended to
use <CODE>set_fg_color()</CODE> to set the colour of a solid fill pattern. The preferred method is now to
use <CODE>set_bg_color()</CODE>, although for backward compatibility the role of <CODE>set_fg_color()</CODE> and <CODE>set_bg_color()</CODE> are interchangeable when using a solid fill pattern.

</P>
<P>
For further examples see the 'Patterns' worksheet created by formats.pl.

</P>
<P>
<HR>
<H2><A NAME="set_border_">set_border()</A></H2>
<P>
<PRE>
    Also applies to:    set_bottom()
                        set_top()
                        set_left()
                        set_right()
</PRE>
</P>
<P>
<PRE>
    Default state:      Border is off
    Default action:     Set border type 1
    Valid args:         0 No border
                        1 Thin single border
                        2 Medium single border
                        3 Dashed border
                        4 Dotted border
                        5 Thick single border
                        6 Double line border
                        7 Hair border
</PRE>
</P>
<P>
A cell border is comprised of a border on the bottom, top, left and right.
These can be set to the same value using <CODE>set_border()</CODE> or individually using the relevant method calls shown above. Examples of
the available border styles are shown in the 'Borders' worksheet created by
formats.pl.

</P>
<P>
<HR>
<H2><A NAME="set_border_color_">set_border_color()</A></H2>
<P>
<PRE>
    Also applies to:    set_bottom_color()
                        set_top_color()
                        set_left_color()
                        set_right_color()
</PRE>
</P>
<P>
<PRE>
    Default state:      Color is off
    Default action:     Undefined
    Valid args:         See set_color()
</PRE>
</P>
<P>
Set the colour of the cell borders.

</P>
<P>
<HR>
<H2><A NAME="copy_format_">copy($format)</A></H2>
<P>
This method is used to copy all of the properties from one Format object to
another:

</P>
<P>
<PRE>
    my $lorry1 = $workbook-&gt;addformat();
    $lorry1-&gt;set_bold();
    $lorry1-&gt;set_italic();
    $lorry1-&gt;set_color('red');    # lorry1 is bold, italic and red
</PRE>
</P>
<P>
<PRE>
    my $lorry2 = $workbook-&gt;addformat();
    $lorry2-&gt;copy($lorry1);
    $lorry2-&gt;set_color('yellow'); # lorry2 is bold, italic and yellow
</PRE>
</P>
<P>
It 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.

</P>
<P>
Note: this is not a copy constructor, both objects must exist prior to
copying.

</P>
<P>
<HR>
<H1><A NAME="COLOURS_IN_EXCEL">COLOURS IN EXCEL</A></H1>
<P>
Excel provides a colour palette of 56 colours. In Spreadsheet::WriteExcel
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:

</P>
<P>
<PRE>
    my $format = $workbook-&gt;addformat(
                                        color =&gt; 12, # index for blue
                                        font  =&gt; 'Arial',
                                        size  =&gt; 12,
                                        bold  =&gt; 1,
                                     );
</PRE>
</P>
<P>
The most commonly used colours can also be accessed by name. The name acts
as a simple alias for the colour index:

</P>
<P>
<PRE>
    black     =&gt;    8
    blue      =&gt;   12
    brown     =&gt;   16
    cyan      =&gt;   15
    gray      =&gt;   23
    green     =&gt;   17
    lime      =&gt;   11
    magenta   =&gt;   14
    navy      =&gt;   18
    orange    =&gt;   53
    purple    =&gt;   20
    red       =&gt;   10
    silver    =&gt;   22
    white     =&gt;    9
    yellow    =&gt;   13
</PRE>
</P>
<P>
For example:

</P>
<P>
<PRE>
    my $font = $workbook-&gt;addformat(color =&gt; 'red');
</PRE>
</P>
<P>
Users of VBA in Excel should note that the equivalent colour indices are in
the range 1..56 instead of 8..63.

</P>
<P>
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 <CODE>set_custom_color()</CODE> workbook method to adjust the RGB (red green blue) components of the
colour:

</P>
<P>
<PRE>
    my $ferrari = $workbook-&gt;set_custom_color(40, 216, 12, 12);
</PRE>
</P>
<P>
<PRE>
    my $format  = $workbook-&gt;addformat(
                                        bg_color =&gt; $ferrari,
                                        pattern  =&gt; 1,
                                        border   =&gt; 1
                                      );
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write_blank('A1', $format);
</PRE>
</P>
<P>
Spreadsheet::WriteExcel uses the Excel 97/2000 default colour palette.
However, for backward compatibility the Excel 5 palette can be specified
instead using the <CODE>set_palette_xl5()</CODE> workbook method.

</P>
<P>
The default Excel colour palette is shown in <CODE>palette.html</CODE> in the <CODE>doc</CODE> directory of the distro. You can generate an Excel version of the palette
using <CODE>colors.pl</CODE> in the <CODE>examples</CODE> directory.

</P>
<P>
A comparison of the colour components in the Excel 5 and Excel 97+ colour
palettes is shown in <CODE>rgb5-97.txt</CODE> in the <CODE>doc</CODE> directory.

</P>
<P>
You may also find the following links helpful:

</P>
<P>
A detailed look at Excel's colour palette: <A
HREF="http://www.geocities.com/davemcritchie/excel/colors.htm">http://www.geocities.com/davemcritchie/excel/colors.htm</A>


</P>
<P>
A decimal RGB chart: <A
HREF="http://www.hypersolutions.org/pages/rgbdec.html">http://www.hypersolutions.org/pages/rgbdec.html</A>


</P>
<P>
A hex RGB chart: : <A
HREF="http://www.hypersolutions.org/pages/rgbhex.html">http://www.hypersolutions.org/pages/rgbhex.html</A>


</P>
<P>
<HR>
<H1><A NAME="DATES_IN_EXCEL">DATES IN EXCEL</A></H1>
<P>
Dates and times in Excel are represented by real numbers, for example
&quot;Jan 1 2001 12:30 AM&quot; is represented by the number 36892.521.

</P>
<P>
The integer part of the number stores the number of days since the epoch
and the fractional part stores the percentage of the day.

</P>
<P>
The epoch can be either 1900 or 1904. Excel for Windows uses 1900 and Excel
for Macintosh uses 1904. The epochs are:

</P>
<P>
<PRE>
    1900: 0 January 1900 i.e. 31 December 1899
    1904: 1 January 1904
</PRE>
</P>
<P>
By default Spreadsheet::WriteExcel uses the Windows/1900 format although it
generally isn't an issue since Excel on Windows and the Macintosh will
convert automatically between one system and the other. To use the 1904
epoch you must use the <CODE>set_1904()</CODE> workbook method.

</P>
<P>
There are two things to note about the 1900 date format. The first is that
the epoch starts on 0 January 1900. The second is that the year 1900 is
erroneously but deliberately treated as a leap year. Therefore you must add
an extra day to dates after 28 February 1900. The reason for this anomaly
is explained at <A
HREF="http://support.microsoft.com/support/kb/articles/Q181/3/70.asp">http://support.microsoft.com/support/kb/articles/Q181/3/70.asp</A>


</P>
<P>
A date or time in Excel is like any other number. To display the number as
a date you must apply a number format to it. Refer to the <CODE>set_num_format()</CODE> method above:

</P>
<P>
<PRE>
    $format-&gt;set_num_format('mmm d yyyy hh:mm AM/PM');
    $worksheet-&gt;write('A1', 36892.521 , $format); # Jan 1 2001 12:30 AM
</PRE>
</P>
<P>
The <CODE>Spreadsheet::WriteExcel::Utility</CODE> module that is included in the distro contains helper functions for dealing
with dates and times in Excel, for example:

</P>
<P>
<PRE>
    $date = xl_date_list(2002, 1, 1);         # 37257
    $date = xl_parse_date(&quot;11 July 1997&quot;);    # 35622
    $time = xl_parse_time('3:21:36 PM');      # 0.64
    $date = xl_decode_date_EU(&quot;13 May 2002&quot;); # 37389
</PRE>
</P>
<P>
These functions deal automatically with the s1900 leap year issue described
above.

</P>
<P>
The date and time functions are based on functions provided by the <CODE>Date::Calc</CODE> and <CODE>Date::Manip</CODE> modules. These modules are very useful if you plan to manipulate dates in
different formats.

</P>
<P>
There is also the <CODE>excel_date1.pl</CODE> program in the <CODE>examples</CODE> directory of the WriteExcel distribution which was written by Andrew
Benham. It contains a detailed description of the problems involved in
calculating dates in Excel. It does not require any external modules.

</P>
<P>
It is also possible to get Excel to calculate dates for you by defining a
function:

</P>
<P>
<PRE>
    $worksheet-&gt;write('A1', '=DATEVALUE(&quot;1-Jan-2001&quot;)');
</PRE>
</P>
<P>
However, this carries a performance overhead in Spreadsheet::WriteExcel due
to the parsing of the formula and it shouldn't be used for programs that
deal with a large number of dates, unless you use it in conjunction with <CODE>store_formula()</CODE> and <CODE>repeat_formula()</CODE> .

</P>
<P>
<HR>
<H1><A NAME="FORMULAS_AND_FUNCTIONS_IN_EXCEL">FORMULAS AND FUNCTIONS IN EXCEL</A></H1>
<P>
<HR>
<H2><A NAME="Caveats">Caveats</A></H2>
<P>
The first thing to note is that there are still some outstanding issues
with the implementation of formulas and functions:

</P>
<P>
<PRE>
    1. Writing a formula is much slower than writing the equivalent string.
    2. You cannot use embedded double quotes in strings.
    3. You cannot use arrays constants, i.e. {1;2;3}, in functions.
    4. Unary minus isn't supported.
    5. Whitespace is not preserved around operators.
    6. Named ranges are not supported.
</PRE>
</P>
<P>
However, these constraints will be removed in future versions. They are
here because of a trade-off between features and time. Also, it is possible
to work around issues 1 and 2 using the <CODE>store_formula()</CODE> and <CODE>repeat_formula()</CODE> methods as described later in this section.

</P>
<P>
<HR>
<H2><A NAME="Introduction">Introduction</A></H2>
<P>
The following is a brief introduction to formulas and functions in Excel
and Spreadsheet::WriteExcel.

</P>
<P>
A formula is a string that begins with an equals sign:

</P>
<P>
<PRE>
    '=A1+B1'
    '=AVERAGE(1, 2, 3)'
</PRE>
</P>
<P>
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.

</P>
<P>
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
IV i.e. 0 to 255, rows range from 1 to 16384. The <CODE>Spreadsheet::WriteExcel::Utility</CODE> module that is included in the distro contains helper functions for dealing
with A1 notation, for example:

</P>
<P>
<PRE>
    use Spreadsheet::WriteExcel::Utility;
</PRE>
</P>
<P>
<PRE>
    ($row, $col) = xl_cell_to_rowcol('C2');  # (1, 2)
    $str         = xl_rowcol_to_cell(1, 2);  # C2
</PRE>
</P>
<P>
The Excel <CODE>$</CODE> 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.

</P>
<P>
<PRE>
    '=A1'   # Column and row are relative
    '=$A1'  # Column is absolute and row is relative
    '=A$1'  # Column is relative and row is absolute
    '=$A$1' # Column and row are absolute
</PRE>
</P>
<P>
Formulas can also refer to cells in other worksheets of the current
workbook. For example:

</P>
<P>
<PRE>
    '=Sheet2!A1'
    '=Sheet2!A1:A5'
    '=Sheet2:Sheet3!A1'
    '=Sheet2:Sheet3!A1:A5'
    q{='Test Data'!A1}
    q{='Test Data1:Test Data2'!A1}
</PRE>
</P>
<P>
The sheet reference and the cell reference are separated by  <CODE>!</CODE> the exclamation mark symbol. If worksheet names contain spaces, commas o
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 <CODE>q{}</CODE> to protect the quotes. See <CODE>perlop</CODE> in the main Perl documentation. Only valid sheet names that have been added
using the <CODE>addworksheet()</CODE> method can be used in formulas. You cannot reference external workbooks.

</P>
<P>
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:

</P>
<P>
<PRE>
    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)   # Not yet supported
       %      Percent (Not modulus)     13%      # Not supported, [1]
</PRE>
</P>
<P>
<PRE>
    Comparison operators:
    =====================
    Operator  Meaning                   Example
        =     Equal to                  A1 =  B1 # Equivalent to ==
        &lt;&gt;    Not equal to              A1 &lt;&gt; B1 # Equivalent to !=
        &gt;     Greater than              A1 &gt;  B1
        &lt;     Less than                 A1 &lt;  B1
        &gt;=    Greater than or equal to  A1 &gt;= B1
        &lt;=    Less than or equal to     A1 &lt;= B1
</PRE>
</P>
<P>
<PRE>
    String operator:
    ================
    Operator  Meaning                   Example
        &amp;     Concatenation             &quot;Hello &quot; &amp; &quot;World!&quot; # [2]
</PRE>
</P>
<P>
<PRE>
    Reference operators:
    ====================
    Operator  Meaning                   Example
        :     Range operator            A1:A4               # [3]
        ,     Union operator            SUM(1, 2+2, B3)     # [4]
</PRE>
</P>
<P>
<PRE>
    Notes:
    [1]: You can get a percentage with formatting and modulus with MOD().
    [2]: Equivalent to (&quot;Hello &quot; . &quot;World!&quot;) in Perl.
    [3]: This range is equivalent to cells A1, A2, A3 and A4.
    [4]: The comma behaves like the list separator in Perl.
</PRE>
</P>
<P>
The range and comma operators can have different symbols in non-English
versions of Excel. These will be supported in a later version of
Spreadsheet::WriteExcel. European users of Excel take note:

</P>
<P>
<PRE>
    $worksheet-&gt;write('A1', '=SUM(1; 2; 3)'); # Wrong!!
    $worksheet-&gt;write('A1', '=SUM(1, 2, 3)'); # Okay
</PRE>
</P>
<P>
The following table lists all of the core functions supported by Excel 5
and Spreadsheet::WriteExcel. Any additional functions that are available
through the &quot;Analysis ToolPak&quot; or other add-ins are not
supported. These functions have all been tested to verify that they work.

</P>
<P>
<PRE>
    ABS           DB            INDIRECT      NORMINV       SLN
    ACOS          DCOUNT        INFO          NORMSDIST     SLOPE
    ACOSH         DCOUNTA       INT           NORMSINV      SMALL
    ADDRESS       DDB           INTERCEPT     NOT           SQRT
    AND           DEGREES       IPMT          NOW           STANDARDIZE
    AREAS         DEVSQ         IRR           NPER          STDEV
    ASIN          DGET          ISBLANK       NPV           STDEVP
    ASINH         DMAX          ISERR         ODD           STEYX
    ATAN          DMIN          ISERROR       OFFSET        SUBSTITUTE
    ATAN2         DOLLAR        ISLOGICAL     OR            SUBTOTAL
    ATANH         DPRODUCT      ISNA          PEARSON       SUM
    AVEDEV        DSTDEV        ISNONTEXT     PERCENTILE    SUMIF
    AVERAGE       DSTDEVP       ISNUMBER      PERCENTRANK   SUMPRODUCT
    BETADIST      DSUM          ISREF         PERMUT        SUMSQ
    BETAINV       DVAR          ISTEXT        PI            SUMX2MY2
    BINOMDIST     DVARP         KURT          PMT           SUMX2PY2
    CALL          ERROR.TYPE    LARGE         POISSON       SUMXMY2
    CEILING       EVEN          LEFT          POWER         SYD
    CELL          EXACT         LEN           PPMT          T
    CHAR          EXP           LINEST        PROB          TAN
    CHIDIST       EXPONDIST     LN            PRODUCT       TANH
    CHIINV        FACT          LOG           PROPER        TDIST
    CHITEST       FALSE         LOG10         PV            TEXT
    CHOOSE        FDIST         LOGEST        QUARTILE      TIME
    CLEAN         FIND          LOGINV        RADIANS       TIMEVALUE
    CODE          FINV          LOGNORMDIST   RAND          TINV
    COLUMN        FISHER        LOOKUP        RANK          TODAY
    COLUMNS       FISHERINV     LOWER         RATE          TRANSPOSE
    COMBIN        FIXED         MATCH         REGISTER.ID   TREND
    CONCATENATE   FLOOR         MAX           REPLACE       TRIM
    CONFIDENCE    FORECAST      MDETERM       REPT          TRIMMEAN
    CORREL        FREQUENCY     MEDIAN        RIGHT         TRUE
    COS           FTEST         MID           ROMAN         TRUNC
    COSH          FV            MIN           ROUND         TTEST
    COUNT         GAMMADIST     MINUTE        ROUNDDOWN     TYPE
    COUNTA        GAMMAINV      MINVERSE      ROUNDUP       UPPER
    COUNTBLANK    GAMMALN       MIRR          ROW           VALUE
    COUNTIF       GEOMEAN       MMULT         ROWS          VAR
    COVAR         GROWTH        MOD           RSQ           VARP
    CRITBINOM     HARMEAN       MODE          SEARCH        VDB
    DATE          HLOOKUP       MONTH         SECOND        VLOOKUP
    DATEVALUE     HOUR          N             SIGN          WEEKDAY
    DAVERAGE      HYPGEOMDIST   NA            SIN           WEIBULL
    DAY           IF            NEGBINOMDIST  SINH          YEAR
    DAYS360       INDEX         NORMDIST      SKEW          ZTEST
</PRE>
</P>
<P>
You can also modify the module to support function names in the following
languages: German, French, Spanish, Portuguese, Dutch, Finnish, Italian and
Swedish. See the <CODE>function_locale.pl</CODE> program in the <CODE>examples</CODE> directory of the distro.

</P>
<P>
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
links: <A
HREF="http://msdn.microsoft.com/library/default.asp?URL=/library/officedev/office97/s88f2.htm">http://msdn.microsoft.com/library/default.asp?URL=/library/officedev/office97/s88f2.htm</A>
and <A
HREF="http://msdn.microsoft.com/library/default.asp?URL=/library/en-us/office97/s992f.htm">http://msdn.microsoft.com/library/default.asp?URL=/library/en-us/office97/s992f.htm</A>


</P>
<P>
If your formula doesn't work in Spreadsheet::WriteExcel try the following:

</P>
<P>
<PRE>
    1. Verify that the formula works in Excel (or Gnumeric or OpenOffice).
    2. Ensure that it isn't on the Caveats list shown above.
    3. Ensure that cell references and formula names are in uppercase.
    4. Ensure that you are using ':' as the range operator, A1:A4.
    5. Ensure that you are using ',' as the union operator, SUM(1,2,3).
    6. Ensure that the function is in the above table.
</PRE>
</P>
<P>
If you go through steps 1-6 and you still have a problem, mail me.

</P>
<P>
<HR>
<H2><A NAME="Improving_performance_when_worki">Improving performance when working with formulas</A></H2>
<P>
Writing a large number of formulas with Spreadsheet::WriteExcel can be
slow. This is due to the fact that each formula has to be parsed and with
the current implementation this is computationally expensive.

</P>
<P>
However, in a lot of cases the formulas that you write will be quite
similar, for example:

</P>
<P>
<PRE>
    $worksheet-&gt;write_formula('B1',    '=A1 * 3 + 50',    $format);
    $worksheet-&gt;write_formula('B2',    '=A2 * 3 + 50',    $format);
    ...
    ...
    $worksheet-&gt;write_formula('B99',   '=A999 * 3 + 50',  $format);
    $worksheet-&gt;write_formula('B1000', '=A1000 * 3 + 50', $format);
</PRE>
</P>
<P>
In this example the cell reference changes in iterations from <CODE>A1</CODE> to <CODE>A1000</CODE>. The parser treats this variable as a <EM>token</EM> and arranges it according to predefined rules. However, since the parser is
oblivious to the value of the token, it is essentially performing the same
calculation 1000 times. This is inefficient.

</P>
<P>
The way to avoid this inefficiency and thereby speed up the writing of
formulas is to parse the formula once and then repeatedly substitute
similar tokens.

</P>
<P>
A formula can be parsed and stored via the <CODE>store_formula()</CODE> worksheet method. You can then use the <CODE>repeat_formula()</CODE> method to substitute <CODE>$pattern</CODE>, <CODE>$replace</CODE> pairs in the stored formula:

</P>
<P>
<PRE>
    my $formula = $worksheet-&gt;store_formula('=A1 * 3 + 50');
</PRE>
</P>
<P>
<PRE>
    for my $row (0..999) {
        $worksheet-&gt;repeat_formula($row, 1, $formula, $format, 'A1', 'A'.($row +1));
    }
</PRE>
</P>
<P>
On an arbitrary test machine this method was 10 times faster than the brute
force method shown above.

</P>
<P>
The token substitution can also be used to work around some of the current
parsing limitations. For example, the parser cannot currently handle double
quotes in strings such as the string <CODE>Hello &quot;World&quot;</CODE> which would be written in an Excel formula as <CODE>=&quot;Hello &quot;&quot;World&quot;&quot;&quot;</CODE>. The doubling of the double quotes here is an Excel requirement. You can
use <CODE>repeat_formula()</CODE> to work around this limitation as follows:

</P>
<P>
<PRE>
    my $formula = $worksheet-&gt;store_formula('=&quot;Hello qqWorldqq&quot;');
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;repeat_formula('A1', $formula, $format, ('qq', '&quot;&quot;') x 2);
</PRE>
</P>
<P>
For more information about how Spreadsheet::WriteExcel parses and stores
formulas see the <CODE>Spreadsheet::WriteExcel::Formula</CODE> man page.

</P>
<P>
It should be noted however that the overall speed of direct formula parsing
will be improved in a future version.

</P>
<P>
<HR>
<H1><A NAME="EXAMPLES">EXAMPLES</A></H1>
<P>
<HR>
<H2><A NAME="Example_1">Example 1</A></H2>
<P>
The following example shows some of the basic features of
Spreadsheet::WriteExcel.

</P>
<P>
<PRE>
    #!/usr/bin/perl -w
</PRE>
</P>
<P>
<PRE>
    use strict;
    use Spreadsheet::WriteExcel;
</PRE>
</P>
<P>
<PRE>
    # Create a new workbook called simple.xls and add a worksheet
    my $workbook  = Spreadsheet::WriteExcel-&gt;new(&quot;simple.xls&quot;);
    my $worksheet = $workbook-&gt;addworksheet();
</PRE>
</P>
<P>
<PRE>
    # The general syntax is write($row, $column, $token). Note that row and
    # column are zero indexed
</PRE>
</P>
<P>
<PRE>
    # Write some text
    $worksheet-&gt;write(0, 0,  &quot;Hi Excel!&quot;);
</PRE>
</P>
<P>
<PRE>
    # Write some numbers
    $worksheet-&gt;write(2, 0,  3);          # Writes 3
    $worksheet-&gt;write(3, 0,  3.00000);    # Writes 3
    $worksheet-&gt;write(4, 0,  3.00001);    # Writes 3.00001
    $worksheet-&gt;write(5, 0,  3.14159);    # TeX revision no.?
</PRE>
</P>
<P>
<PRE>
    # Write some formulas
    $worksheet-&gt;write(7, 0,  '=A3 + A6');
    $worksheet-&gt;write(8, 0,  '=IF(A5&gt;3,&quot;Yes&quot;, &quot;No&quot;)');
</PRE>
</P>
<P>
<PRE>
    # Write a hyperlink
    $worksheet-&gt;write(10, 0, '<A HREF="http://www.perl.com/">http://www.perl.com/</A>');
</PRE>
</P>

<br><center><img SRC="simple.gif" ALT="The output from simple.pl"></center>

<P>
<HR>
<H2><A NAME="Example_2">Example 2</A></H2>
<P>
The following is a general example which demonstrates some features of
working with multiple worksheets.

</P>
<P>
<PRE>
    #!/usr/bin/perl -w
</PRE>
</P>
<P>
<PRE>
    use strict;
    use Spreadsheet::WriteExcel;
</PRE>
</P>
<P>
<PRE>
    # Create a new Excel workbook
    my $workbook = Spreadsheet::WriteExcel-&gt;new(&quot;regions.xls&quot;);
</PRE>
</P>
<P>
<PRE>
    # Add some worksheets
    my $north = $workbook-&gt;addworksheet(&quot;North&quot;);
    my $south = $workbook-&gt;addworksheet(&quot;South&quot;);
    my $east  = $workbook-&gt;addworksheet(&quot;East&quot;);
    my $west  = $workbook-&gt;addworksheet(&quot;West&quot;);
</PRE>
</P>
<P>
<PRE>
    # Add a Format
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_bold();
    $format-&gt;set_color('blue');
</PRE>
</P>
<P>
<PRE>
    # Add a caption to each worksheet
    foreach my $worksheet ($workbook-&gt;sheets()) {
        $worksheet-&gt;write(0, 0, &quot;Sales&quot;, $format);
    }
</PRE>
</P>
<P>
<PRE>
    # Write some data
    $north-&gt;write(0, 1, 200000);
    $south-&gt;write(0, 1, 100000);
    $east-&gt;write (0, 1, 150000);
    $west-&gt;write (0, 1, 100000);
</PRE>
</P>
<P>
<PRE>
    # Set the active worksheet
    $south-&gt;activate();
</PRE>
</P>
<P>
<PRE>
    # Set the width of the first column
    $south-&gt;set_column(0, 0, 20);
</PRE>
</P>
<P>
<PRE>
    # Set the active cell
    $south-&gt;set_selection(0, 1);
</PRE>
</P>

<br><center><img SRC="regions.gif" ALT="The output from regions.pl"></center>

<P>
<HR>
<H2><A NAME="Example_3">Example 3</A></H2>
<P>
This example shows how to use a conditional numerical format with colours
to indicate if a share price has gone up or down.

</P>
<P>
<PRE>
    use strict;
    use Spreadsheet::WriteExcel;
</PRE>
</P>
<P>
<PRE>
    # Create a new workbook and add a worksheet
    my $workbook  = Spreadsheet::WriteExcel-&gt;new(&quot;stocks.xls&quot;);
    my $worksheet = $workbook-&gt;addworksheet();
</PRE>
</P>
<P>
<PRE>
    # Set the column width for columns 1, 2, 3 and 4
    $worksheet-&gt;set_column(0, 3, 15);
</PRE>
</P>
<P>
<PRE>
    # Create a format for the column headings
    my $header = $workbook-&gt;addformat();
    $header-&gt;set_bold();
    $header-&gt;set_size(12);
    $header-&gt;set_color('blue');
</PRE>
</P>
<P>
<PRE>
    # Create a format for the stock price
    my $f_price = $workbook-&gt;addformat();
    $f_price-&gt;set_align('left');
    $f_price-&gt;set_num_format('$0.00');
</PRE>
</P>
<P>
<PRE>
    # Create a format for the stock volume
    my $f_volume = $workbook-&gt;addformat();
    $f_volume-&gt;set_align('left');
    $f_volume-&gt;set_num_format('#,##0');
</PRE>
</P>
<P>
<PRE>
    # Create a format for the price change. This is an example of a conditional
    # format. The number is formatted as a percentage. If it is positive it is
    # formatted in green, if it is negative it is formatted in red and if it is
    # zero it is formatted as the default font colour (in this case black).
    # Note: the [Green] format produces an unappealing lime green. Try
    # [Color 10] instead for a dark green.
    #
    my $f_change = $workbook-&gt;addformat();
    $f_change-&gt;set_align('left');
    $f_change-&gt;set_num_format('[Green]0.0%;[Red]-0.0%;0.0%');
</PRE>
</P>
<P>
<PRE>
    # Write out the data
    $worksheet-&gt;write(0, 0, 'Company',$header);
    $worksheet-&gt;write(0, 1, 'Price',  $header);
    $worksheet-&gt;write(0, 2, 'Volume', $header);
    $worksheet-&gt;write(0, 3, 'Change', $header);
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(1, 0, 'Damage Inc.'       );
    $worksheet-&gt;write(1, 1, 30.25,    $f_price ); # $30.25
    $worksheet-&gt;write(1, 2, 1234567,  $f_volume); # 1,234,567
    $worksheet-&gt;write(1, 3, 0.085,    $f_change); # 8.5% in green
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(2, 0, 'Dump Corp.'        );
    $worksheet-&gt;write(2, 1, 1.56,     $f_price ); # $1.56
    $worksheet-&gt;write(2, 2, 7564,     $f_volume); # 7,564
    $worksheet-&gt;write(2, 3, -0.015,   $f_change); # -1.5% in red
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(3, 0, 'Rev Ltd.'          );
    $worksheet-&gt;write(3, 1, 0.13,     $f_price ); # $0.13
    $worksheet-&gt;write(3, 2, 321,      $f_volume); # 321
    $worksheet-&gt;write(3, 3, 0,        $f_change); # 0 in the font color (black)
</PRE>
</P>

<br><center><img SRC="stocks.gif" ALT="The output from stocks.pl"></center>

<P>
<HR>
<H2><A NAME="Example_4">Example 4</A></H2>
<P>
The following is a simple example of using functions.

</P>
<P>
<PRE>
    #!/usr/bin/perl -w
</PRE>
</P>
<P>
<PRE>
    use strict;
    use Spreadsheet::WriteExcel;
</PRE>
</P>
<P>
<PRE>
    # Create a new workbook and add a worksheet
    my $workbook  = Spreadsheet::WriteExcel-&gt;new(&quot;stats.xls&quot;);
    my $worksheet = $workbook-&gt;addworksheet('Test data');
</PRE>
</P>
<P>
<PRE>
    # Set the column width for columns 1
    $worksheet-&gt;set_column(0, 0, 20);
</PRE>
</P>
<P>
<PRE>
    # Create a format for the headings
    my $format = $workbook-&gt;addformat();
    $format-&gt;set_bold();
</PRE>
</P>
<P>
<PRE>
    # Write the sample data
    $worksheet-&gt;write(0, 0, 'Sample', $format);
    $worksheet-&gt;write(0, 1, 1);
    $worksheet-&gt;write(0, 2, 2);
    $worksheet-&gt;write(0, 3, 3);
    $worksheet-&gt;write(0, 4, 4);
    $worksheet-&gt;write(0, 5, 5);
    $worksheet-&gt;write(0, 6, 6);
    $worksheet-&gt;write(0, 7, 7);
    $worksheet-&gt;write(0, 8, 8);
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(1, 0, 'Length', $format);
    $worksheet-&gt;write(1, 1, 25.4);
    $worksheet-&gt;write(1, 2, 25.4);
    $worksheet-&gt;write(1, 3, 24.8);
    $worksheet-&gt;write(1, 4, 25.0);
    $worksheet-&gt;write(1, 5, 25.3);
    $worksheet-&gt;write(1, 6, 24.9);
    $worksheet-&gt;write(1, 7, 25.2);
    $worksheet-&gt;write(1, 8, 24.8);
</PRE>
</P>
<P>
<PRE>
    # Write some statistical functions
    $worksheet-&gt;write(4,  0, 'Count', $format);
    $worksheet-&gt;write(4,  1, '=COUNT(B1:I1)');
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(5,  0, 'Sum', $format);
    $worksheet-&gt;write(5,  1, '=SUM(B2:I2)');
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(6,  0, 'Average', $format);
    $worksheet-&gt;write(6,  1, '=AVERAGE(B2:I2)');
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(7,  0, 'Min', $format);
    $worksheet-&gt;write(7,  1, '=MIN(B2:I2)');
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(8,  0, 'Max', $format);
    $worksheet-&gt;write(8,  1, '=MAX(B2:I2)');
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(9,  0, 'Standard Deviation', $format);
    $worksheet-&gt;write(9,  1, '=STDEV(B2:I2)');
</PRE>
</P>
<P>
<PRE>
    $worksheet-&gt;write(10, 0, 'Kurtosis', $format);
    $worksheet-&gt;write(10, 1, '=KURT(B2:I2)');
</PRE>
</P>

<br><center><img SRC="stats.gif" ALT="The output from stats.pl"></center>

<P>
<HR>
<H2><A NAME="Example_5">Example 5</A></H2>
<P>
The following example converts a tab separated file called <CODE>tab.txt</CODE> into an Excel file called <CODE>tab.xls</CODE>.

</P>
<P>
<PRE>
    #!/usr/bin/perl -w
</PRE>
</P>
<P>
<PRE>
    use strict;
    use Spreadsheet::WriteExcel;
</PRE>
</P>
<P>
<PRE>
    open (TABFILE, &quot;tab.txt&quot;) or die &quot;tab.txt: $!&quot;;
</PRE>
</P>
<P>
<PRE>
    my $workbook  = Spreadsheet::WriteExcel-&gt;new(&quot;tab.xls&quot;);
    my $worksheet = $workbook-&gt;addworksheet();
</PRE>
</P>
<P>
<PRE>
    # Row and column are zero indexed
    my $row = 0;
</PRE>
</P>
<P>
<PRE>
    while (&lt;TABFILE&gt;) {
        chomp;
        # Split on single tab
        my @Fld = split('\t', $_);
</PRE>
</P>
<P>
<PRE>
        my $col = 0;
        foreach my $token (@Fld) {
            $worksheet-&gt;write($row, $col, $token);
            $col++;
        }
        $row++;
    }
</PRE>
</P>
<P>
<HR>
<H2><A NAME="Additional_Examples">Additional Examples</A></H2>
<P>
If you performed a normal installation the following examples files should
have been copied to your <CODE>~site/Spreadsheet/WriteExcel/examples</CODE> directory:

</P>
<P>
The following is a description of the example files that are provided with
Spreadsheet::WriteExcel. They are intended to demonstrate the different
features and options of the module.

</P>
<P>
<PRE>
    Getting started
    ===============
    simple.pl           An example of some of the basic features.
    regions.pl          Demonstrates multiple worksheets.
    stats.pl            Basic formulas and functions.
    formats.pl          Creates a demo of the available formatting.
    demo.pl             Creates a demo of some of the features.
</PRE>
</P>
<P>
<PRE>
    Advanced
    ========
    sales.pl            An example of a simple sales spreadsheet.
    stocks.pl           Demonstrates conditional formatting.
    headers.pl          Examples of worksheet headers and footers.
    write_array.pl      Example of writing 1D or 2D arrays of data.
    chess.pl            An example of formatting using properties.
    colors.pl           Demo of the colour palette and named colours.
    images.pl           Adding bitmap images to worksheets.
    sendmail.pl         Send an Excel email attachment using Mail::Sender.
    stats_ext.pl        Same as stats.pl with external references.
    repeat.pl           Example of writing repeated formulas.
    long_string.pl      Workaround long string limitation with a formula.
    cgi.pl              A simple CGI program.
    mod_perl.pl         A simple mod_perl program.
    hyperlink1.pl       Shows how to create web hyperlinks.
    hyperlink2.pl       Examples of internal and external hyperlinks.
    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.
    textwrap.pl         Demonstrates text wrapping options.
    panes.pl            An examples of how to create panes.
    protection.pl       Example of cell locking and formula hiding.
    copyformat.pl       Example of copying a cell format.
    win32ole.pl         A sample Win32::OLE example for comparison.
    easter_egg.pl       Expose the Excel97 flight simulator. A must see.
</PRE>
</P>
<P>
<PRE>
    Utility
    =======
    convertA1.pl        Helper functions for dealing with A1 notation.
    lecxe.pl            Convert Excel to WriteExcel using Win32::OLE.
    csv2xls.pl          Program to convert a CSV file to an Excel file.
    tab2xls.pl          Program to convert a tab separated file to xls.
    datecalc1.pl        Convert Unix/Perl time to Excel time.
    datecalc2.pl        Calculate an Excel date using Date::Calc.
    writemany.pl        Write an 2d array of values in one go.
</PRE>
</P>
<P>
<PRE>
    Developer
    =========
    function_locale.pl  Add non-English function names to Formula.pm.
    filehandle.pl       Examples of working with filehandles.
    writeA1.pl          Example of how to extend the module.
    comments.pl         Add cell comments to Excel 5 worksheets.
    bigfile.pl          Write past the 7MB limit with OLE::Storage_Lite.
</PRE>
</P>
<P>
There are additional examples of a CGI application that uses
Spreadsheet::WriteExcel available at the website of the German Unix/web
journal iX: <A
HREF="ftp://ftp.heise.de/pub/ix/ix_listings/2001_06/perl.tgz">ftp://ftp.heise.de/pub/ix/ix_listings/2001_06/perl.tgz</A>


</P>
<P>
<HR>
<H1><A NAME="LIMITATIONS">LIMITATIONS</A></H1>
<P>
The following limits are imposed by Excel or the version of the BIFF file
that has been implemented:

</P>
<P>
<PRE>
    Description                          Limit   Source
    -----------------------------------  ------  -------
    Maximum number of chars in a string  255     Excel 5
    Maximum number of columns            256     Excel All versions
    Maximum number of rows in Excel 5    16384   Excel 5
    Maximum number of rows in Excel 97   65536   Excel 97
    Maximum chars in a sheet name        31      Excel All versions
    Maximum chars in a header/footer     254     Excel All versions
</PRE>
</P>
<P>
Note: the maximum row reference in a formula is the Excel 5 row limit of
16384.

</P>
<P>
The 255 character limit will be removed when the module moves to the Excel
97+ format. In the meantime, you can work around this limit using a
formula. See the <CODE>long_string.pl</CODE> program in the <CODE>examples</CODE> directory of the distro. See also  <A HREF="#TO_DO">TO DO</A> for information about the Excel97 pre-release version of this module. 

</P>
<P>
The minimum file size is 6K due to the OLE overhead. The maximum file size
is approximately 7MB (7087104 bytes) of BIFF data. This can be extended by
using Takanori Kawai's OLE::Storage_Lite module <A
HREF="http://search.cpan.org/search?dist=OLE-Storage_Lite">http://search.cpan.org/search?dist=OLE-Storage_Lite</A>
see the <CODE>bigfile.pl</CODE> example in the <CODE>examples</CODE> directory of the distro.

</P>
<P>
<HR>
<H1><A NAME="REQUIREMENTS">REQUIREMENTS</A></H1>
<P>
This module requires Perl 5.005 (or later), Parse::RecDescent and
File::Temp:

</P>
<P>
<PRE>
    <A HREF="http://search.cpan.org/search?dist=Parse-RecDescent">http://search.cpan.org/search?dist=Parse-RecDescent</A>
    <A HREF="http://search.cpan.org/search?dist=File-Temp">http://search.cpan.org/search?dist=File-Temp</A>
</PRE>
</P>
<P>
<HR>
<H1><A NAME="INSTALLATION">INSTALLATION</A></H1>
<P>
See the INSTALL or install.html docs that come with the distribution or:

</P>
<P>
<A
HREF="http://search.cpan.org/doc/JMCNAMARA/Spreadsheet-WriteExcel-0.38/WriteExcel/doc/install.html">http://search.cpan.org/doc/JMCNAMARA/Spreadsheet-WriteExcel-0.38/WriteExcel/doc/install.html</A>


</P>
<P>
<HR>
<H1><A NAME="PORTABILITY">PORTABILITY</A></H1>
<P>
Spreadsheet::WriteExcel will work on the majority of Windows, UNIX and
Macintosh platforms. Specifically, the module will work on any system where
perl packs floats in the 64 bit IEEE format. The float must also be in
little-endian format but it will be reversed if necessary. Thus:

</P>
<P>
<PRE>
    print join(&quot; &quot;, map { sprintf &quot;%#02x&quot;, $_ } unpack(&quot;C*&quot;, pack &quot;d&quot;, 1.2345)), &quot;\n&quot;;
</PRE>
</P>
<P>
should give (or in reverse order):

</P>
<P>
<PRE>
    0x8d 0x97 0x6e 0x12 0x83 0xc0 0xf3 0x3f
</PRE>
</P>
<P>
In general, if you don't know whether your system supports a 64 bit IEEE
float or not, it probably does. If your system doesn't, WriteExcel will <CODE>croak()</CODE> with the message given in the <A HREF="#DIAGNOSTICS">DIAGNOSTICS</A> section. You can check which platforms the module has been tested on at the
CPAN testers site: <A
HREF="http://testers.cpan.org/search?request=dist&dist=Spreadsheet-WriteExcel">http://testers.cpan.org/search?request=dist&dist=Spreadsheet-WriteExcel</A>


</P>
<P>
<HR>
<H1><A NAME="DIAGNOSTICS">DIAGNOSTICS</A></H1>
<DL>
<DT><A NAME="item_Filename">Filename required by Spreadsheet::WriteExcel-&gt;new()</A><DD>
<P>
A filename must be given in the constructor.

</P>
<DT><A NAME="item_Can">Can't open filename. It may be in use or protected.</A><DD>
<P>
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.

</P>
<DT><A NAME="item_Unable">Unable to create tmp files via File::Temp::tempfile()...</A><DD>
<P>
This is a <CODE>-w</CODE> warning. You will see it if you are using Spreadsheet::WriteExcel in an
environment where temporary files cannot be created, in which case all data
will be stored in memory. The warning is for information only: it does not
affect creation but it will affect the speed of execution for large files.
See the <CODE>set_tempdir</CODE> workbook method.

</P>
<DT><A NAME="item_Maximum">Maximum file size, 7087104, exceeded.</A><DD>
<P>
The current OLE implementation only supports a maximum BIFF file of this
size. This limit can be extended, see the <A HREF="#LIMITATIONS">LIMITATIONS</A> section.

</P>
<DT>Can't locate Parse/RecDescent.pm in @INC ...<DD>
<P>
Spreadsheet::WriteExcel requires the Parse::RecDescent module. Download it
from CPAN: <A
HREF="http://search.cpan.org/search?dist=Parse-RecDescent">http://search.cpan.org/search?dist=Parse-RecDescent</A>


</P>
<DT><A NAME="item_Couldn">Couldn't parse formula ...</A><DD>
<P>
There are a large number of warnings which relate to badly formed formulas
and functions. See the <A HREF="#FORMULAS_AND_FUNCTIONS_IN_EXCEL">FORMULAS AND FUNCTIONS IN EXCEL</A> section for suggestions on how to avoid these errors. You should also check
the formula in Excel to ensure that it is valid.

</P>
<DT><A NAME="item_Required">Required floating point format not supported on this platform.</A><DD>
<P>
Operating system doesn't support 64 bit IEEE float or it is byte-ordered in
a way unknown to WriteExcel.

</P>
<DT><A NAME="item__file_xls_">'file.xls' cannot be accessed. The file may be read-only ...</A><DD>
<P>
You may sometimes encounter the following error when trying to open a file
in Excel: &quot;file.xls cannot be accessed. The file may be read-only, or
you may be trying to access a read-only location. Or, the server the
document is stored on may not be responding.&quot;

</P>
<P>
This error generally means that the Excel file has been corrupted. There
are two likely causes of this: the file was FTPed in ASCII mode instead of
binary mode or else the file was created with UTF8 data returned by an XML
parser. See <A HREF="#WORKING_WITH_XML">WORKING WITH XML</A> for further details.

</P>
</DL>
<P>
<HR>
<H1><A NAME="THE_EXCEL_BINARY_FORMAT">THE EXCEL BINARY FORMAT</A></H1>
<P>
The following is some general information about the Excel binary format for
anyone who may be interested.

</P>
<P>
Excel data is stored in the &quot;Binary Interchange File Format&quot;
(BIFF) file format. Details of this format are given in the Excel SDK, the
&quot;Excel Developer's Kit&quot; from Microsoft Press. It is also included
in the MSDN CD library but is no longer available on the MSDN website.
Versions of the BIFF documentation are available at www.wotsit.org, <A
HREF="http://www.wotsit.org/search.asp?page=2&s=database">http://www.wotsit.org/search.asp?page=2&s=database</A>


</P>
<P>
Charles Wybble has collected together almost all of the available
information about the Excel file format. See &quot;The Chicago
Project&quot; at <A
HREF="http://chicago.sourceforge.net/devel/">http://chicago.sourceforge.net/devel/</A>


</P>
<P>
Daniel Rentz of OpenOffice has also written a detailed description of the
Excel workbook records, see <A
HREF="http://sc.openoffice.org/excelfileformat.pdf">http://sc.openoffice.org/excelfileformat.pdf</A>


</P>
<P>
The BIFF portion of the Excel file is comprised of contiguous binary
records that have different functions and that hold different types of
data. Each BIFF record is comprised of the following three parts:

</P>
<P>
<PRE>
        Record name;   Hex identifier, length = 2 bytes
        Record length; Length of following data, length = 2 bytes
        Record data;   Data, length = variable
</PRE>
</P>
<P>
The BIFF data is stored along with other data in an OLE Compound File. This
is a structured storage which acts like a file system within a file. A
Compound File is comprised of storages and streams which, to follow the
file system analogy, are like directories and files.

</P>
<P>
The documentation for the OLE::Storage module, <A
HREF="http://user.cs.tu-berlin.de/~schwartz/pmh/guide.html">http://user.cs.tu-berlin.de/~schwartz/pmh/guide.html</A>
, contains one of the few descriptions of the OLE Compound File in the
public domain. The Digital Imaging Group have also detailed the OLE format
in the JPEG2000 specification: see Appendix A of <A
HREF="http://www.i3a.org/pdf/wg1n1017.pdf">http://www.i3a.org/pdf/wg1n1017.pdf</A>


</P>
<P>
For a open source implementation of the OLE library see the 'cole' library
at <A HREF="http://atena.com/libole2.php">http://atena.com/libole2.php</A>

</P>
<P>
The source code for the Excel plugin of the Gnumeric spreadsheet also
contains information relevant to the Excel BIFF format and the OLE
container, <A
HREF="http://www.gnome.org/projects/gnumeric/">http://www.gnome.org/projects/gnumeric/</A>
and <A
HREF="ftp://ftp.ximian.com/pub/ximian-source/">ftp://ftp.ximian.com/pub/ximian-source/</A>


</P>
<P>
In addition the source code for OpenOffice is available at <A
HREF="http://www.openoffice.org/">http://www.openoffice.org/</A>

</P>
<P>
An article describing Spreadsheet::WriteExcel and how it works appears in
Issue #19 of The Perl Journal, <A
HREF="http://www.samag.com/documents/s=1272/sam05030004/">http://www.samag.com/documents/s=1272/sam05030004/</A>
It is reproduced, by kind permission, in the <CODE>doc</CODE> directory of the distro.

</P>
<P>
Please note that the provision of this information does not constitute an
invitation to start hacking at the BIFF or OLE file formats. There are more
interesting ways to waste your time. ;-)

</P>
<P>
<HR>
<H1><A NAME="WRITING_EXCEL_FILES">WRITING EXCEL FILES</A></H1>
<P>
Depending on your requirements, background and general sensibilities you
may prefer one of the following methods of getting data into Excel:

</P>
<UL>
<LI><A NAME="item_Win32">Win32::OLE module and office automation</A>
<P>
This requires a Windows platform and an installed copy of Excel. This is
the most powerful and complete method for interfacing with Excel. See <A
HREF="http://www.activestate.com/ASPN/Reference/Products/ActivePerl-5.6/faq/Windows/ActivePerl-Winfaq12.html">http://www.activestate.com/ASPN/Reference/Products/ActivePerl-5.6/faq/Windows/ActivePerl-Winfaq12.html</A>
and <A
HREF="http://www.activestate.com/ASPN/Reference/Products/ActivePerl-5.6/site/lib/Win32/OLE.html">http://www.activestate.com/ASPN/Reference/Products/ActivePerl-5.6/site/lib/Win32/OLE.html</A>
If your main platform is UNIX but you have the resources to set up a
separate Win32/MSOffice server, you can convert office documents to text,
postscript or PDF using Win32::OLE. For a demonstration of how to do this
using Perl see Docserver: <A
HREF="http://search.cpan.org/search?mode=module&query=docserver">http://search.cpan.org/search?mode=module&query=docserver</A>


</P>
<LI><A NAME="item_CSV">CSV, comma separated variables or text</A>
<P>
If the file extension is <CODE>csv</CODE>, Excel will open and convert this format automatically. Generating a valid
CSV file isn't as easy as it seems. Have a look at the DBD::RAM, DBD::CSV,
Text::xSV and Text::CSV_XS modules.

</P>
<LI><A NAME="item_DBI">DBI with DBD::ADO or DBD::ODBC</A>
<P>
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.

</P>
<LI><A NAME="item_DBD">DBD::Excel</A>
<P>
You can also access Spreadsheet::WriteExcel using the standard DBI
interface via Takanori Kawai's DBD::Excel module <A
HREF="http://search.cpan.org/search?dist=DBD-Excel.">http://search.cpan.org/search?dist=DBD-Excel.</A>


</P>
<LI><A NAME="item_Spreadsheet">Spreadsheet::WriteExcel::Simple</A>
<P>
This provides an easier interface to Spreadsheet::WriteExcel: <A
HREF="http://search.cpan.org/search?dist=Spreadsheet-WriteExcel-Simple">http://search.cpan.org/search?dist=Spreadsheet-WriteExcel-Simple</A>


</P>
<LI><A NAME="item_Spreadsheet">Spreadsheet::WriteExcel::FromDB</A>
<P>
This is a useful module for creating Excel files directly from a DB table:
<A
HREF="http://search.cpan.org/search?dist=Spreadsheet-WriteExcel-FromDB">http://search.cpan.org/search?dist=Spreadsheet-WriteExcel-FromDB</A>


</P>
<LI><A NAME="item_HTML">HTML tables</A>
<P>
This is an easy way of adding formatting via a text based format.

</P>
<LI><A NAME="item_XML">XML or HTML</A>
<P>
The Excel XML and HTML file specification are available from <A
HREF="http://msdn.microsoft.com/library/officedev/ofxml2k/ofxml2k.htm">http://msdn.microsoft.com/library/officedev/ofxml2k/ofxml2k.htm</A>


</P>
</UL>
<P>
For other Perl-Excel modules try the following search: <A
HREF="http://search.cpan.org/search?mode=module&query=excel">http://search.cpan.org/search?mode=module&query=excel</A>


</P>
<P>
<HR>
<H1><A NAME="READING_EXCEL_FILES">READING EXCEL FILES</A></H1>
<P>
To read data from Excel files try:

</P>
<UL>
<LI><A NAME="item_Spreadsheet">Spreadsheet::ParseExcel</A>
<P>
This uses the OLE::Storage-Lite module to extract data from an Excel file.
<A
HREF="http://search.cpan.org/search?dist=Spreadsheet-ParseExcel">http://search.cpan.org/search?dist=Spreadsheet-ParseExcel</A>


</P>
<LI><A NAME="item_Spreadsheet">Spreadsheet::ParseExcel_XLHTML</A>
<P>
This module uses Spreadsheet::ParseExcel's interface but uses xlHtml (see
below) to do the conversion: <A
HREF="http://search.cpan.org/search?dist=Spreadsheet-ParseExcel_XLHTML">http://search.cpan.org/search?dist=Spreadsheet-ParseExcel_XLHTML</A>
Spreadsheet::ParseExcel_XLHTML

</P>
<LI><A NAME="item_xlHtml">xlHtml</A>
<P>
This is an open source &quot;Excel to HTML Converter&quot; C/C++ project at
<A HREF="http://www.xlhtml.org/">http://www.xlhtml.org/</A> See also, the
OLE Filters Project at <A
HREF="http://atena.com/libole2.php">http://atena.com/libole2.php</A>

</P>
<LI>DBD::Excel
<P>
You can also access Spreadsheet::ParseExcel using the standard DBI
interface via Takanori Kawai's DBD::Excel module <A
HREF="http://search.cpan.org/search?dist=DBD-Excel.">http://search.cpan.org/search?dist=DBD-Excel.</A>


</P>
<LI>Win32::OLE module and office automation
<P>
See, the section <A HREF="#WRITING_EXCEL_FILES">WRITING EXCEL FILES</A>.

</P>
<LI>HTML tables
<P>
If the files are saved from Excel in a HTML format the data can be accessed
using HTML::TableExtract <A
HREF="http://search.cpan.org/search?dist=HTML-TableExtract">http://search.cpan.org/search?dist=HTML-TableExtract</A>


</P>
<LI><A NAME="item_DBI">DBI with DBD::ADO or DBD::ODBC.</A>
<P>
See, the section <A HREF="#WRITING_EXCEL_FILES">WRITING EXCEL FILES</A>.

</P>
<LI><A NAME="item_XML">XML::Excel</A>
<P>
Converts Excel files to XML using Spreadsheet::ParseExcel <A
HREF="http://search.cpan.org/search?dist=XML-Excel.">http://search.cpan.org/search?dist=XML-Excel.</A>


</P>
<LI><A NAME="item_OLE">OLE::Storage, aka LAOLA</A>
<P>
This is a Perl interface to OLE file formats. In particular, the distro
contains an Excel to HTML converter called Herbert, <A
HREF="http://user.cs.tu-berlin.de/~schwartz/pmh/">http://user.cs.tu-berlin.de/~schwartz/pmh/</A>
This has been superseded by the Spreadsheet::ParseExcel module.

</P>
</UL>
<P>
For other Perl-Excel modules try the following search: <A
HREF="http://search.cpan.org/search?mode=module&query=excel">http://search.cpan.org/search?mode=module&query=excel</A>


</P>
<P>
If you wish to view Excel files on a UNIX/Linux platform check out the
excellent Gnumeric spreadsheet application at <A
HREF="http://www.gnome.org/projects/gnumeric/">http://www.gnome.org/projects/gnumeric/</A>
or OpenOffice at <A
HREF="http://www.openoffice.org/">http://www.openoffice.org/</A>

</P>
<P>
If you wish to view Excel files on a Windows platform which doesn't have
Excel installed you can use the free Microsoft Excel Viewer <A
HREF="http://office.microsoft.com/downloads/2000/xlviewer.aspx">http://office.microsoft.com/downloads/2000/xlviewer.aspx</A>


</P>
<P>
<HR>
<H1><A NAME="WORKING_WITH_XML">WORKING WITH XML</A></H1>
<P>
You must be careful when using XML data in conjunction with
Spreadsheet::WriteExcel due to the fact that data returned by XML parsers
is generally in UTF8 format.

</P>
<P>
When UTF8 strings are added to Spreadsheet::WriteExcel's internal data it
causes the generated Excel file to become corrupt.

</P>
<P>
To avoid this problems you should convert the output data to ASCII or
ISO-8859-1 using one of the following methods:

</P>
<P>
<PRE>
    $new_str = pack 'C*', unpack 'U*', $utf8_str;
</PRE>
</P>
<P>
<PRE>
    use Unicode::MapUTF8 'from_utf8';
    $new_str = from_utf8({-str =&gt; $utf8_str, -charset =&gt; 'ISO-8859-1'});
</PRE>
</P>
<P>
If you are interested in creating an XML spreadsheet format you should be
aware that Excel 2000 and later versions can read XML data directly. The
Excel XML file specification is available at <A
HREF="http://msdn.microsoft.com/library/officedev/ofxml2k/ofxml2k.htm">http://msdn.microsoft.com/library/officedev/ofxml2k/ofxml2k.htm</A>


</P>
<P>
<HR>
<H1><A NAME="BUGS">BUGS</A></H1>
<P>
Formulas are formulae.

</P>
<P>
XML data can cause Excel files created by Spreadsheet::WriteExcel to become
corrupt. See <A HREF="#WORKING_WITH_XML">WORKING WITH XML</A> for further details.

</P>
<P>
If you do not add a format to each cell of a <CODE>merge_cells()</CODE> range it will cause Excel97 to crash, use the safer <CODE>merge_range()</CODE> method instead.

</P>
<P>
Nested formulas sometimes aren't parsed correctly and give a result of
&quot;#VALUE&quot;. If you come across a formula that parses like this, let
me know.

</P>
<P>
Spreadsheet::ParseExcel: All formulas created by Spreadsheet::WriteExcel
are read as having a value of zero. This is because Spreadsheet::WriteExcel
only stores the formula and not the calculated result.

</P>
<P>
OpenOffice: Numerical formats are not displayed due to some missing records
in Spreadsheet::WriteExcel. URLs are not displayed as links.

</P>
<P>
Gnumeric: Some formatting is not displayed correctly. URLs are not
displayed as links.

</P>
<P>
MS Access: The Excel files that are produced by this module are not
compatible with MS Access. Use DBI or ODBC instead.

</P>
<P>
The lack of a portable way of writing a little-endian 64 bit IEEE float.
There is beta code available to fix this. Let me know if you wish to test
it on your platform.

</P>
<P>
<HR>
<H1><A NAME="TO_DO">TO DO</A></H1>
<P>
The roadmap is as follows:

</P>
<UL>
<LI><A NAME="item_Move">Move to Excel97/2000 format as standard.</A>
<P>
This will allow strings greater than 255 characters and eventually Unicode.
A working pre-releases is available, see <A
HREF="http://freshmeat.net/projects/writeexcel/#comment-22753.">http://freshmeat.net/projects/writeexcel/#comment-22753.</A>
Others pre-release versions will be announced at Freshmeat, see below.

</P>
</UL>
<P>
You can keep up to date with future releases by registering as a user with
Freshmeat <A HREF="http://freshmeat.net/">http://freshmeat.net/</A> and
subscribing to Spreadsheet::WriteExcel at the project page <A
HREF="http://freshmeat.net/projects/writeexcel/">http://freshmeat.net/projects/writeexcel/</A>
You will then receive mailed updates when a new version is released.
Alternatively you can keep an eye on <A
HREF="news://comp.lang.perl.announce">news://comp.lang.perl.announce</A>

</P>
<P>
Also, here are some of the most requested features that probably won't get
added:

</P>
<UL>
<LI><A NAME="item_Graphs">Graphs.</A>
<P>
The format is documented but it would require too much work to implement.
It would also require too much work to design a useable interface to the
hundreds of features in an Excel graph. So that's two too much works.
Nevertheless, I do hope to *try* implement graphs. However, it is a long
term goal. It won't be available for at least 6 months, even if you read
this in 6 months time.

</P>
<LI><A NAME="item_Macros">Macros.</A>
<P>
This would solve the previous problem neatly. However, the format of Excel
macros isn't documented.

</P>
<LI><A NAME="item_Some">Some feature that you really need. ;-)</A>
</UL>
<P>
If there is some feature of an Excel file that you really, really need then
you should use Win32::OLE with Excel on Windows. If you are on Unix you
could consider connecting to a Windows server via Docserver or SOAP, see <A HREF="#WRITING_EXCEL_FILES">WRITING EXCEL FILES</A>.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
Spreadsheet::ParseExcel. <A
HREF="http://search.cpan.org/search?dist=Spreadsheet-ParseExcel">http://search.cpan.org/search?dist=Spreadsheet-ParseExcel</A>


</P>
<P>
Spreadsheet::WriteExcel::FromDB. <A
HREF="http://search.cpan.org/search?dist=Spreadsheet-WriteExcel-FromDB">http://search.cpan.org/search?dist=Spreadsheet-WriteExcel-FromDB</A>


</P>
<P>
&quot;Reading and writing Excel files with Perl&quot; by Teodor Zlatanov,
atIBM developerWorks: <A
HREF="http://www-106.ibm.com/developerworks/library/l-pexcel/">http://www-106.ibm.com/developerworks/library/l-pexcel/</A>


</P>
<P>
&quot;Excel-Dateien mit Perl erstellen - Controller im Glück&quot; by Peter
Dintelmann and Christian Kirsch in the German Unix/web journal iX: <A
HREF="http://www.heise.de/ix/artikel/2001/06/175/">http://www.heise.de/ix/artikel/2001/06/175/</A>


</P>
<P>
&quot;Spreadsheet::WriteExcel&quot; in The Perl Journal: <A
HREF="http://www.samag.com/documents/s=1272/sam05030004/">http://www.samag.com/documents/s=1272/sam05030004/</A>


</P>
<P>
Spreadsheet::WriteExcel documentation in Japanese by Takanori Kawai. <A
HREF="http://member.nifty.ne.jp/hippo2000/perltips/Spreadsheet/WriteExcel.htm">http://member.nifty.ne.jp/hippo2000/perltips/Spreadsheet/WriteExcel.htm</A>


</P>
<P>
Oesterly user brushes with fame: <A
HREF="http://oesterly.com/releases/12102000.html">http://oesterly.com/releases/12102000.html</A>


</P>
<P>
<HR>
<H1><A NAME="ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</A></H1>
<P>
The following people contributed to the debugging and testing of
Spreadsheet::WriteExcel:

</P>
<P>
Alexander Farber, Andre de Bruin, Arthur@ais, Artur Silveira da Cunha,
Borgar Olsen, Brian White, Bob Mackay, Cedric Bouvier, Chad Johnson, CPAN
testers, Daniel Berger, Daniel Gardner, Ernesto Baschny, Felipe Pérez
Galiana, Gordon.Simpson, Hanc Pavel, Harold Bamford, James Holmes, Johan
Ekenberg, Johann Hanne, J.C. Wren, Kenneth Stacey, Keith Miller, Kyle Krom,
Markus Schmitz, Michael Buschauer, Mike Blazer, Michael Erickson, Ning Xie,
Paul J. Falbe, Paul Medynski, Peter Dintelmann, Pierre Laplante, Praveen
Kotha, Reto Badertscher, Rich Sorden, Shane Ashby, Shenyu Zheng, Steve
Sapovits, Sven Passig, Troy Daniels, Vahe Sarkissian.

</P>
<P>
The following people contributed code, examples or Excel information:

</P>
<P>
Andrew Benham, Bill Young, Cedric Bouvier, Charles Wybble, Daniel Rentz,
Ian Penman, Pierre-Jean Vouette, Marco Geri, Sam Kington, Takanori Kawai,
Tom O'Sullivan.

</P>
<P>
Many thanks to Ron McKelvey, Ronzo Consulting for Siemens, who sponsored
the development of the formula caching routines.

</P>
<P>
Additional thanks to Takanori Kawai for translating the documentation into
Japanese.

</P>
<P>
Dirk Eddelbuettel maintains the Debian distro.

</P>
<P>
Thanks to Damian Conway for the excellent Parse::RecDescent.

</P>
<P>
Thanks to Tim Jenness for File::Temp.

</P>
<P>
Thanks to Michael Meeks and Jody Goldberg for their work on Gnumeric.

</P>
<P>
<HR>
<H1><A NAME="AUTHOR">AUTHOR</A></H1>
<P>
John McNamara <A HREF="mailto:jmcnamara@cpan.org">jmcnamara@cpan.org</A>

</P>
<P>
<PRE>
    New Amsterdam,
    It's become much too much.
    Do I take possession
    Of everything she touches.
    Should I step on the brakes
    To get out of your clutches.
    Should I speak double Dutch
    To a real double Duchess.
</PRE>
</P>
<P>
<PRE>
        -- Elvis Costello
</PRE>
</P>
<P>
<HR>
<H1><A NAME="COPYRIGHT">COPYRIGHT</A></H1>
<P>
© MM-MMII, John McNamara.

</P>
<P>
All Rights Reserved. This module is free software. It may be used,
redistributed and/or modified under the same terms as Perl itself.

</P>

</BODY>

</HTML>