|
| 1 | +<?php |
| 2 | + |
| 3 | +error_reporting(E_ALL); |
| 4 | + |
| 5 | +if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { |
| 6 | + define('EOL', PHP_EOL); |
| 7 | +} |
| 8 | +else { |
| 9 | + define('EOL', '<br />'); |
| 10 | +} |
| 11 | + |
| 12 | +require_once '../Classes/PHPWord.php'; |
| 13 | + |
| 14 | +// New Word Document |
| 15 | +echo date('H:i:s') , " Create new PHPWord object" , EOL; |
| 16 | +$PHPWord = new PHPWord(); |
| 17 | +$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' . |
| 18 | + 'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. ' . |
| 19 | + 'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. ' . |
| 20 | + 'Suspendisse congue congue leo sed pellentesque.'; |
| 21 | + |
| 22 | +// Normal |
| 23 | +$section = $PHPWord->createSection(); |
| 24 | +$section->addText('Normal paragraph. ' . $filler); |
| 25 | + |
| 26 | +// Two columns |
| 27 | +$section = $PHPWord->createSection(array( |
| 28 | + 'colsNum' => 2, |
| 29 | + 'colsSpace' => 1440, |
| 30 | + 'breakType' => 'continuous')); |
| 31 | +$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler); |
| 32 | + |
| 33 | +// Normal |
| 34 | +$section = $PHPWord->createSection(array('breakType' => 'continuous')); |
| 35 | +$section->addText('Normal paragraph again. ' . $filler); |
| 36 | + |
| 37 | +// Three columns |
| 38 | +$section = $PHPWord->createSection(array( |
| 39 | + 'colsNum' => 3, |
| 40 | + 'colsSpace' => 720, |
| 41 | + 'breakType' => 'continuous')); |
| 42 | +$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler); |
| 43 | + |
| 44 | +// Normal |
| 45 | +$section = $PHPWord->createSection(array('breakType' => 'continuous')); |
| 46 | +$section->addText('Normal paragraph again.'); |
| 47 | + |
| 48 | +// Save File |
| 49 | +echo date('H:i:s') , " Write to Word2007 format" , EOL; |
| 50 | +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); |
| 51 | +$objWriter->save(str_replace('.php', '.docx', __FILE__)); |
| 52 | + |
| 53 | +// echo date('H:i:s') , " Write to OpenDocumentText format" , EOL; |
| 54 | +// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); |
| 55 | +// $objWriter->save(str_replace('.php', '.odt', __FILE__)); |
| 56 | + |
| 57 | +// echo date('H:i:s') , " Write to RTF format" , EOL; |
| 58 | +// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); |
| 59 | +// $objWriter->save(str_replace('.php', '.rtf', __FILE__)); |
| 60 | + |
| 61 | + |
| 62 | +// Echo memory peak usage |
| 63 | +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; |
| 64 | + |
| 65 | +// Echo done |
| 66 | +echo date('H:i:s') , " Done writing file" , EOL; |
0 commit comments