cvs: peardoc /en/package/fileformats/spreadsheet-excel-writer intro.xml intro_format.xml
| From: | Xavier Noguer Gallego | Date: | Sat, 26 Apr 2003 00:40:10 +0000 |
| Subject: | cvs: peardoc /en/package/fileformats/spreadsheet-excel-writer intro.xml intro_format.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-657@lists.php.net to get a copy of this message | ||
xnoguer Fri Apr 25 20:40:10 2003 EDT
Modified files:
/peardoc/en/package/fileformats/spreadsheet-excel-writer intro.xml
intro_format.xml
Log:
making tutorials more complete
Index: peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml diff -u peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml:1.4 peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml:1.5 --- peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml:1.4 Thu Apr 10 19:40:36 2003 +++ peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml Fri Apr 25 20:40:10 2003 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <refentry id="package.fileformats.spreadsheet-excel-writer.intro"> <refnamediv> <refname>Introduction</refname> @@ -8,7 +8,7 @@ <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro.whatis"> <title>What is Spreadsheet_Excel_Writer?</title> <para> - <classname>Spreadsheet_Excel_Writer</classname> is a tool for generating + <classname>Spreadsheet_Excel_Writer</classname> is a tool for creating Excel files without the need for COM components. The files generated by the current version of <classname>Spreadsheet_Excel_Writer</classname> correspond to the Excel 5 (BIFF5) format, so all functionality until @@ -69,12 +69,72 @@ with <classname>Spreadsheet_Excel_Writer</classname>, is that ampersand sign (&) that appears when we created our worksheet. That ampersand means we are referencing a Worksheet object instead of copying it. If you don't - know what that means, don't worry, all you have to remember is to allways + know what that means, don't worry, all you have to remember is to always use ampersands when calling <link - linkend="package.fileformats.spreadsheet-excel-writer.workbook.addworksheet"> + linkend="package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-workbook.addworksheet"> <function>addWorksheet</function></link> for creating a worksheet, or <link - linkend="package.fileformats.spreadsheet-excel-writer.workbook.addformat"><function>addFormat</function></link> for creating a format. + linkend="package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-workbook.addformat"><function>addFormat</function></link> for creating a format. + </para> + </refsect1> + <refsect1 + id="package.fileformats.spreadsheet-excel-writer.intro.saving-to-regular-file"> + <title>Saving to a regular file</title> + <para> + You may have noticed also the following line: + <programlisting role="php"> +<![CDATA[ +// sending HTTP headers +$workbook->send('test.xls'); +]]> + </programlisting> + What that means is that we are sending our spreadsheet to a browser. + But what if we just want to save the spreadsheet in our machine? Well, you + just have to omit that line and give a valid file path to the workbook + constructor. + </para> + <para> + For example, if we wanted to save the same spreadsheet we created in our + first example to a file named 'test.xls', we would do it like so: + </para> + <example> + <title>Saving to a regular file</title> + <programlisting role="php"> +<![CDATA[ +<?php +require_once 'Spreadsheet/Excel/Writer.php'; + +// We give the path to our file here +$workbook = new Spreadsheet_Excel_Writer('test.xls'); + +$worksheet =& $workbook->addWorksheet('My first worksheet'); + +$worksheet->write(0, 0, 'Name'); +$worksheet->write(0, 1, 'Age'); +$worksheet->write(1, 0, 'John Smith'); +$worksheet->write(1, 1, 30); +$worksheet->write(2, 0, 'Johann Schmidt'); +$worksheet->write(2, 1, 31); +$worksheet->write(3, 0, 'Juan Herrera'); +$worksheet->write(3, 1, 32); + +// We still need to explicitly close the workbook +$workbook->close(); +?> +]]> + </programlisting> + </example> + </refsect1> + + <refsect1 + id="package.fileformats.spreadsheet-excel-writer.intro.more-tutorials"> + <title>More tutorials</title> + <para> + If you would like to learn about formatting (fonts, cell color, text + alignment, etc...) with <classname>Spreadsheet_Excel_Writer</classname>, + you can check the formatting tutorial <link + linkend="package.fileformats.spreadsheet-excel-writer.intro-format"> + here</link>. </para> </refsect1> Index: peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml diff -u peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml:1.2 peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml:1.3 --- peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml:1.2 Thu Apr 10 20:43:29 2003 +++ peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml Fri Apr 25 20:40:10 2003 @@ -1,11 +1,11 @@ -<!-- $Revision: 1.2 $ --> -<refentry id="package.fileformats.spreadsheet-excel-writer.intro_format"> +<!-- $Revision: 1.3 $ --> +<refentry id="package.fileformats.spreadsheet-excel-writer.intro-format"> <refnamediv> <refname>Formatting Tutorial</refname> <refpurpose>how to give format to cells in a spreadsheet</refpurpose> </refnamediv> - <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro_format.whatis"> + <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro-format.whatis"> <title>What is a format?</title> <para> A format is an object of type <classname>Spreadsheet_Excel_Writer_Format</classname>. @@ -15,7 +15,7 @@ </para> </refsect1> - <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro_format.using-it"> + <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro-format.using-it"> <title>Using it</title> <para> Formats can't be created directly by a <citetitle>new</citetitle> call. @@ -55,7 +55,7 @@ </para> </refsect1> - <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro_format.something-useful"> + <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro-format.something-useful"> <title>Making something useful</title> <para> Well, we just created our first format, but we didn't use it. Not very @@ -82,7 +82,7 @@ using the company's colors for those titles?". </para> <para> - There a number of ways for dealing with this situation, but in + There are a number of ways for dealing with this situation, but in this tutorial we will stick to the one which will keep your job. </para> <para> @@ -136,7 +136,7 @@ $format_title->setFgColor('blue'); $worksheet =& $workbook->addWorksheet(); -$worksheet->write(0, 0, "Profits for Dotcom.Com", $format_title); +$worksheet->write(0, 0, "Quarterly Profits for Dotcom.Com", $format_title); // While we are at it, why not throw some more numbers around $worksheet->write(1, 0, "Quarter", $format_bold); $worksheet->write(1, 1, "Profit", $format_bold); @@ -145,6 +145,73 @@ $worksheet->write(3, 0, "Q2"); $worksheet->write(3, 1, 0); +$workbook->send('test.xls'); +$workbook->close(); +?> +]]> + </programlisting> + </example> + </refsect1> + + <refsect1 + id="package.fileformats.spreadsheet-excel-writer.intro-format.merging-cells"> + <title>Merging cells</title> + <para> + If you just tested the previous example you might have noticed that the + title would need several cells to be seen correctly, but the format we + applied only works for the first cell. So our title does not look very + nice. + </para> + <para> + What can we do to fix that? Well, you could tell your boss that the title + looks ok to you, and that he really needs to visit an ophthalmologist. + Or you could use cell merging in order to make the title spread over + several cells. + </para> + <para> + For this you have to use the <link + linkend="package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.setalign"> + <function>setAlign</function></link> method with 'merge' as argument, + and create some empty cells so the title can 'use' them as a sort of + background (there will be a better way to do this in a future version of + <classname>Spreadsheet_Excel_Writer</classname>). + </para> + <para> + Applying merging to our example script, we would have this: + </para> + <example> + <title>Merging cells</title> + <programlisting role="php"> +<![CDATA[ +<?php +require_once 'Spreadsheet/Excel/Writer.php'; +$workbook = new Spreadsheet_Excel_Writer(); + +$format_bold =& $workbook->addFormat(); +$format_bold->setBold(); + +$format_title =& $workbook->addFormat(); +$format_title->setBold(); +$format_title->setColor('yellow'); +$format_title->setPattern(1); +$format_title->setFgColor('blue'); +// let's merge +$format_title->setAlign('merge'); + +$worksheet =& $workbook->addWorksheet(); +$worksheet->write(0, 0, "Quarterly Profits for Dotcom.Com", $format_title); +// Couple of empty cells to make it look better +$worksheet->write(0, 1, "", $format_title); +$worksheet->write(0, 2, "", $format_title); +$worksheet->write(1, 0, "Quarter", $format_bold); +$worksheet->write(1, 1, "Profit", $format_bold); +$worksheet->write(2, 0, "Q1"); +$worksheet->write(2, 1, 0); +$worksheet->write(3, 0, "Q2"); +$worksheet->write(3, 1, 0); + +$workbook->send('test.xls'); +$workbook->close(); ?> ]]> </programlisting>
Index: peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml diff -u peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml:1.4 peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml:1.5 --- peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml:1.4 Thu Apr 10 19:40:36 2003 +++ peardoc/en/package/fileformats/spreadsheet-excel-writer/intro.xml Fri Apr 25 20:40:10 2003 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <refentry id="package.fileformats.spreadsheet-excel-writer.intro"> <refnamediv> <refname>Introduction</refname> @@ -8,7 +8,7 @@ <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro.whatis"> <title>What is Spreadsheet_Excel_Writer?</title> <para> - <classname>Spreadsheet_Excel_Writer</classname> is a tool for generating + <classname>Spreadsheet_Excel_Writer</classname> is a tool for creating Excel files without the need for COM components. The files generated by the current version of <classname>Spreadsheet_Excel_Writer</classname> correspond to the Excel 5 (BIFF5) format, so all functionality until @@ -69,12 +69,72 @@ with <classname>Spreadsheet_Excel_Writer</classname>, is that ampersand sign (&) that appears when we created our worksheet. That ampersand means we are referencing a Worksheet object instead of copying it. If you don't - know what that means, don't worry, all you have to remember is to allways + know what that means, don't worry, all you have to remember is to always use ampersands when calling <link - linkend="package.fileformats.spreadsheet-excel-writer.workbook.addworksheet"> + linkend="package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-workbook.addworksheet"> <function>addWorksheet</function></link> for creating a worksheet, or <link - linkend="package.fileformats.spreadsheet-excel-writer.workbook.addformat"><function>addFormat</function></link> for creating a format. + linkend="package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-workbook.addformat"><function>addFormat</function></link> for creating a format. + </para> + </refsect1> + <refsect1 + id="package.fileformats.spreadsheet-excel-writer.intro.saving-to-regular-file"> + <title>Saving to a regular file</title> + <para> + You may have noticed also the following line: + <programlisting role="php"> +<![CDATA[ +// sending HTTP headers +$workbook->send('test.xls'); +]]> + </programlisting> + What that means is that we are sending our spreadsheet to a browser. + But what if we just want to save the spreadsheet in our machine? Well, you + just have to omit that line and give a valid file path to the workbook + constructor. + </para> + <para> + For example, if we wanted to save the same spreadsheet we created in our + first example to a file named 'test.xls', we would do it like so: + </para> + <example> + <title>Saving to a regular file</title> + <programlisting role="php"> +<![CDATA[ +<?php +require_once 'Spreadsheet/Excel/Writer.php'; + +// We give the path to our file here +$workbook = new Spreadsheet_Excel_Writer('test.xls'); + +$worksheet =& $workbook->addWorksheet('My first worksheet'); + +$worksheet->write(0, 0, 'Name'); +$worksheet->write(0, 1, 'Age'); +$worksheet->write(1, 0, 'John Smith'); +$worksheet->write(1, 1, 30); +$worksheet->write(2, 0, 'Johann Schmidt'); +$worksheet->write(2, 1, 31); +$worksheet->write(3, 0, 'Juan Herrera'); +$worksheet->write(3, 1, 32); + +// We still need to explicitly close the workbook +$workbook->close(); +?> +]]> + </programlisting> + </example> + </refsect1> + + <refsect1 + id="package.fileformats.spreadsheet-excel-writer.intro.more-tutorials"> + <title>More tutorials</title> + <para> + If you would like to learn about formatting (fonts, cell color, text + alignment, etc...) with <classname>Spreadsheet_Excel_Writer</classname>, + you can check the formatting tutorial <link + linkend="package.fileformats.spreadsheet-excel-writer.intro-format"> + here</link>. </para> </refsect1> Index: peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml diff -u peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml:1.2 peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml:1.3 --- peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml:1.2 Thu Apr 10 20:43:29 2003 +++ peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml Fri Apr 25 20:40:10 2003 @@ -1,11 +1,11 @@ -<!-- $Revision: 1.2 $ --> -<refentry id="package.fileformats.spreadsheet-excel-writer.intro_format"> +<!-- $Revision: 1.3 $ --> +<refentry id="package.fileformats.spreadsheet-excel-writer.intro-format"> <refnamediv> <refname>Formatting Tutorial</refname> <refpurpose>how to give format to cells in a spreadsheet</refpurpose> </refnamediv> - <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro_format.whatis"> + <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro-format.whatis"> <title>What is a format?</title> <para> A format is an object of type <classname>Spreadsheet_Excel_Writer_Format</classname>. @@ -15,7 +15,7 @@ </para> </refsect1> - <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro_format.using-it"> + <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro-format.using-it"> <title>Using it</title> <para> Formats can't be created directly by a <citetitle>new</citetitle> call. @@ -55,7 +55,7 @@ </para> </refsect1> - <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro_format.something-useful"> + <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro-format.something-useful"> <title>Making something useful</title> <para> Well, we just created our first format, but we didn't use it. Not very @@ -82,7 +82,7 @@ using the company's colors for those titles?". </para> <para> - There a number of ways for dealing with this situation, but in + There are a number of ways for dealing with this situation, but in this tutorial we will stick to the one which will keep your job. </para> <para> @@ -136,7 +136,7 @@ $format_title->setFgColor('blue'); $worksheet =& $workbook->addWorksheet(); -$worksheet->write(0, 0, "Profits for Dotcom.Com", $format_title); +$worksheet->write(0, 0, "Quarterly Profits for Dotcom.Com", $format_title); // While we are at it, why not throw some more numbers around $worksheet->write(1, 0, "Quarter", $format_bold); $worksheet->write(1, 1, "Profit", $format_bold); @@ -145,6 +145,73 @@ $worksheet->write(3, 0, "Q2"); $worksheet->write(3, 1, 0); +$workbook->send('test.xls'); +$workbook->close(); +?> +]]> + </programlisting> + </example> + </refsect1> + + <refsect1 + id="package.fileformats.spreadsheet-excel-writer.intro-format.merging-cells"> + <title>Merging cells</title> + <para> + If you just tested the previous example you might have noticed that the + title would need several cells to be seen correctly, but the format we + applied only works for the first cell. So our title does not look very + nice. + </para> + <para> + What can we do to fix that? Well, you could tell your boss that the title + looks ok to you, and that he really needs to visit an ophthalmologist. + Or you could use cell merging in order to make the title spread over + several cells. + </para> + <para> + For this you have to use the <link + linkend="package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.setalign"> + <function>setAlign</function></link> method with 'merge' as argument, + and create some empty cells so the title can 'use' them as a sort of + background (there will be a better way to do this in a future version of + <classname>Spreadsheet_Excel_Writer</classname>). + </para> + <para> + Applying merging to our example script, we would have this: + </para> + <example> + <title>Merging cells</title> + <programlisting role="php"> +<![CDATA[ +<?php +require_once 'Spreadsheet/Excel/Writer.php'; +$workbook = new Spreadsheet_Excel_Writer(); + +$format_bold =& $workbook->addFormat(); +$format_bold->setBold(); + +$format_title =& $workbook->addFormat(); +$format_title->setBold(); +$format_title->setColor('yellow'); +$format_title->setPattern(1); +$format_title->setFgColor('blue'); +// let's merge +$format_title->setAlign('merge'); + +$worksheet =& $workbook->addWorksheet(); +$worksheet->write(0, 0, "Quarterly Profits for Dotcom.Com", $format_title); +// Couple of empty cells to make it look better +$worksheet->write(0, 1, "", $format_title); +$worksheet->write(0, 2, "", $format_title); +$worksheet->write(1, 0, "Quarter", $format_bold); +$worksheet->write(1, 1, "Profit", $format_bold); +$worksheet->write(2, 0, "Q1"); +$worksheet->write(2, 1, 0); +$worksheet->write(3, 0, "Q2"); +$worksheet->write(3, 1, 0); + +$workbook->send('test.xls'); +$workbook->close(); ?> ]]> </programlisting>