From 938d78f40b275b8a72ab357c45b004f64b364ae9 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 6 Mar 2014 22:07:09 +0700 Subject: [PATCH] Samples: (1) Superscript and subscript; (2) Multicolumn --- samples/Sample_04_Textrun.php | 5 +++ samples/Sample_05_Multicolumn.php | 66 +++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 samples/Sample_05_Multicolumn.php diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php index 80ad2d3c..164afc3c 100644 --- a/samples/Sample_04_Textrun.php +++ b/samples/Sample_04_Textrun.php @@ -30,6 +30,11 @@ $textrun = $section->createTextRun('pStyle'); $textrun->addText('Each textrun can contain native text, link elements or an image.'); $textrun->addText(' No break is placed after adding an element.', 'BoldText'); +$textrun->addText(' Both '); +$textrun->addText('superscript', array('superScript' => true)); +$textrun->addText(' and '); +$textrun->addText('subscript', array('subScript' => true)); +$textrun->addText(' are also available.'); $textrun->addText(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText'); $textrun->addText(' Sample Link: '); $textrun->addLink('http://www.google.com', null, 'NLink'); diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php new file mode 100644 index 00000000..a7889a85 --- /dev/null +++ b/samples/Sample_05_Multicolumn.php @@ -0,0 +1,66 @@ +'); +} + +require_once '../Classes/PHPWord.php'; + +// New Word Document +echo date('H:i:s') , " Create new PHPWord object" , EOL; +$PHPWord = new PHPWord(); +$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' . + 'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. ' . + 'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. ' . + 'Suspendisse congue congue leo sed pellentesque.'; + +// Normal +$section = $PHPWord->createSection(); +$section->addText('Normal paragraph. ' . $filler); + +// Two columns +$section = $PHPWord->createSection(array( + 'colsNum' => 2, + 'colsSpace' => 1440, + 'breakType' => 'continuous')); +$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler); + +// Normal +$section = $PHPWord->createSection(array('breakType' => 'continuous')); +$section->addText('Normal paragraph again. ' . $filler); + +// Three columns +$section = $PHPWord->createSection(array( + 'colsNum' => 3, + 'colsSpace' => 720, + 'breakType' => 'continuous')); +$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler); + +// Normal +$section = $PHPWord->createSection(array('breakType' => 'continuous')); +$section->addText('Normal paragraph again.'); + +// Save File +echo date('H:i:s') , " Write to Word2007 format" , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save(str_replace('.php', '.docx', __FILE__)); + +// echo date('H:i:s') , " Write to OpenDocumentText format" , EOL; +// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); +// $objWriter->save(str_replace('.php', '.odt', __FILE__)); + +// echo date('H:i:s') , " Write to RTF format" , EOL; +// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); +// $objWriter->save(str_replace('.php', '.rtf', __FILE__)); + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL;