The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<html><head><title>Spreadsheet::WriteExcel</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
<link rel="stylesheet" type="text/css" title="pod_stylesheet" href="http://search.cpan.org/s/style.css">

</head>
<body class='pod'>
<!--
  generated by Pod::Simple::HTML v3.01,
  using Pod::Simple::PullParser v2.02,
  under Perl v5.00503 at Tue Sep  9 00:24:13 2008 GMT.

 If you want to change this HTML document, you probably shouldn't do that
   by changing it directly.  Instead, see about changing the calling options
   to Pod::Simple::HTML, and/or subclassing Pod::Simple::HTML,
   then reconverting this document from the Pod source.
   When in doubt, email the author of Pod::Simple::HTML for advice.
   See 'perldoc Pod::Simple::HTML' for more info.

-->

<!-- start doc -->
<a name='___top' class='dummyTopAnchor' ></a>

<div class='indexgroup'>
<ul   class='indexList indexList1'>
  <li class='indexItem indexItem1'><a href='#NAME'>NAME</a></li>
  <li class='indexItem indexItem1'><a href='#VERSION'>VERSION</a></li>
  <li class='indexItem indexItem1'><a href='#SYNOPSIS'>SYNOPSIS</a></li>
  <li class='indexItem indexItem1'><a href='#DESCRIPTION'>DESCRIPTION</a></li>
  <li class='indexItem indexItem1'><a href='#QUICK_START'>QUICK START</a></li>
  <li class='indexItem indexItem1'><a href='#WORKBOOK_METHODS'>WORKBOOK METHODS</a></li>
  <ul   class='indexList indexList2'>
    <li class='indexItem indexItem2'><a href='#new()'>new()</a></li>
    <li class='indexItem indexItem2'><a href='#add_worksheet(%24sheetname%2C_%24utf_16_be)'>add_worksheet($sheetname, $utf_16_be)</a></li>
    <li class='indexItem indexItem2'><a href='#add_format(%25properties)'>add_format(%properties)</a></li>
    <li class='indexItem indexItem2'><a href='#add_chart_ext(%24chart_data%2C_%24chartname)'>add_chart_ext($chart_data, $chartname)</a></li>
    <li class='indexItem indexItem2'><a href='#close()'>close()</a></li>
    <li class='indexItem indexItem2'><a href='#compatibility_mode()'>compatibility_mode()</a></li>
    <li class='indexItem indexItem2'><a href='#set_properties()'>set_properties()</a></li>
    <li class='indexItem indexItem2'><a href='#set_tempdir()'>set_tempdir()</a></li>
    <li class='indexItem indexItem2'><a href='#set_custom_color(%24index%2C_%24red%2C_%24green%2C_%24blue)'>set_custom_color($index, $red, $green, $blue)</a></li>
    <li class='indexItem indexItem2'><a href='#sheets(0%2C_1%2C_...)'>sheets(0, 1, ...)</a></li>
    <li class='indexItem indexItem2'><a href='#set_1904()'>set_1904()</a></li>
    <li class='indexItem indexItem2'><a href='#set_codepage(%24codepage)'>set_codepage($codepage)</a></li>
  </ul>
  <li class='indexItem indexItem1'><a href='#WORKSHEET_METHODS'>WORKSHEET METHODS</a></li>
  <ul   class='indexList indexList2'>
    <li class='indexItem indexItem2'><a href='#Cell_notation'>Cell notation</a></li>
    <li class='indexItem indexItem2'><a href='#write(%24row%2C_%24column%2C_%24token%2C_%24format)'>write($row, $column, $token, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_number(%24row%2C_%24column%2C_%24number%2C_%24format)'>write_number($row, $column, $number, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_string(%24row%2C_%24column%2C_%24string%2C_%24format)'>write_string($row, $column, $string, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_utf16be_string(%24row%2C_%24column%2C_%24string%2C_%24format)'>write_utf16be_string($row, $column, $string, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_utf16le_string(%24row%2C_%24column%2C_%24string%2C_%24format)'>write_utf16le_string($row, $column, $string, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#keep_leading_zeros()'>keep_leading_zeros()</a></li>
    <li class='indexItem indexItem2'><a href='#write_blank(%24row%2C_%24column%2C_%24format)'>write_blank($row, $column, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_row(%24row%2C_%24column%2C_%24array_ref%2C_%24format)'>write_row($row, $column, $array_ref, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_col(%24row%2C_%24column%2C_%24array_ref%2C_%24format)'>write_col($row, $column, $array_ref, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_date_time(%24row%2C_%24col%2C_%24date_string%2C_%24format)'>write_date_time($row, $col, $date_string, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_url(%24row%2C_%24col%2C_%24url%2C_%24label%2C_%24format)'>write_url($row, $col, $url, $label, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_url_range(%24row1%2C_%24col1%2C_%24row2%2C_%24col2%2C_%24url%2C_%24string%2C_%24format)'>write_url_range($row1, $col1, $row2, $col2, $url, $string, $format)</a></li>
    <li class='indexItem indexItem2'><a href='#write_formula(%24row%2C_%24column%2C_%24formula%2C_%24format%2C_%24value)'>write_formula($row, $column, $formula, $format, $value)</a></li>
    <li class='indexItem indexItem2'><a href='#store_formula(%24formula)'>store_formula($formula)</a></li>
    <li class='indexItem indexItem2'><a href='#repeat_formula(%24row%2C_%24col%2C_%24formula%2C_%24format%2C_(%24pattern_%3D%3E_%24replace%2C_...))'>repeat_formula($row, $col, $formula, $format, ($pattern =&#62; $replace, ...))</a></li>
    <li class='indexItem indexItem2'><a href='#write_comment(%24row%2C_%24column%2C_%24string%2C_...)'>write_comment($row, $column, $string, ...)</a></li>
    <li class='indexItem indexItem2'><a href='#show_comments()'>show_comments()</a></li>
    <li class='indexItem indexItem2'><a href='#add_write_handler(%24re%2C_%24code_ref)'>add_write_handler($re, $code_ref)</a></li>
    <li class='indexItem indexItem2'><a href='#insert_image(%24row%2C_%24col%2C_%24filename%2C_%24x%2C_%24y%2C_%24scale_x%2C_%24scale_y)'>insert_image($row, $col, $filename, $x, $y, $scale_x, $scale_y)</a></li>
    <li class='indexItem indexItem2'><a href='#embed_chart(%24row%2C_%24col%2C_%24filename%2C_%24x%2C_%24y%2C_%24scale_x%2C_%24scale_y)'>embed_chart($row, $col, $filename, $x, $y, $scale_x, $scale_y)</a></li>
    <li class='indexItem indexItem2'><a href='#data_validation()'>data_validation()</a></li>
    <li class='indexItem indexItem2'><a href='#get_name()'>get_name()</a></li>
    <li class='indexItem indexItem2'><a href='#activate()'>activate()</a></li>
    <li class='indexItem indexItem2'><a href='#select()'>select()</a></li>
    <li class='indexItem indexItem2'><a href='#hide()'>hide()</a></li>
    <li class='indexItem indexItem2'><a href='#set_first_sheet()'>set_first_sheet()</a></li>
    <li class='indexItem indexItem2'><a href='#protect(%24password)'>protect($password)</a></li>
    <li class='indexItem indexItem2'><a href='#set_selection(%24first_row%2C_%24first_col%2C_%24last_row%2C_%24last_col)'>set_selection($first_row, $first_col, $last_row, $last_col)</a></li>
    <li class='indexItem indexItem2'><a href='#set_row(%24row%2C_%24height%2C_%24format%2C_%24hidden%2C_%24level%2C_%24collapsed)'>set_row($row, $height, $format, $hidden, $level, $collapsed)</a></li>
    <li class='indexItem indexItem2'><a href='#set_column(%24first_col%2C_%24last_col%2C_%24width%2C_%24format%2C_%24hidden%2C_%24level%2C_%24collapsed)'>set_column($first_col, $last_col, $width, $format, $hidden, $level, $collapsed)</a></li>
    <li class='indexItem indexItem2'><a href='#outline_settings(%24visible%2C_%24symbols_below%2C_%24symbols_right%2C_%24auto_style)'>outline_settings($visible, $symbols_below, $symbols_right, $auto_style)</a></li>
    <li class='indexItem indexItem2'><a href='#freeze_panes(%24row%2C_%24col%2C_%24top_row%2C_%24left_col)'>freeze_panes($row, $col, $top_row, $left_col)</a></li>
    <li class='indexItem indexItem2'><a href='#split_panes(%24y%2C_%24x%2C_%24top_row%2C_%24left_col)'>split_panes($y, $x, $top_row, $left_col)</a></li>
    <li class='indexItem indexItem2'><a href='#merge_range(%24first_row%2C_%24first_col%2C_%24last_row%2C_%24last_col%2C_%24token%2C_%24format%2C_%24utf_16_be)'>merge_range($first_row, $first_col, $last_row, $last_col, $token, $format, $utf_16_be)</a></li>
    <li class='indexItem indexItem2'><a href='#set_zoom(%24scale)'>set_zoom($scale)</a></li>
    <li class='indexItem indexItem2'><a href='#right_to_left()'>right_to_left()</a></li>
    <li class='indexItem indexItem2'><a href='#hide_zero()'>hide_zero()</a></li>
    <li class='indexItem indexItem2'><a href='#set_tab_color()'>set_tab_color()</a></li>
    <li class='indexItem indexItem2'><a href='#autofilter(%24first_row%2C_%24first_col%2C_%24last_row%2C_%24last_col)'>autofilter($first_row, $first_col, $last_row, $last_col)</a></li>
    <li class='indexItem indexItem2'><a href='#filter_column(%24column%2C_%24expression)'>filter_column($column, $expression)</a></li>
  </ul>
  <li class='indexItem indexItem1'><a href='#PAGE_SET-UP_METHODS'>PAGE SET-UP METHODS</a></li>
  <ul   class='indexList indexList2'>
    <li class='indexItem indexItem2'><a href='#set_landscape()'>set_landscape()</a></li>
    <li class='indexItem indexItem2'><a href='#set_portrait()'>set_portrait()</a></li>
    <li class='indexItem indexItem2'><a href='#set_page_view()'>set_page_view()</a></li>
    <li class='indexItem indexItem2'><a href='#set_paper(%24index)'>set_paper($index)</a></li>
    <li class='indexItem indexItem2'><a href='#center_horizontally()'>center_horizontally()</a></li>
    <li class='indexItem indexItem2'><a href='#center_vertically()'>center_vertically()</a></li>
    <li class='indexItem indexItem2'><a href='#set_margins(%24inches)'>set_margins($inches)</a></li>
    <li class='indexItem indexItem2'><a href='#set_header(%24string%2C_%24margin)'>set_header($string, $margin)</a></li>
    <li class='indexItem indexItem2'><a href='#set_footer()'>set_footer()</a></li>
    <li class='indexItem indexItem2'><a href='#repeat_rows(%24first_row%2C_%24last_row)'>repeat_rows($first_row, $last_row)</a></li>
    <li class='indexItem indexItem2'><a href='#repeat_columns(%24first_col%2C_%24last_col)'>repeat_columns($first_col, $last_col)</a></li>
    <li class='indexItem indexItem2'><a href='#hide_gridlines(%24option)'>hide_gridlines($option)</a></li>
    <li class='indexItem indexItem2'><a href='#print_row_col_headers()'>print_row_col_headers()</a></li>
    <li class='indexItem indexItem2'><a href='#print_area(%24first_row%2C_%24first_col%2C_%24last_row%2C_%24last_col)'>print_area($first_row, $first_col, $last_row, $last_col)</a></li>
    <li class='indexItem indexItem2'><a href='#print_across()'>print_across()</a></li>
    <li class='indexItem indexItem2'><a href='#fit_to_pages(%24width%2C_%24height)'>fit_to_pages($width, $height)</a></li>
    <li class='indexItem indexItem2'><a href='#set_start_page(%24start_page)'>set_start_page($start_page)</a></li>
    <li class='indexItem indexItem2'><a href='#set_print_scale(%24scale)'>set_print_scale($scale)</a></li>
    <li class='indexItem indexItem2'><a href='#set_h_pagebreaks(%40breaks)'>set_h_pagebreaks(@breaks)</a></li>
    <li class='indexItem indexItem2'><a href='#set_v_pagebreaks(%40breaks)'>set_v_pagebreaks(@breaks)</a></li>
  </ul>
  <li class='indexItem indexItem1'><a href='#CELL_FORMATTING'>CELL FORMATTING</a></li>
  <ul   class='indexList indexList2'>
    <li class='indexItem indexItem2'><a href='#Creating_and_using_a_Format_object'>Creating and using a Format object</a></li>
    <li class='indexItem indexItem2'><a href='#Format_methods_and_Format_properties'>Format methods and Format properties</a></li>
    <li class='indexItem indexItem2'><a href='#Working_with_formats'>Working with formats</a></li>
  </ul>
  <li class='indexItem indexItem1'><a href='#FORMAT_METHODS'>FORMAT METHODS</a></li>
  <ul   class='indexList indexList2'>
    <li class='indexItem indexItem2'><a href='#set_format_properties(%25properties)'>set_format_properties(%properties)</a></li>
    <li class='indexItem indexItem2'><a href='#set_font(%24fontname)'>set_font($fontname)</a></li>
    <li class='indexItem indexItem2'><a href='#set_size()'>set_size()</a></li>
    <li class='indexItem indexItem2'><a href='#set_color()'>set_color()</a></li>
    <li class='indexItem indexItem2'><a href='#set_bold()'>set_bold()</a></li>
    <li class='indexItem indexItem2'><a href='#set_italic()'>set_italic()</a></li>
    <li class='indexItem indexItem2'><a href='#set_underline()'>set_underline()</a></li>
    <li class='indexItem indexItem2'><a href='#set_font_strikeout()'>set_font_strikeout()</a></li>
    <li class='indexItem indexItem2'><a href='#set_font_script()'>set_font_script()</a></li>
    <li class='indexItem indexItem2'><a href='#set_font_outline()'>set_font_outline()</a></li>
    <li class='indexItem indexItem2'><a href='#set_font_shadow()'>set_font_shadow()</a></li>
    <li class='indexItem indexItem2'><a href='#set_num_format()'>set_num_format()</a></li>
    <li class='indexItem indexItem2'><a href='#set_locked()'>set_locked()</a></li>
    <li class='indexItem indexItem2'><a href='#set_hidden()'>set_hidden()</a></li>
    <li class='indexItem indexItem2'><a href='#set_align()'>set_align()</a></li>
    <li class='indexItem indexItem2'><a href='#set_center_across()'>set_center_across()</a></li>
    <li class='indexItem indexItem2'><a href='#set_text_wrap()'>set_text_wrap()</a></li>
    <li class='indexItem indexItem2'><a href='#set_rotation()'>set_rotation()</a></li>
    <li class='indexItem indexItem2'><a href='#set_indent()'>set_indent()</a></li>
    <li class='indexItem indexItem2'><a href='#set_shrink()'>set_shrink()</a></li>
    <li class='indexItem indexItem2'><a href='#set_text_justlast()'>set_text_justlast()</a></li>
    <li class='indexItem indexItem2'><a href='#set_pattern()'>set_pattern()</a></li>
    <li class='indexItem indexItem2'><a href='#set_bg_color()'>set_bg_color()</a></li>
    <li class='indexItem indexItem2'><a href='#set_fg_color()'>set_fg_color()</a></li>
    <li class='indexItem indexItem2'><a href='#set_border()'>set_border()</a></li>
    <li class='indexItem indexItem2'><a href='#set_border_color()'>set_border_color()</a></li>
    <li class='indexItem indexItem2'><a href='#copy(%24format)'>copy($format)</a></li>
  </ul>
  <li class='indexItem indexItem1'><a href='#UNICODE_IN_EXCEL'>UNICODE IN EXCEL</a></li>
  <li class='indexItem indexItem1'><a href='#COLOURS_IN_EXCEL'>COLOURS IN EXCEL</a></li>
  <li class='indexItem indexItem1'><a href='#DATES_AND_TIME_IN_EXCEL'>DATES AND TIME IN EXCEL</a></li>
  <ul   class='indexList indexList2'>
    <li class='indexItem indexItem2'><a href='#An_Excel_date%2Ftime_is_a_number_plus_a_format'>An Excel date/time is a number plus a format</a></li>
    <li class='indexItem indexItem2'><a href='#Spreadsheet%3A%3AWriteExcel_doesn%27t_automatically_convert_date%2Ftime_strings'>Spreadsheet::WriteExcel doesn&#39;t automatically convert date/time strings</a></li>
    <li class='indexItem indexItem2'><a href='#Converting_dates_and_times_to_an_Excel_date_or_time'>Converting dates and times to an Excel date or time</a></li>
  </ul>
  <li class='indexItem indexItem1'><a href='#OUTLINES_AND_GROUPING_IN_EXCEL'>OUTLINES AND GROUPING IN EXCEL</a></li>
  <li class='indexItem indexItem1'><a href='#DATA_VALIDATION_IN_EXCEL'>DATA VALIDATION IN EXCEL</a></li>
  <ul   class='indexList indexList2'>
    <li class='indexItem indexItem2'><a href='#data_validation(%24row%2C_%24col%2C_%7B_parameter_%3D%3E_%27value%27%2C_..._%7D)'>data_validation($row, $col, { parameter =&#62; &#39;value&#39;, ... })</a></li>
    <li class='indexItem indexItem2'><a href='#validate'>validate</a></li>
    <li class='indexItem indexItem2'><a href='#criteria'>criteria</a></li>
    <li class='indexItem indexItem2'><a href='#value_%7C_minimum_%7C_source'>value | minimum | source</a></li>
    <li class='indexItem indexItem2'><a href='#maximum'>maximum</a></li>
    <li class='indexItem indexItem2'><a href='#ignore_blank'>ignore_blank</a></li>
    <li class='indexItem indexItem2'><a href='#dropdown'>dropdown</a></li>
    <li class='indexItem indexItem2'><a href='#input_title'>input_title</a></li>
    <li class='indexItem indexItem2'><a href='#input_message'>input_message</a></li>
    <li class='indexItem indexItem2'><a href='#show_input'>show_input</a></li>
    <li class='indexItem indexItem2'><a href='#error_title'>error_title</a></li>
    <li class='indexItem indexItem2'><a href='#error_message'>error_message</a></li>
    <li class='indexItem indexItem2'><a href='#error_type'>error_type</a></li>
    <li class='indexItem indexItem2'><a href='#show_error'>show_error</a></li>
    <li class='indexItem indexItem2'><a href='#Examples'>Examples</a></li>
  </ul>
  <li class='indexItem indexItem1'><a href='#FORMULAS_AND_FUNCTIONS_IN_EXCEL'>FORMULAS AND FUNCTIONS IN EXCEL</a></li>
  <ul   class='indexList indexList2'>
    <li class='indexItem indexItem2'><a href='#Caveats'>Caveats</a></li>
    <li class='indexItem indexItem2'><a href='#Introduction'>Introduction</a></li>
    <li class='indexItem indexItem2'><a href='#Improving_performance_when_working_with_formulas'>Improving performance when working with formulas</a></li>
  </ul>
  <li class='indexItem indexItem1'><a href='#EXAMPLES'>EXAMPLES</a></li>
  <ul   class='indexList indexList2'>
    <li class='indexItem indexItem2'><a href='#Example_1'>Example 1</a></li>
    <li class='indexItem indexItem2'><a href='#Example_2'>Example 2</a></li>
    <li class='indexItem indexItem2'><a href='#Example_3'>Example 3</a></li>
    <li class='indexItem indexItem2'><a href='#Example_4'>Example 4</a></li>
    <li class='indexItem indexItem2'><a href='#Example_5'>Example 5</a></li>
    <li class='indexItem indexItem2'><a href='#Additional_Examples'>Additional Examples</a></li>
  </ul>
  <li class='indexItem indexItem1'><a href='#LIMITATIONS'>LIMITATIONS</a></li>
  <li class='indexItem indexItem1'><a href='#DOWNLOADING'>DOWNLOADING</a></li>
  <li class='indexItem indexItem1'><a href='#REQUIREMENTS'>REQUIREMENTS</a></li>
  <li class='indexItem indexItem1'><a href='#INSTALLATION'>INSTALLATION</a></li>
  <li class='indexItem indexItem1'><a href='#PORTABILITY'>PORTABILITY</a></li>
  <li class='indexItem indexItem1'><a href='#DIAGNOSTICS'>DIAGNOSTICS</a></li>
  <li class='indexItem indexItem1'><a href='#THE_EXCEL_BINARY_FORMAT'>THE EXCEL BINARY FORMAT</a></li>
  <li class='indexItem indexItem1'><a href='#WRITING_EXCEL_FILES'>WRITING EXCEL FILES</a></li>
  <li class='indexItem indexItem1'><a href='#READING_EXCEL_FILES'>READING EXCEL FILES</a></li>
  <li class='indexItem indexItem1'><a href='#MODIFYING_AND_REWRITING_EXCEL_FILES'>MODIFYING AND REWRITING EXCEL FILES</a></li>
  <li class='indexItem indexItem1'><a href='#Warning_about_XML%3A%3AParser_and_perl_5.6'>Warning about XML::Parser and perl 5.6</a></li>
  <li class='indexItem indexItem1'><a href='#Warning_about_Office_Service_Pack_3'>Warning about Office Service Pack 3</a></li>
  <li class='indexItem indexItem1'><a href='#BUGS'>BUGS</a></li>
  <li class='indexItem indexItem1'><a href='#TO_DO'>TO DO</a></li>
  <li class='indexItem indexItem1'><a href='#MAILING_LIST'>MAILING LIST</a></li>
  <li class='indexItem indexItem1'><a href='#DONATIONS'>DONATIONS</a></li>
  <li class='indexItem indexItem1'><a href='#SEE_ALSO'>SEE ALSO</a></li>
  <li class='indexItem indexItem1'><a href='#ACKNOWLEDGMENTS'>ACKNOWLEDGMENTS</a></li>
  <li class='indexItem indexItem1'><a href='#DISCLAIMER_OF_WARRANTY'>DISCLAIMER OF WARRANTY</a></li>
  <li class='indexItem indexItem1'><a href='#LICENSE'>LICENSE</a></li>
  <li class='indexItem indexItem1'><a href='#AUTHOR'>AUTHOR</a></li>
  <li class='indexItem indexItem1'><a href='#COPYRIGHT'>COPYRIGHT</a></li>
</ul>
</div>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="NAME"
>NAME</a></h1>

<p>Spreadsheet::WriteExcel - Write to a cross-platform Excel binary file.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="VERSION"
>VERSION</a></h1>

<p>This document refers to version 2.25 of Spreadsheet::WriteExcel,
released September 9,
2008.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    use Spreadsheet::WriteExcel;

    # Create a new Excel workbook
    my $workbook = Spreadsheet::WriteExcel-&#62;new(&#39;perl.xls&#39;);

    # Add a worksheet
    $worksheet = $workbook-&#62;add_worksheet();

    #  Add and define a format
    $format = $workbook-&#62;add_format(); # Add a format
    $format-&#62;set_bold();
    $format-&#62;set_color(&#39;red&#39;);
    $format-&#62;set_align(&#39;center&#39;);

    # Write a formatted and unformatted string, row and column notation.
    $col = $row = 0;
    $worksheet-&#62;write($row, $col, &#39;Hi Excel!&#39;, $format);
    $worksheet-&#62;write(1,    $col, &#39;Hi Excel!&#39;);

    # Write a number and a formula using A1 notation
    $worksheet-&#62;write(&#39;A3&#39;, 1.2345);
    $worksheet-&#62;write(&#39;A4&#39;, &#39;=SIN(PI()/4)&#39;);</pre>

<h1><a class='u' href='#___top' title='click to go to top of document'
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 97, 2000, 2002 and 2003.</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.org.</p>

<p>This module cannot be used to write to an existing Excel file (See <a href="#MODIFYING_AND_REWRITING_EXCEL_FILES" class="podlinkpod"
>&#34;MODIFYING AND REWRITING EXCEL FILES&#34;</a>).</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="QUICK_START"
>QUICK START</a></h1>

<p>Spreadsheet::WriteExcel tries to provide an interface to as many of Excel&#39;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 <i>workbook</i> (i.e. file) using <code lang='und' xml:lang='und'>new()</code>.</p>

<p>2. Add a <i>worksheet</i> to the new workbook using <code lang='und' xml:lang='und'>add_worksheet()</code>.</p>

<p>3. Write to the worksheet using <code lang='und' xml:lang='und'>write()</code>.</p>

<p>Like this:</p>

<pre lang='und' xml:lang='und'>    use Spreadsheet::WriteExcel;                             # Step 0

    my $workbook = Spreadsheet::WriteExcel-&#62;new(&#39;perl.xls&#39;); # Step 1
    $worksheet   = $workbook-&#62;add_worksheet();               # Step 2
    $worksheet-&#62;write(&#39;A1&#39;, &#39;Hi Excel!&#39;);                    # Step 3</pre>

<p>This will create an Excel file called <code lang='und' xml:lang='und'>perl.xls</code> with a single worksheet and the text <code lang='und' xml:lang='und'>&#39;Hi Excel!&#39;</code> in the relevant cell. And that&#39;s it. Okay, so there is actually a zeroth step as well, but <code lang='und' xml:lang='und'>use module</code> goes without saying. There are also more than 80 examples that come with the distribution and which you can use to get you started. See <a href="http://search.cpan.org/perldoc?EXAMPLES" class="podlinkpod"
>EXAMPLES</a>.</p>

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

<h1><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    new()
    add_worksheet()
    add_format()
    add_chart_ext()
    close()
    compatibility_mode()
    set_properties()
    set_tempdir()
    set_custom_color()
    sheets()
    set_1904()
    set_codepage()</pre>

<p>If you are unfamiliar with object oriented interfaces or the way that they are implemented in Perl have a look at <code lang='und' xml:lang='und'>perlobj</code> and <code lang='und' xml:lang='und'>perltoot</code> in the main Perl documentation.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="new()"
>new()</a></h2>

<p>A new Excel workbook is created using the <code lang='und' xml:lang='und'>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>

<pre lang='und' xml:lang='und'>    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;filename.xls&#39;);
    my $worksheet = $workbook-&#62;add_worksheet();
    $worksheet-&#62;write(0, 0, &#39;Hi Excel!&#39;);</pre>

<p>Here are some other examples of using <code lang='und' xml:lang='und'>new()</code> with filenames:</p>

<pre lang='und' xml:lang='und'>    my $workbook1 = Spreadsheet::WriteExcel-&#62;new($filename);
    my $workbook2 = Spreadsheet::WriteExcel-&#62;new(&#39;/tmp/filename.xls&#39;);
    my $workbook3 = Spreadsheet::WriteExcel-&#62;new(&#34;c:\\tmp\\filename.xls&#34;);
    my $workbook4 = Spreadsheet::WriteExcel-&#62;new(&#39;c:\tmp\filename.xls&#39;);</pre>

<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 lang='und' xml:lang='und'>\</code> or to use single quotes to ensure that it isn&#39;t interpolated. For more information see <code lang='und' xml:lang='und'>perlfaq5: Why can&#39;t I use &#34;C:\temp\foo&#34; in DOS paths?</code>.</p>

<p>The <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>close()</code> method.</p>

<p>If the file cannot be created, due to file permissions or some other reason, <code lang='und' xml:lang='und'>new</code> will return <code lang='und' xml:lang='und'>undef</code>. Therefore, it is good practice to check the return value of <code lang='und' xml:lang='und'>new</code> before proceeding. As usual the Perl variable <code lang='und' xml:lang='und'>$!</code> will be set if there is a file creation error. You will also see one of the warning messages detailed in <a href="http://search.cpan.org/perldoc?DIAGNOSTICS" class="podlinkpod"
>DIAGNOSTICS</a>:</p>

<pre lang='und' xml:lang='und'>    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;protected.xls&#39;);
    die &#34;Problems creating new Excel file: $!&#34; unless defined $workbook;</pre>

<p>You can also pass a valid filehandle to the <code lang='und' xml:lang='und'>new()</code> constructor. For example in a CGI program you could do something like this:</p>

<pre lang='und' xml:lang='und'>    binmode(STDOUT);
    my $workbook  = Spreadsheet::WriteExcel-&#62;new(\*STDOUT);</pre>

<p>The requirement for <code lang='und' xml:lang='und'>binmode()</code> is explained below.</p>

<p>For CGI programs you can also use the special Perl filename <code lang='und' xml:lang='und'>&#39;-&#39;</code> which will redirect the output to STDOUT:</p>

<pre lang='und' xml:lang='und'>    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;-&#39;);</pre>

<p>See also, the <code lang='und' xml:lang='und'>cgi.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<p>However, this special case will not work in <code lang='und' xml:lang='und'>mod_perl</code> programs where you will have to do something like the following:</p>

<pre lang='und' xml:lang='und'>    # mod_perl 1
    ...
    tie *XLS, &#39;Apache&#39;;
    binmode(XLS);
    my $workbook  = Spreadsheet::WriteExcel-&#62;new(\*XLS);
    ...

    # mod_perl 2
    ...
    tie *XLS =&#62; $r;  # Tie to the Apache::RequestRec object
    binmode(*XLS);
    my $workbook  = Spreadsheet::WriteExcel-&#62;new(\*XLS);
    ...</pre>

<p>See also, the <code lang='und' xml:lang='und'>mod_perl1.pl</code> and <code lang='und' xml:lang='und'>mod_perl2.pl</code> programs in the <code lang='und' xml:lang='und'>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 scalar.</p>

<p>For example here is a way to write an Excel file to a scalar with <code lang='und' xml:lang='und'>perl 5.8</code>:</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    # Requires perl 5.8 or later
    open my $fh, &#39;&#62;&#39;, \my $str or die &#34;Failed to open filehandle: $!&#34;;

    my $workbook  = Spreadsheet::WriteExcel-&#62;new($fh);
    my $worksheet = $workbook-&#62;add_worksheet();

    $worksheet-&#62;write(0, 0,  &#39;Hi Excel!&#39;);

    $workbook-&#62;close();

    # The Excel file in now in $str. Remember to binmode() the output
    # filehandle before printing it.
    binmode STDOUT;
    print $str;</pre>

<p>See also the <code lang='und' xml:lang='und'>write_to_scalar.pl</code> and <code lang='und' xml:lang='und'>filehandle.pl</code> programs in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<p><b>Note about the requirement for</b> <code lang='und' xml:lang='und'>binmode()</code>. An Excel file is comprised of binary data. Therefore, if you are using a filehandle you should ensure that you <code lang='und' xml:lang='und'>binmode()</code> it prior to passing it to <code lang='und' xml:lang='und'>new()</code>.You should do this regardless of whether you are on a Windows platform or not. This applies especially to users of perl 5.8 on systems where <code lang='und' xml:lang='und'>UTF-8</code> is likely to be in operation such as RedHat Linux 9. If your program, either intentionally or not, writes <code lang='und' xml:lang='und'>UTF-8</code> data to a filehandle that is passed to <code lang='und' xml:lang='und'>new()</code> it will corrupt the Excel file that is created.</p>

<p>You don&#39;t have to worry about <code lang='und' xml:lang='und'>binmode()</code> if you are using filenames instead of filehandles. Spreadsheet::WriteExcel performs the <code lang='und' xml:lang='und'>binmode()</code> internally when it converts the filename to a filehandle. For more information about <code lang='und' xml:lang='und'>binmode()</code> see <code lang='und' xml:lang='und'>perlfunc</code> and <code lang='und' xml:lang='und'>perlopentut</code> in the main Perl documentation.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="add_worksheet($sheetname,_$utf_16_be)"
>add_worksheet($sheetname, $utf_16_be)</a></h2>

<p>At least one worksheet should be added to a new workbook. A worksheet is used to write data into cells:</p>

<pre lang='und' xml:lang='und'>    $worksheet1 = $workbook-&#62;add_worksheet();           # Sheet1
    $worksheet2 = $workbook-&#62;add_worksheet(&#39;Foglio2&#39;);  # Foglio2
    $worksheet3 = $workbook-&#62;add_worksheet(&#39;Data&#39;);     # Data
    $worksheet4 = $workbook-&#62;add_worksheet();           # Sheet4</pre>

<p>If <code lang='und' xml:lang='und'>$sheetname</code> is not specified the default Excel convention will be followed, i.e. Sheet1, Sheet2, etc. The <code lang='und' xml:lang='und'>$utf_16_be</code> parameter is optional, see below.</p>

<p>The worksheet name must be a valid Excel worksheet name, i.e. it cannot contain any of the following characters, <code lang='und' xml:lang='und'>[ ] : * ? / \</code> and it must be less than 32 characters. In addition, you cannot use the same, case insensitive, <code lang='und' xml:lang='und'>$sheetname</code> for more than one worksheet.</p>

<p>On systems with <code lang='und' xml:lang='und'>perl 5.8</code> and later the <code lang='und' xml:lang='und'>add_worksheet()</code> method will also handle strings in <code lang='und' xml:lang='und'>UTF-8</code> format.</p>

<pre lang='und' xml:lang='und'>    $worksheet = $workbook-&#62;add_worksheet(&#34;\x{263a}&#34;); # Smiley</pre>

<p>On earlier Perl systems your can specify <code lang='und' xml:lang='und'>UTF-16BE</code> worksheet names using an additional optional parameter:</p>

<pre lang='und' xml:lang='und'>    my $name = pack &#39;n&#39;, 0x263a;
    $worksheet = $workbook-&#62;add_worksheet($name, 1);   # Smiley</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="add_format(%properties)"
>add_format(%properties)</a></h2>

<p>The <code lang='und' xml:lang='und'>add_format()</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>

<pre lang='und' xml:lang='und'>    $format1 = $workbook-&#62;add_format(%props); # Set properties at creation
    $format2 = $workbook-&#62;add_format();       # Set properties later</pre>

<p>See the <a href="#CELL_FORMATTING" class="podlinkpod"
>&#34;CELL FORMATTING&#34;</a> section for more details about Format properties and how to set them.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="add_chart_ext($chart_data,_$chartname)"
>add_chart_ext($chart_data, $chartname)</a></h2>

<p>This method is use to include externally generated charts in a Spreadsheet::WriteExcel file.</p>

<pre lang='und' xml:lang='und'>    my $chart = $workbook-&#62;add_chart_ext(&#39;chart01.bin&#39;, &#39;Chart1&#39;);</pre>

<p>This feature is new and would be best described as experimental. Read <code lang='und' xml:lang='und'>charts.txt</code> in the charts directory of the distro for a full explanation.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="close()"
>close()</a></h2>

<p>In general your Excel file will be closed automatically when your program ends or when the Workbook object goes out of scope, however the <code lang='und' xml:lang='und'>close()</code> method can be used to explicitly close an Excel file.</p>

<pre lang='und' xml:lang='und'>    $workbook-&#62;close();</pre>

<p>An explicit <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>close()</code> may be required to prevent perl&#39;s garbage collector from disposing of the Workbook, Worksheet and Format objects in the wrong order. Situations where this can occur are:</p>

<ul>
<li>If <code lang='und' xml:lang='und'>my()</code> was not used to declare the scope of a workbook variable created using <code lang='und' xml:lang='und'>new()</code>.</li><p class="pad"></p>

<li>If the <code lang='und' xml:lang='und'>new()</code>, <code lang='und' xml:lang='und'>add_worksheet()</code> or <code lang='und' xml:lang='und'>add_format()</code> methods are called in subroutines.</li><p class="pad"></p>
</ul>

<p>The reason for this is that Spreadsheet::WriteExcel relies on Perl&#39;s <code lang='und' xml:lang='und'>DESTROY</code> mechanism to trigger destructor methods in a specific sequence. This may not happen in cases where the Workbook, Worksheet and Format variables are not lexically scoped or where they have different lexical scopes.</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 lang='und' xml:lang='und'>close()</code>.</p>

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

<pre lang='und' xml:lang='und'>    $workbook-&#62;close() or die &#34;Error closing file: $!&#34;;</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="compatibility_mode()"
>compatibility_mode()</a></h2>

<p>This method is used to improve compatibility with third party applications that read Excel files.</p>

<pre lang='und' xml:lang='und'>    $workbook-&#62;compatibility_mode();</pre>

<p>An Excel file is comprised of binary records that describe properties of a spreadsheet. Excel is reasonably liberal about this and, outside of a core subset, it doesn&#39;t require every possible record to be present when it reads a file. This is also true of Gnumeric and OpenOffice.Org Calc.</p>

<p>Spreadsheet::WriteExcel takes advantage of this fact to omit some records in order to minimise the amount of data stored in memory and to simplify and speed up the writing of files. However, some third party applications that read Excel files often expect certain records to be present. In &#34;compatibility mode&#34; Spreadsheet::WriteExcel writes these records and tries to be as close to an Excel generated file as possible.</p>

<p>Applications that require <code lang='und' xml:lang='und'>compatibility_mode()</code> are Apache POI, Apple Numbers, and Quickoffice on Nokia, Palm and other devices. You should also use <code lang='und' xml:lang='und'>compatibility_mode()</code> if your Excel file will be used as an external data source by another Excel file.</p>

<p>If you encounter other situations that require <code lang='und' xml:lang='und'>compatibility_mode()</code>, please let me know.</p>

<p>It should be noted that <code lang='und' xml:lang='und'>compatibility_mode()</code> requires additional data to be stored in memory and additional processing. This incurs a memory and speed penalty and may not be suitable for very large files (&#62;20MB).</p>

<p>You must call <code lang='und' xml:lang='und'>compatibility_mode()</code> before calling <code lang='und' xml:lang='und'>add_worksheet()</code>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_properties()"
>set_properties()</a></h2>

<p>The <code lang='und' xml:lang='und'>set_properties</code> method can be used to set the document properties of the Excel file created by <code lang='und' xml:lang='und'>Spreadsheet::WriteExcel</code>. These properties are visible when you use the <code lang='und' xml:lang='und'>File-&#62;Properties</code> menu option in Excel and are also available to external applications that read or index windows files.</p>

<p>The properties should be passed as a hash of values as follows:</p>

<pre lang='und' xml:lang='und'>    $workbook-&#62;set_properties(
        title    =&#62; &#39;This is an example spreadsheet&#39;,
        author   =&#62; &#39;John McNamara&#39;,
        comments =&#62; &#39;Created with Perl and Spreadsheet::WriteExcel&#39;,
    );</pre>

<p>The properties that can be set are:</p>

<pre lang='und' xml:lang='und'>    title
    subject
    author
    manager
    company
    category
    keywords
    comments</pre>

<p>User defined properties are not supported due to effort required.</p>

<p>In perl 5.8+ you can also pass UTF-8 strings as properties. See <a href="#UNICODE_IN_EXCEL" class="podlinkpod"
>&#34;UNICODE IN EXCEL&#34;</a>.</p>

<pre lang='und' xml:lang='und'>    my $smiley = chr 0x263A;

    $workbook-&#62;set_properties(
        subject =&#62; &#34;Happy now? $smiley&#34;,
    );</pre>

<p>With older versions of perl you can use a module to convert a non-ASCII string to a binary representation of UTF-8 and then pass an additional <code lang='und' xml:lang='und'>utf8</code> flag to <code lang='und' xml:lang='und'>set_properties()</code>:</p>

<pre lang='und' xml:lang='und'>    my $smiley = pack &#39;H*&#39;, &#39;E298BA&#39;;

    $workbook-&#62;set_properties(
        subject =&#62; &#34;Happy now? $smiley&#34;,
        utf8    =&#62; 1,
    );</pre>

<p>Usually Spreadsheet::WriteExcel allows you to use UTF-16 with pre 5.8 versions of perl. However, document properties don&#39;t support UTF-16 for these type of strings.</p>

<p>In order to promote the usefulness of Perl and the Spreadsheet::WriteExcel module consider adding a comment such as the following when using document properties:</p>

<pre lang='und' xml:lang='und'>    $workbook-&#62;set_properties(
        ...,
        comments =&#62; &#39;Created with Perl and Spreadsheet::WriteExcel&#39;,
        ...,
    );</pre>

<p>This feature requires that the <code lang='und' xml:lang='und'>OLE::Storage_Lite</code> module is installed (which is usually the case for a standard Spreadsheet::WriteExcel installation). However, this also means that the resulting OLE document may <b>possibly</b> be buggy for files less than 7MB since it hasn&#39;t been as rigorously tested in that domain. As a result of this <code lang='und' xml:lang='und'>set_properties</code> is currently incompatible with Gnumeric for files less than 7MB. This is being investigated. If you encounter any problems with this features let me know.</p>

<p>For convenience it is possible to pass either a hash or hash ref of arguments to this method.</p>

<p>See also the <code lang='und' xml:lang='und'>properties.pl</code> program in the examples directory of the distro.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_tempdir()"
>set_tempdir()</a></h2>

<p>For speed and efficiency <code lang='und' xml:lang='und'>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.</p>

<p>The problem occurs mainly with IIS on Windows although it could feasibly occur on Unix systems as well. The problem generally occurs because the default temp file directory is defined as <code lang='und' xml:lang='und'>C:/</code> or some other directory that IIS doesn&#39;t provide write access to.</p>

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

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use Spreadsheet::WriteExcel;

    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;test.xls&#39;);
    my $worksheet = $workbook-&#62;add_worksheet();</pre>

<p>To avoid this problem the <code lang='und' xml:lang='und'>set_tempdir()</code> method can be used to specify a directory that is accessible for the creation of temporary files.</p>

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

<pre lang='und' xml:lang='und'>    perl -MFile::Spec -le &#34;print File::Spec-&#62;tmpdir&#34;</pre>

<p>Even if the default temporary file directory is accessible you may wish to specify an alternative location for security or maintenance reasons:</p>

<pre lang='und' xml:lang='und'>    $workbook-&#62;set_tempdir(&#39;/tmp/writeexcel&#39;);
    $workbook-&#62;set_tempdir(&#39;c:\windows\temp\writeexcel&#39;);</pre>

<p>The directory for the temporary file must exist, <code lang='und' xml:lang='und'>set_tempdir()</code> will not create a new directory.</p>

<p>One disadvantage of using the <code lang='und' xml:lang='und'>set_tempdir()</code> method is that on some Windows systems it will limit you to approximately 800 concurrent tempfiles. This means that a single program running on one of these systems will be limited to creating a total of 800 workbook and worksheet objects. You can run multiple, non-concurrent programs to work around this if necessary.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_custom_color($index,_$red,_$green,_$blue)"
>set_custom_color($index, $red, $green, $blue)</a></h2>

<p>The <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>$index</code> should be in the range 8..63, see <a href="#COLOURS_IN_EXCEL" class="podlinkpod"
>&#34;COLOURS IN EXCEL&#34;</a>.</p>

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

<pre lang='und' xml:lang='und'>     8   =&#62;   black
     9   =&#62;   white
    10   =&#62;   red
    11   =&#62;   lime
    12   =&#62;   blue
    13   =&#62;   yellow
    14   =&#62;   magenta
    15   =&#62;   cyan
    16   =&#62;   brown
    17   =&#62;   green
    18   =&#62;   navy
    20   =&#62;   purple
    22   =&#62;   silver
    23   =&#62;   gray
    33   =&#62;   pink
    53   =&#62;   orange</pre>

<p>A new colour is set using its RGB (red green blue) components. The <code lang='und' xml:lang='und'>$red</code>, <code lang='und' xml:lang='und'>$green</code> and <code lang='und' xml:lang='und'>$blue</code> values must be in the range 0..255. You can determine the required values in Excel using the <code lang='und' xml:lang='und'>Tools-&#62;Options-&#62;Colors-&#62;Modify</code> dialog.</p>

<p>The <code lang='und' xml:lang='und'>set_custom_color()</code> workbook method can also be used with a HTML style <code lang='und' xml:lang='und'>#rrggbb</code> hex value:</p>

<pre lang='und' xml:lang='und'>    $workbook-&#62;set_custom_color(40, 255,  102,  0   ); # Orange
    $workbook-&#62;set_custom_color(40, 0xFF, 0x66, 0x00); # Same thing
    $workbook-&#62;set_custom_color(40, &#39;#FF6600&#39;       ); # Same thing

    my $font = $workbook-&#62;add_format(color =&#62; 40); # Use the modified colour</pre>

<p>The return value from <code lang='und' xml:lang='und'>set_custom_color()</code> is the index of the colour that was changed:</p>

<pre lang='und' xml:lang='und'>    my $ferrari = $workbook-&#62;set_custom_color(40, 216, 12, 12);

    my $format  = $workbook-&#62;add_format(
                                        bg_color =&#62; $ferrari,
                                        pattern  =&#62; 1,
                                        border   =&#62; 1
                                      );</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="sheets(0,_1,_...)"
>sheets(0, 1, ...)</a></h2>

<p>The <code lang='und' xml:lang='und'>sheets()</code> method returns a list, or a sliced list, of the worksheets in a workbook.</p>

<p>If no arguments are passed the method returns a list of all the worksheets in the workbook. This is useful if you want to repeat an operation on each worksheet:</p>

<pre lang='und' xml:lang='und'>    foreach $worksheet ($workbook-&#62;sheets()) {
       print $worksheet-&#62;get_name();
    }</pre>

<p>You can also specify a slice list to return one or more worksheet objects:</p>

<pre lang='und' xml:lang='und'>    $worksheet = $workbook-&#62;sheets(0);
    $worksheet-&#62;write(&#39;A1&#39;, &#39;Hello&#39;);</pre>

<p>Or since return value from <code lang='und' xml:lang='und'>sheets()</code> is a reference to a worksheet object you can write the above example as:</p>

<pre lang='und' xml:lang='und'>    $workbook-&#62;sheets(0)-&#62;write(&#39;A1&#39;, &#39;Hello&#39;);</pre>

<p>The following example returns the first and last worksheet in a workbook:</p>

<pre lang='und' xml:lang='und'>    foreach $worksheet ($workbook-&#62;sheets(0, -1)) {
       # Do something
    }</pre>

<p>Array slices are explained in the perldata manpage.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
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 lang='und' xml:lang='und'>set_1904()</code> workbook method. You can query the current value by calling the <code lang='und' xml:lang='und'>get_1904()</code> workbook method. This returns 0 for 1900 and 1 for 1904.</p>

<p>See also <a href="#DATES_AND_TIME_IN_EXCEL" class="podlinkpod"
>&#34;DATES AND TIME IN EXCEL&#34;</a> for more information about working with Excel&#39;s date system.</p>

<p>In general you probably won&#39;t need to use <code lang='und' xml:lang='und'>set_1904()</code>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
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 lang='und' xml:lang='und'>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>

<pre lang='und' xml:lang='und'>    $workbook-&#62;set_codepage(1); # ANSI, MS Windows
    $workbook-&#62;set_codepage(2); # Apple Macintosh</pre>

<p>The <code lang='und' xml:lang='und'>set_codepage()</code> method is rarely required.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="WORKSHEET_METHODS"
>WORKSHEET METHODS</a></h1>

<p>A new worksheet is created by calling the <code lang='und' xml:lang='und'>add_worksheet()</code> method from a workbook object:</p>

<pre lang='und' xml:lang='und'>    $worksheet1 = $workbook-&#62;add_worksheet();
    $worksheet2 = $workbook-&#62;add_worksheet();</pre>

<p>The following methods are available through a new worksheet:</p>

<pre lang='und' xml:lang='und'>    write()
    write_number()
    write_string()
    write_utf16be_string()
    write_utf16le_string()
    keep_leading_zeros()
    write_blank()
    write_row()
    write_col()
    write_date_time()
    write_url()
    write_url_range()
    write_formula()
    store_formula()
    repeat_formula()
    write_comment()
    show_comments()
    add_write_handler()
    insert_image()
    embed_chart()
    data_validation()
    get_name()
    activate()
    select()
    hide()
    set_first_sheet()
    protect()
    set_selection()
    set_row()
    set_column()
    outline_settings()
    freeze_panes()
    split_panes()
    merge_range()
    set_zoom()
    right_to_left()
    hide_zero()
    set_tab_color()
    autofilter()</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    (0, 0)      # The top left cell in row-column notation.
    (&#39;A1&#39;)      # The top left cell in A1 notation.

    (1999, 29)  # Row-column notation.
    (&#39;AD2000&#39;)  # The same cell in A1 notation.</pre>

<p>Row-column notation is useful if you are referring to cells programmatically:</p>

<pre lang='und' xml:lang='und'>    for my $i (0 .. 9) {
        $worksheet-&#62;write($i, 0, &#39;Hello&#39;); # Cells A1 to A10
    }</pre>

<p>A1 notation is useful for setting up a worksheet manually and for working with formulas:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write(&#39;H1&#39;, 200);
    $worksheet-&#62;write(&#39;H2&#39;, &#39;=H1+1&#39;);</pre>

<p>In formulas and applicable methods you can also use the <code lang='und' xml:lang='und'>A:A</code> column notation:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write(&#39;A1&#39;, &#39;=SUM(B:B)&#39;);</pre>

<p>The <code lang='und' xml:lang='und'>Spreadsheet::WriteExcel::Utility</code> module that is included in the distro contains helper functions for dealing with A1 notation, for example:</p>

<pre lang='und' xml:lang='und'>    use Spreadsheet::WriteExcel::Utility;

    ($row, $col)    = xl_cell_to_rowcol(&#39;C2&#39;);  # (1, 2)
    $str            = xl_rowcol_to_cell(1, 2);  # C2</pre>

<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>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write($row,_$column,_$token,_$format)"
>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 lang='und' xml:lang='und'>write()</code> method acts as a general alias for several more specific methods:</p>

<pre lang='und' xml:lang='und'>    write_string()
    write_number()
    write_blank()
    write_formula()
    write_url()
    write_row()
    write_col()</pre>

<p>The general rule is that if the data looks like a <i>something</i> then a <i>something</i> is written. Here are some examples in both row-column and A1 notation:</p>

<pre lang='und' xml:lang='und'>                                                      # Same as:
    $worksheet-&#62;write(0, 0, &#39;Hello&#39;                ); # write_string()
    $worksheet-&#62;write(1, 0, &#39;One&#39;                  ); # write_string()
    $worksheet-&#62;write(2, 0,  2                     ); # write_number()
    $worksheet-&#62;write(3, 0,  3.00001               ); # write_number()
    $worksheet-&#62;write(4, 0,  &#34;&#34;                    ); # write_blank()
    $worksheet-&#62;write(5, 0,  &#39;&#39;                    ); # write_blank()
    $worksheet-&#62;write(6, 0,  undef                 ); # write_blank()
    $worksheet-&#62;write(7, 0                         ); # write_blank()
    $worksheet-&#62;write(8, 0,  &#39;http://www.perl.com/&#39;); # write_url()
    $worksheet-&#62;write(&#39;A9&#39;,  &#39;ftp://ftp.cpan.org/&#39; ); # write_url()
    $worksheet-&#62;write(&#39;A10&#39;, &#39;internal:Sheet1!A1&#39;  ); # write_url()
    $worksheet-&#62;write(&#39;A11&#39;, &#39;external:c:\foo.xls&#39; ); # write_url()
    $worksheet-&#62;write(&#39;A12&#39;, &#39;=A3 + 3*A4&#39;          ); # write_formula()
    $worksheet-&#62;write(&#39;A13&#39;, &#39;=SIN(PI()/4)&#39;        ); # write_formula()
    $worksheet-&#62;write(&#39;A14&#39;, \@array               ); # write_row()
    $worksheet-&#62;write(&#39;A15&#39;, [\@array]             ); # write_col()

    # And if the keep_leading_zeros property is set:
    $worksheet-&#62;write(&#39;A16,  2                     ); # write_number()
    $worksheet-&#62;write(&#39;A17,  02                    ); # write_string()
    $worksheet-&#62;write(&#39;A18,  00002                 ); # write_string()</pre>

<p>The &#34;looks like&#34; rule is defined by regular expressions:</p>

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

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

<p><code lang='und' xml:lang='und'>write_blank()</code> if <code lang='und' xml:lang='und'>$token</code> is undef or a blank string: <code lang='und' xml:lang='und'>undef</code>, <code lang='und' xml:lang='und'>&#34;&#34;</code> or <code lang='und' xml:lang='und'>&#39;&#39;</code>.</p>

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

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

<p><code lang='und' xml:lang='und'>write_formula()</code> if the first character of <code lang='und' xml:lang='und'>$token</code> is <code lang='und' xml:lang='und'>&#34;=&#34;</code>.</p>

<p><code lang='und' xml:lang='und'>write_row()</code> if <code lang='und' xml:lang='und'>$token</code> is an array ref.</p>

<p><code lang='und' xml:lang='und'>write_col()</code> if <code lang='und' xml:lang='und'>$token</code> is an array ref of array refs.</p>

<p><code lang='und' xml:lang='und'>write_string()</code> if none of the previous conditions apply.</p>

<p>The <code lang='und' xml:lang='und'>$format</code> parameter is optional. It should be a valid Format object, see <a href="#CELL_FORMATTING" class="podlinkpod"
>&#34;CELL FORMATTING&#34;</a>:</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_bold();
    $format-&#62;set_color(&#39;red&#39;);
    $format-&#62;set_align(&#39;center&#39;);

    $worksheet-&#62;write(4, 0, &#39;Hello&#39;, $format); # Formatted string</pre>

<p>The write() method will ignore empty strings or <code lang='und' xml:lang='und'>undef</code> tokens unless a format is also supplied. As such you needn&#39;t worry about special handling for empty or <code lang='und' xml:lang='und'>undef</code> values in your data. See also the <code lang='und' xml:lang='und'>write_blank()</code> method.</p>

<p>One problem with the <code lang='und' xml:lang='und'>write()</code> method is that occasionally data looks like a number but you don&#39;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 zero(s) will be stripped. You can change this default behaviour by using the <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>keep_leading_zeros()</code> section for a full discussion of this issue.</p>

<p>You can also add your own data handlers to the <code lang='und' xml:lang='und'>write()</code> method using <code lang='und' xml:lang='und'>add_write_handler()</code>.</p>

<p>On systems with <code lang='und' xml:lang='und'>perl 5.8</code> and later the <code lang='und' xml:lang='und'>write()</code> method will also handle Unicode strings in <code lang='und' xml:lang='und'>UTF-8</code> format.</p>

<p>The <code lang='und' xml:lang='und'>write</code> methods return:</p>

<pre lang='und' xml:lang='und'>    0 for success.
   -1 for insufficient number of arguments.
   -2 for row or column out of bounds.
   -3 for string too long.</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_number($row,_$column,_$number,_$format)"
>write_number($row, $column, $number, $format)</a></h2>

<p>Write an integer or a float to the cell specified by <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$column</code>:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_number(0, 0,  123456);
    $worksheet-&#62;write_number(&#39;A2&#39;,  2.3451);</pre>

<p>See the note about <a href="#Cell_notation" class="podlinkpod"
>&#34;Cell notation&#34;</a>. The <code lang='und' xml:lang='und'>$format</code> parameter is optional.</p>

<p>In general it is sufficient to use the <code lang='und' xml:lang='und'>write()</code> method.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_string($row,_$column,_$string,_$format)"
>write_string($row, $column, $string, $format)</a></h2>

<p>Write a string to the cell specified by <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$column</code>:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_string(0, 0, &#39;Your text here&#39; );
    $worksheet-&#62;write_string(&#39;A2&#39;, &#39;or here&#39; );</pre>

<p>The maximum string size is 32767 characters. However the maximum string segment that Excel can display in a cell is 1000. All 32767 characters can be displayed in the formula bar.</p>

<p>The <code lang='und' xml:lang='und'>$format</code> parameter is optional.</p>

<p>On systems with <code lang='und' xml:lang='und'>perl 5.8</code> and later the <code lang='und' xml:lang='und'>write()</code> method will also handle strings in <code lang='und' xml:lang='und'>UTF-8</code> format. With older perls you can also write Unicode in <code lang='und' xml:lang='und'>UTF16</code> format via the <code lang='und' xml:lang='und'>write_utf16be_string()</code> method. See also the <code lang='und' xml:lang='und'>unicode_*.pl</code> programs in the examples directory of the distro.</p>

<p>In general it is sufficient to use the <code lang='und' xml:lang='und'>write()</code> method. However, you may sometimes wish to use the <code lang='und' xml:lang='und'>write_string()</code> method to write data that looks like a number but that you don&#39;t want treated as a number. For example, zip codes or phone numbers:</p>

<pre lang='und' xml:lang='und'>    # Write as a plain string
    $worksheet-&#62;write_string(&#39;A1&#39;, &#39;01209&#39;);</pre>

<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 lang='und' xml:lang='und'>@</code>:</p>

<pre lang='und' xml:lang='und'>    # Format as a string. Doesn&#39;t change to a number when edited
    my $format1 = $workbook-&#62;add_format(num_format =&#62; &#39;@&#39;);
    $worksheet-&#62;write_string(&#39;A2&#39;, &#39;01209&#39;, $format1);</pre>

<p>See also the note about <a href="#Cell_notation" class="podlinkpod"
>&#34;Cell notation&#34;</a>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_utf16be_string($row,_$column,_$string,_$format)"
>write_utf16be_string($row, $column, $string, $format)</a></h2>

<p>This method is used to write <code lang='und' xml:lang='und'>UTF-16BE</code> strings to a cell in Excel. It is functionally the same as the <code lang='und' xml:lang='und'>write_string()</code> method except that the string should be in <code lang='und' xml:lang='und'>UTF-16BE</code> Unicode format. It is generally easier, when using Spreadsheet::WriteExcel, to write unicode strings in <code lang='und' xml:lang='und'>UTF-8</code> format, see <a href="#UNICODE_IN_EXCEL" class="podlinkpod"
>&#34;UNICODE IN EXCEL&#34;</a>. The <code lang='und' xml:lang='und'>write_utf16be_string()</code> method is mainly of use in versions of perl prior to 5.8.</p>

<p>The following is a simple example showing how to write some Unicode strings in <code lang='und' xml:lang='und'>UTF-16BE</code> format:</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w


    use strict;
    use Spreadsheet::WriteExcel;
    use Unicode::Map();

    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;utf_16_be.xls&#39;);
    my $worksheet = $workbook-&#62;add_worksheet();

    # Increase the column width for clarity
    $worksheet-&#62;set_column(&#39;A:A&#39;, 25);


    # Write a Unicode character
    #
    my $smiley = pack &#39;n&#39;, 0x263a;

    # Increase the font size for legibility.
    my $big_font = $workbook-&#62;add_format(size =&#62; 72);

    $worksheet-&#62;write_utf16be_string(&#39;A3&#39;, $smiley, $big_font);



    # Write a phrase in Cyrillic using a hex-encoded string
    #
    my $str = pack &#39;H*&#39;, &#39;042d0442043e0020044404400430043704300020043d&#39; .
                         &#39;043000200440044304410441043a043e043c0021&#39;;

    $worksheet-&#62;write_utf16be_string(&#39;A5&#39;, $str);



    # Map a string to UTF-16BE using an external module.
    #
    my $map   = Unicode::Map-&#62;new(&#39;ISO-8859-1&#39;);
    my $utf16 = $map-&#62;to_unicode(&#39;Hello world!&#39;);

    $worksheet-&#62;write_utf16be_string(&#39;A7&#39;, $utf16);</pre>

<p>You can convert ASCII encodings to the required <code lang='und' xml:lang='und'>UTF-16BE</code> format using one of the many Unicode modules on CPAN. For example <code lang='und' xml:lang='und'>Unicode::Map</code> and <code lang='und' xml:lang='und'>Unicode::String</code>: http://search.cpan.org/author/MSCHWARTZ/Unicode-Map/Map.pm and http://search.cpan.org/author/GAAS/Unicode-String/String.pm</p>

<p>For a full list of the Perl Unicode modules see: http://search.cpan.org/search?query=unicode&#38;mode=all</p>

<p><code lang='und' xml:lang='und'>UTF-16BE</code> is the format most often returned by <code lang='und' xml:lang='und'>Perl</code> modules that generate <code lang='und' xml:lang='und'>UTF-16</code>. To write <code lang='und' xml:lang='und'>UTF-16</code> strings in little-endian format use the <code lang='und' xml:lang='und'>write_utf16be_string_le()</code> method below.</p>

<p>The <code lang='und' xml:lang='und'>write_utf16be_string()</code> method was previously called <code lang='und' xml:lang='und'>write_unicode()</code>. That, overly general, name is still supported but deprecated.</p>

<p>See also the <code lang='und' xml:lang='und'>unicode_*.pl</code> programs in the examples directory of the distro.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_utf16le_string($row,_$column,_$string,_$format)"
>write_utf16le_string($row, $column, $string, $format)</a></h2>

<p>This method is the same as <code lang='und' xml:lang='und'>write_utf16be()</code> except that the string should be 16-bit characters in little-endian format. This is generally referred to as <code lang='und' xml:lang='und'>UTF-16LE</code>. See <a href="#UNICODE_IN_EXCEL" class="podlinkpod"
>&#34;UNICODE IN EXCEL&#34;</a>.</p>

<p><code lang='und' xml:lang='und'>UTF-16</code> data can be changed from little-endian to big-endian format (and vice-versa) as follows:</p>

<pre lang='und' xml:lang='und'>    $utf16be = pack &#39;n*&#39;, unpack &#39;v*&#39;, $utf16le;</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
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 lang='und' xml:lang='und'>write()</code> method.</p>

<p>The <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>write_number()</code>. One problem with this approach is that occasionally data looks like a number but you don&#39;t want it treated as a number.</p>

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

<p>To get around this you can use one of three options. Write a formatted number, write the number as a string or use the <code lang='und' xml:lang='und'>keep_leading_zeros()</code> method to change the default behaviour of <code lang='und' xml:lang='und'>write()</code>:</p>

<pre lang='und' xml:lang='und'>    # Implicitly write a number, the leading zero is removed: 1209
    $worksheet-&#62;write(&#39;A1&#39;, &#39;01209&#39;);

    # Write a zero padded number using a format: 01209
    my $format1 = $workbook-&#62;add_format(num_format =&#62; &#39;00000&#39;);
    $worksheet-&#62;write(&#39;A2&#39;, &#39;01209&#39;, $format1);

    # Write explicitly as a string: 01209
    $worksheet-&#62;write_string(&#39;A3&#39;, &#39;01209&#39;);

    # Write implicitly as a string: 01209
    $worksheet-&#62;keep_leading_zeros();
    $worksheet-&#62;write(&#39;A4&#39;, &#39;01209&#39;);</pre>

<p>The above code would generate a worksheet that looked like the following:</p>

<pre lang='und' xml:lang='und'>     -----------------------------------------------------------
    |   |     A     |     B     |     C     |     D     | ...
     -----------------------------------------------------------
    | 1 |      1209 |           |           |           | ...
    | 2 |     01209 |           |           |           | ...
    | 3 | 01209     |           |           |           | ...
    | 4 | 01209     |           |           |           | ...</pre>

<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" class="podlinkpod"
>&#34;CELL FORMATTING&#34;</a>.</p>

<p>It should be noted that if the user edits the data in examples <code lang='und' xml:lang='und'>A3</code> and <code lang='und' xml:lang='und'>A4</code> the strings will revert back to numbers. Again this is Excel&#39;s default behaviour. To avoid this you can use the text format <code lang='und' xml:lang='und'>@</code>:</p>

<pre lang='und' xml:lang='und'>    # Format as a string (01209)
    my $format2 = $workbook-&#62;add_format(num_format =&#62; &#39;@&#39;);
    $worksheet-&#62;write_string(&#39;A5&#39;, &#39;01209&#39;, $format2);</pre>

<p>The <code lang='und' xml:lang='und'>keep_leading_zeros()</code> property is off by default. The <code lang='und' xml:lang='und'>keep_leading_zeros()</code> method takes 0 or 1 as an argument. It defaults to 1 if an argument isn&#39;t specified:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;keep_leading_zeros();  # Set on
    $worksheet-&#62;keep_leading_zeros(1); # Set on
    $worksheet-&#62;keep_leading_zeros(0); # Set off</pre>

<p>See also the <code lang='und' xml:lang='und'>add_write_handler()</code> method.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_blank($row,_$column,_$format)"
>write_blank($row, $column, $format)</a></h2>

<p>Write a blank cell specified by <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$column</code>:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_blank(0, 0, $format);</pre>

<p>This method is used to add formatting to a cell which doesn&#39;t contain a string or number value.</p>

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

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

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write(&#39;A1&#39;,  undef, $format); # write_blank()
    $worksheet-&#62;write(&#39;A2&#39;,  undef         ); # Ignored</pre>

<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" class="podlinkpod"
>&#34;Cell notation&#34;</a>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_row($row,_$column,_$array_ref,_$format)"
>write_row($row, $column, $array_ref, $format)</a></h2>

<p>The <code lang='und' xml:lang='und'>write_row()</code> method can be used to write a 1D or 2D array of data in one go. This is useful for converting the results of a database query into an Excel worksheet. You must pass a reference to the array of data rather than the array itself. The <code lang='und' xml:lang='und'>write()</code> method is then called for each element of the data. For example:</p>

<pre lang='und' xml:lang='und'>    @array      = (&#39;awk&#39;, &#39;gawk&#39;, &#39;mawk&#39;);
    $array_ref  = \@array;

    $worksheet-&#62;write_row(0, 0, $array_ref);

    # The above example is equivalent to:
    $worksheet-&#62;write(0, 0, $array[0]);
    $worksheet-&#62;write(0, 1, $array[1]);
    $worksheet-&#62;write(0, 2, $array[2]);</pre>

<p>Note: For convenience the <code lang='und' xml:lang='und'>write()</code> method behaves in the same way as <code lang='und' xml:lang='und'>write_row()</code> if it is passed an array reference. Therefore the following two method calls are equivalent:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_row(&#39;A1&#39;, $array_ref); # Write a row of data
    $worksheet-&#62;write(    &#39;A1&#39;, $array_ref); # Same thing</pre>

<p>As with all of the write methods the <code lang='und' xml:lang='und'>$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>

<pre lang='und' xml:lang='und'>    @eec =  (
                [&#39;maggie&#39;, &#39;milly&#39;, &#39;molly&#39;, &#39;may&#39;  ],
                [13,       14,      15,      16     ],
                [&#39;shell&#39;,  &#39;star&#39;,  &#39;crab&#39;,  &#39;stone&#39;]
            );

    $worksheet-&#62;write_row(&#39;A1&#39;, \@eec);</pre>

<p>Would produce a worksheet as follows:</p>

<pre lang='und' xml:lang='und'>     -----------------------------------------------------------
    |   |    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>To write the data in a row-column order refer to the <code lang='und' xml:lang='und'>write_col()</code> method below.</p>

<p>Any <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>perlref</code> and <code lang='und' xml:lang='und'>perlreftut</code> in the main Perl documentation. To find out more about 2D arrays or &#34;lists of lists&#34; refer to <code lang='und' xml:lang='und'>perllol</code>.</p>

<p>The <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>write()</code> method above.</p>

<p>See also the <code lang='und' xml:lang='und'>write_arrays.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<p>The <code lang='und' xml:lang='und'>write_row()</code> method allows the following idiomatic conversion of a text file to an Excel file:</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;file.xls&#39;);
    my $worksheet = $workbook-&#62;add_worksheet();

    open INPUT, &#39;file.txt&#39; or die &#34;Couldn&#39;t open file: $!&#34;;

    $worksheet-&#62;write($.-1, 0, [split]) while &#60;INPUT&#62;;</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_col($row,_$column,_$array_ref,_$format)"
>write_col($row, $column, $array_ref, $format)</a></h2>

<p>The <code lang='und' xml:lang='und'>write_col()</code> method can be used to write a 1D or 2D array of data in one go. This is useful for converting the results of a database query into an Excel worksheet. You must pass a reference to the array of data rather than the array itself. The <code lang='und' xml:lang='und'>write()</code> method is then called for each element of the data. For example:</p>

<pre lang='und' xml:lang='und'>    @array      = (&#39;awk&#39;, &#39;gawk&#39;, &#39;mawk&#39;);
    $array_ref  = \@array;

    $worksheet-&#62;write_col(0, 0, $array_ref);

    # The above example is equivalent to:
    $worksheet-&#62;write(0, 0, $array[0]);
    $worksheet-&#62;write(1, 0, $array[1]);
    $worksheet-&#62;write(2, 0, $array[2]);</pre>

<p>As with all of the write methods the <code lang='und' xml:lang='und'>$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>

<pre lang='und' xml:lang='und'>    @eec =  (
                [&#39;maggie&#39;, &#39;milly&#39;, &#39;molly&#39;, &#39;may&#39;  ],
                [13,       14,      15,      16     ],
                [&#39;shell&#39;,  &#39;star&#39;,  &#39;crab&#39;,  &#39;stone&#39;]
            );

    $worksheet-&#62;write_col(&#39;A1&#39;, \@eec);</pre>

<p>Would produce a worksheet as follows:</p>

<pre lang='und' xml:lang='und'>     -----------------------------------------------------------
    |   |    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>To write the data in a column-row order refer to the <code lang='und' xml:lang='und'>write_row()</code> method above.</p>

<p>Any <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>write()</code> method can be used as a synonym for <code lang='und' xml:lang='und'>write_row()</code> and <code lang='und' xml:lang='und'>write_row()</code> handles nested array refs as columns. Therefore, the following two method calls are equivalent although the more explicit call to <code lang='und' xml:lang='und'>write_col()</code> would be preferable for maintainability:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_col(&#39;A1&#39;, $array_ref    ); # Write a column of data
    $worksheet-&#62;write(    &#39;A1&#39;, [ $array_ref ]); # Same thing</pre>

<p>To find out more about array references refer to <code lang='und' xml:lang='und'>perlref</code> and <code lang='und' xml:lang='und'>perlreftut</code> in the main Perl documentation. To find out more about 2D arrays or &#34;lists of lists&#34; refer to <code lang='und' xml:lang='und'>perllol</code>.</p>

<p>The <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>write()</code> method above.</p>

<p>See also the <code lang='und' xml:lang='und'>write_arrays.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_date_time($row,_$col,_$date_string,_$format)"
>write_date_time($row, $col, $date_string, $format)</a></h2>

<p>The <code lang='und' xml:lang='und'>write_date_time()</code> method can be used to write a date or time to the cell specified by <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$column</code>:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_date_time(&#39;A1&#39;, &#39;2004-05-13T23:20&#39;, $date_format);</pre>

<p>The <code lang='und' xml:lang='und'>$date_string</code> should be in the following format:</p>

<pre lang='und' xml:lang='und'>    yyyy-mm-ddThh:mm:ss.sss</pre>

<p>This conforms to an ISO8601 date but it should be noted that the full range of ISO8601 formats are not supported.</p>

<p>The following variations on the <code lang='und' xml:lang='und'>$date_string</code> parameter are permitted:</p>

<pre lang='und' xml:lang='und'>    yyyy-mm-ddThh:mm:ss.sss         # Standard format
    yyyy-mm-ddT                     # No time
              Thh:mm:ss.sss         # No date
    yyyy-mm-ddThh:mm:ss.sssZ        # Additional Z (but not time zones)
    yyyy-mm-ddThh:mm:ss             # No fractional seconds
    yyyy-mm-ddThh:mm                # No seconds</pre>

<p>Note that the <code lang='und' xml:lang='und'>T</code> is required in all cases.</p>

<p>A date should always have a <code lang='und' xml:lang='und'>$format</code>, otherwise it will appear as a number, see <a href="#DATES_AND_TIME_IN_EXCEL" class="podlinkpod"
>&#34;DATES AND TIME IN EXCEL&#34;</a> and <a href="#CELL_FORMATTING" class="podlinkpod"
>&#34;CELL FORMATTING&#34;</a>. Here is a typical example:</p>

<pre lang='und' xml:lang='und'>    my $date_format = $workbook-&#62;add_format(num_format =&#62; &#39;mm/dd/yy&#39;);
    $worksheet-&#62;write_date_time(&#39;A1&#39;, &#39;2004-05-13T23:20&#39;, $date_format);</pre>

<p>Valid dates should be in the range 1900-01-01 to 9999-12-31, for the 1900 epoch and 1904-01-01 to 9999-12-31, for the 1904 epoch. As with Excel, dates outside these ranges will be written as a string.</p>

<p>See also the date_time.pl program in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_url($row,_$col,_$url,_$label,_$format)"
>write_url($row, $col, $url, $label, $format)</a></h2>

<p>Write a hyperlink to a URL in the cell specified by <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$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 label is specified. The parameters <code lang='und' xml:lang='und'>$label</code> and the <code lang='und' xml:lang='und'>$format</code> are optional and their position is interchangeable.</p>

<p>The label is written using the <code lang='und' xml:lang='und'>write()</code> method. Therefore it is possible to write strings, numbers or formulas as labels.</p>

<p>There are four web style URI&#39;s supported: <code lang='und' xml:lang='und'>http://</code>, <code lang='und' xml:lang='und'>https://</code>, <code lang='und' xml:lang='und'>ftp://</code> and <code lang='und' xml:lang='und'>mailto:</code>:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_url(0, 0,  &#39;ftp://www.perl.org/&#39;                  );
    $worksheet-&#62;write_url(1, 0,  &#39;http://www.perl.com/&#39;, &#39;Perl home&#39;    );
    $worksheet-&#62;write_url(&#39;A3&#39;,  &#39;http://www.perl.com/&#39;, $format        );
    $worksheet-&#62;write_url(&#39;A4&#39;,  &#39;http://www.perl.com/&#39;, &#39;Perl&#39;, $format);
    $worksheet-&#62;write_url(&#39;A5&#39;,  &#39;mailto:jmcnamara@cpan.org&#39;            );</pre>

<p>There are two local URIs supported: <code lang='und' xml:lang='und'>internal:</code> and <code lang='und' xml:lang='und'>external:</code>. These are used for hyperlinks to internal worksheet references or external workbook and worksheet references:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_url(&#39;A6&#39;,  &#39;internal:Sheet2!A1&#39;                   );
    $worksheet-&#62;write_url(&#39;A7&#39;,  &#39;internal:Sheet2!A1&#39;,   $format        );
    $worksheet-&#62;write_url(&#39;A8&#39;,  &#39;internal:Sheet2!A1:B2&#39;                );
    $worksheet-&#62;write_url(&#39;A9&#39;,  q{internal:&#39;Sales Data&#39;!A1}            );
    $worksheet-&#62;write_url(&#39;A10&#39;, &#39;external:c:\temp\foo.xls&#39;             );
    $worksheet-&#62;write_url(&#39;A11&#39;, &#39;external:c:\temp\foo.xls#Sheet2!A1&#39;   );
    $worksheet-&#62;write_url(&#39;A12&#39;, &#39;external:..\..\..\foo.xls&#39;            );
    $worksheet-&#62;write_url(&#39;A13&#39;, &#39;external:..\..\..\foo.xls#Sheet2!A1&#39;  );
    $worksheet-&#62;write_url(&#39;A13&#39;, &#39;external:\\\\NETWORK\share\foo.xls&#39;   );</pre>

<p>All of the these URI types are recognised by the <code lang='und' xml:lang='und'>write()</code> method, see above.</p>

<p>Worksheet references are typically of the form <code lang='und' xml:lang='und'>Sheet1!A1</code>. You can also refer to a worksheet range using the standard Excel notation: <code lang='und' xml:lang='und'>Sheet1!A1:B2</code>.</p>

<p>In external links the workbook and worksheet name must be separated by the <code lang='und' xml:lang='und'>#</code> character: <code lang='und' xml:lang='und'>external:Workbook.xls#Sheet1!A1&#39;</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 lang='und' xml:lang='und'>my_name</code> in the workbook <code lang='und' xml:lang='und'>c:\temp\foo.xls</code> you could link to it as follows:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_url(&#39;A14&#39;, &#39;external:c:\temp\foo.xls#my_name&#39;);</pre>

<p>Note, you cannot currently create named ranges with <code lang='und' xml:lang='und'>Spreadsheet::WriteExcel</code>.</p>

<p>Excel requires that worksheet names containing spaces or non alphanumeric characters are single quoted as follows <code lang='und' xml:lang='und'>&#39;Sales Data&#39;!A1</code>. If you need to do this in a single quoted string then you can either escape the single quotes <code lang='und' xml:lang='und'>\&#39;</code> or use the quote operator <code lang='und' xml:lang='und'>q{}</code> as described in <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>\\NETWORK\etc</code>. In order to generate this in a single or double quoted string you will have to escape the backslashes, <code lang='und' xml:lang='und'>&#39;\\\\NETWORK\etc&#39;</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 lang='und' xml:lang='und'>perlfaq5: Why can&#39;t I use &#34;C:\temp\foo&#34; 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>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_url(&#39;A14&#39;, &#34;external:c:/temp/foo.xls&#34;             );
    $worksheet-&#62;write_url(&#39;A15&#39;, &#39;external://NETWORK/share/foo.xls&#39;     );</pre>

<p>See also, the note about <a href="#Cell_notation" class="podlinkpod"
>&#34;Cell notation&#34;</a>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_url_range($row1,_$col1,_$row2,_$col2,_$url,_$string,_$format)"
>write_url_range($row1, $col1, $row2, $col2, $url, $string, $format)</a></h2>

<p>This method is essentially the same as the <code lang='und' xml:lang='und'>write_url()</code> method described above. The main difference is that you can specify a link for a range of cells:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_url(0, 0, 0, 3, &#39;ftp://www.perl.org/&#39;              );
    $worksheet-&#62;write_url(1, 0, 0, 3, &#39;http://www.perl.com/&#39;, &#39;Perl home&#39;);
    $worksheet-&#62;write_url(&#39;A3:D3&#39;,    &#39;internal:Sheet2!A1&#39;               );
    $worksheet-&#62;write_url(&#39;A4:D4&#39;,    &#39;external:c:\temp\foo.xls&#39;         );</pre>

<p>This method is generally only required when used in conjunction with merged cells. See the <code lang='und' xml:lang='und'>merge_range()</code> method and the <code lang='und' xml:lang='und'>merge</code> property of a Format object, <a href="#CELL_FORMATTING" class="podlinkpod"
>&#34;CELL FORMATTING&#34;</a>.</p>

<p>There is no way to force this behaviour through the <code lang='und' xml:lang='und'>write()</code> method.</p>

<p>The parameters <code lang='und' xml:lang='und'>$string</code> and the <code lang='und' xml:lang='und'>$format</code> are optional and their position is interchangeable. However, they are applied only to the first cell in the range.</p>

<p>See also, the note about <a href="#Cell_notation" class="podlinkpod"
>&#34;Cell notation&#34;</a>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_formula($row,_$column,_$formula,_$format,_$value)"
>write_formula($row, $column, $formula, $format, $value)</a></h2>

<p>Write a formula or function to the cell specified by <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$column</code>:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_formula(0, 0, &#39;=$B$3 + B4&#39;  );
    $worksheet-&#62;write_formula(1, 0, &#39;=SIN(PI()/4)&#39;);
    $worksheet-&#62;write_formula(2, 0, &#39;=SUM(B1:B5)&#39; );
    $worksheet-&#62;write_formula(&#39;A4&#39;, &#39;=IF(A3&#62;1,&#34;Yes&#34;, &#34;No&#34;)&#39;   );
    $worksheet-&#62;write_formula(&#39;A5&#39;, &#39;=AVERAGE(1, 2, 3, 4)&#39;    );
    $worksheet-&#62;write_formula(&#39;A6&#39;, &#39;=DATEVALUE(&#34;1-Jan-2001&#34;)&#39;);</pre>

<p>See the note about <a href="#Cell_notation" class="podlinkpod"
>&#34;Cell notation&#34;</a>. For more information about writing Excel formulas see <a href="#FORMULAS_AND_FUNCTIONS_IN_EXCEL" class="podlinkpod"
>&#34;FORMULAS AND FUNCTIONS IN EXCEL&#34;</a></p>

<p>See also the section &#34;Improving performance when working with formulas&#34; and the <code lang='und' xml:lang='und'>store_formula()</code> and <code lang='und' xml:lang='und'>repeat_formula()</code> methods.</p>

<p>If required, it is also possible to specify the calculated value of the formula. This is occasionally necessary when working with non-Excel applications that don&#39;t calculated the value of the formula. The calculated <code lang='und' xml:lang='und'>$value</code> is added at the end of the argument list:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write(&#39;A1&#39;, &#39;=2+2&#39;, $format, 4);</pre>

<p>However, this probably isn&#39;t something that will ever need to do. If you do use this feature then do so with care.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="store_formula($formula)"
>store_formula($formula)</a></h2>

<p>The <code lang='und' xml:lang='und'>store_formula()</code> method is used in conjunction with <code lang='und' xml:lang='und'>repeat_formula()</code> to speed up the generation of repeated formulas. See &#34;Improving performance when working with formulas&#34; in <a href="#FORMULAS_AND_FUNCTIONS_IN_EXCEL" class="podlinkpod"
>&#34;FORMULAS AND FUNCTIONS IN EXCEL&#34;</a>.</p>

<p>The <code lang='und' xml:lang='und'>store_formula()</code> method pre-parses a textual representation of a formula and stores it for use at a later stage by the <code lang='und' xml:lang='und'>repeat_formula()</code> method.</p>

<p><code lang='und' xml:lang='und'>store_formula()</code> carries the same speed penalty as <code lang='und' xml:lang='und'>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>

<pre lang='und' xml:lang='und'>    my $sin = $worksheet-&#62;store_formula(&#39;=SIN(A1)&#39;);
    my $cos = $worksheet-&#62;store_formula(&#39;=COS(A1)&#39;);

    $worksheet-&#62;repeat_formula(&#39;B1&#39;, $sin, $format, &#39;A1&#39;, &#39;A2&#39;);
    $worksheet-&#62;repeat_formula(&#39;C1&#39;, $cos, $format, &#39;A1&#39;, &#39;A2&#39;);</pre>

<p>Although <code lang='und' xml:lang='und'>store_formula()</code> is a worksheet method the return value can be used in any worksheet:</p>

<pre lang='und' xml:lang='und'>    my $now = $worksheet-&#62;store_formula(&#39;=NOW()&#39;);

    $worksheet1-&#62;repeat_formula(&#39;B1&#39;, $now);
    $worksheet2-&#62;repeat_formula(&#39;B1&#39;, $now);
    $worksheet3-&#62;repeat_formula(&#39;B1&#39;, $now);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="repeat_formula($row,_$col,_$formula,_$format,_($pattern_=&#62;_$replace,_...))"
>repeat_formula($row, $col, $formula, $format, ($pattern =&#62; $replace, ...))</a></h2>

<p>The <code lang='und' xml:lang='und'>repeat_formula()</code> method is used in conjunction with <code lang='und' xml:lang='und'>store_formula()</code> to speed up the generation of repeated formulas. See &#34;Improving performance when working with formulas&#34; in <a href="#FORMULAS_AND_FUNCTIONS_IN_EXCEL" class="podlinkpod"
>&#34;FORMULAS AND FUNCTIONS IN EXCEL&#34;</a>.</p>

<p>In many respects <code lang='und' xml:lang='und'>repeat_formula()</code> behaves like <code lang='und' xml:lang='und'>write_formula()</code> except that it is significantly faster.</p>

<p>The <code lang='und' xml:lang='und'>repeat_formula()</code> method creates a new formula based on the pre-parsed tokens returned by <code lang='und' xml:lang='und'>store_formula()</code>. The new formula is generated by substituting <code lang='und' xml:lang='und'>$pattern</code>, <code lang='und' xml:lang='und'>$replace</code> pairs in the stored formula:</p>

<pre lang='und' xml:lang='und'>    my $formula = $worksheet-&#62;store_formula(&#39;=A1 * 3 + 50&#39;);

    for my $row (0..99) {
        $worksheet-&#62;repeat_formula($row, 1, $formula, $format, &#39;A1&#39;, &#39;A&#39;.($row +1));
    }</pre>

<p>It should be noted that <code lang='und' xml:lang='und'>repeat_formula()</code> doesn&#39;t modify the tokens. In the above example the substitution is always made against the original token, <code lang='und' xml:lang='und'>A1</code>, which doesn&#39;t change.</p>

<p>As usual, you can use <code lang='und' xml:lang='und'>undef</code> if you don&#39;t wish to specify a <code lang='und' xml:lang='und'>$format</code>:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;repeat_formula(&#39;B2&#39;, $formula, $format, &#39;A1&#39;, &#39;A2&#39;);
    $worksheet-&#62;repeat_formula(&#39;B3&#39;, $formula, undef,   &#39;A1&#39;, &#39;A3&#39;);</pre>

<p>The substitutions are made from left to right and you can use as many <code lang='und' xml:lang='und'>$pattern</code>, <code lang='und' xml:lang='und'>$replace</code> pairs as you need. However, each substitution is made only once:</p>

<pre lang='und' xml:lang='und'>    my $formula = $worksheet-&#62;store_formula(&#39;=A1 + A1&#39;);

    # Gives &#39;=B1 + A1&#39;
    $worksheet-&#62;repeat_formula(&#39;B1&#39;, $formula, undef, &#39;A1&#39;, &#39;B1&#39;);

    # Gives &#39;=B1 + B1&#39;
    $worksheet-&#62;repeat_formula(&#39;B2&#39;, $formula, undef, (&#39;A1&#39;, &#39;B1&#39;) x 2);</pre>

<p>Since the <code lang='und' xml:lang='und'>$pattern</code> is interpolated each time that it is used it is worth using the <code lang='und' xml:lang='und'>qr</code> operator to quote the pattern. The <code lang='und' xml:lang='und'>qr</code> operator is explained in the <code lang='und' xml:lang='und'>perlop</code> man page.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;repeat_formula(&#39;B1&#39;, $formula, $format, qr/A1/, &#39;A2&#39;);</pre>

<p>Care should be taken with the values that are substituted. The formula returned by <code lang='und' xml:lang='und'>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.</p>

<p>You should also be careful to avoid false matches. For example the following snippet is meant to change the stored formula in steps from <code lang='und' xml:lang='und'>=A1 + SIN(A1)</code> to <code lang='und' xml:lang='und'>=A10 + SIN(A10)</code>.</p>

<pre lang='und' xml:lang='und'>    my $formula = $worksheet-&#62;store_formula(&#39;=A1 + SIN(A1)&#39;);

    for my $row (1 .. 10) {
        $worksheet-&#62;repeat_formula($row -1, 1, $formula, undef,
                                    qw/A1/, &#39;A&#39; . $row,   #! Bad.
                                    qw/A1/, &#39;A&#39; . $row    #! Bad.
                                  );
    }</pre>

<p>However it contains a bug. In the last iteration of the loop when <code lang='und' xml:lang='und'>$row</code> is 10 the following substitutions will occur:</p>

<pre lang='und' xml:lang='und'>    s/A1/A10/;    changes    =A1 + SIN(A1)     to    =A10 + SIN(A1)
    s/A1/A10/;    changes    =A10 + SIN(A1)    to    =A100 + SIN(A1) # !!</pre>

<p>The solution in this case is to use a more explicit match such as <code lang='und' xml:lang='und'>qw/^A1$/</code>:</p>

<pre lang='und' xml:lang='und'>        $worksheet-&#62;repeat_formula($row -1, 1, $formula, undef,
                                    qw/^A1$/, &#39;A&#39; . $row,
                                    qw/^A1$/, &#39;A&#39; . $row
                                  );</pre>

<p>Another similar problem occurs due to the fact that substitutions are made in order. For example the following snippet is meant to change the stored formula from <code lang='und' xml:lang='und'>=A10 + A11</code> to <code lang='und' xml:lang='und'>=A11 + A12</code>:</p>

<pre lang='und' xml:lang='und'>    my $formula = $worksheet-&#62;store_formula(&#39;=A10 + A11&#39;);

    $worksheet-&#62;repeat_formula(&#39;A1&#39;, $formula, undef,
                                qw/A10/, &#39;A11&#39;,   #! Bad.
                                qw/A11/, &#39;A12&#39;    #! Bad.
                              );</pre>

<p>However, the actual substitution yields <code lang='und' xml:lang='und'>=A12 + A11</code>:</p>

<pre lang='und' xml:lang='und'>    s/A10/A11/;    changes    =A10 + A11    to    =A11 + A11
    s/A11/A12/;    changes    =A11 + A11    to    =A12 + A11 # !!</pre>

<p>The solution here would be to reverse the order of the substitutions or to start with a stored formula that won&#39;t yield a false match such as <code lang='und' xml:lang='und'>=X10 + Y11</code>:</p>

<pre lang='und' xml:lang='und'>    my $formula = $worksheet-&#62;store_formula(&#39;=X10 + Y11&#39;);

    $worksheet-&#62;repeat_formula(&#39;A1&#39;, $formula, undef,
                                qw/X10/, &#39;A11&#39;,
                                qw/Y11/, &#39;A12&#39;
                              );</pre>

<p>If you think that you have a problem related to a false match you can check the tokens that you are substituting against as follows.</p>

<pre lang='und' xml:lang='und'>    my $formula = $worksheet-&#62;store_formula(&#39;=A1*5+4&#39;);
    print &#34;@$formula\n&#34;;</pre>

<p>See also the <code lang='und' xml:lang='und'>repeat.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="write_comment($row,_$column,_$string,_...)"
>write_comment($row, $column, $string, ...)</a></h2>

<p>The <code lang='und' xml:lang='und'>write_comment()</code> method is used to add a comment to a cell. A cell comment is indicated in Excel by a small red triangle in the upper right-hand corner of the cell. Moving the cursor over the red triangle will reveal the comment.</p>

<p>The following example shows how to add a comment to a cell:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write        (2, 2, &#39;Hello&#39;);
    $worksheet-&#62;write_comment(2, 2, &#39;This is a comment.&#39;);</pre>

<p>As usual you can replace the <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$column</code> parameters with an <code lang='und' xml:lang='und'>A1</code> cell reference. See the note about <a href="#Cell_notation" class="podlinkpod"
>&#34;Cell notation&#34;</a>.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write        (&#39;C3&#39;, &#39;Hello&#39;);
    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;This is a comment.&#39;);</pre>

<p>On systems with <code lang='und' xml:lang='und'>perl 5.8</code> and later the <code lang='und' xml:lang='und'>write_comment()</code> method will also handle strings in <code lang='und' xml:lang='und'>UTF-8</code> format.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#34;\x{263a}&#34;);       # Smiley
    $worksheet-&#62;write_comment(&#39;C4&#39;, &#39;Comment ca va?&#39;);</pre>

<p>In addition to the basic 3 argument form of <code lang='und' xml:lang='und'>write_comment()</code> you can pass in several optional key/value pairs to control the format of the comment. For example:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, visible =&#62; 1, author =&#62; &#39;Perl&#39;);</pre>

<p>Most of these options are quite specific and in general the default comment behaviour will be all that you need. However, should you need greater control over the format of the cell comment the following options are available:</p>

<pre lang='und' xml:lang='und'>    encoding
    author
    author_encoding
    visible
    x_scale
    width
    y_scale
    height
    color
    start_cell
    start_row
    start_col
    x_offset
    y_offset</pre>

<dl>
<dt><a name="Option:_encoding"
>Option: encoding</a></dt><p class="pad"></p>

<dd>This option is used to indicate that the comment string is encoded as <code lang='und' xml:lang='und'>UTF-16BE</code>.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    my $comment = pack &#39;n&#39;, 0x263a; # UTF-16BE Smiley symbol

    $worksheet-&#62;write_comment(&#39;C3&#39;, $comment, encoding =&#62; 1);</pre>

<dd>If you wish to use Unicode characters in the comment string then the preferred method is to use perl 5.8 and <code lang='und' xml:lang='und'>UTF-8</code> strings, see <a href="#UNICODE_IN_EXCEL" class="podlinkpod"
>&#34;UNICODE IN EXCEL&#34;</a>.</dd><p class="pad"></p>

<dt><a name="Option:_author"
>Option: author</a></dt><p class="pad"></p>

<dd>This option is used to indicate who the author of the comment is. Excel displays the author of the comment in the status bar at the bottom of the worksheet. This is usually of interest in corporate environments where several people might review and provide comments to a workbook.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Atonement&#39;, author =&#62; &#39;Ian McEwan&#39;);</pre>

<dt><a name="Option:_author_encoding"
>Option: author_encoding</a></dt><p class="pad"></p>

<dd>This option is used to indicate that the author string is encoded as <code lang='und' xml:lang='und'>UTF-16BE</code>.</dd><p class="pad"></p>

<dt><a name="Option:_visible"
>Option: visible</a></dt><p class="pad"></p>

<dd>This option is used to make a cell comment visible when the worksheet is opened. The default behaviour in Excel is that comments are initially hidden. However, it is also possible in Excel to make individual or all comments visible. In Spreadsheet::WriteExcel individual comments can be made visible as follows:</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, visible =&#62; 1);</pre>

<dd>It is possible to make all comments in a worksheet visible using the <code lang='und' xml:lang='und'>show_comments()</code> worksheet method (see below). Alternatively, if all of the cell comments have been made visible you can hide individual comments:</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, visible =&#62; 0);</pre>

<dt><a name="Option:_x_scale"
>Option: x_scale</a></dt><p class="pad"></p>

<dd>This option is used to set the width of the cell comment box as a factor of the default width.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, x_scale =&#62; 2);
    $worksheet-&#62;write_comment(&#39;C4&#39;, &#39;Hello&#39;, x_scale =&#62; 4.2);</pre>

<dt><a name="Option:_width"
>Option: width</a></dt><p class="pad"></p>

<dd>This option is used to set the width of the cell comment box explicitly in pixels.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, width =&#62; 200);</pre>

<dt><a name="Option:_y_scale"
>Option: y_scale</a></dt><p class="pad"></p>

<dd>This option is used to set the height of the cell comment box as a factor of the default height.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, y_scale =&#62; 2);
    $worksheet-&#62;write_comment(&#39;C4&#39;, &#39;Hello&#39;, y_scale =&#62; 4.2);</pre>

<dt><a name="Option:_height"
>Option: height</a></dt><p class="pad"></p>

<dd>This option is used to set the height of the cell comment box explicitly in pixels.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, height =&#62; 200);</pre>

<dt><a name="Option:_color"
>Option: color</a></dt><p class="pad"></p>

<dd>This option is used to set the background colour of cell comment box. You can use one of the named colours recognised by Spreadsheet::WriteExcel or a colour index. See <a href="#COLOURS_IN_EXCEL" class="podlinkpod"
>&#34;COLOURS IN EXCEL&#34;</a>.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, color =&#62; &#39;green&#39;);
    $worksheet-&#62;write_comment(&#39;C4&#39;, &#39;Hello&#39;, color =&#62; 0x35);    # Orange</pre>

<dt><a name="Option:_start_cell"
>Option: start_cell</a></dt><p class="pad"></p>

<dd>This option is used to set the cell in which the comment will appear. By default Excel displays comments one cell to the right and one cell above the cell to which the comment relates. However, you can change this behaviour if you wish. In the following example the comment which would appear by default in cell <code lang='und' xml:lang='und'>D2</code> is moved to <code lang='und' xml:lang='und'>E2</code>.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, start_cell =&#62; &#39;E2&#39;);</pre>

<dt><a name="Option:_start_row"
>Option: start_row</a></dt><p class="pad"></p>

<dd>This option is used to set the row in which the comment will appear. See the <code lang='und' xml:lang='und'>start_cell</code> option above. The row is zero indexed.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, start_row =&#62; 0);</pre>

<dt><a name="Option:_start_col"
>Option: start_col</a></dt><p class="pad"></p>

<dd>This option is used to set the column in which the comment will appear. See the <code lang='und' xml:lang='und'>start_cell</code> option above. The column is zero indexed.</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, start_col =&#62; 4);</pre>

<dt><a name="Option:_x_offset"
>Option: x_offset</a></dt><p class="pad"></p>

<dd>This option is used to change the x offset, in pixels, of a comment within a cell:</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, $comment, x_offset =&#62; 30);</pre>

<dt><a name="Option:_y_offset"
>Option: y_offset</a></dt><p class="pad"></p>

<dd>This option is used to change the y offset, in pixels, of a comment within a cell:</dd><p class="pad"></p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, $comment, x_offset =&#62; 30);</pre>
</dl>

<p>You can apply as many of these options as you require.</p>

<p><b>Note about row height and comments</b>. If you specify the height of a row that contains a comment then Spreadsheet::WriteExcel will adjust the height of the comment to maintain the default or user specified dimensions. However, the height of a row can also be adjusted automatically by Excel if the text wrap property is set or large fonts are used in the cell. This means that the height of the row is unknown to WriteExcel at run time and thus the comment box is stretched with the row. Use the <code lang='und' xml:lang='und'>set_row()</code> method to specify the row height explicitly and avoid this problem.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="show_comments()"
>show_comments()</a></h2>

<p>This method is used to make all cell comments visible when a worksheet is opened.</p>

<p>Individual comments can be made visible using the <code lang='und' xml:lang='und'>visible</code> parameter of the <code lang='und' xml:lang='und'>write_comment</code> method (see above):</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, visible =&#62; 1);</pre>

<p>If all of the cell comments have been made visible you can hide individual comments as follows:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_comment(&#39;C3&#39;, &#39;Hello&#39;, visible =&#62; 0);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="add_write_handler($re,_$code_ref)"
>add_write_handler($re, $code_ref)</a></h2>

<p>This method is used to extend the Spreadsheet::WriteExcel write() method to handle user defined data.</p>

<p>If you refer to the section on <code lang='und' xml:lang='und'>write()</code> above you will see that it acts as an alias for several more specific <code lang='und' xml:lang='und'>write_*</code> methods. However, it doesn&#39;t always act in exactly the way that you would like it to.</p>

<p>One solution is to filter the input data yourself and call the appropriate <code lang='und' xml:lang='und'>write_*</code> method. Another approach is to use the <code lang='und' xml:lang='und'>add_write_handler()</code> method to add your own automated behaviour to <code lang='und' xml:lang='und'>write()</code>.</p>

<p>The <code lang='und' xml:lang='und'>add_write_handler()</code> method take two arguments, <code lang='und' xml:lang='und'>$re</code>, a regular expression to match incoming data and <code lang='und' xml:lang='und'>$code_ref</code> a callback function to handle the matched data:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;add_write_handler(qr/^\d\d\d\d$/, \&#38;my_write);</pre>

<p>(In the these examples the <code lang='und' xml:lang='und'>qr</code> operator is used to quote the regular expression strings, see <a href="http://search.cpan.org/perldoc?perlop" class="podlinkpod"
>perlop</a> for more details).</p>

<p>The method is used as follows. say you wished to write 7 digit ID numbers as a string so that any leading zeros were preserved*, you could do something like the following:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;add_write_handler(qr/^\d{7}$/, \&#38;write_my_id);


    sub write_my_id {
        my $worksheet = shift;
        return $worksheet-&#62;write_string(@_);
    }</pre>

<p>* You could also use the <code lang='und' xml:lang='und'>keep_leading_zeros()</code> method for this.</p>

<p>Then if you call <code lang='und' xml:lang='und'>write()</code> with an appropriate string it will be handled automatically:</p>

<pre lang='und' xml:lang='und'>    # Writes 0000000. It would normally be written as a number; 0.
    $worksheet-&#62;write(&#39;A1&#39;, &#39;0000000&#39;);</pre>

<p>The callback function will receive a reference to the calling worksheet and all of the other arguments that were passed to <code lang='und' xml:lang='und'>write()</code>. The callback will see an <code lang='und' xml:lang='und'>@_</code> argument list that looks like the following:</p>

<pre lang='und' xml:lang='und'>    $_[0]   A ref to the calling worksheet. *
    $_[1]   Zero based row number.
    $_[2]   Zero based column number.
    $_[3]   A number or string or token.
    $_[4]   A format ref if any.
    $_[5]   Any other arguments.
    ...

    *  It is good style to shift this off the list so the @_ is the same
       as the argument list seen by write().</pre>

<p>Your callback should <code lang='und' xml:lang='und'>return()</code> the return value of the <code lang='und' xml:lang='und'>write_*</code> method that was called or <code lang='und' xml:lang='und'>undef</code> to indicate that you rejected the match and want <code lang='und' xml:lang='und'>write()</code> to continue as normal.</p>

<p>So for example if you wished to apply the previous filter only to ID values that occur in the first column you could modify your callback function as follows:</p>

<pre lang='und' xml:lang='und'>    sub write_my_id {
        my $worksheet = shift;
        my $col       = $_[1];

        if ($col == 0) {
            return $worksheet-&#62;write_string(@_);
        }
        else {
            # Reject the match and return control to write()
            return undef;
        }
    }</pre>

<p>Now, you will get different behaviour for the first column and other columns:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write(&#39;A1&#39;, &#39;0000000&#39;); # Writes 0000000
    $worksheet-&#62;write(&#39;B1&#39;, &#39;0000000&#39;); # Writes 0</pre>

<p>You may add more than one handler in which case they will be called in the order that they were added.</p>

<p>Note, the <code lang='und' xml:lang='und'>add_write_handler()</code> method is particularly suited for handling dates.</p>

<p>See the <code lang='und' xml:lang='und'>write_handler 1-4</code> programs in the <code lang='und' xml:lang='und'>examples</code> directory for further examples.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="insert_image($row,_$col,_$filename,_$x,_$y,_$scale_x,_$scale_y)"
>insert_image($row, $col, $filename, $x, $y, $scale_x, $scale_y)</a></h2>

<p>This method can be used to insert a image into a worksheet. The image can be in PNG, JPEG or BMP format. The <code lang='und' xml:lang='und'>$x</code>, <code lang='und' xml:lang='und'>$y</code>, <code lang='und' xml:lang='und'>$scale_x</code> and <code lang='und' xml:lang='und'>$scale_y</code> parameters are optional.</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;insert_image(&#39;A1&#39;, &#39;perl.bmp&#39;);
    $worksheet2-&#62;insert_image(&#39;A1&#39;, &#39;../images/perl.bmp&#39;);
    $worksheet3-&#62;insert_image(&#39;A1&#39;, &#39;.c:\images\perl.bmp&#39;);</pre>

<p>The parameters <code lang='und' xml:lang='und'>$x</code> and <code lang='und' xml:lang='und'>$y</code> can be used to specify an offset from the top left hand corner of the cell specified by <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$col</code>. The offset values are in pixels.</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;insert_image(&#39;A1&#39;, &#39;perl.bmp&#39;, 32, 10);</pre>

<p>The default width of a cell is 63 pixels. The default height of a cell is 17 pixels. The pixels offsets can be calculated using the following relationships:</p>

<pre lang='und' xml:lang='und'>    Wp = int(12We)   if We &#60;  1
    Wp = int(7We +5) if We &#62;= 1
    Hp = int(4/3He)

    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>The offsets can be greater than the width or height of the underlying cell. This can be occasionally useful if you wish to align two or more images relative to the same cell.</p>

<p>The parameters <code lang='und' xml:lang='und'>$scale_x</code> and <code lang='und' xml:lang='und'>$scale_y</code> can be used to scale the inserted image horizontally and vertically:</p>

<pre lang='und' xml:lang='und'>    # Scale the inserted image: width x 2.0, height x 0.8
    $worksheet-&#62;insert_image(&#39;A1&#39;, &#39;perl.bmp&#39;, 0, 0, 2, 0.8);</pre>

<p>See also the <code lang='und' xml:lang='und'>images.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<p>Note: you must call <code lang='und' xml:lang='und'>set_row()</code> or <code lang='und' xml:lang='und'>set_column()</code> before <code lang='und' xml:lang='und'>insert_image()</code> if you wish to change the default dimensions of any of the rows or columns that the image occupies. The height of a row can also change if you use a font that is larger than the default. This in turn will affect the scaling of your image. To avoid this you should explicitly set the height of the row using <code lang='und' xml:lang='und'>set_row()</code> if it contains a font size that will change the row height.</p>

<p>BMP images must be 24 bit, true colour, bitmaps. In general it is best to avoid BMP images since they aren&#39;t compressed. The older <code lang='und' xml:lang='und'>insert_bitmap()</code> method is still supported but deprecated.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="embed_chart($row,_$col,_$filename,_$x,_$y,_$scale_x,_$scale_y)"
>embed_chart($row, $col, $filename, $x, $y, $scale_x, $scale_y)</a></h2>

<p>This method can be used to insert a chart into a worksheet. The chart must first be extracted from an existing Excel file. See the separate <code lang='und' xml:lang='und'>Charts</code> documentation.</p>

<p>Here is an example:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;embed_chart(&#39;B2&#39;, &#39;sales_chart.bin&#39;);</pre>

<p>The <code lang='und' xml:lang='und'>$x</code>, <code lang='und' xml:lang='und'>$y</code>, <code lang='und' xml:lang='und'>$scale_x</code> and <code lang='und' xml:lang='und'>$scale_y</code> parameters are optional.</p>

<p>The parameters <code lang='und' xml:lang='und'>$x</code> and <code lang='und' xml:lang='und'>$y</code> can be used to specify an offset from the top left hand corner of the cell specified by <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$col</code>. The offset values are in pixels. See the <code lang='und' xml:lang='und'>insert_image</code> method above for more information on sizes.</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;embed_chart(&#39;B2&#39;, &#39;sales_chart.bin&#39;, 3, 3);</pre>

<p>The parameters <code lang='und' xml:lang='und'>$scale_x</code> and <code lang='und' xml:lang='und'>$scale_y</code> can be used to scale the inserted image horizontally and vertically:</p>

<pre lang='und' xml:lang='und'>    # Scale the width by 120% and the height by 150%
    $worksheet-&#62;embed_chart(&#39;B2&#39;, &#39;sales_chart.bin&#39;, 0, 0, 1.2, 1.5);</pre>

<p>The easiest way to calculate the required scaling is to create a test chart worksheet with Spreadsheet::WriteExcel. Then open the file, select the chart and drag the corner to get the required size. While holding down the mouse the scale of the resized chart is shown to the left of the formula bar.</p>

<p>See also the example programs in the <code lang='und' xml:lang='und'>charts</code> directory of the distro.</p>

<p>Note: you must call <code lang='und' xml:lang='und'>set_row()</code> or <code lang='und' xml:lang='und'>set_column()</code> before <code lang='und' xml:lang='und'>embed_chart()</code> if you wish to change the default dimensions of any of the rows or columns that the chart occupies. The height of a row can also change if you use a font that is larger than the default. This in turn will affect the scaling of your chart. To avoid this you should explicitly set the height of the row using <code lang='und' xml:lang='und'>set_row()</code> if it contains a font size that will change the row height.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="data_validation()"
>data_validation()</a></h2>

<p>The <code lang='und' xml:lang='und'>data_validation()</code> method is used to construct an Excel data validation or to limit the user input to a dropdown list of values.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;B3&#39;,
        {
            validate =&#62; &#39;integer&#39;,
            criteria =&#62; &#39;&#62;&#39;,
            value    =&#62; 100,
        });

    $worksheet-&#62;data_validation(&#39;B5:B9&#39;,
        {
            validate =&#62; &#39;list&#39;,
            value    =&#62; [&#39;open&#39;, &#39;high&#39;, &#39;close&#39;],
        });</pre>

<p>This method contains a lot of parameters and is described in detail in a separate section <a href="#DATA_VALIDATION_IN_EXCEL" class="podlinkpod"
>&#34;DATA VALIDATION IN EXCEL&#34;</a>.</p>

<p>See also the <code lang='und' xml:lang='und'>data_validate.pl</code> program in the examples directory of the distro</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="get_name()"
>get_name()</a></h2>

<p>The <code lang='und' xml:lang='und'>get_name()</code> method is used to retrieve the name of a worksheet. For example:</p>

<pre lang='und' xml:lang='und'>    foreach my $sheet ($workbook-&#62;sheets()) {
        print $sheet-&#62;get_name();
    }</pre>

<p>For reasons related to the design of Spreadsheet::WriteExcel and to the internals of Excel there is no <code lang='und' xml:lang='und'>set_name()</code> method. The only way to set the worksheet name is via the <code lang='und' xml:lang='und'>add_worksheet()</code> method.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="activate()"
>activate()</a></h2>

<p>The <code lang='und' xml:lang='und'>activate()</code> method is used to specify which worksheet is initially visible in a multi-sheet workbook:</p>

<pre lang='und' xml:lang='und'>    $worksheet1 = $workbook-&#62;add_worksheet(&#39;To&#39;);
    $worksheet2 = $workbook-&#62;add_worksheet(&#39;the&#39;);
    $worksheet3 = $workbook-&#62;add_worksheet(&#39;wind&#39;);

    $worksheet3-&#62;activate();</pre>

<p>This is similar to the Excel VBA activate method. More than one worksheet can be selected via the <code lang='und' xml:lang='und'>select()</code> method, see below, however only one worksheet can be active.</p>

<p>The default active worksheet is the first worksheet.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="select()"
>select()</a></h2>

<p>The <code lang='und' xml:lang='und'>select()</code> method is used to indicate that a worksheet is selected in a multi-sheet workbook:</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;activate();
    $worksheet2-&#62;select();
    $worksheet3-&#62;select();</pre>

<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 lang='und' xml:lang='und'>activate()</code> method will also appear as selected.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="hide()"
>hide()</a></h2>

<p>The <code lang='und' xml:lang='und'>hide()</code> method is used to hide a worksheet:</p>

<pre lang='und' xml:lang='und'>    $worksheet2-&#62;hide();</pre>

<p>You may wish to hide a worksheet in order to avoid confusing a user with intermediate data or calculations.</p>

<p>A hidden worksheet can not be activated or selected so this method is mutually exclusive with the <code lang='und' xml:lang='und'>activate()</code> and <code lang='und' xml:lang='und'>select()</code> methods. In addition, since the first worksheet will default to being the active worksheet, you cannot hide the first worksheet without activating another sheet:</p>

<pre lang='und' xml:lang='und'>    $worksheet2-&#62;activate();
    $worksheet1-&#62;hide();</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_first_sheet()"
>set_first_sheet()</a></h2>

<p>The <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>set_first_sheet()</code>:</p>

<pre lang='und' xml:lang='und'>    for (1..20) {
        $workbook-&#62;add_worksheet;
    }

    $worksheet21 = $workbook-&#62;add_worksheet();
    $worksheet22 = $workbook-&#62;add_worksheet();

    $worksheet21-&#62;set_first_sheet();
    $worksheet22-&#62;activate();</pre>

<p>This method is not required very often. The default value is the first worksheet.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="protect($password)"
>protect($password)</a></h2>

<p>The <code lang='und' xml:lang='und'>protect()</code> method is used to protect a worksheet from modification:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;protect();</pre>

<p>It can be turned off in Excel via the <code lang='und' xml:lang='und'>Tools-&#62;Protection-&#62;Unprotect Sheet</code> menu command.</p>

<p>The <code lang='und' xml:lang='und'>protect()</code> method also has the effect of enabling a cell&#39;s <code lang='und' xml:lang='und'>locked</code> and <code lang='und' xml:lang='und'>hidden</code> properties if they have been set. A &#34;locked&#34; cell cannot be edited. A &#34;hidden&#34; cell will display the results of a formula but not the formula itself. In Excel a cell&#39;s locked property is on by default.</p>

<pre lang='und' xml:lang='und'>    # Set some format properties
    my $unlocked  = $workbook-&#62;add_format(locked =&#62; 0);
    my $hidden    = $workbook-&#62;add_format(hidden =&#62; 1);

    # Enable worksheet protection
    $worksheet-&#62;protect();

    # This cell cannot be edited, it is locked by default
    $worksheet-&#62;write(&#39;A1&#39;, &#39;=1+2&#39;);

    # This cell can be edited
    $worksheet-&#62;write(&#39;A2&#39;, &#39;=1+2&#39;, $unlocked);

    # The formula in this cell isn&#39;t visible
    $worksheet-&#62;write(&#39;A3&#39;, &#39;=1+2&#39;, $hidden);</pre>

<p>See also the <code lang='und' xml:lang='und'>set_locked</code> and <code lang='und' xml:lang='und'>set_hidden</code> format methods in <a href="#CELL_FORMATTING" class="podlinkpod"
>&#34;CELL FORMATTING&#34;</a>.</p>

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

<pre lang='und' xml:lang='und'>    $worksheet-&#62;protect(&#39;drowssap&#39;);</pre>

<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&#39;s own workbook level password protection does provide strong encryption in Excel 97+. For technical reasons this will never be supported by <code lang='und' xml:lang='und'>Spreadsheet::WriteExcel</code>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_selection($first_row,_$first_col,_$last_row,_$last_col)"
>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 lang='und' xml:lang='und'>$last_row</code> and <code lang='und' xml:lang='und'>$last_col</code> can be omitted. The active cell within a selected range is determined by the order in which <code lang='und' xml:lang='und'>$first</code> and <code lang='und' xml:lang='und'>$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" class="podlinkpod"
>&#34;Cell notation&#34;</a>.</p>

<p>Examples:</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;set_selection(3, 3);       # 1. Cell D4.
    $worksheet2-&#62;set_selection(3, 3, 6, 6); # 2. Cells D4 to G7.
    $worksheet3-&#62;set_selection(6, 6, 3, 3); # 3. Cells G7 to D4.
    $worksheet4-&#62;set_selection(&#39;D4&#39;);       # Same as 1.
    $worksheet5-&#62;set_selection(&#39;D4:G7&#39;);    # Same as 2.
    $worksheet6-&#62;set_selection(&#39;G7:D4&#39;);    # Same as 3.</pre>

<p>The default cell selections is (0, 0), &#39;A1&#39;.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_row($row,_$height,_$format,_$hidden,_$level,_$collapsed)"
>set_row($row, $height, $format, $hidden, $level, $collapsed)</a></h2>

<p>This method can be used to change the default properties of a row. All parameters apart from <code lang='und' xml:lang='und'>$row</code> are optional.</p>

<p>The most common use for this method is to change the height of a row:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(0, 20); # Row 1 height set to 20</pre>

<p>If you wish to set the format without changing the height you can pass <code lang='und' xml:lang='und'>undef</code> as the height parameter:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(0, undef, $format);</pre>

<p>The <code lang='und' xml:lang='und'>$format</code> parameter will be applied to any cells in the row that don&#39;t have a format. For example</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(0, undef, $format1);    # Set the format for row 1
    $worksheet-&#62;write(&#39;A1&#39;, &#39;Hello&#39;);           # Defaults to $format1
    $worksheet-&#62;write(&#39;B1&#39;, &#39;Hello&#39;, $format2); # Keeps $format2</pre>

<p>If you wish to define a row format in this way you should call the method before any calls to <code lang='und' xml:lang='und'>write()</code>. Calling it afterwards will overwrite any format that was previously specified.</p>

<p>The <code lang='und' xml:lang='und'>$hidden</code> parameter should be set to 1 if you wish to hide a row. This can be used, for example, to hide intermediary steps in a complicated calculation:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(0, 20,    $format, 1);
    $worksheet-&#62;set_row(1, undef, undef,   1);</pre>

<p>The <code lang='und' xml:lang='und'>$level</code> parameter is used to set the outline level of the row. Outlines are described in <a href="#OUTLINES_AND_GROUPING_IN_EXCEL" class="podlinkpod"
>&#34;OUTLINES AND GROUPING IN EXCEL&#34;</a>. Adjacent rows with the same outline level are grouped together into a single outline.</p>

<p>The following example sets an outline level of 1 for rows 1 and 2 (zero-indexed):</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(1, undef, undef, 0, 1);
    $worksheet-&#62;set_row(2, undef, undef, 0, 1);</pre>

<p>The <code lang='und' xml:lang='und'>$hidden</code> parameter can also be used to hide collapsed outlined rows when used in conjunction with the <code lang='und' xml:lang='und'>$level</code> parameter.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(1, undef, undef, 1, 1);
    $worksheet-&#62;set_row(2, undef, undef, 1, 1);</pre>

<p>For collapsed outlines you should also indicate which row has the collapsed <code lang='und' xml:lang='und'>+</code> symbol using the optional <code lang='und' xml:lang='und'>$collapsed</code> parameter.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(3, undef, undef, 0, 0, 1);</pre>

<p>For a more complete example see the <code lang='und' xml:lang='und'>outline.pl</code> and <code lang='und' xml:lang='und'>outline_collapsed.pl</code> programs in the examples directory of the distro.</p>

<p>Excel allows up to 7 outline levels. Therefore the <code lang='und' xml:lang='und'>$level</code> parameter should be in the range <code lang='und' xml:lang='und'>0 &#60;= $level &#60;= 7</code>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_column($first_col,_$last_col,_$width,_$format,_$hidden,_$level,_$collapsed)"
>set_column($first_col, $last_col, $width, $format, $hidden, $level, $collapsed)</a></h2>

<p>This method can be used to change the default properties of a single column or a range of columns. All parameters apart from <code lang='und' xml:lang='und'>$first_col</code> and <code lang='und' xml:lang='und'>$last_col</code> are optional.</p>

<p>If <code lang='und' xml:lang='und'>set_column()</code> is applied to a single column the value of <code lang='und' xml:lang='und'>$first_col</code> and <code lang='und' xml:lang='und'>$last_col</code> should be the same. In the case where <code lang='und' xml:lang='und'>$last_col</code> is zero it is set to the same value as <code lang='und' xml:lang='und'>$first_col</code>.</p>

<p>It is also possible, and generally clearer, to specify a column range using the form of A1 notation used for columns. See the note about <a href="#Cell_notation" class="podlinkpod"
>&#34;Cell notation&#34;</a>.</p>

<p>Examples:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_column(0, 0,  20); # Column  A   width set to 20
    $worksheet-&#62;set_column(1, 3,  30); # Columns B-D width set to 30
    $worksheet-&#62;set_column(&#39;E:E&#39;, 20); # Column  E   width set to 20
    $worksheet-&#62;set_column(&#39;F:H&#39;, 30); # Columns F-H width set to 30</pre>

<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 &#34;AutoFit&#34; for a column in the Excel file format. This feature is only available at runtime from within Excel.</p>

<p>As usual the <code lang='und' xml:lang='und'>$format</code> parameter is optional, for additional information, see <a href="#CELL_FORMATTING" class="podlinkpod"
>&#34;CELL FORMATTING&#34;</a>. If you wish to set the format without changing the width you can pass <code lang='und' xml:lang='und'>undef</code> as the width parameter:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_column(0, 0, undef, $format);</pre>

<p>The <code lang='und' xml:lang='und'>$format</code> parameter will be applied to any cells in the column that don&#39;t have a format. For example</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_column(&#39;A:A&#39;, undef, $format1); # Set format for col 1
    $worksheet-&#62;write(&#39;A1&#39;, &#39;Hello&#39;);               # Defaults to $format1
    $worksheet-&#62;write(&#39;A2&#39;, &#39;Hello&#39;, $format2);     # Keeps $format2</pre>

<p>If you wish to define a column format in this way you should call the method before any calls to <code lang='und' xml:lang='und'>write()</code>. If you call it afterwards it won&#39;t have any effect.</p>

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

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(0, undef,        $format1); # Set format for row 1
    $worksheet-&#62;set_column(&#39;A:A&#39;, undef, $format2); # Set format for col 1
    $worksheet-&#62;write(&#39;A1&#39;, &#39;Hello&#39;);               # Defaults to $format1
    $worksheet-&#62;write(&#39;A2&#39;, &#39;Hello&#39;);               # Defaults to $format2</pre>

<p>The <code lang='und' xml:lang='und'>$hidden</code> parameter should be set to 1 if you wish to hide a column. This can be used, for example, to hide intermediary steps in a complicated calculation:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_column(&#39;D:D&#39;, 20,    $format, 1);
    $worksheet-&#62;set_column(&#39;E:E&#39;, undef, undef,   1);</pre>

<p>The <code lang='und' xml:lang='und'>$level</code> parameter is used to set the outline level of the column. Outlines are described in <a href="#OUTLINES_AND_GROUPING_IN_EXCEL" class="podlinkpod"
>&#34;OUTLINES AND GROUPING IN EXCEL&#34;</a>. Adjacent columns with the same outline level are grouped together into a single outline.</p>

<p>The following example sets an outline level of 1 for columns B to G:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_column(&#39;B:G&#39;, undef, undef, 0, 1);</pre>

<p>The <code lang='und' xml:lang='und'>$hidden</code> parameter can also be used to hide collapsed outlined columns when used in conjunction with the <code lang='und' xml:lang='und'>$level</code> parameter.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_column(&#39;B:G&#39;, undef, undef, 1, 1);</pre>

<p>For collapsed outlines you should also indicate which row has the collapsed <code lang='und' xml:lang='und'>+</code> symbol using the optional <code lang='und' xml:lang='und'>$collapsed</code> parameter.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_column(&#39;H:H&#39;, undef, undef, 0, 0, 1);</pre>

<p>For a more complete example see the <code lang='und' xml:lang='und'>outline.pl</code> and <code lang='und' xml:lang='und'>outline_collapsed.pl</code> programs in the examples directory of the distro.</p>

<p>Excel allows up to 7 outline levels. Therefore the <code lang='und' xml:lang='und'>$level</code> parameter should be in the range <code lang='und' xml:lang='und'>0 &#60;= $level &#60;= 7</code>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="outline_settings($visible,_$symbols_below,_$symbols_right,_$auto_style)"
>outline_settings($visible, $symbols_below, $symbols_right, $auto_style)</a></h2>

<p>The <code lang='und' xml:lang='und'>outline_settings()</code> method is used to control the appearance of outlines in Excel. Outlines are described in <a href="#OUTLINES_AND_GROUPING_IN_EXCEL" class="podlinkpod"
>&#34;OUTLINES AND GROUPING IN EXCEL&#34;</a>.</p>

<p>The <code lang='und' xml:lang='und'>$visible</code> parameter is used to control whether or not outlines are visible. Setting this parameter to 0 will cause all outlines on the worksheet to be hidden. They can be unhidden in Excel by means of the &#34;Show Outline Symbols&#34; command button. The default setting is 1 for visible outlines.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;outline_settings(0);</pre>

<p>The <code lang='und' xml:lang='und'>$symbols_below</code> parameter is used to control whether the row outline symbol will appear above or below the outline level bar. The default setting is 1 for symbols to appear below the outline level bar.</p>

<p>The <code lang='und' xml:lang='und'>symbols_right</code> parameter is used to control whether the column outline symbol will appear to the left or the right of the outline level bar. The default setting is 1 for symbols to appear to the right of the outline level bar.</p>

<p>The <code lang='und' xml:lang='und'>$auto_style</code> parameter is used to control whether the automatic outline generator in Excel uses automatic styles when creating an outline. This has no effect on a file generated by <code lang='und' xml:lang='und'>Spreadsheet::WriteExcel</code> but it does have an effect on how the worksheet behaves after it is created. The default setting is 0 for &#34;Automatic Styles&#34; to be turned off.</p>

<p>The default settings for all of these parameters correspond to Excel&#39;s default parameters.</p>

<p>The worksheet parameters controlled by <code lang='und' xml:lang='und'>outline_settings()</code> are rarely used.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="freeze_panes($row,_$col,_$top_row,_$left_col)"
>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 &#34;freeze&#34; these panes so that the splitter bars are not visible. This is the same as the <code lang='und' xml:lang='und'>Window-&#62;Freeze Panes</code> menu command in Excel</p>

<p>The parameters <code lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$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 lang='und' xml:lang='und'>$row</code> and <code lang='und' xml:lang='und'>$col</code> parameters as zero if you do not want either a vertical or horizontal split.</p>

<p>Examples:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;freeze_panes(1, 0); # Freeze the first row
    $worksheet-&#62;freeze_panes(&#39;A2&#39;); # Same using A1 notation
    $worksheet-&#62;freeze_panes(0, 1); # Freeze the first column
    $worksheet-&#62;freeze_panes(&#39;B1&#39;); # Same using A1 notation
    $worksheet-&#62;freeze_panes(1, 2); # Freeze first row and first 2 columns
    $worksheet-&#62;freeze_panes(&#39;C2&#39;); # Same using A1 notation</pre>

<p>The parameters <code lang='und' xml:lang='und'>$top_row</code> and <code lang='und' xml:lang='und'>$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>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;freeze_panes(1, 0, 20, 0);</pre>

<p>You cannot use A1 notation for the <code lang='und' xml:lang='und'>$top_row</code> and <code lang='und' xml:lang='und'>$left_col</code> parameters.</p>

<p>See also the <code lang='und' xml:lang='und'>panes.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distribution.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="split_panes($y,_$x,_$top_row,_$left_col)"
>split_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 lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>$y</code> and <code lang='und' xml:lang='und'>$x</code> are used to specify the vertical and horizontal position of the split. The units for <code lang='und' xml:lang='und'>$y</code> and <code lang='und' xml:lang='und'>$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 lang='und' xml:lang='und'>$y</code> and <code lang='und' xml:lang='und'>$x</code> parameters in terms of the row heights and column widths that you have set or the default values which are <code lang='und' xml:lang='und'>12.75</code> for a row and <code lang='und' xml:lang='und'>8.43</code> for a column.</p>

<p>You can set one of the <code lang='und' xml:lang='und'>$y</code> and <code lang='und' xml:lang='und'>$x</code> parameters as zero if you do not want either a vertical or horizontal split. The parameters <code lang='und' xml:lang='und'>$top_row</code> and <code lang='und' xml:lang='und'>$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>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;split_panes(12.75, 0,    1, 0); # First row
    $worksheet-&#62;split_panes(0,     8.43, 0, 1); # First column
    $worksheet-&#62;split_panes(12.75, 8.43, 1, 1); # First row and column</pre>

<p>You cannot use A1 notation with this method.</p>

<p>See also the <code lang='und' xml:lang='und'>freeze_panes()</code> method and the <code lang='und' xml:lang='und'>panes.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distribution.</p>

<p>Note: This <code lang='und' xml:lang='und'>split_panes()</code> method was called <code lang='und' xml:lang='und'>thaw_panes()</code> in older versions. The older name is still available for backwards compatibility.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="merge_range($first_row,_$first_col,_$last_row,_$last_col,_$token,_$format,_$utf_16_be)"
>merge_range($first_row, $first_col, $last_row, $last_col, $token, $format, $utf_16_be)</a></h2>

<p>Merging cells can be achieved by setting the <code lang='und' xml:lang='und'>merge</code> property of a Format object, see <a href="#CELL_FORMATTING" class="podlinkpod"
>&#34;CELL FORMATTING&#34;</a>. However, this only allows simple Excel5 style horizontal merging which Excel refers to as &#34;center across selection&#34;.</p>

<p>The <code lang='und' xml:lang='und'>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>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format(
                                        border  =&#62; 6,
                                        valign  =&#62; &#39;vcenter&#39;,
                                        align   =&#62; &#39;center&#39;,
                                      );

    $worksheet-&#62;merge_range(&#39;B3:D4&#39;, &#39;Vertical and horizontal&#39;, $format);</pre>

<p><b>WARNING</b>. The format object that is used with a <code lang='und' xml:lang='und'>merge_range()</code> method call is marked internally as being associated with a merged range. It is a fatal error to use a merged format in a non-merged cell. Instead you should use separate formats for merged and non-merged cells. This restriction will be removed in a future release.</p>

<p>The <code lang='und' xml:lang='und'>$utf_16_be</code> parameter is optional, see below.</p>

<p><code lang='und' xml:lang='und'>merge_range()</code> writes its <code lang='und' xml:lang='und'>$token</code> argument using the worksheet <code lang='und' xml:lang='und'>write()</code> method. Therefore it will handle numbers, strings, formulas or urls as required.</p>

<p>Setting the <code lang='und' xml:lang='und'>merge</code> property of the format isn&#39;t required when you are using <code lang='und' xml:lang='und'>merge_range()</code>. In fact using it will exclude the use of any other horizontal alignment option.</p>

<p>On systems with <code lang='und' xml:lang='und'>perl 5.8</code> and later the <code lang='und' xml:lang='und'>merge_range()</code> method will also handle strings in <code lang='und' xml:lang='und'>UTF-8</code> format.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;merge_range(&#39;B3:D4&#39;, &#34;\x{263a}&#34;, $format); # Smiley</pre>

<p>On earlier Perl systems your can specify <code lang='und' xml:lang='und'>UTF-16BE</code> worksheet names using an additional optional parameter:</p>

<pre lang='und' xml:lang='und'>    my $str = pack &#39;n&#39;, 0x263a;
    $worksheet-&#62;merge_range(&#39;B3:D4&#39;, $str, $format, 1); # Smiley</pre>

<p>The full possibilities of this method are shown in the <code lang='und' xml:lang='und'>merge3.pl</code> to <code lang='und' xml:lang='und'>merge6.pl</code> programs in the <code lang='und' xml:lang='und'>examples</code> directory of the distribution.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_zoom($scale)"
>set_zoom($scale)</a></h2>

<p>Set the worksheet zoom factor in the range <code lang='und' xml:lang='und'>10 &#60;= $scale &#60;= 400</code>:</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;set_zoom(50);
    $worksheet2-&#62;set_zoom(75);
    $worksheet3-&#62;set_zoom(300);
    $worksheet4-&#62;set_zoom(400);</pre>

<p>The default zoom factor is 100. You cannot zoom to &#34;Selection&#34; because it is calculated by Excel at run-time.</p>

<p>Note, <code lang='und' xml:lang='und'>set_zoom()</code> does not affect the scale of the printed page. For that you should use <code lang='und' xml:lang='und'>set_print_scale()</code>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="right_to_left()"
>right_to_left()</a></h2>

<p>The <code lang='und' xml:lang='und'>right_to_left()</code> method is used to change the default direction of the worksheet from left-to-right, with the A1 cell in the top left, to right-to-left, with the he A1 cell in the top right.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;right_to_left();</pre>

<p>This is useful when creating Arabic, Hebrew or other near or far eastern worksheets that use right-to-left as the default direction.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="hide_zero()"
>hide_zero()</a></h2>

<p>The <code lang='und' xml:lang='und'>hide_zero()</code> method is used to hide any zero values that appear in cells.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;hide_zero();</pre>

<p>In Excel this option is found under Tools-&#62;Options-&#62;View.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_tab_color()"
>set_tab_color()</a></h2>

<p>The <code lang='und' xml:lang='und'>set_tab_color()</code> method is used to change the colour of the worksheet tab. This feature is only available in Excel 2002 and later. You can use one of the standard colour names provided by the Format object or a colour index. See <a href="#COLOURS_IN_EXCEL" class="podlinkpod"
>&#34;COLOURS IN EXCEL&#34;</a> and the <code lang='und' xml:lang='und'>set_custom_color()</code> method.</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;set_tab_color(&#39;red&#39;);
    $worksheet2-&#62;set_tab_color(0x0C);</pre>

<p>See the <code lang='und' xml:lang='und'>tab_colors.pl</code> program in the examples directory of the distro.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="autofilter($first_row,_$first_col,_$last_row,_$last_col)"
>autofilter($first_row, $first_col, $last_row, $last_col)</a></h2>

<p>This method allows an autofilter to be added to a worksheet. An autofilter is a way of adding drop down lists to the headers of a 2D range of worksheet data. This is turn allow users to filter the data based on simple criteria so that some data is highlighted and some is hidden.</p>

<p>To add an autofilter to a worksheet:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;autofilter(0, 0, 10, 3);
    $worksheet-&#62;autofilter(&#39;A1:D11&#39;);    # Same as above in A1 notation.</pre>

<p>Filter conditions can be applied using the <code lang='und' xml:lang='und'>filter_column()</code> method.</p>

<p>See the <code lang='und' xml:lang='und'>autofilter.pl</code> program in the examples directory of the distro for a more detailed example.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="filter_column($column,_$expression)"
>filter_column($column, $expression)</a></h2>

<p>The <code lang='und' xml:lang='und'>filter_column</code> method can be used to filter columns in a autofilter range based on simple conditions.</p>

<p><b>NOTE:</b> It isn&#39;t sufficient to just specify the filter condition. You must also hide any rows that don&#39;t match the filter condition. Rows are hidden using the <code lang='und' xml:lang='und'>set_row()</code> <code lang='und' xml:lang='und'>visible</code> parameter. <code lang='und' xml:lang='und'>Spreadsheet::WriteExcel</code> cannot do this automatically since it isn&#39;t part of the file format. See the <code lang='und' xml:lang='und'>autofilter.pl</code> program in the examples directory of the distro for an example.</p>

<p>The conditions for the filter are specified using simple expressions:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;filter_column(&#39;A&#39;, &#39;x &#62; 2000&#39;);
    $worksheet-&#62;filter_column(&#39;B&#39;, &#39;x &#62; 2000 and x &#60; 5000&#39;);</pre>

<p>The <code lang='und' xml:lang='und'>$column</code> parameter can either be a zero indexed column number or a string column name.</p>

<p>The following operators are available:</p>

<pre lang='und' xml:lang='und'>    Operator        Synonyms
       ==           =   eq  =~
       !=           &#60;&#62;  ne  !=
       &#62;
       &#60;
       &#62;=
       &#60;=

       and          &#38;&#38;
       or           ||</pre>

<p>The operator synonyms are just syntactic sugar to make you more comfortable using the expressions. It is important to remember that the expressions will be interpreted by Excel and not by perl.</p>

<p>An expression can comprise a single statement or two statements separated by the <code lang='und' xml:lang='und'>and</code> and <code lang='und' xml:lang='und'>or</code> operators. For example:</p>

<pre lang='und' xml:lang='und'>    &#39;x &#60;  2000&#39;
    &#39;x &#62;  2000&#39;
    &#39;x == 2000&#39;
    &#39;x &#62;  2000 and x &#60;  5000&#39;
    &#39;x == 2000 or  x == 5000&#39;</pre>

<p>Filtering of blank or non-blank data can be achieved by using a value of <code lang='und' xml:lang='und'>Blanks</code> or <code lang='und' xml:lang='und'>NonBlanks</code> in the expression:</p>

<pre lang='und' xml:lang='und'>    &#39;x == Blanks&#39;
    &#39;x == NonBlanks&#39;</pre>

<p>Top 10 style filters can be specified using a expression like the following:</p>

<pre lang='und' xml:lang='und'>    Top|Bottom 1-500 Items|%</pre>

<p>For example:</p>

<pre lang='und' xml:lang='und'>    &#39;Top    10 Items&#39;
    &#39;Bottom  5 Items&#39;
    &#39;Top    25 %&#39;
    &#39;Bottom 50 %&#39;</pre>

<p>Excel also allows some simple string matching operations:</p>

<pre lang='und' xml:lang='und'>    &#39;x =~ b*&#39;   # begins with b
    &#39;x !~ b*&#39;   # doesn&#39;t begin with b
    &#39;x =~ *b&#39;   # ends with b
    &#39;x !~ *b&#39;   # doesn&#39;t end with b
    &#39;x =~ *b*&#39;  # contains b
    &#39;x !~ *b*&#39;  # doesn&#39;t contains b</pre>

<p>You can also use <code lang='und' xml:lang='und'>*</code> to match any character or number and <code lang='und' xml:lang='und'>?</code> to match any single character or number. No other regular expression quantifier is supported by Excel&#39;s filters. Excel&#39;s regular expression characters can be escaped using <code lang='und' xml:lang='und'>~</code>.</p>

<p>The placeholder variable <code lang='und' xml:lang='und'>x</code> in the above examples can be replaced by any simple string. The actual placeholder name is ignored internally so the following are all equivalent:</p>

<pre lang='und' xml:lang='und'>    &#39;x     &#60; 2000&#39;
    &#39;col   &#60; 2000&#39;
    &#39;Price &#60; 2000&#39;</pre>

<p>Also, note that a filter condition can only be applied to a column in a range specified by the <code lang='und' xml:lang='und'>autofilter()</code> Worksheet method.</p>

<p>See the <code lang='und' xml:lang='und'>autofilter.pl</code> program in the examples directory of the distro for a more detailed example.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    set_landscape()
    set_portrait()
    set_page_view()
    set_paper()
    center_horizontally()
    center_vertically()
    set_margins()
    set_header()
    set_footer()
    repeat_rows()
    repeat_columns()
    hide_gridlines()
    print_row_col_headers()
    print_area()
    print_across()
    fit_to_pages()
    set_start_page()
    set_print_scale()
    set_h_pagebreaks()
    set_v_pagebreaks()</pre>

<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 lang='und' xml:lang='und'>sheets()</code> method of the <code lang='und' xml:lang='und'>workbook</code> class to access the array of worksheets in a workbook:</p>

<pre lang='und' xml:lang='und'>    foreach $worksheet ($workbook-&#62;sheets()) {
       $worksheet-&#62;set_landscape();
    }</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_landscape()"
>set_landscape()</a></h2>

<p>This method is used to set the orientation of a worksheet&#39;s printed page to landscape:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_landscape(); # Landscape mode</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_portrait()"
>set_portrait()</a></h2>

<p>This method is used to set the orientation of a worksheet&#39;s printed page to portrait. The default worksheet orientation is portrait, so you won&#39;t generally need to call this method.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_portrait(); # Portrait mode</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_page_view()"
>set_page_view()</a></h2>

<p>This method is used to display the worksheet in &#34;Page View&#34; mode. This is currently only supported by Mac Excel, where it is the default.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_page_view();</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    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>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&#39;s printer supports. Therefore, it is best to stick to standard paper types.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_paper(1); # US Letter
    $worksheet-&#62;set_paper(9); # A4</pre>

<p>If you do not specify a paper type the worksheet will print using the printer&#39;s default paper.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="center_horizontally()"
>center_horizontally()</a></h2>

<p>Center the worksheet data horizontally between the margins on the printed page:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;center_horizontally();</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="center_vertically()"
>center_vertically()</a></h2>

<p>Center the worksheet data vertically between the margins on the printed page:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;center_vertically();</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    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>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>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_header($string,_$margin)"
>set_header($string, $margin)</a></h2>

<p>Headers and footers are generated using a <code lang='und' xml:lang='und'>$string</code> which is a combination of plain text and control characters. The <code lang='und' xml:lang='und'>$margin</code> parameter is optional.</p>

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

<pre lang='und' xml:lang='und'>    Control             Category            Description
    =======             ========            ===========
    &#38;L                  Justification       Left
    &#38;C                                      Center
    &#38;R                                      Right

    &#38;P                  Information         Page number
    &#38;N                                      Total number of pages
    &#38;D                                      Date
    &#38;T                                      Time
    &#38;F                                      File name
    &#38;A                                      Worksheet name
    &#38;Z                                      Workbook path

    &#38;fontsize           Font                Font size
    &#38;&#34;font,style&#34;                           Font name and style
    &#38;U                                      Single underline
    &#38;E                                      Double underline
    &#38;S                                      Strikethrough
    &#38;X                                      Superscript
    &#38;Y                                      Subscript

    &#38;&#38;                  Miscellaneous       Literal ampersand &#38;</pre>

<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 lang='und' xml:lang='und'>&#38;L</code>, <code lang='und' xml:lang='und'>&#38;C</code> and <code lang='und' xml:lang='und'>&#38;R</code>.</p>

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

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_header(&#39;&#38;LHello&#39;);

     ---------------------------------------------------------------
    |                                                               |
    | Hello                                                         |
    |                                                               |


    $worksheet-&#62;set_header(&#39;&#38;CHello&#39;);

     ---------------------------------------------------------------
    |                                                               |
    |                          Hello                                |
    |                                                               |


    $worksheet-&#62;set_header(&#39;&#38;RHello&#39;);

     ---------------------------------------------------------------
    |                                                               |
    |                                                         Hello |
    |                                                               |</pre>

<p>For simple text, if you do not specify any justification the text will be centred. However, you must prefix the text with <code lang='und' xml:lang='und'>&#38;C</code> if you specify a font name or any other formatting:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_header(&#39;Hello&#39;);

     ---------------------------------------------------------------
    |                                                               |
    |                          Hello                                |
    |                                                               |</pre>

<p>You can have text in each of the justification regions:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_header(&#39;&#38;LCiao&#38;CBello&#38;RCielo&#39;);

     ---------------------------------------------------------------
    |                                                               |
    | Ciao                     Bello                          Cielo |
    |                                                               |</pre>

<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>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_header(&#39;&#38;CPage &#38;P of &#38;N&#39;);

     ---------------------------------------------------------------
    |                                                               |
    |                        Page 1 of 6                            |
    |                                                               |


    $worksheet-&#62;set_header(&#39;&#38;CUpdated at &#38;T&#39;);

     ---------------------------------------------------------------
    |                                                               |
    |                    Updated at 12:30 PM                        |
    |                                                               |</pre>

<p>You can specify the font size of a section of the text by prefixing it with the control character <code lang='und' xml:lang='und'>&#38;n</code> where <code lang='und' xml:lang='und'>n</code> is the font size:</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;set_header(&#39;&#38;C&#38;30Hello Big&#39;  );
    $worksheet2-&#62;set_header(&#39;&#38;C&#38;10Hello Small&#39;);</pre>

<p>You can specify the font of a section of the text by prefixing it with the control sequence <code lang='und' xml:lang='und'>&#38;&#34;font,style&#34;</code> where <code lang='und' xml:lang='und'>fontname</code> is a font name such as &#34;Courier New&#34; or &#34;Times New Roman&#34; and <code lang='und' xml:lang='und'>style</code> is one of the standard Windows font descriptions: &#34;Regular&#34;, &#34;Italic&#34;, &#34;Bold&#34; or &#34;Bold Italic&#34;:</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;set_header(&#39;&#38;C&#38;&#34;Courier New,Italic&#34;Hello&#39;);
    $worksheet2-&#62;set_header(&#39;&#38;C&#38;&#34;Courier New,Bold Italic&#34;Hello&#39;);
    $worksheet3-&#62;set_header(&#39;&#38;C&#38;&#34;Times New Roman,Regular&#34;Hello&#39;);</pre>

<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 lang='und' xml:lang='und'>&#34;&#34;</code> to indicate a single double quote. For the last example above the equivalent VBA code looks like this:</p>

<pre lang='und' xml:lang='und'>    .LeftHeader   = &#34;&#34;
    .CenterHeader = &#34;&#38;&#34;&#34;Times New Roman,Regular&#34;&#34;Hello&#34;
    .RightHeader  = &#34;&#34;</pre>

<p>To include a single literal ampersand <code lang='und' xml:lang='und'>&#38;</code> in a header or footer you should use a double ampersand <code lang='und' xml:lang='und'>&#38;&#38;</code>:</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;set_header(&#39;&#38;CCuriouser &#38;&#38; Curiouser - Attorneys at Law&#39;);</pre>

<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>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_header(&#39;&#38;CHello&#39;, 0.75);</pre>

<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>On systems with <code lang='und' xml:lang='und'>perl 5.8</code> and later the <code lang='und' xml:lang='und'>set_header()</code> method can also handle Unicode strings in <code lang='und' xml:lang='und'>UTF-8</code> format.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_header(&#34;&#38;C\x{263a}&#34;)</pre>

<p>See, also the <code lang='und' xml:lang='und'>headers.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distribution.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_footer()"
>set_footer()</a></h2>

<p>The syntax of the <code lang='und' xml:lang='und'>set_footer()</code> method is the same as <code lang='und' xml:lang='und'>set_header()</code>, see above.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="repeat_rows($first_row,_$last_row)"
>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 lang='und' xml:lang='und'>repeat_rows()</code> method. The parameters <code lang='und' xml:lang='und'>$first_row</code> and <code lang='und' xml:lang='und'>$last_row</code> are zero based. The <code lang='und' xml:lang='und'>$last_row</code> parameter is optional if you only wish to specify one row:</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;repeat_rows(0);    # Repeat the first row
    $worksheet2-&#62;repeat_rows(0, 1); # Repeat the first two rows</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="repeat_columns($first_col,_$last_col)"
>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 lang='und' xml:lang='und'>repeat_columns()</code> method. The parameters <code lang='und' xml:lang='und'>$first_column</code> and <code lang='und' xml:lang='und'>$last_column</code> are zero based. The <code lang='und' xml:lang='und'>$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" class="podlinkpod"
>&#34;Cell notation&#34;</a>.</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;repeat_columns(0);     # Repeat the first column
    $worksheet2-&#62;repeat_columns(0, 1);  # Repeat the first two columns
    $worksheet3-&#62;repeat_columns(&#39;A:A&#39;); # Repeat the first column
    $worksheet4-&#62;repeat_columns(&#39;A:B&#39;); # Repeat the first two columns</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;hide_gridlines();</pre>

<p>The following values of <code lang='und' xml:lang='und'>$option</code> are valid:</p>

<pre lang='und' xml:lang='und'>    0 : Don&#39;t hide gridlines
    1 : Hide printed gridlines only
    2 : Hide screen and printed gridlines</pre>

<p>If you don&#39;t supply an argument or use <code lang='und' xml:lang='und'>undef</code> the default option is 1, i.e. only the printed gridlines are hidden.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>     ------------------------------------------
    |   |   A   |   B   |   C   |   D   |  ...
     ------------------------------------------
    | 1 |       |       |       |       |  ...
    | 2 |       |       |       |       |  ...
    | 3 |       |       |       |       |  ...
    | 4 |       |       |       |       |  ...
    |...|  ...  |  ...  |  ...  |  ...  |  ...</pre>

<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 lang='und' xml:lang='und'>print_row_col_headers()</code> method :</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;print_row_col_headers();</pre>

<p>Do not confuse these headers with page headers as described in the <code lang='und' xml:lang='und'>set_header()</code> section above.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="print_area($first_row,_$first_col,_$last_row,_$last_col)"
>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" class="podlinkpod"
>&#34;Cell notation&#34;</a>.</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;print_area(&#39;A1:H20&#39;);    # Cells A1 to H20
    $worksheet2-&#62;print_area(0, 0, 19, 7); # The same
    $worksheet2-&#62;print_area(&#39;A:H&#39;);       # Columns A to H if rows have data</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="print_across()"
>print_across()</a></h2>

<p>The <code lang='und' xml:lang='und'>print_across</code> method is used to change the default print direction. This is referred to by Excel as the sheet &#34;page order&#34;.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;print_across();</pre>

<p>The default page order is shown below for a worksheet that extends over 4 pages. The order is called &#34;down then across&#34;:</p>

<pre lang='und' xml:lang='und'>    [1] [3]
    [2] [4]</pre>

<p>However, by using the <code lang='und' xml:lang='und'>print_across</code> method the print order will be changed to &#34;across then down&#34;:</p>

<pre lang='und' xml:lang='und'>    [1] [2]
    [3] [4]</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="fit_to_pages($width,_$height)"
>fit_to_pages($width, $height)</a></h2>

<p>The <code lang='und' xml:lang='und'>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>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;fit_to_pages(1, 1); # Fit to 1x1 pages
    $worksheet2-&#62;fit_to_pages(2, 1); # Fit to 2x1 pages
    $worksheet3-&#62;fit_to_pages(1, 2); # Fit to 1x2 pages</pre>

<p>The print area can be defined using the <code lang='und' xml:lang='und'>print_area()</code> method as described above.</p>

<p>A common requirement is to fit the printed output to <i>n</i> pages wide but have the height be as long as necessary. To achieve this set the <code lang='und' xml:lang='und'>$height</code> to zero or leave it blank:</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;fit_to_pages(1, 0); # 1 page wide and as long as necessary
    $worksheet2-&#62;fit_to_pages(1);    # The same</pre>

<p>Note that although it is valid to use both <code lang='und' xml:lang='und'>fit_to_pages()</code> and <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>fit_to_pages()</code> will override any manual page breaks that are defined in the worksheet.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_start_page($start_page)"
>set_start_page($start_page)</a></h2>

<p>The <code lang='und' xml:lang='und'>set_start_page()</code> method is used to set the number of the starting page when the worksheet is printed out. The default value is 1.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_start_page(2);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
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 lang='und' xml:lang='und'>10 &#60;= $scale &#60;= 400</code> are valid:</p>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;set_print_scale(50);
    $worksheet2-&#62;set_print_scale(75);
    $worksheet3-&#62;set_print_scale(300);
    $worksheet4-&#62;set_print_scale(400);</pre>

<p>The default scale factor is 100. Note, <code lang='und' xml:lang='und'>set_print_scale()</code> does not affect the scale of the visible page in Excel. For that you should use <code lang='und' xml:lang='und'>set_zoom()</code>.</p>

<p>Note also that although it is valid to use both <code lang='und' xml:lang='und'>fit_to_pages()</code> and <code lang='und' xml:lang='und'>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>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;set_h_pagebreaks(20); # Break between row 20 and 21</pre>

<p>The <code lang='und' xml:lang='und'>set_h_pagebreaks()</code> method will accept a list of page breaks and you can call it more than once:</p>

<pre lang='und' xml:lang='und'>    $worksheet2-&#62;set_h_pagebreaks( 20,  40,  60,  80, 100); # Add breaks
    $worksheet2-&#62;set_h_pagebreaks(120, 140, 160, 180, 200); # Add some more</pre>

<p>Note: If you specify the &#34;fit to page&#34; option via the <code lang='und' xml:lang='und'>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>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    $worksheet1-&#62;set_v_pagebreaks(20); # Break between column 20 and 21</pre>

<p>The <code lang='und' xml:lang='und'>set_v_pagebreaks()</code> method will accept a list of page breaks and you can call it more than once:</p>

<pre lang='und' xml:lang='und'>    $worksheet2-&#62;set_v_pagebreaks( 20,  40,  60,  80, 100); # Add breaks
    $worksheet2-&#62;set_v_pagebreaks(120, 140, 160, 180, 200); # Add some more</pre>

<p>Note: If you specify the &#34;fit to page&#34; option via the <code lang='und' xml:lang='und'>fit_to_pages()</code> method it will override all manual page breaks.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
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>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Creating_and_using_a_Format_object"
>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 lang='und' xml:lang='und'>add_format()</code> method as follows:</p>

<pre lang='und' xml:lang='und'>    my $format1 = $workbook-&#62;add_format();       # Set properties later
    my $format2 = $workbook-&#62;add_format(%props); # Set at creation</pre>

<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 lang='und' xml:lang='und'>write</code> methods as follows:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write(0, 0, &#39;One&#39;, $format);
    $worksheet-&#62;write_string(1, 0, &#39;Two&#39;, $format);
    $worksheet-&#62;write_number(2, 0, 3, $format);
    $worksheet-&#62;write_blank(3, 0, $format);</pre>

<p>Formats can also be passed to the worksheet <code lang='und' xml:lang='und'>set_row()</code> and <code lang='und' xml:lang='und'>set_column()</code> methods to define the default property for a row or column.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(0, 15, $format);
    $worksheet-&#62;set_column(0, 0, 15, $format);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Format_methods_and_Format_properties"
>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>

<pre lang='und' xml:lang='und'>    Category   Description       Property        Method Name
    --------   -----------       --------        -----------
    Font       Font type         font            set_font()
               Font size         size            set_size()
               Font color        color           set_color()
               Bold              bold            set_bold()
               Italic            italic          set_italic()
               Underline         underline       set_underline()
               Strikeout         font_strikeout  set_font_strikeout()
               Super/Subscript   font_script     set_font_script()
               Outline           font_outline    set_font_outline()
               Shadow            font_shadow     set_font_shadow()

    Number     Numeric format    num_format      set_num_format()

    Protection Lock cells        locked          set_locked()
               Hide formulas     hidden          set_hidden()

    Alignment  Horizontal align  align           set_align()
               Vertical align    valign          set_align()
               Rotation          rotation        set_rotation()
               Text wrap         text_wrap       set_text_wrap()
               Justify last      text_justlast   set_text_justlast()
               Center across     center_across   set_center_across()
               Indentation       indent          set_indent()
               Shrink to fit     shrink          set_shrink()

    Pattern    Cell pattern      pattern         set_pattern()
               Background color  bg_color        set_bg_color()
               Foreground color  fg_color        set_fg_color()

    Border     Cell border       border          set_border()
               Bottom border     bottom          set_bottom()
               Top border        top             set_top()
               Left border       left            set_left()
               Right border      right           set_right()
               Border color      border_color    set_border_color()
               Bottom color      bottom_color    set_bottom_color()
               Top color         top_color       set_top_color()
               Left color        left_color      set_left_color()
               Right color       right_color     set_right_color()</pre>

<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>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_bold();
    $format-&#62;set_color(&#39;red&#39;);</pre>

<p>By comparison the properties can be set directly by passing a hash of properties to the Format constructor:</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format(bold =&#62; 1, color =&#62; &#39;red&#39;);</pre>

<p>or after the Format has been constructed by means of the <code lang='und' xml:lang='und'>set_format_properties()</code> method as follows:</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_format_properties(bold =&#62; 1, color =&#62; &#39;red&#39;);</pre>

<p>You can also store the properties in one or more named hashes and pass them to the required method:</p>

<pre lang='und' xml:lang='und'>    my %font    = (
                    font  =&#62; &#39;Arial&#39;,
                    size  =&#62; 12,
                    color =&#62; &#39;blue&#39;,
                    bold  =&#62; 1,
                  );

    my %shading = (
                    bg_color =&#62; &#39;green&#39;,
                    pattern  =&#62; 1,
                  );


    my $format1 = $workbook-&#62;add_format(%font);           # Font only
    my $format2 = $workbook-&#62;add_format(%font, %shading); # Font and shading</pre>

<p>The provision of two ways of setting properties might lead you to wonder which is the best way. The method mechanism may be better is you prefer setting properties via method calls (which the author did when they were code was first written) otherwise passing properties to the constructor has proved to be a little more flexible and self documenting in practice. An additional advantage of working with property hashes is that it allows you to share formatting between workbook objects as shown in the example above.</p>

<p>The Perl/Tk style of adding properties is also supported:</p>

<pre lang='und' xml:lang='und'>    my %font    = (
                    -font      =&#62; &#39;Arial&#39;,
                    -size      =&#62; 12,
                    -color     =&#62; &#39;blue&#39;,
                    -bold      =&#62; 1,
                  );</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
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&#39;t possible to use a Format with a write() 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>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_bold();
    $format-&#62;set_color(&#39;red&#39;);
    $worksheet-&#62;write(&#39;A1&#39;, &#39;Cell A1&#39;, $format);
    $format-&#62;set_color(&#39;green&#39;);
    $worksheet-&#62;write(&#39;B1&#39;, &#39;Cell B1&#39;, $format);</pre>

<p>Cell A1 is assigned the Format <code lang='und' xml:lang='und'>$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>

<pre lang='und' xml:lang='und'>    my $format1 = $workbook-&#62;add_format();
    $format1-&#62;set_bold();  # Turns bold on
    $format1-&#62;set_bold(1); # Also turns bold on
    $format1-&#62;set_bold(0); # Turns bold off</pre>

<h1><a class='u' href='#___top' title='click to go to top of document'
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 lang='und' xml:lang='und'>formats.pl</code> in the <code lang='und' xml:lang='und'>examples</code> directory of the WriteExcel distribution. This program creates an Excel workbook called <code lang='und' xml:lang='und'>formats.xls</code> which contains examples of almost all the format types.</p>

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

<pre lang='und' xml:lang='und'>    set_font()
    set_size()
    set_color()
    set_bold()
    set_italic()
    set_underline()
    set_font_strikeout()
    set_font_script()
    set_font_outline()
    set_font_shadow()
    set_num_format()
    set_locked()
    set_hidden()
    set_align()
    set_rotation()
    set_text_wrap()
    set_text_justlast()
    set_center_across()
    set_indent()
    set_shrink()
    set_pattern()
    set_bg_color()
    set_fg_color()
    set_border()
    set_bottom()
    set_top()
    set_left()
    set_right()
    set_border_color()
    set_bottom_color()
    set_top_color()
    set_left_color()
    set_right_color()</pre>

<p>The above methods can also be applied directly as properties. For example <code lang='und' xml:lang='und'>$format-&#62;set_bold()</code> is equivalent to <code lang='und' xml:lang='und'>$workbook-&#62;add_format(bold =&#62; 1)</code>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_format_properties(%properties)"
>set_format_properties(%properties)</a></h2>

<p>The properties of an existing Format object can be also be set by means of <code lang='und' xml:lang='und'>set_format_properties()</code>:</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_format_properties(bold =&#62; 1, color =&#62; &#39;red&#39;);</pre>

<p>However, this method is here mainly for legacy reasons. It is preferable to set the properties in the format constructor:</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format(bold =&#62; 1, color =&#62; &#39;red&#39;);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_font($fontname)"
>set_font($fontname)</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Font is Arial
    Default action:     None
    Valid args:         Any valid font name</pre>

<p>Specify the font used:</p>

<pre lang='und' xml:lang='und'>    $format-&#62;set_font(&#39;Times New Roman&#39;);</pre>

<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 &#39;Arial&#39;, &#39;Times New Roman&#39; and &#39;Courier New&#39;. See also the Fonts worksheet created by formats.pl</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_size()"
>set_size()</a></h2>

<pre lang='und' xml:lang='und'>    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>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 set_row() worksheet method.</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_size(30);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_color()"
>set_color()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Excels default color, usually black
    Default action:     Set the default color
    Valid args:         Integers from 8..63 or the following strings:
                        &#39;black&#39;
                        &#39;blue&#39;
                        &#39;brown&#39;
                        &#39;cyan&#39;
                        &#39;gray&#39;
                        &#39;green&#39;
                        &#39;lime&#39;
                        &#39;magenta&#39;
                        &#39;navy&#39;
                        &#39;orange&#39;
                        &#39;pink&#39;
                        &#39;purple&#39;
                        &#39;red&#39;
                        &#39;silver&#39;
                        &#39;white&#39;
                        &#39;yellow&#39;</pre>

<p>Set the font colour. The <code lang='und' xml:lang='und'>set_color()</code> method is used as follows:</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_color(&#39;red&#39;);
    $worksheet-&#62;write(0, 0, &#39;wheelbarrow&#39;, $format);</pre>

<p>Note: The <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>set_bg_color()</code> and <code lang='und' xml:lang='und'>set_pattern()</code> methods.</p>

<p>For additional examples see the &#39;Named colors&#39; and &#39;Standard colors&#39; worksheets created by formats.pl in the examples directory.</p>

<p>See also <a href="#COLOURS_IN_EXCEL" class="podlinkpod"
>&#34;COLOURS IN EXCEL&#34;</a>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_bold()"
>set_bold()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      bold is off
    Default action:     Turn bold on
    Valid args:         0, 1 [1]</pre>

<p>Set the bold property of the font:</p>

<pre lang='und' xml:lang='und'>    $format-&#62;set_bold();  # Turn bold on</pre>

<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>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_italic()"
>set_italic()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Italic is off
    Default action:     Turn italic on
    Valid args:         0, 1</pre>

<p>Set the italic property of the font:</p>

<pre lang='und' xml:lang='und'>    $format-&#62;set_italic();  # Turn italic on</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_underline()"
>set_underline()</a></h2>

<pre lang='und' xml:lang='und'>    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>Set the underline property of the font.</p>

<pre lang='und' xml:lang='und'>    $format-&#62;set_underline();   # Single underline</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_font_strikeout()"
>set_font_strikeout()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Strikeout is off
    Default action:     Turn strikeout on
    Valid args:         0, 1</pre>

<p>Set the strikeout property of the font.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_font_script()"
>set_font_script()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Super/Subscript is off
    Default action:     Turn Superscript on
    Valid args:         0  = Normal
                        1  = Superscript
                        2  = Subscript</pre>

<p>Set the superscript/subscript property of the font. This format is currently not very useful.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_font_outline()"
>set_font_outline()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Outline is off
    Default action:     Turn outline on
    Valid args:         0, 1</pre>

<p>Macintosh only.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_font_shadow()"
>set_font_shadow()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Shadow is off
    Default action:     Turn shadow on
    Valid args:         0, 1</pre>

<p>Macintosh only.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_num_format()"
>set_num_format()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      General format
    Default action:     Format index 1
    Valid args:         See the following table</pre>

<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&#39;s built-in formats:</p>

<pre lang='und' xml:lang='und'>    my $format1 = $workbook-&#62;add_format();
    my $format2 = $workbook-&#62;add_format();
    $format1-&#62;set_num_format(&#39;d mmm yyyy&#39;); # Format string
    $format2-&#62;set_num_format(0x0f);         # Format index

    $worksheet-&#62;write(0, 0, 36892.521, $format1);      # 1 Jan 2001
    $worksheet-&#62;write(0, 0, 36892.521, $format2);      # 1-Jan-01</pre>

<p>Using format strings you can define very sophisticated formatting of numbers.</p>

<pre lang='und' xml:lang='und'>    $format01-&#62;set_num_format(&#39;0.000&#39;);
    $worksheet-&#62;write(0,  0, 3.1415926, $format01);    # 3.142

    $format02-&#62;set_num_format(&#39;#,##0&#39;);
    $worksheet-&#62;write(1,  0, 1234.56,   $format02);    # 1,235

    $format03-&#62;set_num_format(&#39;#,##0.00&#39;);
    $worksheet-&#62;write(2,  0, 1234.56,   $format03);    # 1,234.56

    $format04-&#62;set_num_format(&#39;$0.00&#39;);
    $worksheet-&#62;write(3,  0, 49.99,     $format04);    # $49.99

    # Note you can use other currency symbols such as the pound or yen as well.
    # Other currencies may require the use of Unicode.

    $format07-&#62;set_num_format(&#39;mm/dd/yy&#39;);
    $worksheet-&#62;write(6,  0, 36892.521, $format07);    # 01/01/01

    $format08-&#62;set_num_format(&#39;mmm d yyyy&#39;);
    $worksheet-&#62;write(7,  0, 36892.521, $format08);    # Jan 1 2001

    $format09-&#62;set_num_format(&#39;d mmmm yyyy&#39;);
    $worksheet-&#62;write(8,  0, 36892.521, $format09);    # 1 January 2001

    $format10-&#62;set_num_format(&#39;dd/mm/yyyy hh:mm AM/PM&#39;);
    $worksheet-&#62;write(9,  0, 36892.521, $format10);    # 01/01/2001 12:30 AM

    $format11-&#62;set_num_format(&#39;0 &#34;dollar and&#34; .00 &#34;cents&#34;&#39;);
    $worksheet-&#62;write(10, 0, 1.87,      $format11);    # 1 dollar and .87 cents

    # Conditional formatting
    $format12-&#62;set_num_format(&#39;[Green]General;[Red]-General;General&#39;);
    $worksheet-&#62;write(11, 0, 123,       $format12);    # &#62; 0 Green
    $worksheet-&#62;write(12, 0, -45,       $format12);    # &#60; 0 Red
    $worksheet-&#62;write(13, 0, 0,         $format12);    # = 0 Default colour

    # Zip code
    $format13-&#62;set_num_format(&#39;00000&#39;);
    $worksheet-&#62;write(14, 0, &#39;01209&#39;,   $format13);</pre>

<p>The number system used for dates is described in <a href="#DATES_AND_TIME_IN_EXCEL" class="podlinkpod"
>&#34;DATES AND TIME IN EXCEL&#34;</a>.</p>

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

<pre lang='und' xml:lang='und'>    [Black] [Blue] [Cyan] [Green] [Magenta] [Red] [White] [Yellow]</pre>

<p>Alternatively you can specify the colour based on a colour index as follows: <code lang='und' xml:lang='und'>[Color n]</code>, where n is a standard Excel colour index - 7. See the &#39;Standard colors&#39; worksheet created by formats.pl.</p>

<p>For more information refer to the documentation on formatting in the <code lang='und' xml:lang='und'>doc</code> directory of the Spreadsheet::WriteExcel distro, the Excel on-line help or http://office.microsoft.com/en-gb/assistance/HP051995001033.aspx</p>

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

<p>Excel&#39;s built-in formats are shown in the following table:</p>

<pre lang='und' xml:lang='und'>    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);_(* &#34;-&#34;_);_(@_)
    42      0x2a    _($* #,##0_);_($* (#,##0);_($* &#34;-&#34;_);_(@_)
    43      0x2b    _(* #,##0.00_);_(* (#,##0.00);_(* &#34;-&#34;??_);_(@_)
    44      0x2c    _($* #,##0.00_);_($* (#,##0.00);_($* &#34;-&#34;??_);_(@_)
    45      0x2d    mm:ss
    46      0x2e    [h]:mm:ss
    47      0x2f    mm:ss.0
    48      0x30    ##0.0E+0
    49      0x31    @</pre>

<p>For examples of these formatting codes see the &#39;Numerical formats&#39; worksheet created by formats.pl. See also the number_formats1.html and the number_formats2.html documents in the <code lang='und' xml:lang='und'>doc</code> directory of the distro.</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>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_locked()"
>set_locked()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Cell locking is on
    Default action:     Turn locking on
    Valid args:         0, 1</pre>

<p>This property can be used to prevent modification of a cells contents. Following Excel&#39;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 lang='und' xml:lang='und'>protect()</code> method.</p>

<pre lang='und' xml:lang='und'>    my $locked  = $workbook-&#62;add_format();
    $locked-&#62;set_locked(1); # A non-op

    my $unlocked = $workbook-&#62;add_format();
    $locked-&#62;set_locked(0);

    # Enable worksheet protection
    $worksheet-&#62;protect();

    # This cell cannot be edited.
    $worksheet-&#62;write(&#39;A1&#39;, &#39;=1+2&#39;, $locked);

    # This cell can be edited.
    $worksheet-&#62;write(&#39;A2&#39;, &#39;=1+2&#39;, $unlocked);</pre>

<p>Note: This offers weak protection even with a password, see the note in relation to the <code lang='und' xml:lang='und'>protect()</code> method.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_hidden()"
>set_hidden()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Formula hiding is off
    Default action:     Turn hiding on
    Valid args:         0, 1</pre>

<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 lang='und' xml:lang='und'>protect()</code> method.</p>

<pre lang='und' xml:lang='und'>    my $hidden = $workbook-&#62;add_format();
    $hidden-&#62;set_hidden();

    # Enable worksheet protection
    $worksheet-&#62;protect();

    # The formula in this cell isn&#39;t visible
    $worksheet-&#62;write(&#39;A1&#39;, &#39;=1+2&#39;, $hidden);</pre>

<p>Note: This offers weak protection even with a password, see the note in relation to the <code lang='und' xml:lang='und'>protect()</code> method.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_align()"
>set_align()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Alignment is off
    Default action:     Left alignment
    Valid args:         &#39;left&#39;              Horizontal
                        &#39;center&#39;
                        &#39;right&#39;
                        &#39;fill&#39;
                        &#39;justify&#39;
                        &#39;center_across&#39;

                        &#39;top&#39;               Vertical
                        &#39;vcenter&#39;
                        &#39;bottom&#39;
                        &#39;vjustify&#39;</pre>

<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>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_align(&#39;center&#39;);
    $format-&#62;set_align(&#39;vcenter&#39;);
    $worksheet-&#62;set_row(0, 30);
    $worksheet-&#62;write(0, 0, &#39;X&#39;, $format);</pre>

<p>Text can be aligned across two or more adjacent cells using the <code lang='und' xml:lang='und'>center_across</code> property. However, for genuine merged cells it is better to use the <code lang='und' xml:lang='und'>merge_range()</code> worksheet method.</p>

<p>The <code lang='und' xml:lang='und'>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 lang='und' xml:lang='und'>set_text_wrap()</code> method.</p>

<p>For further examples see the &#39;Alignment&#39; worksheet created by formats.pl.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_center_across()"
>set_center_across()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Center across selection is off
    Default action:     Turn center across on
    Valid args:         1</pre>

<p>Text can be aligned across two or more adjacent cells using the <code lang='und' xml:lang='und'>set_center_across()</code> method. This is an alias for the <code lang='und' xml:lang='und'>set_align(&#39;center_across&#39;)</code> method call.</p>

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

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_center_across();

    $worksheet-&#62;write(1, 1, &#39;Center across selection&#39;, $format);
    $worksheet-&#62;write_blank(1, 2, $format);</pre>

<p>See also the <code lang='und' xml:lang='und'>merge1.pl</code> to <code lang='und' xml:lang='und'>merge6.pl</code> programs in the <code lang='und' xml:lang='und'>examples</code> directory and the <code lang='und' xml:lang='und'>merge_range()</code> method.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_text_wrap()"
>set_text_wrap()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Text wrap is off
    Default action:     Turn text wrap on
    Valid args:         0, 1</pre>

<p>Here is an example using the text wrap property, the escape character <code lang='und' xml:lang='und'>\n</code> is used to indicate the end of line:</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_text_wrap();
    $worksheet-&#62;write(0, 0, &#34;It&#39;s\na bum\nwrap&#34;, $format);</pre>

<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 lang='und' xml:lang='und'>set_align(&#39;vjustify&#39;)</code> method. See the <code lang='und' xml:lang='und'>textwrap.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_rotation()"
>set_rotation()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Text rotation is off
    Default action:     None
    Valid args:         Integers in the range -90 to 90 and 270</pre>

<p>Set the rotation of the text in a cell. The rotation can be any angle in the range -90 to 90 degrees.</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_rotation(30);
    $worksheet-&#62;write(0, 0, &#39;This text is rotated&#39;, $format);</pre>

<p>The angle 270 is also supported. This indicates text where the letters run from top to bottom.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_indent()"
>set_indent()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Text indentation is off
    Default action:     Indent text 1 level
    Valid args:         Positive integers</pre>

<p>This method can be used to indent text. The argument, which should be an integer, is taken as the level of indentation:</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_indent(2);
    $worksheet-&#62;write(0, 0, &#39;This text is indented&#39;, $format);</pre>

<p>Indentation is a horizontal alignment property. It will override any other horizontal properties but it can be used in conjunction with vertical properties.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_shrink()"
>set_shrink()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Text shrinking is off
    Default action:     Turn &#34;shrink to fit&#34; on
    Valid args:         1</pre>

<p>This method can be used to shrink text so that it fits in a cell.</p>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();
    $format-&#62;set_shrink();
    $worksheet-&#62;write(0, 0, &#39;Honey, I shrunk the text!&#39;, $format);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_text_justlast()"
>set_text_justlast()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Justify last is off
    Default action:     Turn justify last on
    Valid args:         0, 1</pre>

<p>Only applies to Far Eastern versions of Excel.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_pattern()"
>set_pattern()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Pattern is off
    Default action:     Solid fill is on
    Valid args:         0 .. 18</pre>

<p>Set the background pattern of a cell.</p>

<p>Examples of the available patterns are shown in the &#39;Patterns&#39; 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>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_bg_color()"
>set_bg_color()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Color is off
    Default action:     Solid fill.
    Valid args:         See set_color()</pre>

<p>The <code lang='und' xml:lang='und'>set_bg_color()</code> method can be used to set the background colour of a pattern. Patterns are defined via the <code lang='und' xml:lang='und'>set_pattern()</code> method. If a pattern hasn&#39;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>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format();

    $format-&#62;set_pattern(); # This is optional when using a solid fill

    $format-&#62;set_bg_color(&#39;green&#39;);
    $worksheet-&#62;write(&#39;A1&#39;, &#39;Ray&#39;, $format);</pre>

<p>For further examples see the &#39;Patterns&#39; worksheet created by formats.pl.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_fg_color()"
>set_fg_color()</a></h2>

<pre lang='und' xml:lang='und'>    Default state:      Color is off
    Default action:     Solid fill.
    Valid args:         See set_color()</pre>

<p>The <code lang='und' xml:lang='und'>set_fg_color()</code> method can be used to set the foreground colour of a pattern.</p>

<p>For further examples see the &#39;Patterns&#39; worksheet created by formats.pl.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_border()"
>set_border()</a></h2>

<pre lang='und' xml:lang='und'>    Also applies to:    set_bottom()
                        set_top()
                        set_left()
                        set_right()

    Default state:      Border is off
    Default action:     Set border type 1
    Valid args:         0-13, See below.</pre>

<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 lang='und' xml:lang='und'>set_border()</code> or individually using the relevant method calls shown above.</p>

<p>The following shows the border styles sorted by Spreadsheet::WriteExcel index number:</p>

<pre lang='und' xml:lang='und'>    Index   Name            Weight   Style
    =====   =============   ======   ===========
    0       None            0
    1       Continuous      1        -----------
    2       Continuous      2        -----------
    3       Dash            1        - - - - - -
    4       Dot             1        . . . . . .
    5       Continuous      3        -----------
    6       Double          3        ===========
    7       Continuous      0        -----------
    8       Dash            2        - - - - - -
    9       Dash Dot        1        - . - . - .
    10      Dash Dot        2        - . - . - .
    11      Dash Dot Dot    1        - . . - . .
    12      Dash Dot Dot    2        - . . - . .
    13      SlantDash Dot   2        / - . / - .</pre>

<p>The following shows the borders sorted by style:</p>

<pre lang='und' xml:lang='und'>    Name            Weight   Style         Index
    =============   ======   ===========   =====
    Continuous      0        -----------   7
    Continuous      1        -----------   1
    Continuous      2        -----------   2
    Continuous      3        -----------   5
    Dash            1        - - - - - -   3
    Dash            2        - - - - - -   8
    Dash Dot        1        - . - . - .   9
    Dash Dot        2        - . - . - .   10
    Dash Dot Dot    1        - . . - . .   11
    Dash Dot Dot    2        - . . - . .   12
    Dot             1        . . . . . .   4
    Double          3        ===========   6
    None            0                      0
    SlantDash Dot   2        / - . / - .   13</pre>

<p>The following shows the borders in the order shown in the Excel Dialog.</p>

<pre lang='und' xml:lang='und'>    Index   Style             Index   Style
    =====   =====             =====   =====
    0       None              12      - . . - . .
    7       -----------       13      / - . / - .
    4       . . . . . .       10      - . - . - .
    11      - . . - . .       8       - - - - - -
    9       - . - . - .       2       -----------
    3       - - - - - -       5       -----------
    1       -----------       6       ===========</pre>

<p>Examples of the available border styles are shown in the &#39;Borders&#39; worksheet created by formats.pl.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="set_border_color()"
>set_border_color()</a></h2>

<pre lang='und' xml:lang='und'>    Also applies to:    set_bottom_color()
                        set_top_color()
                        set_left_color()
                        set_right_color()

    Default state:      Color is off
    Default action:     Undefined
    Valid args:         See set_color()</pre>

<p>Set the colour of the cell borders. A cell border is comprised of a border on the bottom, top, left and right. These can be set to the same colour using <code lang='und' xml:lang='und'>set_border_color()</code> or individually using the relevant method calls shown above. Examples of the border styles and colours are shown in the &#39;Borders&#39; worksheet created by formats.pl.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    my $lorry1 = $workbook-&#62;add_format();
    $lorry1-&#62;set_bold();
    $lorry1-&#62;set_italic();
    $lorry1-&#62;set_color(&#39;red&#39;);    # lorry1 is bold, italic and red

    my $lorry2 = $workbook-&#62;add_format();
    $lorry2-&#62;copy($lorry1);
    $lorry2-&#62;set_color(&#39;yellow&#39;); # lorry2 is bold, italic and yellow</pre>

<p>The <code lang='und' xml:lang='und'>copy()</code> method is only useful if you are using the method interface to Format properties. It generally isn&#39;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>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="UNICODE_IN_EXCEL"
>UNICODE IN EXCEL</a></h1>

<p>The following is a brief introduction to handling Unicode in <code lang='und' xml:lang='und'>Spreadsheet::WriteExcel</code>.</p>

<p><i>For a more general introduction to Unicode handling in Perl see</i> <a href="http://search.cpan.org/perldoc?perlunitut" class="podlinkpod"
>perlunitut</a> and <a href="http://search.cpan.org/perldoc?perluniintro" class="podlinkpod"
>perluniintro</a>.</p>

<p>When using Spreadsheet::WriteExcel the best and easiest way to write unicode strings to an Excel file is to use <code lang='und' xml:lang='und'>UTF-8</code> encoded strings and perl 5.8 (or later). Spreadsheet::WriteExcel also allows you to write unicode strings using older perls but it generally requires more work, as explained below.</p>

<p>Internally, Excel encodes unicode data as <code lang='und' xml:lang='und'>UTF-16LE</code> (where LE means little-endian). If you are using perl 5.8+ then Spreadsheet::WriteExcel will convert <code lang='und' xml:lang='und'>UTF-8</code> strings to <code lang='und' xml:lang='und'>UTF-16LE</code> when required. No further intervention is required from the programmer, for example:</p>

<pre lang='und' xml:lang='und'>    # perl 5.8+ example:
    my $smiley = &#34;\x{263A}&#34;;

    $worksheet-&#62;write(&#39;A1&#39;, &#39;Hello world&#39;); # ASCII
    $worksheet-&#62;write(&#39;A2&#39;, $smiley);       # UTF-8</pre>

<p>Spreadsheet::WriteExcel also lets you write unicode data as <code lang='und' xml:lang='und'>UTF-16</code>. Since the majority of CPAN modules default to <code lang='und' xml:lang='und'>UTF-16BE</code> (big-endian) Spreadsheet::WriteExcel also uses <code lang='und' xml:lang='und'>UTF-16BE</code> and converts it internally to <code lang='und' xml:lang='und'>UTF-16LE</code>:</p>

<pre lang='und' xml:lang='und'>    # perl 5.005 example:
    my $smiley = pack &#39;n&#39;, 0x263A;

    $worksheet-&#62;write               (&#39;A3&#39;, &#39;Hello world&#39;); # ASCII
    $worksheet-&#62;write_utf16be_string(&#39;A4&#39;, $smiley);       # UTF-16</pre>

<p>Although the above examples look similar there is an important difference. With <code lang='und' xml:lang='und'>uft8</code> and perl 5.8+ Spreadsheet::WriteExcel treats <code lang='und' xml:lang='und'>UTF-8</code> strings in exactly the same way as any other string. However, with <code lang='und' xml:lang='und'>UTF16</code> data we need to distinguish it from other strings either by calling a separate function or by passing an additional flag to indicate the data type.</p>

<p>If you are dealing with non-ASCII characters that aren&#39;t in <code lang='und' xml:lang='und'>UTF-8</code> then perl 5.8+ provides useful tools in the guise of the <code lang='und' xml:lang='und'>Encode</code> module to help you to convert to the required format. For example:</p>

<pre lang='und' xml:lang='und'>    use Encode &#39;decode&#39;;

    my $string = &#39;some string with koi8-r characters&#39;;
       $string = decode(&#39;koi8-r&#39;, $string); # koi8-r to utf8</pre>

<p>Alternatively you can read data from an encoded file and convert it to <code lang='und' xml:lang='und'>UTF-8</code> as you read it in:</p>

<pre lang='und' xml:lang='und'>    my $file = &#39;unicode_koi8r.txt&#39;;
    open FH, &#39;&#60;:encoding(koi8-r)&#39;, $file  or die &#34;Couldn&#39;t open $file: $!\n&#34;;

    my $row = 0;
    while (&#60;FH&#62;) {
        # Data read in is now in utf8 format.
        chomp;
        $worksheet-&#62;write($row++, 0,  $_);
    }</pre>

<p>These methodologies are explained in more detail in <a href="http://search.cpan.org/perldoc?perlunitut" class="podlinkpod"
>perlunitut</a>, <a href="http://search.cpan.org/perldoc?perluniintro" class="podlinkpod"
>perluniintro</a> and <a href="http://search.cpan.org/perldoc?perlunicode" class="podlinkpod"
>perlunicode</a>.</p>

<p>See also the <code lang='und' xml:lang='und'>unicode_*.pl</code> programs in the examples directory of the distro.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    my $format = $workbook-&#62;add_format(
                                        color =&#62; 12, # index for blue
                                        font  =&#62; &#39;Arial&#39;,
                                        size  =&#62; 12,
                                        bold  =&#62; 1,
                                     );</pre>

<p>The most commonly used colours can also be accessed by name. The name acts as a simple alias for the colour index:</p>

<pre lang='und' xml:lang='und'>    black     =&#62;    8
    blue      =&#62;   12
    brown     =&#62;   16
    cyan      =&#62;   15
    gray      =&#62;   23
    green     =&#62;   17
    lime      =&#62;   11
    magenta   =&#62;   14
    navy      =&#62;   18
    orange    =&#62;   53
    pink      =&#62;   33
    purple    =&#62;   20
    red       =&#62;   10
    silver    =&#62;   22
    white     =&#62;    9
    yellow    =&#62;   13</pre>

<p>For example:</p>

<pre lang='und' xml:lang='und'>    my $font = $workbook-&#62;add_format(color =&#62; &#39;red&#39;);</pre>

<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 lang='und' xml:lang='und'>set_custom_color()</code> workbook method to adjust the RGB (red green blue) components of the colour:</p>

<pre lang='und' xml:lang='und'>    my $ferrari = $workbook-&#62;set_custom_color(40, 216, 12, 12);

    my $format  = $workbook-&#62;add_format(
                                        bg_color =&#62; $ferrari,
                                        pattern  =&#62; 1,
                                        border   =&#62; 1
                                      );

    $worksheet-&#62;write_blank(&#39;A1&#39;, $format);</pre>

<p>The default Excel 97 colour palette is shown in <code lang='und' xml:lang='und'>palette.html</code> in the <code lang='und' xml:lang='und'>doc</code> directory of the distro. You can generate an Excel version of the palette using <code lang='und' xml:lang='und'>colors.pl</code> in the <code lang='und' xml:lang='und'>examples</code> directory.</p>

<p>A comparison of the colour components in the Excel 5 and Excel 97+ colour palettes is shown in <code lang='und' xml:lang='und'>rgb5-97.txt</code> in the <code lang='und' xml:lang='und'>doc</code> directory.</p>

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

<p>A detailed look at Excel&#39;s colour palette: http://www.mvps.org/dmcritchie/excel/colors.htm</p>

<p>A decimal RGB chart: http://www.hypersolutions.org/pages/rgbdec.html</p>

<p>A hex RGB chart: : http://www.hypersolutions.org/pages/rgbhex.html</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="DATES_AND_TIME_IN_EXCEL"
>DATES AND TIME IN EXCEL</a></h1>

<p>There are two important things to understand about dates and times in Excel:</p>

<dl>
<dt><a name="1_A_date/time_in_Excel_is_a_real_number_plus_an_Excel_number_format."
>1 A date/time in Excel is a real number plus an Excel number format.</a></dt><p class="pad"></p>

<dt><a name="2_Spreadsheet::WriteExcel_doesn&#39;t_automatically_convert_date/time_strings_in_write()_to_an_Excel_date/time."
>2 Spreadsheet::WriteExcel doesn&#39;t automatically convert date/time strings in <code lang='und' xml:lang='und'>write()</code> to an Excel date/time.</a></dt><p class="pad"></p>
</dl>

<p>These two points are explained in more detail below along with some suggestions on how to convert times and dates to the required format.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="An_Excel_date/time_is_a_number_plus_a_format"
>An Excel date/time is a number plus a format</a></h2>

<p>If you write a date string with <code lang='und' xml:lang='und'>write()</code> then all you will get is a string:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write(&#39;A1&#39;, &#39;02/03/04&#39;); # !! Writes a string not a date. !!</pre>

<p>Dates and times in Excel are represented by real numbers, for example &#34;Jan 1 2001 12:30 AM&#34; 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>A date or time in Excel is just like any other number. To have the number display as a date you must apply an Excel number format to it. Here are some examples.</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;date_examples.xls&#39;);
    my $worksheet = $workbook-&#62;add_worksheet();

    $worksheet-&#62;set_column(&#39;A:A&#39;, 30); # For extra visibility.

    my $number    = 39506.5;

    $worksheet-&#62;write(&#39;A1&#39;, $number);            #     39506.5

    my $format2 = $workbook-&#62;add_format(num_format =&#62; &#39;dd/mm/yy&#39;);
    $worksheet-&#62;write(&#39;A2&#39;, $number , $format2); #     28/02/08

    my $format3 = $workbook-&#62;add_format(num_format =&#62; &#39;mm/dd/yy&#39;);
    $worksheet-&#62;write(&#39;A3&#39;, $number , $format3); #     02/28/08

    my $format4 = $workbook-&#62;add_format(num_format =&#62; &#39;d-m-yyyy&#39;);
    $worksheet-&#62;write(&#39;A4&#39;, $number , $format4); #     28-2-2008

    my $format5 = $workbook-&#62;add_format(num_format =&#62; &#39;dd/mm/yy hh:mm&#39;);
    $worksheet-&#62;write(&#39;A5&#39;, $number , $format5); #     28/02/08 12:00

    my $format6 = $workbook-&#62;add_format(num_format =&#62; &#39;d mmm yyyy&#39;);
    $worksheet-&#62;write(&#39;A6&#39;, $number , $format6); #     28 Feb 2008

    my $format7 = $workbook-&#62;add_format(num_format =&#62; &#39;mmm d yyyy hh:mm AM/PM&#39;);
    $worksheet-&#62;write(&#39;A7&#39;, $number , $format7); #     Feb 28 2008 12:00 PM</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Spreadsheet::WriteExcel_doesn&#39;t_automatically_convert_date/time_strings"
>Spreadsheet::WriteExcel doesn&#39;t automatically convert date/time strings</a></h2>

<p>Spreadsheet::WriteExcel doesn&#39;t automatically convert input date strings into Excel&#39;s formatted date numbers due to the large number of possible date formats and also due to the possibility of misinterpretation.</p>

<p>For example, does <code lang='und' xml:lang='und'>02/03/04</code> mean March 2 2004, February 3 2004 or even March 4 2002.</p>

<p>Therefore, in order to handle dates you will have to convert them to numbers and apply an Excel format. Some methods for converting dates are listed in the next section.</p>

<p>The most direct way is to convert your dates to the ISO8601 <code lang='und' xml:lang='und'>yyyy-mm-ddThh:mm:ss.sss</code> date format and use the <code lang='und' xml:lang='und'>write_date_time()</code> worksheet method:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_date_time(&#39;A2&#39;, &#39;2001-01-01T12:20&#39;, $format);</pre>

<p>See the <code lang='und' xml:lang='und'>write_date_time()</code> section of the documentation for more details.</p>

<p>A general methodology for handling date strings with <code lang='und' xml:lang='und'>write_date_time()</code> is:</p>

<pre lang='und' xml:lang='und'>    1. Identify incoming date/time strings with a regex.
    2. Extract the component parts of the date/time using the same regex.
    3. Convert the date/time to the ISO8601 format.
    4. Write the date/time using write_date_time() and a number format.</pre>

<p>Here is an example:</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    my $workbook    = Spreadsheet::WriteExcel-&#62;new(&#39;example.xls&#39;);
    my $worksheet   = $workbook-&#62;add_worksheet();

    # Set the default format for dates.
    my $date_format = $workbook-&#62;add_format(num_format =&#62; &#39;mmm d yyyy&#39;);

    # Increase column width to improve visibility of data.
    $worksheet-&#62;set_column(&#39;A:C&#39;, 20);

    # Simulate reading from a data source.
    my $row = 0;

    while (&#60;DATA&#62;) {
        chomp;

        my $col  = 0;
        my @data = split &#39; &#39;;

        for my $item (@data) {

            # Match dates in the following formats: d/m/yy, d/m/yyyy
            if ($item =~ qr[^(\d{1,2})/(\d{1,2})/(\d{4})$]) {

                # Change to the date format required by write_date_time().
                my $date = sprintf &#34;%4d-%02d-%02dT&#34;, $3, $2, $1;

                $worksheet-&#62;write_date_time($row, $col++, $date, $date_format);
            }
            else {
                # Just plain data
                $worksheet-&#62;write($row, $col++, $item);
            }
        }
        $row++;
    }

    __DATA__
    Item    Cost    Date
    Book    10      1/9/2007
    Beer    4       12/9/2007
    Bed     500     5/10/2007</pre>

<p>For a slightly more advanced solution you can modify the <code lang='und' xml:lang='und'>write()</code> method to handle date formats of your choice via the <code lang='und' xml:lang='und'>add_write_handler()</code> method. See the <code lang='und' xml:lang='und'>add_write_handler()</code> section of the docs and the write_handler3.pl and write_handler4.pl programs in the examples directory of the distro.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Converting_dates_and_times_to_an_Excel_date_or_time"
>Converting dates and times to an Excel date or time</a></h2>

<p>The <code lang='und' xml:lang='und'>write_date_time()</code> method above is just one way of handling dates and times.</p>

<p>The <a href="http://search.cpan.org/perldoc?Spreadsheet%3A%3AWriteExcel%3A%3AUtility" class="podlinkpod"
>Spreadsheet::WriteExcel::Utility</a> module which is included in the distro has date/time handling functions:</p>

<pre lang='und' xml:lang='und'>    use Spreadsheet::WriteExcel::Utility;

    $date           = xl_date_list(2002, 1, 1);         # 37257
    $date           = xl_parse_date(&#34;11 July 1997&#34;);    # 35622
    $time           = xl_parse_time(&#39;3:21:36 PM&#39;);      # 0.64
    $date           = xl_decode_date_EU(&#34;13 May 2002&#34;); # 37389</pre>

<p>Note: some of these functions require additional CPAN modules.</p>

<p>For date conversions using the CPAN <code lang='und' xml:lang='und'>DateTime</code> framework see <a href="http://search.cpan.org/perldoc?DateTime%3A%3AFormat%3A%3AExcel" class="podlinkpod"
>DateTime::Format::Excel</a> http://search.cpan.org/search?dist=DateTime-Format-Excel</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="OUTLINES_AND_GROUPING_IN_EXCEL"
>OUTLINES AND GROUPING IN EXCEL</a></h1>

<p>Excel allows you to group rows or columns so that they can be hidden or displayed with a single mouse click. This feature is referred to as outlines.</p>

<p>Outlines can reduce complex data down to a few salient sub-totals or summaries.</p>

<p>This feature is best viewed in Excel but the following is an ASCII representation of what a worksheet with three outlines might look like. Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at level 1. The lines at the left hand side are called outline level bars.</p>

<pre lang='und' xml:lang='und'>            ------------------------------------------
     1 2 3 |   |   A   |   B   |   C   |   D   |  ...
            ------------------------------------------
      _    | 1 |   A   |       |       |       |  ...
     |  _  | 2 |   B   |       |       |       |  ...
     | |   | 3 |  (C)  |       |       |       |  ...
     | |   | 4 |  (D)  |       |       |       |  ...
     | -   | 5 |   E   |       |       |       |  ...
     |  _  | 6 |   F   |       |       |       |  ...
     | |   | 7 |  (G)  |       |       |       |  ...
     | |   | 8 |  (H)  |       |       |       |  ...
     | -   | 9 |   I   |       |       |       |  ...
     -     | . |  ...  |  ...  |  ...  |  ...  |  ...</pre>

<p>Clicking the minus sign on each of the level 2 outlines will collapse and hide the data as shown in the next figure. The minus sign changes to a plus sign to indicate that the data in the outline is hidden.</p>

<pre lang='und' xml:lang='und'>            ------------------------------------------
     1 2 3 |   |   A   |   B   |   C   |   D   |  ...
            ------------------------------------------
      _    | 1 |   A   |       |       |       |  ...
     |     | 2 |   B   |       |       |       |  ...
     | +   | 5 |   E   |       |       |       |  ...
     |     | 6 |   F   |       |       |       |  ...
     | +   | 9 |   I   |       |       |       |  ...
     -     | . |  ...  |  ...  |  ...  |  ...  |  ...</pre>

<p>Clicking on the minus sign on the level 1 outline will collapse the remaining rows as follows:</p>

<pre lang='und' xml:lang='und'>            ------------------------------------------
     1 2 3 |   |   A   |   B   |   C   |   D   |  ...
            ------------------------------------------
           | 1 |   A   |       |       |       |  ...
     +     | . |  ...  |  ...  |  ...  |  ...  |  ...</pre>

<p>Grouping in <code lang='und' xml:lang='und'>Spreadsheet::WriteExcel</code> is achieved by setting the outline level via the <code lang='und' xml:lang='und'>set_row()</code> and <code lang='und' xml:lang='und'>set_column()</code> worksheet methods:</p>

<pre lang='und' xml:lang='und'>    set_row($row, $height, $format, $hidden, $level, $collapsed)
    set_column($first_col, $last_col, $width, $format, $hidden, $level, $collapsed)</pre>

<p>The following example sets an outline level of 1 for rows 1 and 2 (zero-indexed) and columns B to G. The parameters <code lang='und' xml:lang='und'>$height</code> and <code lang='und' xml:lang='und'>$XF</code> are assigned default values since they are undefined:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(1, undef, undef, 0, 1);
    $worksheet-&#62;set_row(2, undef, undef, 0, 1);
    $worksheet-&#62;set_column(&#39;B:G&#39;, undef, undef, 0, 1);</pre>

<p>Excel allows up to 7 outline levels. Therefore the <code lang='und' xml:lang='und'>$level</code> parameter should be in the range <code lang='und' xml:lang='und'>0 &#60;= $level &#60;= 7</code>.</p>

<p>Rows and columns can be collapsed by setting the <code lang='und' xml:lang='und'>$hidden</code> flag for the hidden rows/columns and setting the <code lang='und' xml:lang='und'>$collapsed</code> flag for the row/column that has the collapsed <code lang='und' xml:lang='und'>+</code> symbol:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;set_row(1, undef, undef, 1, 1);
    $worksheet-&#62;set_row(2, undef, undef, 1, 1);
    $worksheet-&#62;set_row(3, undef, undef, 0, 0, 1);        # Collapsed flag.

    $worksheet-&#62;set_column(&#39;B:G&#39;, undef, undef, 1, 1);
    $worksheet-&#62;set_column(&#39;H:H&#39;, undef, undef, 0, 0, 1); # Collapsed flag.</pre>

<p>Note: Setting the <code lang='und' xml:lang='und'>$collapsed</code> flag is particularly important for compatibility with OpenOffice.org and Gnumeric.</p>

<p>For a more complete example see the <code lang='und' xml:lang='und'>outline.pl</code> and <code lang='und' xml:lang='und'>outline_collapsed.pl</code> programs in the examples directory of the distro.</p>

<p>Some additional outline properties can be set via the <code lang='und' xml:lang='und'>outline_settings()</code> worksheet method, see above.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="DATA_VALIDATION_IN_EXCEL"
>DATA VALIDATION IN EXCEL</a></h1>

<p>Data validation is a feature of Excel which allows you to restrict the data that a users enters in a cell and to display help and warning messages. It also allows you to restrict input to values in a drop down list.</p>

<p>A typical use case might be to restrict data in a cell to integer values in a certain range, to provide a help message to indicate the required value and to issue a warning if the input data doesn&#39;t meet the stated criteria. In Spreadsheet::WriteExcel we could do that as follows:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;B3&#39;,
        {
            validate        =&#62; &#39;integer&#39;,
            criteria        =&#62; &#39;between&#39;,
            minimum         =&#62; 1,
            maximum         =&#62; 100,
            input_title     =&#62; &#39;Input an integer:&#39;,
            input_message   =&#62; &#39;Between 1 and 100&#39;,
            error_message   =&#62; &#39;Sorry, try again.&#39;,
        });</pre>

<p>The above example would look like this in Excel: <a href="http://homepage.eircom.net/~jmcnamara/perl/data_validation.jpg" class="podlinkurl"
>http://homepage.eircom.net/~jmcnamara/perl/data_validation.jpg</a>.</p>

<center>
<img src="http://homepage.eircom.net/~jmcnamara/perl/data_validation.jpg" alt="The output from the above example">
</center>


<p>For more information on data validation see the following Microsoft support article &#34;Description and examples of data validation in Excel&#34;: <a href="http://support.microsoft.com/kb/211485" class="podlinkurl"
>http://support.microsoft.com/kb/211485</a>.</p>

<p>The following sections describe how to use the <code lang='und' xml:lang='und'>data_validation()</code> method and its various options.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="data_validation($row,_$col,_{_parameter_=&#62;_&#39;value&#39;,_..._})"
>data_validation($row, $col, { parameter =&#62; &#39;value&#39;, ... })</a></h2>

<p>The <code lang='und' xml:lang='und'>data_validation()</code> method is used to construct an Excel data validation.</p>

<p>It can be applied to a single cell or a range of cells. You can pass 3 parameters such as <code lang='und' xml:lang='und'>($row, $col, {...})</code> or 5 parameters such as <code lang='und' xml:lang='und'>($first_row, $first_col, $last_row, $last_col, {...})</code>. You can also use <code lang='und' xml:lang='und'>A1</code> style notation. For example:</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(0, 0,       {...});
    $worksheet-&#62;data_validation(0, 0, 4, 1, {...});

    # Which are the same as:

    $worksheet-&#62;data_validation(&#39;A1&#39;,       {...});
    $worksheet-&#62;data_validation(&#39;A1:B5&#39;,    {...});</pre>

<p>See also the note about <a href="#Cell_notation" class="podlinkpod"
>&#34;Cell notation&#34;</a> for more information.</p>

<p>The last parameter in <code lang='und' xml:lang='und'>data_validation()</code> must be a hash ref containing the parameters that describe the type and style of the data validation. The allowable parameters are:</p>

<pre lang='und' xml:lang='und'>    validate
    criteria
    value | minimum | source
    maximum
    ignore_blank
    dropdown

    input_title
    input_message
    show_input

    error_title
    error_message
    error_type
    show_error</pre>

<p>These parameters are explained in the following sections. Most of the parameters are optional, however, you will generally require the three main options <code lang='und' xml:lang='und'>validate</code>, <code lang='und' xml:lang='und'>criteria</code> and <code lang='und' xml:lang='und'>value</code>.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;B3&#39;,
        {
            validate =&#62; &#39;integer&#39;,
            criteria =&#62; &#39;&#62;&#39;,
            value    =&#62; 100,
        });</pre>

<p>The <code lang='und' xml:lang='und'>data_validation</code> method returns:</p>

<pre lang='und' xml:lang='und'>     0 for success.
    -1 for insufficient number of arguments.
    -2 for row or column out of bounds.
    -3 for incorrect parameter or value.</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="validate"
>validate</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>validate</code> parameter is used to set the type of data that you wish to validate. It is always required and it has no default value. Allowable values are:</p>

<pre lang='und' xml:lang='und'>    any
    integer
    decimal
    list
    date
    time
    length
    custom</pre>

<ul>
<li><b>any</b> is used to specify that the type of data is unrestricted. This is the same as not applying a data validation. It is only provided for completeness and isn&#39;t used very often in the context of Spreadsheet::WriteExcel.</li><p class="pad"></p>

<li><b>integer</b> restricts the cell to integer values. Excel refers to this as &#39;whole number&#39;.</li><p class="pad"></p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;integer&#39;,
    criteria =&#62; &#39;&#62;&#39;,
    value    =&#62; 100,</pre>

<li><b>decimal</b> restricts the cell to decimal values.</li><p class="pad"></p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;decimal&#39;,
    criteria =&#62; &#39;&#62;&#39;,
    value    =&#62; 38.6,</pre>

<li><b>list</b> restricts the cell to a set of user specified values. These can be passed in an array ref or as a cell range (named ranges aren&#39;t currently supported):</li><p class="pad"></p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;list&#39;,
    value    =&#62; [&#39;open&#39;, &#39;high&#39;, &#39;close&#39;],
    # Or like this:
    value    =&#62; &#39;B1:B3&#39;,</pre>

<p>Excel requires that range references are only to cells on the same worksheet.</p>

<li><b>date</b> restricts the cell to date values. Dates in Excel are expressed as integer values but you can also pass an ISO860 style string as used in <code lang='und' xml:lang='und'>write_date_time()</code>. See also <a href="#DATES_AND_TIME_IN_EXCEL" class="podlinkpod"
>&#34;DATES AND TIME IN EXCEL&#34;</a> for more information about working with Excel&#39;s dates.</li><p class="pad"></p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;date&#39;,
    criteria =&#62; &#39;&#62;&#39;,
    value    =&#62; 39653, # 24 July 2008
    # Or like this:
    value    =&#62; &#39;2008-07-24T&#39;,</pre>

<li><b>time</b> restricts the cell to time values. Times in Excel are expressed as decimal values but you can also pass an ISO860 style string as used in <code lang='und' xml:lang='und'>write_date_time()</code>. See also <a href="#DATES_AND_TIME_IN_EXCEL" class="podlinkpod"
>&#34;DATES AND TIME IN EXCEL&#34;</a> for more information about working with Excel&#39;s times.</li><p class="pad"></p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;time&#39;,
    criteria =&#62; &#39;&#62;&#39;,
    value    =&#62; 0.5, # Noon
    # Or like this:
    value    =&#62; &#39;T12:00:00&#39;,</pre>

<li><b>length</b> restricts the cell data based on an integer string length. Excel refers to this as &#39;Text length&#39;.</li><p class="pad"></p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;length&#39;,
    criteria =&#62; &#39;&#62;&#39;,
    value    =&#62; 10,</pre>

<li><b>custom</b> restricts the cell based on an external Excel formula that returns a <code lang='und' xml:lang='und'>TRUE/FALSE</code> value.</li><p class="pad"></p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;custom&#39;,
    value    =&#62; &#39;=IF(A10&#62;B10,TRUE,FALSE)&#39;,</pre>
</ul>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="criteria"
>criteria</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>criteria</code> parameter is used to set the criteria by which the data in the cell is validated. It is almost always required except for the <code lang='und' xml:lang='und'>list</code> and <code lang='und' xml:lang='und'>custom</code> validate options. It has no default value. Allowable values are:</p>

<pre lang='und' xml:lang='und'>    &#39;between&#39;
    &#39;not between&#39;
    &#39;equal to&#39;                  |  &#39;==&#39;  |  &#39;=&#39;
    &#39;not equal to&#39;              |  &#39;!=&#39;  |  &#39;&#60;&#62;&#39;
    &#39;greater than&#39;              |  &#39;&#62;&#39;
    &#39;less than&#39;                 |  &#39;&#60;&#39;
    &#39;greater than or equal to&#39;  |  &#39;&#62;=&#39;
    &#39;less than or equal to&#39;     |  &#39;&#60;=&#39;</pre>

<p>You can either use Excel&#39;s textual description strings, in the first column above, or the more common operator alternatives. The following are equivalent:</p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;integer&#39;,
    criteria =&#62; &#39;greater than&#39;,
    value    =&#62; 100,

    validate =&#62; &#39;integer&#39;,
    criteria =&#62; &#39;&#62;&#39;,
    value    =&#62; 100,</pre>

<p>The <code lang='und' xml:lang='und'>list</code> and <code lang='und' xml:lang='und'>custom</code> validate options don&#39;t require a <code lang='und' xml:lang='und'>criteria</code>. If you specify one it will be ignored.</p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;list&#39;,
    value    =&#62; [&#39;open&#39;, &#39;high&#39;, &#39;close&#39;],

    validate =&#62; &#39;custom&#39;,
    value    =&#62; &#39;=IF(A10&#62;B10,TRUE,FALSE)&#39;,</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="value_|_minimum_|_source"
>value | minimum | source</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>value</code> parameter is used to set the limiting value to which the <code lang='und' xml:lang='und'>criteria</code> is applied. It is always required and it has no default value. You can also use the synonyms <code lang='und' xml:lang='und'>minimum</code> or <code lang='und' xml:lang='und'>source</code> to make the validation a little clearer and closer to Excel&#39;s description of the parameter:</p>

<pre lang='und' xml:lang='und'>    # Use &#39;value&#39;
    validate =&#62; &#39;integer&#39;,
    criteria =&#62; &#39;&#62;&#39;,
    value    =&#62; 100,

    # Use &#39;minimum&#39;
    validate =&#62; &#39;integer&#39;,
    criteria =&#62; &#39;between&#39;,
    minimum  =&#62; 1,
    maximum  =&#62; 100,

    # Use &#39;source&#39;
    validate =&#62; &#39;list&#39;,
    source   =&#62; &#39;B1:B3&#39;,</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="maximum"
>maximum</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>maximum</code> parameter is used to set the upper limiting value when the <code lang='und' xml:lang='und'>criteria</code> is either <code lang='und' xml:lang='und'>&#39;between&#39;</code> or <code lang='und' xml:lang='und'>&#39;not between&#39;</code>:</p>

<pre lang='und' xml:lang='und'>    validate =&#62; &#39;integer&#39;,
    criteria =&#62; &#39;between&#39;,
    minimum  =&#62; 1,
    maximum  =&#62; 100,</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="ignore_blank"
>ignore_blank</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>ignore_blank</code> parameter is used to toggle on and off the &#39;Ignore blank&#39; option in the Excel data validation dialog. When the option is on the data validation is not applied to blank data in the cell. It is on by default.</p>

<pre lang='und' xml:lang='und'>    ignore_blank =&#62; 0,  # Turn the option off</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="dropdown"
>dropdown</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>dropdown</code> parameter is used to toggle on and off the &#39;In-cell dropdown&#39; option in the Excel data validation dialog. When the option is on a dropdown list will be shown for <code lang='und' xml:lang='und'>list</code> validations. It is on by default.</p>

<pre lang='und' xml:lang='und'>    dropdown =&#62; 0,      # Turn the option off</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="input_title"
>input_title</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>input_title</code> parameter is used to set the title of the input message that is displayed when a cell is entered. It has no default value and is only displayed if the input message is displayed. See the <code lang='und' xml:lang='und'>input_message</code> parameter below.</p>

<pre lang='und' xml:lang='und'>    input_title   =&#62; &#39;This is the input title&#39;,</pre>

<p>The maximum title length is 32 characters. UTF8 strings are handled automatically in perl 5.8 and later.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="input_message"
>input_message</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>input_message</code> parameter is used to set the input message that is displayed when a cell is entered. It has no default value.</p>

<pre lang='und' xml:lang='und'>    validate      =&#62; &#39;integer&#39;,
    criteria      =&#62; &#39;between&#39;,
    minimum       =&#62; 1,
    maximum       =&#62; 100,
    input_title   =&#62; &#39;Enter the applied discount:&#39;,
    input_message =&#62; &#39;between 1 and 100&#39;,</pre>

<p>The message can be split over several lines using newlines, <code lang='und' xml:lang='und'>&#34;\n&#34;</code> in double quoted strings.</p>

<pre lang='und' xml:lang='und'>    input_message =&#62; &#34;This is\na test.&#34;,</pre>

<p>The maximum message length is 255 characters. UTF8 strings are handled automatically in perl 5.8 and later.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="show_input"
>show_input</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>show_input</code> parameter is used to toggle on and off the &#39;Show input message when cell is selected&#39; option in the Excel data validation dialog. When the option is off an input message is not displayed even if it has been set using <code lang='und' xml:lang='und'>input_message</code>. It is on by default.</p>

<pre lang='und' xml:lang='und'>    show_input =&#62; 0,      # Turn the option off</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="error_title"
>error_title</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>error_title</code> parameter is used to set the title of the error message that is displayed when the data validation criteria is not met. The default error title is &#39;Microsoft Excel&#39;.</p>

<pre lang='und' xml:lang='und'>    error_title   =&#62; &#39;Input value is not valid&#39;,</pre>

<p>The maximum title length is 32 characters. UTF8 strings are handled automatically in perl 5.8 and later.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="error_message"
>error_message</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>error_message</code> parameter is used to set the error message that is displayed when a cell is entered. The default error message is &#34;The value you entered is not valid.\nA user has restricted values that can be entered into the cell.&#34;.</p>

<pre lang='und' xml:lang='und'>    validate      =&#62; &#39;integer&#39;,
    criteria      =&#62; &#39;between&#39;,
    minimum       =&#62; 1,
    maximum       =&#62; 100,
    error_title   =&#62; &#39;Input value is not valid&#39;,
    error_message =&#62; &#39;It should be an integer between 1 and 100&#39;,</pre>

<p>The message can be split over several lines using newlines, <code lang='und' xml:lang='und'>&#34;\n&#34;</code> in double quoted strings.</p>

<pre lang='und' xml:lang='und'>    input_message =&#62; &#34;This is\na test.&#34;,</pre>

<p>The maximum message length is 255 characters. UTF8 strings are handled automatically in perl 5.8 and later.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="error_type"
>error_type</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>error_type</code> parameter is used to specify the type of error dialog that is displayed. There are 3 options:</p>

<pre lang='und' xml:lang='und'>    &#39;stop&#39;
    &#39;warning&#39;
    &#39;information&#39;</pre>

<p>The default is <code lang='und' xml:lang='und'>&#39;stop&#39;</code>.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="show_error"
>show_error</a></h2>

<p>This parameter is passed in a hash ref to <code lang='und' xml:lang='und'>data_validation()</code>.</p>

<p>The <code lang='und' xml:lang='und'>show_error</code> parameter is used to toggle on and off the &#39;Show error alert after invalid data is entered&#39; option in the Excel data validation dialog. When the option is off an error message is not displayed even if it has been set using <code lang='und' xml:lang='und'>error_message</code>. It is on by default.</p>

<pre lang='und' xml:lang='und'>    show_error =&#62; 0,      # Turn the option off</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Examples"
>Examples</a></h2>

<p>Example 1. Limiting input to an integer greater than a fixed value.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;A1&#39;,
        {
            validate        =&#62; &#39;integer&#39;,
            criteria        =&#62; &#39;&#62;&#39;,
            value           =&#62; 0,
        });</pre>

<p>Example 2. Limiting input to an integer greater than a fixed value where the value is referenced from a cell.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;A2&#39;,
        {
            validate        =&#62; &#39;integer&#39;,
            criteria        =&#62; &#39;&#62;&#39;,
            value           =&#62; &#39;=E3&#39;,
        });</pre>

<p>Example 3. Limiting input to a decimal in a fixed range.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;A3&#39;,
        {
            validate        =&#62; &#39;decimal&#39;,
            criteria        =&#62; &#39;between&#39;,
            minimum         =&#62; 0.1,
            maximum         =&#62; 0.5,
        });</pre>

<p>Example 4. Limiting input to a value in a dropdown list.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;A4&#39;,
        {
            validate        =&#62; &#39;list&#39;,
            source          =&#62; [&#39;open&#39;, &#39;high&#39;, &#39;close&#39;],
        });</pre>

<p>Example 5. Limiting input to a value in a dropdown list where the list is specified as a cell range.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;A5&#39;,
        {
            validate        =&#62; &#39;list&#39;,
            source          =&#62; &#39;=E4:G4&#39;,
        });</pre>

<p>Example 6. Limiting input to a date in a fixed range.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;A6&#39;,
        {
            validate        =&#62; &#39;date&#39;,
            criteria        =&#62; &#39;between&#39;,
            minimum         =&#62; &#39;2008-01-01T&#39;,
            maximum         =&#62; &#39;2008-12-12T&#39;,
        });</pre>

<p>Example 7. Displaying a message when the cell is selected.</p>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;data_validation(&#39;A7&#39;,
        {
            validate      =&#62; &#39;integer&#39;,
            criteria      =&#62; &#39;between&#39;,
            minimum       =&#62; 1,
            maximum       =&#62; 100,
            input_title   =&#62; &#39;Enter an integer:&#39;,
            input_message =&#62; &#39;between 1 and 100&#39;,
        });</pre>

<p>See also the <code lang='und' xml:lang='und'>data_validate.pl</code> program in the examples directory of the distro.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="FORMULAS_AND_FUNCTIONS_IN_EXCEL"
>FORMULAS AND FUNCTIONS IN EXCEL</a></h1>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    1. Writing a formula is much slower than writing the equivalent string.
    2. You cannot use array constants, i.e. {1;2;3}, in functions.
    3. Unary minus isn&#39;t supported.
    4. Whitespace is not preserved around operators.
    5. Named ranges are not supported.
    6. Array formulas are not supported.</pre>

<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 issue 1 using the <code lang='und' xml:lang='und'>store_formula()</code> and <code lang='und' xml:lang='und'>repeat_formula()</code> methods as described later in this section.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    &#39;=A1+B1&#39;
    &#39;=AVERAGE(1, 2, 3)&#39;</pre>

<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 65536. The <code lang='und' xml:lang='und'>Spreadsheet::WriteExcel::Utility</code> module that is included in the distro contains helper functions for dealing with A1 notation, for example:</p>

<pre lang='und' xml:lang='und'>    use Spreadsheet::WriteExcel::Utility;

    ($row, $col) = xl_cell_to_rowcol(&#39;C2&#39;);  # (1, 2)
    $str         = xl_rowcol_to_cell(1, 2);  # C2</pre>

<p>The Excel <code lang='und' xml:lang='und'>$</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>

<pre lang='und' xml:lang='und'>    &#39;=A1&#39;   # Column and row are relative
    &#39;=$A1&#39;  # Column is absolute and row is relative
    &#39;=A$1&#39;  # Column is relative and row is absolute
    &#39;=$A$1&#39; # Column and row are absolute</pre>

<p>Formulas can also refer to cells in other worksheets of the current workbook. For example:</p>

<pre lang='und' xml:lang='und'>    &#39;=Sheet2!A1&#39;
    &#39;=Sheet2!A1:A5&#39;
    &#39;=Sheet2:Sheet3!A1&#39;
    &#39;=Sheet2:Sheet3!A1:A5&#39;
    q{=&#39;Test Data&#39;!A1}
    q{=&#39;Test Data1:Test Data2&#39;!A1}</pre>

<p>The sheet reference and the cell reference are separated by <code lang='und' xml:lang='und'>!</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 lang='und' xml:lang='und'>q{}</code> to protect the quotes. See <code lang='und' xml:lang='und'>perlop</code> in the main Perl documentation. Only valid sheet names that have been added using the <code lang='und' xml:lang='und'>add_worksheet()</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&#39;s formulas. The majority of the operators are the same as Perl&#39;s, differences are indicated:</p>

<pre lang='und' xml:lang='und'>    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]


    Comparison operators:
    =====================
    Operator  Meaning                   Example
        =     Equal to                  A1 =  B1 # Equivalent to ==
        &#60;&#62;    Not equal to              A1 &#60;&#62; B1 # Equivalent to !=
        &#62;     Greater than              A1 &#62;  B1
        &#60;     Less than                 A1 &#60;  B1
        &#62;=    Greater than or equal to  A1 &#62;= B1
        &#60;=    Less than or equal to     A1 &#60;= B1


    String operator:
    ================
    Operator  Meaning                   Example
        &#38;     Concatenation             &#34;Hello &#34; &#38; &#34;World!&#34; # [2]


    Reference operators:
    ====================
    Operator  Meaning                   Example
        :     Range operator            A1:A4               # [3]
        ,     Union operator            SUM(1, 2+2, B3)     # [4]


    Notes:
    [1]: You can get a percentage with formatting and modulus with MOD().
    [2]: Equivalent to (&#34;Hello &#34; . &#34;World!&#34;) 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>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>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write(&#39;A1&#39;, &#39;=SUM(1; 2; 3)&#39;); # Wrong!!
    $worksheet-&#62;write(&#39;A1&#39;, &#39;=SUM(1, 2, 3)&#39;); # Okay</pre>

<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 &#34;Analysis ToolPak&#34; or other add-ins are not supported. These functions have all been tested to verify that they work.</p>

<pre lang='und' xml:lang='und'>    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>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 lang='und' xml:lang='und'>function_locale.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<p>For a general introduction to Excel&#39;s formulas and an explanation of the syntax of the function refer to the Excel help files or the following: http://office.microsoft.com/en-us/assistance/CH062528031033.aspx</p>

<p>If your formula doesn&#39;t work in Spreadsheet::WriteExcel try the following:</p>

<pre lang='und' xml:lang='und'>    1. Verify that the formula works in Excel (or Gnumeric or OpenOffice.org).
    2. Ensure that it isn&#39;t on the Caveats list shown above.
    3. Ensure that cell references and formula names are in uppercase.
    4. Ensure that you are using &#39;:&#39; as the range operator, A1:A4.
    5. Ensure that you are using &#39;,&#39; as the union operator, SUM(1,2,3).
    6. Ensure that the function is in the above table.</pre>

<p>If you go through steps 1-6 and you still have a problem, mail me.</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Improving_performance_when_working_with_formulas"
>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>

<pre lang='und' xml:lang='und'>    $worksheet-&#62;write_formula(&#39;B1&#39;,    &#39;=A1 * 3 + 50&#39;,    $format);
    $worksheet-&#62;write_formula(&#39;B2&#39;,    &#39;=A2 * 3 + 50&#39;,    $format);
    ...
    ...
    $worksheet-&#62;write_formula(&#39;B99&#39;,   &#39;=A999 * 3 + 50&#39;,  $format);
    $worksheet-&#62;write_formula(&#39;B1000&#39;, &#39;=A1000 * 3 + 50&#39;, $format);</pre>

<p>In this example the cell reference changes in iterations from <code lang='und' xml:lang='und'>A1</code> to <code lang='und' xml:lang='und'>A1000</code>. The parser treats this variable as a <i>token</i> 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 lang='und' xml:lang='und'>store_formula()</code> worksheet method. You can then use the <code lang='und' xml:lang='und'>repeat_formula()</code> method to substitute <code lang='und' xml:lang='und'>$pattern</code>, <code lang='und' xml:lang='und'>$replace</code> pairs in the stored formula:</p>

<pre lang='und' xml:lang='und'>    my $formula = $worksheet-&#62;store_formula(&#39;=A1 * 3 + 50&#39;);

    for my $row (0..999) {
        $worksheet-&#62;repeat_formula($row, 1, $formula, $format, &#39;A1&#39;, &#39;A&#39;.($row +1));
    }</pre>

<p>On an arbitrary test machine this method was 10 times faster than the brute force method shown above.</p>

<p>For more information about how Spreadsheet::WriteExcel parses and stores formulas see the <code lang='und' xml:lang='und'>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>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="EXAMPLES"
>EXAMPLES</a></h1>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Example_1"
>Example 1</a></h2>

<p>The following example shows some of the basic features of Spreadsheet::WriteExcel.</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    # Create a new workbook called simple.xls and add a worksheet
    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;simple.xls&#39;);
    my $worksheet = $workbook-&#62;add_worksheet();

    # The general syntax is write($row, $column, $token). Note that row and
    # column are zero indexed

    # Write some text
    $worksheet-&#62;write(0, 0,  &#39;Hi Excel!&#39;);


    # Write some numbers
    $worksheet-&#62;write(2, 0,  3);          # Writes 3
    $worksheet-&#62;write(3, 0,  3.00000);    # Writes 3
    $worksheet-&#62;write(4, 0,  3.00001);    # Writes 3.00001
    $worksheet-&#62;write(5, 0,  3.14159);    # TeX revision no.?


    # Write some formulas
    $worksheet-&#62;write(7, 0,  &#39;=A3 + A6&#39;);
    $worksheet-&#62;write(8, 0,  &#39;=IF(A5&#62;3,&#34;Yes&#34;, &#34;No&#34;)&#39;);


    # Write a hyperlink
    $worksheet-&#62;write(10, 0, &#39;http://www.perl.com/&#39;);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Example_2"
>Example 2</a></h2>

<p>The following is a general example which demonstrates some features of working with multiple worksheets.</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    # Create a new Excel workbook
    my $workbook = Spreadsheet::WriteExcel-&#62;new(&#39;regions.xls&#39;);

    # Add some worksheets
    my $north = $workbook-&#62;add_worksheet(&#39;North&#39;);
    my $south = $workbook-&#62;add_worksheet(&#39;South&#39;);
    my $east  = $workbook-&#62;add_worksheet(&#39;East&#39;);
    my $west  = $workbook-&#62;add_worksheet(&#39;West&#39;);

    # Add a Format
    my $format = $workbook-&#62;add_format();
    $format-&#62;set_bold();
    $format-&#62;set_color(&#39;blue&#39;);

    # Add a caption to each worksheet
    foreach my $worksheet ($workbook-&#62;sheets()) {
        $worksheet-&#62;write(0, 0, &#39;Sales&#39;, $format);
    }

    # Write some data
    $north-&#62;write(0, 1, 200000);
    $south-&#62;write(0, 1, 100000);
    $east-&#62;write (0, 1, 150000);
    $west-&#62;write (0, 1, 100000);

    # Set the active worksheet
    $south-&#62;activate();

    # Set the width of the first column
    $south-&#62;set_column(0, 0, 20);

    # Set the active cell
    $south-&#62;set_selection(0, 1);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    use strict;
    use Spreadsheet::WriteExcel;

    # Create a new workbook and add a worksheet
    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;stocks.xls&#39;);
    my $worksheet = $workbook-&#62;add_worksheet();

    # Set the column width for columns 1, 2, 3 and 4
    $worksheet-&#62;set_column(0, 3, 15);


    # Create a format for the column headings
    my $header = $workbook-&#62;add_format();
    $header-&#62;set_bold();
    $header-&#62;set_size(12);
    $header-&#62;set_color(&#39;blue&#39;);


    # Create a format for the stock price
    my $f_price = $workbook-&#62;add_format();
    $f_price-&#62;set_align(&#39;left&#39;);
    $f_price-&#62;set_num_format(&#39;$0.00&#39;);


    # Create a format for the stock volume
    my $f_volume = $workbook-&#62;add_format();
    $f_volume-&#62;set_align(&#39;left&#39;);
    $f_volume-&#62;set_num_format(&#39;#,##0&#39;);


    # 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-&#62;add_format();
    $f_change-&#62;set_align(&#39;left&#39;);
    $f_change-&#62;set_num_format(&#39;[Green]0.0%;[Red]-0.0%;0.0%&#39;);


    # Write out the data
    $worksheet-&#62;write(0, 0, &#39;Company&#39;,$header);
    $worksheet-&#62;write(0, 1, &#39;Price&#39;,  $header);
    $worksheet-&#62;write(0, 2, &#39;Volume&#39;, $header);
    $worksheet-&#62;write(0, 3, &#39;Change&#39;, $header);

    $worksheet-&#62;write(1, 0, &#39;Damage Inc.&#39;       );
    $worksheet-&#62;write(1, 1, 30.25,    $f_price ); # $30.25
    $worksheet-&#62;write(1, 2, 1234567,  $f_volume); # 1,234,567
    $worksheet-&#62;write(1, 3, 0.085,    $f_change); # 8.5% in green

    $worksheet-&#62;write(2, 0, &#39;Dump Corp.&#39;        );
    $worksheet-&#62;write(2, 1, 1.56,     $f_price ); # $1.56
    $worksheet-&#62;write(2, 2, 7564,     $f_volume); # 7,564
    $worksheet-&#62;write(2, 3, -0.015,   $f_change); # -1.5% in red

    $worksheet-&#62;write(3, 0, &#39;Rev Ltd.&#39;          );
    $worksheet-&#62;write(3, 1, 0.13,     $f_price ); # $0.13
    $worksheet-&#62;write(3, 2, 321,      $f_volume); # 321
    $worksheet-&#62;write(3, 3, 0,        $f_change); # 0 in the font color (black)</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Example_4"
>Example 4</a></h2>

<p>The following is a simple example of using functions.</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    # Create a new workbook and add a worksheet
    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;stats.xls&#39;);
    my $worksheet = $workbook-&#62;add_worksheet(&#39;Test data&#39;);

    # Set the column width for columns 1
    $worksheet-&#62;set_column(0, 0, 20);


    # Create a format for the headings
    my $format = $workbook-&#62;add_format();
    $format-&#62;set_bold();


    # Write the sample data
    $worksheet-&#62;write(0, 0, &#39;Sample&#39;, $format);
    $worksheet-&#62;write(0, 1, 1);
    $worksheet-&#62;write(0, 2, 2);
    $worksheet-&#62;write(0, 3, 3);
    $worksheet-&#62;write(0, 4, 4);
    $worksheet-&#62;write(0, 5, 5);
    $worksheet-&#62;write(0, 6, 6);
    $worksheet-&#62;write(0, 7, 7);
    $worksheet-&#62;write(0, 8, 8);

    $worksheet-&#62;write(1, 0, &#39;Length&#39;, $format);
    $worksheet-&#62;write(1, 1, 25.4);
    $worksheet-&#62;write(1, 2, 25.4);
    $worksheet-&#62;write(1, 3, 24.8);
    $worksheet-&#62;write(1, 4, 25.0);
    $worksheet-&#62;write(1, 5, 25.3);
    $worksheet-&#62;write(1, 6, 24.9);
    $worksheet-&#62;write(1, 7, 25.2);
    $worksheet-&#62;write(1, 8, 24.8);

    # Write some statistical functions
    $worksheet-&#62;write(4,  0, &#39;Count&#39;, $format);
    $worksheet-&#62;write(4,  1, &#39;=COUNT(B1:I1)&#39;);

    $worksheet-&#62;write(5,  0, &#39;Sum&#39;, $format);
    $worksheet-&#62;write(5,  1, &#39;=SUM(B2:I2)&#39;);

    $worksheet-&#62;write(6,  0, &#39;Average&#39;, $format);
    $worksheet-&#62;write(6,  1, &#39;=AVERAGE(B2:I2)&#39;);

    $worksheet-&#62;write(7,  0, &#39;Min&#39;, $format);
    $worksheet-&#62;write(7,  1, &#39;=MIN(B2:I2)&#39;);

    $worksheet-&#62;write(8,  0, &#39;Max&#39;, $format);
    $worksheet-&#62;write(8,  1, &#39;=MAX(B2:I2)&#39;);

    $worksheet-&#62;write(9,  0, &#39;Standard Deviation&#39;, $format);
    $worksheet-&#62;write(9,  1, &#39;=STDEV(B2:I2)&#39;);

    $worksheet-&#62;write(10, 0, &#39;Kurtosis&#39;, $format);
    $worksheet-&#62;write(10, 1, &#39;=KURT(B2:I2)&#39;);</pre>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Example_5"
>Example 5</a></h2>

<p>The following example converts a tab separated file called <code lang='und' xml:lang='und'>tab.txt</code> into an Excel file called <code lang='und' xml:lang='und'>tab.xls</code>.</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    open (TABFILE, &#39;tab.txt&#39;) or die &#34;tab.txt: $!&#34;;

    my $workbook  = Spreadsheet::WriteExcel-&#62;new(&#39;tab.xls&#39;);
    my $worksheet = $workbook-&#62;add_worksheet();

    # Row and column are zero indexed
    my $row = 0;

    while (&#60;TABFILE&#62;) {
        chomp;
        # Split on single tab
        my @Fld = split(&#39;\t&#39;, $_);

        my $col = 0;
        foreach my $token (@Fld) {
            $worksheet-&#62;write($row, $col, $token);
            $col++;
        }
        $row++;
    }</pre>

<p>NOTE: This is a simple conversion program for illustrative purposes only. For converting a CSV or Tab separated or any other type of delimited text file to Excel I recommend the more rigorous csv2xls program that is part of H.Merijn Brand&#39;s Text::CSV_XS module distro.</p>

<p>See the examples/csv2xls link here: http://search.cpan.org/~hmbrand/Text-CSV_XS/MANIFEST</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
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 lang='und' xml:lang='und'>~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>

<pre lang='und' xml:lang='und'>    Getting started
    ===============
    bug_report.pl           A template for submitting bug reports.
    a_simple.pl             An example of some of the basic features.
    demo.pl                 Creates a demo of some of the features.
    formats.pl              Creates a demo of the available formatting.
    regions.pl              Demonstrates multiple worksheets.
    stats.pl                Basic formulas and functions.

    Advanced
    ========
    autofilter.pl           Examples of worksheet autofilters.
    autofit.pl              Simulate Excel&#39;s autofit for column widths.
    bigfile.pl              Write past the 7MB limit with OLE::Storage_Lite.
    cgi.pl                  A simple CGI program.
    chess.pl                An example of formatting using properties.
    colors.pl               Demo of the colour palette and named colours.
    comments1.pl            Add comments to worksheet cells.
    comments2.pl            Add comments with advanced options.
    copyformat.pl           Example of copying a cell format.
    data_validate.pl        An example of data validation and dropdown lists.
    diag_border.pl          A simple example of diagonal cell borders.
    easter_egg.pl           Expose the Excel97 flight simulator. A must see.
    filehandle.pl           Examples of working with filehandles.
    formula_result.pl       Formulas with user specified results.
    headers.pl              Examples of worksheet headers and footers.
    hide_sheet.pl           Simple example of hiding a worksheet.
    hyperlink1.pl           Shows how to create web hyperlinks.
    hyperlink2.pl           Examples of internal and external hyperlinks.
    images.pl               Adding bitmap images to worksheets.
    indent.pl               An example of cell indentation.
    merge1.pl               A simple example of cell merging.
    merge2.pl               A simple example of cell merging with formatting.
    merge3.pl               Add hyperlinks to merged cells.
    merge4.pl               An advanced example of merging with formatting.
    merge5.pl               An advanced example of merging with formatting.
    merge6.pl               An example of merging with Unicode strings.
    mod_perl1.pl            A simple mod_perl 1 program.
    mod_perl2.pl            A simple mod_perl 2 program.
    outline.pl              An example of outlines and grouping.
    outline_collapsed.pl    Examples of collapsed outlines and grouping.
    panes.pl                An examples of how to create panes.
    properties.pl           Add document properties to a workbook.
    protection.pl           Example of cell locking and formula hiding.
    repeat.pl               Example of writing repeated formulas.
    right_to_left.pl        Change default sheet direction to right to left.
    row_wrap.pl             How to wrap data from one worksheet onto another.
    sales.pl                An example of a simple sales spreadsheet.
    sendmail.pl             Send an Excel email attachment using Mail::Sender.
    stats_ext.pl            Same as stats.pl with external references.
    stocks.pl               Demonstrates conditional formatting.
    tab_colors.pl           Example of how to set worksheet tab colours.
    textwrap.pl             Demonstrates text wrapping options.
    win32ole.pl             A sample Win32::OLE example for comparison.
    write_arrays.pl         Example of writing 1D or 2D arrays of data.
    write_handler1.pl       Example of extending the write() method. Step 1.
    write_handler2.pl       Example of extending the write() method. Step 2.
    write_handler3.pl       Example of extending the write() method. Step 3.
    write_handler4.pl       Example of extending the write() method. Step 4.
    write_to_scalar.pl      Example of writing an Excel file to a Perl scalar.


    Unicode
    =======
    unicode_utf16.pl        Simple example of using Unicode UTF16 strings.
    unicode_utf16_japan.pl  Write Japanese Unicode strings using UTF-16.
    unicode_cyrillic.pl     Write Russian Cyrillic strings using UTF-8.
    unicode_list.pl         List the chars in a Unicode font.
    unicode_2022_jp.pl      Japanese: ISO-2022-JP to utf8 in perl 5.8.
    unicode_8859_11.pl      Thai:     ISO-8859_11 to utf8 in perl 5.8.
    unicode_8859_7.pl       Greek:    ISO-8859_7  to utf8 in perl 5.8.
    unicode_big5.pl         Chinese:  BIG5        to utf8 in perl 5.8.
    unicode_cp1251.pl       Russian:  CP1251      to utf8 in perl 5.8.
    unicode_cp1256.pl       Arabic:   CP1256      to utf8 in perl 5.8.
    unicode_koi8r.pl        Russian:  KOI8-R      to utf8 in perl 5.8.
    unicode_polish_utf8.pl  Polish :  UTF8        to utf8 in perl 5.8.
    unicode_shift_jis.pl    Japanese: Shift JIS   to utf8 in perl 5.8.


    Utility
    =======
    csv2xls.pl              Program to convert a CSV file to an Excel file.
    datecalc1.pl            Convert Unix/Perl time to Excel time.
    datecalc2.pl            Calculate an Excel date using Date::Calc.
    lecxe.pl                Convert Excel to WriteExcel using Win32::OLE.
    tab2xls.pl              Program to convert a tab separated file to xls.


    Developer
    =========
    convertA1.pl            Helper functions for dealing with A1 notation.
    function_locale.pl      Add non-English function names to Formula.pm.
    writeA1.pl              Example of how to extend the module.</pre>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="LIMITATIONS"
>LIMITATIONS</a></h1>

<p>The following limits are imposed by Excel:</p>

<pre lang='und' xml:lang='und'>    Description                          Limit
    -----------------------------------  ------
    Maximum number of chars in a string  32767
    Maximum number of columns            256
    Maximum number of rows               65536
    Maximum chars in a sheet name        31
    Maximum chars in a header/footer     254</pre>

<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 installing Takanori Kawai&#39;s OLE::Storage_Lite module http://search.cpan.org/search?dist=OLE-Storage_Lite see the <code lang='und' xml:lang='und'>bigfile.pl</code> example in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="DOWNLOADING"
>DOWNLOADING</a></h1>

<p>The latest version of this module is always available at: http://search.cpan.org/search?dist=Spreadsheet-WriteExcel/</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="REQUIREMENTS"
>REQUIREMENTS</a></h1>

<p>This module requires Perl &#62;= 5.005, Parse::RecDescent, File::Temp and OLE::Storage_Lite:</p>

<pre lang='und' xml:lang='und'>    http://search.cpan.org/search?dist=Parse-RecDescent/ # For formulas.
    http://search.cpan.org/search?dist=File-Temp/        # For set_tempdir().
    http://search.cpan.org/search?dist=OLE-Storage_Lite/ # For files &#62; 7MB.</pre>

<p>Note, these aren&#39;t strict requirements. Spreadsheet::WriteExcel will work without these modules if you don&#39;t use write_formula(), set_tempdir() or create files greater than 7MB. However, it is best to install them if possible and they will be installed automatically if you use a tool such as CPAN.pm or ppm.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="INSTALLATION"
>INSTALLATION</a></h1>

<p>See the INSTALL or install.html docs that come with the distribution or:</p>

<p>http://search.cpan.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.24/INSTALL</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
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>

<pre lang='und' xml:lang='und'>    print join(&#39; &#39;, map { sprintf &#39;%#02x&#39;, $_ } unpack(&#39;C*&#39;, pack &#39;d&#39;, 1.2345)), &#34;\n&#34;;</pre>

<p>should give (or in reverse order):</p>

<pre lang='und' xml:lang='und'>    0x8d 0x97 0x6e 0x12 0x83 0xc0 0xf3 0x3f</pre>

<p>In general, if you don&#39;t know whether your system supports a 64 bit IEEE float or not, it probably does. If your system doesn&#39;t, WriteExcel will <code lang='und' xml:lang='und'>croak()</code> with the message given in the <a href="http://search.cpan.org/perldoc?DIAGNOSTICS" class="podlinkpod"
>DIAGNOSTICS</a> section. You can check which platforms the module has been tested on at the CPAN testers site: http://testers.cpan.org/search?request=dist&#38;dist=Spreadsheet-WriteExcel</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="DIAGNOSTICS"
>DIAGNOSTICS</a></h1>

<dl>
<dt><a name="Filename_required_by_Spreadsheet::WriteExcel-&#62;new()"
>Filename required by Spreadsheet::WriteExcel-&#62;new()</a></dt><p class="pad"></p>

<dd>A filename must be given in the constructor.</dd><p class="pad"></p>

<dt><a name="Can&#39;t_open_filename._It_may_be_in_use_or_protected."
>Can&#39;t open filename. It may be in use or protected.</a></dt><p class="pad"></p>

<dd>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.</dd><p class="pad"></p>

<dt><a name="Unable_to_create_tmp_files_via_File::Temp::tempfile()..."
>Unable to create tmp files via File::Temp::tempfile()...</a></dt><p class="pad"></p>

<dd>This is a <code lang='und' xml:lang='und'>-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 lang='und' xml:lang='und'>set_tempdir</code> workbook method.</dd><p class="pad"></p>

<dt><a name="Maximum_file_size,_7087104,_exceeded."
>Maximum file size, 7087104, exceeded.</a></dt><p class="pad"></p>

<dd>The current OLE implementation only supports a maximum BIFF file of this size. This limit can be extended, see the <a href="http://search.cpan.org/perldoc?LIMITATIONS" class="podlinkpod"
>LIMITATIONS</a> section.</dd><p class="pad"></p>

<dt><a name="Can&#39;t_locate_Parse/RecDescent.pm_in_@INC_..."
>Can&#39;t locate Parse/RecDescent.pm in @INC ...</a></dt><p class="pad"></p>

<dd>Spreadsheet::WriteExcel requires the Parse::RecDescent module. Download it from CPAN: http://search.cpan.org/search?dist=Parse-RecDescent</dd><p class="pad"></p>

<dt><a name="Couldn&#39;t_parse_formula_..."
>Couldn&#39;t parse formula ...</a></dt><p class="pad"></p>

<dd>There are a large number of warnings which relate to badly formed formulas and functions. See the <a href="#FORMULAS_AND_FUNCTIONS_IN_EXCEL" class="podlinkpod"
>&#34;FORMULAS AND FUNCTIONS IN EXCEL&#34;</a> section for suggestions on how to avoid these errors. You should also check the formula in Excel to ensure that it is valid.</dd><p class="pad"></p>

<dt><a name="Required_floating_point_format_not_supported_on_this_platform."
>Required floating point format not supported on this platform.</a></dt><p class="pad"></p>

<dd>Operating system doesn&#39;t support 64 bit IEEE float or it is byte-ordered in a way unknown to WriteExcel.</dd><p class="pad"></p>

<dt><a name="&#39;file.xls&#39;_cannot_be_accessed._The_file_may_be_read-only_..."
>&#39;file.xls&#39; cannot be accessed. The file may be read-only ...</a></dt><p class="pad"></p>

<dd>You may sometimes encounter the following error when trying to open a file in Excel: &#34;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.&#34;</dd><p class="pad"></p>

<dd>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 <code lang='und' xml:lang='und'>UTF-8</code> data returned by an XML parser. See <a href="#Warning_about_XML%3A%3AParser_and_perl_5.6" class="podlinkpod"
>&#34;Warning about XML::Parser and perl 5.6&#34;</a> for further details.</dd><p class="pad"></p>
</dl>

<h1><a class='u' href='#___top' title='click to go to top of document'
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 &#34;Binary Interchange File Format&#34; (BIFF) file format. Details of this format are given in &#34;Excel 97-2007 Binary File Format Specification&#34; http://www.microsoft.com/interop/docs/OfficeBinaryFormats.mspx</p>

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

<p>Charles Wybble has collected together additional information about the Excel file format. See &#34;The Chicago Project&#34; at http://chicago.sourceforge.net/devel/</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 OLE format is explained in the &#34;Windows Compound Binary File Format Specification&#34; http://www.microsoft.com/interop/docs/supportingtechnologies.mspx</p>

<p>The Digital Imaging Group have also detailed the OLE format in the JPEG2000 specification: see Appendix A of http://www.i3a.org/pdf/wg1n1017.pdf</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>

<h1><a class='u' href='#___top' title='click to go to top of document'
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>Win32::OLE module and office automation</li><p class="pad"></p>

<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 http://www.activestate.com/ASPN/Reference/Products/ActivePerl-5.6/faq/Windows/ActivePerl-Winfaq12.html and http://www.activestate.com/ASPN/Reference/Products/ActivePerl-5.6/site/lib/Win32/OLE.html 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: http://search.cpan.org/search?mode=module&#38;query=docserver</p>

<li>CSV, comma separated variables or text</li><p class="pad"></p>

<p>If the file extension is <code lang='und' xml:lang='und'>csv</code>, Excel will open and convert this format automatically. Generating a valid CSV file isn&#39;t as easy as it seems. Have a look at the DBD::RAM, DBD::CSV, Text::xSV and Text::CSV_XS modules.</p>

<li>DBI with DBD::ADO or DBD::ODBC</li><p class="pad"></p>

<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>DBD::Excel</li><p class="pad"></p>

<p>You can also access Spreadsheet::WriteExcel using the standard DBI interface via Takanori Kawai&#39;s DBD::Excel module http://search.cpan.org/dist/DBD-Excel</p>

<li>Spreadsheet::WriteExcelXML</li><p class="pad"></p>

<p>This module allows you to create an Excel XML file using the same interface as Spreadsheet::WriteExcel. See: http://search.cpan.org/dist/Spreadsheet-WriteExcelXML</p>

<li>Excel::Template</li><p class="pad"></p>

<p>This module allows you to create an Excel file from an XML template in a manner similar to HTML::Template. See http://search.cpan.org/dist/Excel-Template/</p>

<li>Spreadsheet::WriteExcel::FromXML</li><p class="pad"></p>

<p>This module allows you to turn a simple XML file into an Excel file using Spreadsheet::WriteExcel as a back-end. The format of the XML file is defined by a supplied DTD: http://search.cpan.org/dist/Spreadsheet-WriteExcel-FromXML</p>

<li>Spreadsheet::WriteExcel::Simple</li><p class="pad"></p>

<p>This provides an easier interface to Spreadsheet::WriteExcel: http://search.cpan.org/dist/Spreadsheet-WriteExcel-Simple</p>

<li>Spreadsheet::WriteExcel::FromDB</li><p class="pad"></p>

<p>This is a useful module for creating Excel files directly from a DB table: http://search.cpan.org/dist/Spreadsheet-WriteExcel-FromDB</p>

<li>HTML tables</li><p class="pad"></p>

<p>This is an easy way of adding formatting via a text based format.</p>

<li>XML or HTML</li><p class="pad"></p>

<p>The Excel XML and HTML file specification are available from http://msdn.microsoft.com/library/officedev/ofxml2k/ofxml2k.htm</p>
</ul>

<p>For other Perl-Excel modules try the following search: http://search.cpan.org/search?mode=module&#38;query=excel</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="READING_EXCEL_FILES"
>READING EXCEL FILES</a></h1>

<p>To read data from Excel files try:</p>

<ul>
<li>Spreadsheet::ParseExcel</li><p class="pad"></p>

<p>This uses the OLE::Storage-Lite module to extract data from an Excel file. http://search.cpan.org/dist/Spreadsheet-ParseExcel</p>

<li>Spreadsheet::ParseExcel_XLHTML</li><p class="pad"></p>

<p>This module uses Spreadsheet::ParseExcel&#39;s interface but uses xlHtml (see below) to do the conversion: http://search.cpan.org/dist/Spreadsheet-ParseExcel_XLHTML Spreadsheet::ParseExcel_XLHTML</p>

<li>xlHtml</li><p class="pad"></p>

<p>This is an open source &#34;Excel to HTML Converter&#34; C/C++ project at http://chicago.sourceforge.net/xlhtml/</p>

<li>DBD::Excel (reading)</li><p class="pad"></p>

<p>You can also access Spreadsheet::ParseExcel using the standard DBI interface via Takanori Kawai&#39;s DBD::Excel module http://search.cpan.org/dist/DBD-Excel</p>

<li>Win32::OLE module and office automation (reading)</li><p class="pad"></p>

<p>See, the section <a href="#WRITING_EXCEL_FILES" class="podlinkpod"
>&#34;WRITING EXCEL FILES&#34;</a>.</p>

<li>HTML tables (reading)</li><p class="pad"></p>

<p>If the files are saved from Excel in a HTML format the data can be accessed using HTML::TableExtract http://search.cpan.org/dist/HTML-TableExtract</p>

<li>DBI with DBD::ADO or DBD::ODBC.</li><p class="pad"></p>

<p>See, the section <a href="#WRITING_EXCEL_FILES" class="podlinkpod"
>&#34;WRITING EXCEL FILES&#34;</a>.</p>

<li>XML::Excel</li><p class="pad"></p>

<p>Converts Excel files to XML using Spreadsheet::ParseExcel http://search.cpan.org/dist/XML-Excel.</p>

<li>OLE::Storage, aka LAOLA</li><p class="pad"></p>

<p>This is a Perl interface to OLE file formats. In particular, the distro contains an Excel to HTML converter called Herbert, http://user.cs.tu-berlin.de/~schwartz/pmh/ This has been superseded by the Spreadsheet::ParseExcel module.</p>
</ul>

<p>For other Perl-Excel modules try the following search: http://search.cpan.org/search?mode=module&#38;query=excel</p>

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

<p>If you wish to view Excel files on a Windows platform which doesn&#39;t have Excel installed you can use the free Microsoft Excel Viewer http://office.microsoft.com/downloads/2000/xlviewer.aspx</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="MODIFYING_AND_REWRITING_EXCEL_FILES"
>MODIFYING AND REWRITING EXCEL FILES</a></h1>

<p>An Excel file is a binary file within a binary file. It contains several interlinked checksums and changing even one byte can cause it to become corrupted.</p>

<p>As such you cannot simply append or update an Excel file. The only way to achieve this is to read the entire file into memory, make the required changes or additions and then write the file out again.</p>

<p>You can read and rewrite an Excel file using the Spreadsheet::ParseExcel::SaveParser module which is a wrapper around Spreadsheet::ParseExcel and Spreadsheet::WriteExcel. It is part of the Spreadsheet::ParseExcel package: http://search.cpan.org/search?dist=Spreadsheet-ParseExcel</p>

<p>However, you can only rewrite the features that Spreadsheet::WriteExcel supports so macros, graphs and some other features in the original Excel file will be lost. Also, formulas aren&#39;t rewritten, only the result of a formula is written.</p>

<p>Here is an example:</p>

<pre lang='und' xml:lang='und'>    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::ParseExcel;
    use Spreadsheet::ParseExcel::SaveParser;

    # Open the template with SaveParser
    my $parser   = new Spreadsheet::ParseExcel::SaveParser;
    my $template = $parser-&#62;Parse(&#39;template.xls&#39;);

    my $sheet    = 0;
    my $row      = 0;
    my $col      = 0;

    # Get the format from the cell
    my $format   = $template-&#62;{Worksheet}[$sheet]
                            -&#62;{Cells}[$row][$col]
                            -&#62;{FormatNo};

    # Write data to some cells
    $template-&#62;AddCell(0, $row,   $col,   1,     $format);
    $template-&#62;AddCell(0, $row+1, $col, &#34;Hello&#34;, $format);

    # Add a new worksheet
    $template-&#62;AddWorksheet(&#39;New Data&#39;);

    # The SaveParser SaveAs() method returns a reference to a
    # Spreadsheet::WriteExcel object. If you wish you can then
    # use this to access any of the methods that aren&#39;t
    # available from the SaveParser object. If you don&#39;t need
    # to do this just use SaveAs().
    #
    my $workbook;

    {
        # SaveAs generates a lot of harmless warnings about unset
        # Worksheet properties. You can ignore them if you wish.
        local $^W = 0;

        # Rewrite the file or save as a new file
        $workbook = $template-&#62;SaveAs(&#39;new.xls&#39;);
    }

    # Use Spreadsheet::WriteExcel methods
    my $worksheet  = $workbook-&#62;sheets(0);

    $worksheet-&#62;write($row+2, $col, &#34;World2&#34;);

    $workbook-&#62;close();</pre>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="Warning_about_XML::Parser_and_perl_5.6"
>Warning about XML::Parser and perl 5.6</a></h1>

<p>You must be careful when using Spreadsheet::WriteExcel in conjunction with perl 5.6 and XML::Parser (and other XML parsers) due to the fact that the data returned by the parser is generally in <code lang='und' xml:lang='und'>UTF-8</code> format.</p>

<p>When <code lang='und' xml:lang='und'>UTF-8</code> strings are added to Spreadsheet::WriteExcel&#39;s internal data it causes the generated Excel file to become corrupt.</p>

<p>Note, this doesn&#39;t affect perl 5.005 (which doesn&#39;t try to handle <code lang='und' xml:lang='und'>UTF-8</code>) or 5.8 (which handles it correctly).</p>

<p>To avoid this problem you should upgrade to perl 5.8, if possible, or else you should convert the output data from XML::Parser to ASCII or ISO-8859-1 using one of the following methods:</p>

<pre lang='und' xml:lang='und'>    $new_str = pack &#39;C*&#39;, unpack &#39;U*&#39;, $utf8_str;


    use Unicode::MapUTF8 &#39;from_utf8&#39;;
    $new_str = from_utf8({-str =&#62; $utf8_str, -charset =&#62; &#39;ISO-8859-1&#39;});</pre>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="Warning_about_Office_Service_Pack_3"
>Warning about Office Service Pack 3</a></h1>

<p>If you have Office Service Pack 3 (SP3) installed you may see the following warning when you open a file created by Spreadsheet::WriteExcel:</p>

<pre lang='und' xml:lang='und'>    &#34;File Error: data may have been lost&#34;.</pre>

<p>This is usually caused by multiple instances of data in a cell.</p>

<p>SP3 changed Excel&#39;s default behaviour when it encounters multiple data in a cell so that it issues a warning when the file is opened and it displays the first data that was written. Prior to SP3 it didn&#39;t issue a warning and displayed the last data written.</p>

<p>For a longer discussion and some workarounds see the following: http://groups.google.com/group/spreadsheet-writeexcel/browse_thread/thread/3dcea40e6620af3a</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="BUGS"
>BUGS</a></h1>

<p>Formulas are formulae.</p>

<p>XML and <code lang='und' xml:lang='und'>UTF-8</code> data on perl 5.6 can cause Excel files created by Spreadsheet::WriteExcel to become corrupt. See <a href="#Warning_about_XML%3A%3AParser_and_perl_5.6" class="podlinkpod"
>&#34;Warning about XML::Parser and perl 5.6&#34;</a> for further details.</p>

<p>The format object that is used with a <code lang='und' xml:lang='und'>merge_range()</code> method call is marked internally as being associated with a merged range. It is a fatal error to use a merged format in a non-merged cell. The current workaround is to use separate formats for merged and non-merged cell. This restriction will be removed in a future release.</p>

<p>Nested formulas sometimes aren&#39;t parsed correctly and give a result of &#34;#VALUE&#34;. 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.org: No known issues in this release.</p>

<p>Gnumeric: No known issues in this release.</p>

<p>Excel 2008 for Mac: Hyperlinks generate a &#34;File Error: data may have been lost&#34; warning.</p>

<p>If you wish to submit a bug report run the <code lang='und' xml:lang='und'>bug_report.pl</code> program in the <code lang='und' xml:lang='und'>examples</code> directory of the distro.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="TO_DO"
>TO DO</a></h1>

<p>The roadmap is as follows:</p>

<ul>
<li>Add named ranges.</li><p class="pad"></p>
</ul>

<p>Also, here are some of the most requested features that probably won&#39;t get added:</p>

<ul>
<li>Macros.</li><p class="pad"></p>

<p>This would solve some other problems neatly. However, the format of Excel macros isn&#39;t documented.</p>

<li>Some feature that you really need. ;-)</li><p class="pad"></p>
</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" class="podlinkpod"
>&#34;WRITING EXCEL FILES&#34;</a>.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="MAILING_LIST"
>MAILING LIST</a></h1>

<p>There is a Google group for discussing and asking questions about Spreadsheet::WriteExcel. This is a good place to search to see if your question has been asked before: http://groups-beta.google.com/group/spreadsheet-writeexcel/</p>

<p>Alternatively you can keep up to date with future releases by subscribing at: http://freshmeat.net/projects/writeexcel/</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="DONATIONS"
>DONATIONS</a></h1>

<p>If you&#39;d care to donate to the Spreadsheet::WriteExcel project, you can do so via PayPal: http://tinyurl.com/7ayes</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="SEE_ALSO"
>SEE ALSO</a></h1>

<p>Spreadsheet::ParseExcel: http://search.cpan.org/dist/Spreadsheet-ParseExcel</p>

<p>Spreadsheet-WriteExcel-FromXML: http://search.cpan.org/dist/Spreadsheet-WriteExcel-FromXML</p>

<p>Spreadsheet::WriteExcel::FromDB: http://search.cpan.org/dist/Spreadsheet-WriteExcel-FromDB</p>

<p>Excel::Template: http://search.cpan.org/~rkinyon/Excel-Template/</p>

<p>DateTime::Format::Excel: http://search.cpan.org/dist/DateTime-Format-Excel</p>

<p>&#34;Reading and writing Excel files with Perl&#34; by Teodor Zlatanov, at IBM developerWorks: http://www-106.ibm.com/developerworks/library/l-pexcel/</p>

<p>&#34;Excel-Dateien mit Perl erstellen - Controller im Gluck&#34; by Peter Dintelmann and Christian Kirsch in the German Unix/web journal iX: http://www.heise.de/ix/artikel/2001/06/175/</p>

<p>Spreadsheet::WriteExcel documentation in Japanese by Takanori Kawai. http://member.nifty.ne.jp/hippo2000/perltips/Spreadsheet/WriteExcel.htm</p>

<p>Oesterly user brushes with fame: http://oesterly.com/releases/12102000.html</p>

<p>The csv2xls program that is part of Text::CSV_XS: http://search.cpan.org/~hmbrand/Text-CSV_XS/MANIFEST</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="ACKNOWLEDGMENTS"
>ACKNOWLEDGMENTS</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, Bob Rose, Borgar Olsen, Brian Foley, Brian White, Bob Mackay, Cedric Bouvier, Chad Johnson, CPAN testers, Damyan Ivanov, Daniel Berger, Daniel Gardner, Dmitry Kochurov, Eric Frazier, Ernesto Baschny, Felipe Perez Galiana, Gordon Simpson, Hanc Pavel, Harold Bamford, James Holmes, James Wilkinson, Johan Ekenberg, Johann Hanne, Jonathan Scott Duff, J.C. Wren, Kenneth Stacey, Keith Miller, Kyle Krom, Marc Rosenthal, Markus Schmitz, Michael Braig, Michael Buschauer, Mike Blazer, Michael Erickson, Michael W J West, Ning Xie, Paul J. Falbe, Paul Medynski, Peter Dintelmann, Pierre Laplante, Praveen Kotha, Reto Badertscher, Rich Sorden, Shane Ashby, Sharron McKenzie, Shenyu Zheng, Stephan Loescher, Steve Sapovits, Sven Passig, Svetoslav Marinov, Tamas Gulacsi, Troy Daniels, Vahe Sarkissian.</p>

<p>The following people contributed patches, examples or Excel information:</p>

<p>Andrew Benham, Bill Young, Cedric Bouvier, Charles Wybble, Daniel Rentz, David Robins, Franco Venturi, Guy Albertelli, Ian Penman, John Heitmann, Jon Guy, Kyle R. Burton, Pierre-Jean Vouette, Rubio, Marco Geri, Mark Fowler, Matisse Enzer, Sam Kington, Takanori Kawai, Tom O&#39;Sullivan.</p>

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

<p>Many thanks to Cassens Transport who sponsored the development of the embedded charts and autofilters.</p>

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

<p>Gunnar Wolf 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>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="DISCLAIMER_OF_WARRANTY"
>DISCLAIMER OF WARRANTY</a></h1>

<p>Because this software is licensed free of charge, there is no warranty for the software, to the extent permitted by applicable law. Except when otherwise stated in writing the copyright holders and/or other parties provide the software &#34;as is&#34; without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the software is with you. Should the software prove defective, you assume the cost of all necessary servicing, repair, or correction.</p>

<p>In no event unless required by applicable law or agreed to in writing will any copyright holder, or any other party who may modify and/or redistribute the software as permitted by the above licence, be liable to you for damages, including any general, special, incidental, or consequential damages arising out of the use or inability to use the software (including but not limited to loss of data or data being rendered inaccurate or losses sustained by you or third parties or a failure of the software to operate with any other software), even if such holder or other party has been advised of the possibility of such damages.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="LICENSE"
>LICENSE</a></h1>

<p>Either the Perl Artistic Licence http://dev.perl.org/licenses/artistic.html or the GPL http://www.opensource.org/licenses/gpl-license.php</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="AUTHOR"
>AUTHOR</a></h1>

<p>John McNamara jmcnamara@cpan.org</p>

<pre lang='und' xml:lang='und'>    I don&#39;t want to get over you

    I guess I could take a sleeping pill
    And sleep at will
    And not have to go through
    What I go through

    I guess I should take Prozac, right?
    And just smile all night
    At somebody new

    Somebody not too bright
    But sweet and kind
    Who would try to get you off my mind
    I could leave this agony behind
    Which is just what I&#39;d do
    If I wanted to
    But I don&#39;t want to get over you

        -- Stephin Merritt</pre>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="COPYRIGHT"
>COPYRIGHT</a></h1>

<p>Copyright MM-MMVIII, 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>

<!-- end doc -->

</body></html>