ExcelWriterXML
[ class tree: ExcelWriterXML ] [ index: ExcelWriterXML ] [ all elements ]

Source for file example2.php

Documentation is available at example2.php

  1. <?php
  2. /**
  3.  * Detailed example for creating Excel XML docs
  4.  * @package ExcelWriterXML
  5.  * @subpackage examples
  6.  * @filesource
  7.  */
  8.  
  9. /**
  10.  * Include the class for creating Excel XML docs
  11.  */
  12. include('ExcelWriterXML.php');
  13.  
  14. /**
  15.  * Create a new instance of the Excel Writer
  16.  */
  17. $xml new ExcelWriterXML('my file.xml');
  18.  
  19. /**
  20.  * Add some general properties to the document
  21.  */
  22. $xml->docTitle('My Demo Doc');
  23. $xml->docAuthor('Robert F Greer');
  24. $xml->docCompany('Greers.Org');
  25. $xml->docManager('Wife');
  26.  
  27. /**
  28.  * Choose to show any formatting/input errors on a seperate sheet
  29.  */
  30. $xml->showErrorSheet(true);
  31.  
  32. /**
  33.  * Show the style options
  34.  */
  35. $format1 $xml->addStyle('left_rotate60_big');
  36. $format1->alignRotate(60);
  37. $format1->alignHorizontal('Left');
  38. $format1->fontSize('18');
  39.  
  40. $format2 $xml->addStyle('verticaltext_left');
  41. $format2->alignVerticaltext(45);
  42. $format2->alignHorizontal('Left');
  43.  
  44. $format3 $xml->addStyle('wraptext_top');
  45. $format3->alignWraptext();
  46. $format3->alignVertical('Top');
  47.  
  48. /**
  49.  * Create a new sheet with the XML document
  50.  */
  51. $sheet1 $xml->addSheet('Alignment');
  52. /**
  53.  * Add three new cells of type String with difference alignment values.
  54.  * Notice that the style of the each cell can be explicity named or the style
  55.  * reference can be passed.
  56.  */
  57. $sheet1->writeString(1,1,'left_rotate45',$format1);
  58. $sheet1->writeString(1,2,'vertical left','verticaltext_left');
  59. $sheet1->writeString(1,3,'this text has been wrapped and is aligned at the top','wraptext_top');
  60. $sheet1->writeString(1,4,'No style applied');
  61.  
  62.  
  63. $sheet2 $xml->addSheet('Formulas');
  64. /**
  65.  * Wrote three numbers.
  66.  * Rows 4 and 5 show the formulas in R1C1 notation using the writeFormula()
  67.  * function.
  68.  * Also see how comments are added.
  69.  */
  70. $sheet2->columnWidth(1,'100');
  71. $sheet2->writeString(1,1,'Number');
  72. $sheet2->writeNumber(1,2,50);
  73. $sheet2->writeString(2,1,'Number');
  74. $sheet2->writeNumber(2,2,30);
  75. $sheet2->writeString(3,1,'Number');
  76. $sheet2->writeNumber(3,2,20);
  77. $sheet2->writeString(4,1,'=SUM(R[-3]C:R[-1]C)');
  78. $sheet2->writeFormula('Number',4,2,'=SUM(R[-3]C:R[-1]C)');
  79. $sheet2->addComment(4,2,'Here is my formula: =SUM(R[-3]C:R[-1]C)','My NAME');
  80. $sheet2->writeString(5,1,'=SUM(R1C2:R3C2)');
  81. $sheet2->writeFormula('Number',5,2,'=SUM(R1C1:R3C2)');
  82. $sheet2->addComment(5,2,'Here is my formula: =SUM(R1C1:R3C2)');
  83.  
  84. $sheet4 $xml->addSheet('more formatting');
  85. $format4 $xml->addStyle('my style');
  86. $format4->fontBold();
  87. $format4->fontItalic();
  88. $format4->fontUnderline('DoubleAccounting');
  89. $format4->bgColor('Black');
  90. $format4->fontColor('White');
  91. $format4->numberFormatDateTime();
  92. $mydate $sheet4->convertMysqlDateTime('2008-02-14 19:30:00');
  93. $sheet4->writeDateTime(1,1,$mydate,$format4);
  94. // Change the row1 height to 30 pixels
  95. $sheet4->rowHeight(1,'30');
  96. $sheet4->writeString(2,1,'formatted text + cell color + merged + underlined',$format4);
  97. // Merge (2,1) with 4 columns to the right and 2 rows down
  98. $sheet4->cellMerge(2,1,4,2);
  99.  
  100. /**
  101.  * Send the headers, then output the data
  102.  */
  103. $xml->sendHeaders();
  104. $xml->writeData();
  105.  
  106.  
  107. ?>

Documentation generated on Thu, 25 Feb 2010 16:36:54 -0600 by phpDocumentor 1.4.1