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

example

  1. <?php
  2.  
  3. /**
  4.  * Generate a simple sample report.
  5.  *
  6.  * @category   Phpdocx
  7.  * @package    examples
  8.  * @subpackage advanced
  9.  * @copyright  Copyright (c) 2009-2013 Narcea Producciones Multimedia S.L.
  10.  *              (http://www.2mdc.com)
  11.  * @license    http://www.phpdocx.com/wp-content/themes/lightword/pro_license.php
  12.  * @version    2012.12.26
  13.  * @link       http://www.phpdocx.com
  14.  * @since      File available since Release 2.2
  15.  */
  16. require_once '../../classes/CreateDocx.inc';
  17.  
  18. $docx new CreateDocx();
  19.  
  20. // browser stats
  21. $statsFeb2009Feb2010 '
  22. <STATS>
  23.     <BROWSER>
  24.         <NAME>Internet Explorer</NAME>
  25.         <VALUE>58</VALUE>
  26.     </BROWSER>
  27.     <BROWSER>
  28.         <NAME>Firefox</NAME>
  29.         <VALUE>31</VALUE>
  30.     </BROWSER>
  31.     <BROWSER>
  32.         <NAME>Chrome</NAME>
  33.         <VALUE>4</VALUE>
  34.     </BROWSER>
  35.     <BROWSER>
  36.         <NAME>Safari</NAME>
  37.         <VALUE>3</VALUE>
  38.     </BROWSER>
  39.     <BROWSER>
  40.         <NAME>Opera</NAME>
  41.         <VALUE>2</VALUE>
  42.     </BROWSER>
  43.     <BROWSER>
  44.         <NAME>Other</NAME>
  45.         <VALUE>2</VALUE>
  46.     </BROWSER>
  47. </STATS>
  48. ';
  49.  
  50. $statsFeb2010Feb2011 '
  51. <STATS>
  52.     <BROWSER>
  53.         <NAME>Internet Explorer</NAME>
  54.         <VALUE>50</VALUE>
  55.     </BROWSER>
  56.     <BROWSER>
  57.         <NAME>Firefox</NAME>
  58.         <VALUE>31</VALUE>
  59.     </BROWSER>
  60.     <BROWSER>
  61.         <NAME>Chrome</NAME>
  62.         <VALUE>11</VALUE>
  63.     </BROWSER>
  64.     <BROWSER>
  65.         <NAME>Safari</NAME>
  66.         <VALUE>4</VALUE>
  67.     </BROWSER>
  68.     <BROWSER>
  69.         <NAME>Opera</NAME>
  70.         <VALUE>2</VALUE>
  71.     </BROWSER>
  72.     <BROWSER>
  73.         <NAME>Other</NAME>
  74.         <VALUE>2</VALUE>
  75.     </BROWSER>
  76. </STATS>
  77. ';
  78.  
  79. // add text and date in header
  80. $header 'Browsers stats';
  81.  
  82. $paramsHeader array(
  83.     'jc' => 'right',
  84.     'rawWordML' => true
  85. );
  86.  
  87. $headerData $docx->addText($header$paramsHeader);
  88.  
  89. $myHeader $docx->createWordMLFragment(array($headerData));
  90.  
  91. $docx->addHeader(array('default' => $myHeader));
  92.  
  93. // add footer with pager
  94. $footer 'DOCX generated using PHPDOCX PRO';
  95.  
  96. $paramsFooter array(
  97.     'jc' => 'center',
  98.     'rawWordML' => true
  99. );
  100.  
  101. $footerData $docx->addText($footer$paramsFooter);
  102.  
  103. $pager $docx->addPageNumber('numerical'array('jc' => 'center''rawWordML' => true));
  104.  
  105. $myFooter $docx->createWordMLFragment(array($footerData$pager));
  106.  
  107. $docx->addFooter(array('default' => $myFooter));
  108.  
  109. // add line break
  110. $docx->addBreak();
  111. $docx->addBreak();
  112. $docx->addBreak();
  113.  
  114. // read XML Feb209Feb2010
  115. $xmlFeb2009Feb2010 new DOMDocument();
  116. $xmlFeb2009Feb2010->loadXML($statsFeb2009Feb2010);
  117.  
  118. // read XML Feb2010Feb2011
  119. $xmlFeb2010Feb2011 new DOMDocument();
  120. $xmlFeb2010Feb2011->loadXML($statsFeb2010Feb2011);
  121.  
  122. // read stats and create charts
  123. $legendsAndValues array();
  124.  
  125. for ($i 0$i $xmlFeb2009Feb2010->getElementsByTagName("NAME")->length$i++{
  126.     $legendsAndValues[$xmlFeb2009Feb2010->getElementsByTagName("NAME")->item($i)->nodeValuearray(
  127.         $xmlFeb2009Feb2010->getElementsByTagName("VALUE")->item($i)->nodeValue
  128.     );
  129. }
  130.  
  131. $chart array(
  132.     'data' => $legendsAndValues,
  133.     'type' => 'pie3DChart',
  134.     'title' => 'Feb 2009 - Feb 2010',
  135.     'rotX' => 20'rotY' => 20'perspective' => 30,
  136.     'color' => 2,
  137.     'textWrap' => 0,
  138.     'sizeX' => 14'sizeY' => 8,
  139.     'jc' => 'center',
  140.     'showPercent' => 1,
  141. );
  142.  
  143. $docx->addChart($chart);
  144.  
  145. // add line break
  146. $docx->addBreak();
  147. $docx->addBreak();
  148.  
  149. $legendsAndValues array();
  150.  
  151. for($i 0$i $xmlFeb2010Feb2011->getElementsByTagName("NAME")->length$i++{
  152.     $legendsAndValues[$xmlFeb2010Feb2011->getElementsByTagName("NAME")->item($i)->nodeValuearray(
  153.         $xmlFeb2010Feb2011->getElementsByTagName("VALUE")->item($i)->nodeValue
  154.     );
  155. }
  156.  
  157. $chart['data'$legendsAndValues;
  158. $chart['title''Feb 2010 - Feb 2011';
  159.  
  160. $docx->addChart($chart);
  161.  
  162. // add line break
  163. $docx->addBreak();
  164. $docx->addBreak();
  165. $docx->addBreak();
  166.  
  167. // read stats and create table
  168. $table array();
  169.  
  170. $table[array(
  171.     '',
  172.     'Feb 2009 - Feb 2010',
  173.     'Feb 2010 - Feb 2011',
  174. );
  175.  
  176.  
  177. for($i 0$i $xmlFeb2009Feb2010->getElementsByTagName("NAME")->length$i++{
  178.     $paramsHeaderTextTable[0array(
  179.         'text' => $xmlFeb2009Feb2010->getElementsByTagName("NAME")->item($i)->nodeValue,
  180.         'b' => 'single',
  181.         'sz' => 14
  182.     );
  183.  
  184.     $table[array(
  185.         $docx->addElement('addText'$paramsHeaderTextTable),
  186.         $xmlFeb2009Feb2010->getElementsByTagName("VALUE")->item($i)->nodeValue,
  187.         $xmlFeb2010Feb2011->getElementsByTagName("VALUE")->item($i)->nodeValue
  188.     );
  189. }
  190.  
  191. $paramsTable array(
  192.     'border' => 'single',
  193.     'border_sz' => 2,
  194.     'jc' => 'center',
  195.     'size_col' => 2800
  196. );
  197.  
  198. $docx->addTable($table$paramsTable);
  199.  
  200. // add text
  201. $textInfo 'Stats are based on aggregate data collected by StatCounter on a'
  202. ' sample exceeding 15 billion pageviews per month collected from across'
  203. ' the StatCounter network of more than 3 million websites. Stats are '
  204. ' updated and made available every 4 hours, however are subject to '
  205. 'quality assurance testing and revision for 7 days from publication.';
  206.  
  207. $paramsTextInfo array(
  208.     'val' => 1,
  209.     'i' => 'single',
  210.     'sz' => 8
  211. );
  212.  
  213. $docx->addText($textInfo$paramsTextInfo);
  214.  
  215. // add link
  216. $docx->addLink('Source: StatCounter',  array('url'=> 'http://gs.statcounter.com'));
  217.  
  218. // generate DOCX file
  219. $docx->createDocx('../docx/example_report');

Documentation generated on Mon, 13 Jan 2014 13:44:11 +0100 by phpDocumentor 1.4.4