cvs: peardoc /en/package/fileformats/spreadsheet-excel-writer intro_format.xml

From: Date: Thu, 10 Apr 2003 23:41:33 +0000
Subject: cvs: peardoc /en/package/fileformats/spreadsheet-excel-writer intro_format.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-615@lists.php.net to get a copy of this message
xnoguer Thu Apr 10 19:41:33 2003 EDT Added files: /peardoc/en/package/fileformats/spreadsheet-excel-writer intro_format.xml Log: first version of the formatting tutorial Index: peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml +++ peardoc/en/package/fileformats/spreadsheet-excel-writer/intro_format.xml <!-- $Revision: 1.1 $ --> <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"> <title>What is a format?</title> <para> A format is an object of type <classname>Spreadsheet_Excel_Writer_Format</classname>. This format can be applied to cells inside a spreadsheet so that this cells inherit the properties of the format (text alignment, background color, border colors, etc...). </para> </refsect1> <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro_format.using-it"> <title>Using it</title> <para> Formats can't be created directly by a <function>new</function> call. You have to create a format using the <link linkend="package.fileformats.spreadsheet-excel-writer.workbook.addformat"> <function>addFormat</function></link> method from a Workbook, which associates your Format with this Workbook (you can't use the Format with another Workbook). </para> <para> Let's see how <link linkend="package.fileformats.spreadsheet-excel-writer.workbook.addformat"> <function>addFormat</function></link> is used: </para> <example> <title>addFormat usage</title> <programlisting role="php"> <![CDATA[ <?php require_once 'Spreadsheet/Excel/Writer.php'; // Creating a workbook $workbook = new Spreadsheet_Excel_Writer(); // Creating the format $format_bold =& $workbook->addFormat(); $format_bold->setBold(); ?> ]]> </programlisting> </example> <para> There, we just created a bold format. Notice the ampersand sign (&) that appears when we created our format. If you don't create your format like that it will appear as if all the format's properties you set are ignored. </para> </refsect1> <refsect1 id="package.fileformats.spreadsheet-excel-writer.intro_format.something-usefull"> <title>Making something usefull</title> <para> Well, we just created our first format, but we didn't use it. Not very smart. So let's do something useful with a format. </para> <para> Let's say you want to make your regular data filled spreadsheet. Only this time, when you proudly present your beautiful creation to your boss, the thing you most dread happens: <classname>Pointy haired boss</classname> - Mmmmhhh, seems OK. <classname>You</classname> - Yes, I added those totals as you requested. <classname>Pointy haired boss</classname> - Mmmmhhh, you know, there's going to be a lot of customers using this spreadsheet... <classname>You</classname> - So... <classname>Pointy haired boss</classname> - Mmmmhhh, what do you think of changing the style for those headers there? <classname>You</classname> - ... Of course it won't be just those headers: "why don't we center this title here?", "Could you merge those cells over there?", "what do you think of using the company's colors for those titles?". Of course there 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> So let's begin work on the spreadsheet for DotCom.com. </para> <example> <title>First example</title> <programlisting role="php"> <![CDATA[ <?php require_once 'Spreadsheet/Excel/Writer.php'; $workbook = new Spreadsheet_Excel_Writer(); $format_bold =& $workbook->addFormat(); $format_bold->setBold(); // We need a worksheet where to put our data $worksheet =& $workbook->addWorksheet(); // This is our title $worksheet->write(0, 0, "Profits for Dotcom.Com", $format_bold); // And now the data $worksheet->write(0, 0, 0); ?> ]]> </programlisting> </example> <para> There. Now all of those VC's out there are going to be calling like crazy asking for an oportunity to invest on DotCom.com. Wait a minute. These are not regular VC's we are talking about. These are very selective guys who wouldn't trust their money to first start-up they happen to see on the internet. I know, let's put the company's colors in there. </para> <example> <title>Second example</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'); $worksheet =& $workbook->addWorksheet(); $worksheet->write(0, 0, "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); $worksheet->write(2, 0, "Q1"); $worksheet->write(2, 1, 0); $worksheet->write(3, 0, "Q2"); $worksheet->write(3, 1, 0); ?> ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->

« previous php.pear.doc (#615) next »