Samples: (1) Superscript and subscript; (2) Multicolumn

This commit is contained in:
Ivan Lanin 2014-03-06 22:07:09 +07:00
parent f1c2c2fe5e
commit 938d78f40b
2 changed files with 71 additions and 0 deletions

View File

@ -30,6 +30,11 @@ $textrun = $section->createTextRun('pStyle');
$textrun->addText('Each textrun can contain native text, link elements or an image.'); $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(' 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(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText');
$textrun->addText(' Sample Link: '); $textrun->addText(' Sample Link: ');
$textrun->addLink('http://www.google.com', null, 'NLink'); $textrun->addLink('http://www.google.com', null, 'NLink');

View File

@ -0,0 +1,66 @@
<?php
error_reporting(E_ALL);
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
define('EOL', PHP_EOL);
}
else {
define('EOL', '<br />');
}
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;