Reorganize samples and write unsupported element to ODText and RTF
This commit is contained in:
parent
d991fdc6d1
commit
4119c6af07
|
|
@ -254,8 +254,8 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
|
|||
if ($elm->getName() != 'style') {
|
||||
continue;
|
||||
}
|
||||
unset($pStyle);
|
||||
unset($fStyle);
|
||||
$pStyle = null;
|
||||
$fStyle = null;
|
||||
$hasParagraphStyle = isset($elm->pPr);
|
||||
$hasFontStyle = isset($elm->rPr);
|
||||
$styleName = (string)$elm->name['val'];
|
||||
|
|
|
|||
|
|
@ -253,28 +253,25 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
|
|||
$this->_writeTextRun($objWriter, $element);
|
||||
} elseif ($element instanceof PHPWord_Section_TextBreak) {
|
||||
$this->_writeTextBreak($objWriter);
|
||||
/*
|
||||
} elseif ($element instanceof PHPWord_Section_Link) {
|
||||
$this->_writeLink($objWriter, $element);
|
||||
$this->writeUnsupportedElement($objWriter, 'link');
|
||||
} elseif ($element instanceof PHPWord_Section_Title) {
|
||||
$this->_writeTitle($objWriter, $element);
|
||||
$this->writeUnsupportedElement($objWriter, 'title');
|
||||
} elseif ($element instanceof PHPWord_Section_PageBreak) {
|
||||
$this->_writePageBreak($objWriter);
|
||||
$this->writeUnsupportedElement($objWriter, 'page break');
|
||||
} elseif ($element instanceof PHPWord_Section_Table) {
|
||||
$this->_writeTable($objWriter, $element);
|
||||
$this->writeUnsupportedElement($objWriter, 'table');
|
||||
} elseif ($element instanceof PHPWord_Section_ListItem) {
|
||||
$this->_writeListItem($objWriter, $element);
|
||||
$this->writeUnsupportedElement($objWriter, 'list item');
|
||||
} elseif ($element instanceof PHPWord_Section_Image ||
|
||||
$element instanceof PHPWord_Section_MemoryImage) {
|
||||
$this->_writeImage($objWriter, $element);
|
||||
$this->writeUnsupportedElement($objWriter, 'image');
|
||||
} elseif ($element instanceof PHPWord_Section_Object) {
|
||||
$this->_writeObject($objWriter, $element);
|
||||
$this->writeUnsupportedElement($objWriter, 'object');
|
||||
} elseif ($element instanceof PHPWord_TOC) {
|
||||
$this->_writeTOC($objWriter);
|
||||
*/
|
||||
$this->writeUnsupportedElement($objWriter, 'TOC');
|
||||
} else {
|
||||
print_r($element);
|
||||
echo '<br />';
|
||||
$this->writeUnsupportedElement($objWriter, 'other');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -387,4 +384,17 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
|
|||
private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Write unsupported element
|
||||
*
|
||||
* @param PHPWord_Shared_XMLWriter $objWriter
|
||||
* @param string $element
|
||||
*/
|
||||
private function writeUnsupportedElement($objWriter, $element)
|
||||
{
|
||||
$objWriter->startElement('text:p');
|
||||
$objWriter->writeRaw("Cannot write content. This version of PHPWord has not supported {$element} element in ODText.");
|
||||
$objWriter->endElement();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -314,28 +314,25 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
|
|||
$sRTFBody .= $this->getDataContentTextBreak();
|
||||
} elseif ($element instanceof PHPWord_Section_TextRun) {
|
||||
$sRTFBody .= $this->getDataContentTextRun($element);
|
||||
/*
|
||||
} elseif($element instanceof PHPWord_Section_Link) {
|
||||
$this->_writeLink($objWriter, $element);
|
||||
$sRTFBody .= $this->getDataContentUnsupportedElement('link');
|
||||
} elseif($element instanceof PHPWord_Section_Title) {
|
||||
$this->_writeTitle($objWriter, $element);
|
||||
$sRTFBody .= $this->getDataContentUnsupportedElement('title');
|
||||
} elseif($element instanceof PHPWord_Section_PageBreak) {
|
||||
$this->_writePageBreak($objWriter);
|
||||
$sRTFBody .= $this->getDataContentUnsupportedElement('page break');
|
||||
} elseif($element instanceof PHPWord_Section_Table) {
|
||||
$this->_writeTable($objWriter, $element);
|
||||
$sRTFBody .= $this->getDataContentUnsupportedElement('table');
|
||||
} elseif($element instanceof PHPWord_Section_ListItem) {
|
||||
$this->_writeListItem($objWriter, $element);
|
||||
$sRTFBody .= $this->getDataContentUnsupportedElement('list item');
|
||||
} elseif($element instanceof PHPWord_Section_Image ||
|
||||
$element instanceof PHPWord_Section_MemoryImage) {
|
||||
$this->_writeImage($objWriter, $element);
|
||||
$sRTFBody .= $this->getDataContentUnsupportedElement('image');
|
||||
} elseif($element instanceof PHPWord_Section_Object) {
|
||||
$this->_writeObject($objWriter, $element);
|
||||
$sRTFBody .= $this->getDataContentUnsupportedElement('object');
|
||||
} elseif($element instanceof PHPWord_TOC) {
|
||||
$this->_writeTOC($objWriter);
|
||||
*/
|
||||
$sRTFBody .= $this->getDataContentUnsupportedElement('TOC');
|
||||
} else {
|
||||
print_r($element);
|
||||
echo '<br />';
|
||||
$sRTFBody .= $this->getDataContentUnsupportedElement('other');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -381,7 +378,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
|
|||
$this->_lastParagraphStyle = '';
|
||||
}
|
||||
|
||||
if ($styleFont) {
|
||||
if ($styleFont instanceof PHPWord_Style_Font) {
|
||||
if ($styleFont->getColor() != null) {
|
||||
$idxColor = array_search($styleFont->getColor(), $this->_colorTable);
|
||||
if ($idxColor !== false) {
|
||||
|
|
@ -413,7 +410,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
|
|||
}
|
||||
$sRTFText .= $text->getText();
|
||||
|
||||
if ($styleFont) {
|
||||
if ($styleFont instanceof PHPWord_Style_Font) {
|
||||
$sRTFText .= '\cf0';
|
||||
$sRTFText .= '\f0';
|
||||
|
||||
|
|
@ -461,4 +458,19 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
|
|||
|
||||
return '\par' . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write unsupported element
|
||||
*
|
||||
* @param string $element
|
||||
*/
|
||||
private function getDataContentUnsupportedElement($element)
|
||||
{
|
||||
$sRTFText = '';
|
||||
$sRTFText .= '\pard\nowidctlpar' . PHP_EOL;
|
||||
$sRTFText .= "Cannot write content. This version of PHPWord has not supported {$element} element in RTF.";
|
||||
$sRTFText .= '\par' . PHP_EOL;
|
||||
|
||||
return $sRTFText;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,26 +4,41 @@ namespace PHPWord\Tests;
|
|||
use PHPUnit_Framework_TestCase;
|
||||
use PHPWord_Section;
|
||||
|
||||
/**
|
||||
* @covers PHPWord_Section
|
||||
*/
|
||||
class SectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers PHPWord_Section::getSettings
|
||||
*/
|
||||
public function testGetSettings()
|
||||
{
|
||||
$oSection = new PHPWord_Section(0);
|
||||
$this->assertAttributeEquals($oSection->getSettings(), '_settings', new PHPWord_Section(0));
|
||||
}
|
||||
|
||||
public function testGetElementss()
|
||||
/**
|
||||
* @covers PHPWord_Section::getElements
|
||||
*/
|
||||
public function testGetElements()
|
||||
{
|
||||
$oSection = new PHPWord_Section(0);
|
||||
$this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new PHPWord_Section(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPWord_Section::getFooter
|
||||
*/
|
||||
public function testGetFooter()
|
||||
{
|
||||
$oSection = new PHPWord_Section(0);
|
||||
$this->assertAttributeEquals($oSection->getFooter(), '_footer', new PHPWord_Section(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPWord_Section::getHeaders
|
||||
*/
|
||||
public function testGetHeaders()
|
||||
{
|
||||
$oSection = new PHPWord_Section(0);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
<?php
|
||||
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
define('EOL', PHP_EOL);
|
||||
} else {
|
||||
define('EOL', '<br />');
|
||||
}
|
||||
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// New Word Document
|
||||
|
|
@ -29,22 +23,16 @@ $PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100
|
|||
$section->addText('I am styled by two style definitions.', 'rStyle', 'pStyle');
|
||||
$section->addText('I have only a paragraph style definition.', null, 'pStyle');
|
||||
|
||||
// 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__));
|
||||
// Save file
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
|
||||
$objWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
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;
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
<?php
|
||||
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
define('EOL', PHP_EOL);
|
||||
}
|
||||
else {
|
||||
define('EOL', '<br />');
|
||||
}
|
||||
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// New Word Document
|
||||
|
|
@ -42,22 +35,16 @@ $section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab');
|
|||
$section->addText("Left Aligned\tRight Aligned", NULL, 'rightTab');
|
||||
$section->addText("\tCenter Aligned", NULL, 'centerTab');
|
||||
|
||||
// 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__));
|
||||
// Save file
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
|
||||
$objWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
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;
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
<?php
|
||||
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
define('EOL', PHP_EOL);
|
||||
} else {
|
||||
define('EOL', '<br />');
|
||||
}
|
||||
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// New Word Document
|
||||
|
|
@ -34,22 +28,16 @@ $section->addText('This section and we play with header/footer height.');
|
|||
$section->createHeader()->addText('Header');
|
||||
$section->createFooter()->addText('Footer');
|
||||
|
||||
// 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__));
|
||||
// Save file
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
|
||||
$objWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
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;
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
<?php
|
||||
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
define('EOL', PHP_EOL);
|
||||
}
|
||||
else {
|
||||
define('EOL', '<br />');
|
||||
}
|
||||
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// New Word Document
|
||||
|
|
@ -42,21 +35,16 @@ $textrun->addText(' Sample Image: ');
|
|||
$textrun->addImage('old/_earth.jpg', array('width'=>18, 'height'=>18));
|
||||
$textrun->addText(' Here is some more text. ');
|
||||
|
||||
// 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__));
|
||||
// Save file
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
|
||||
$objWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
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;
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
<?php
|
||||
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
define('EOL', PHP_EOL);
|
||||
}
|
||||
else {
|
||||
define('EOL', '<br />');
|
||||
}
|
||||
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// New Word Document
|
||||
|
|
@ -45,22 +38,16 @@ $section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
|
|||
$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__));
|
||||
// Save file
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
|
||||
$objWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
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;
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
<?php
|
||||
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
define('EOL', PHP_EOL);
|
||||
} else {
|
||||
define('EOL', '<br />');
|
||||
}
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// New Word Document
|
||||
|
|
@ -41,14 +36,16 @@ $section->addText('You can also create the footnote directly from the section ma
|
|||
$footnote = $section->createFootnote();
|
||||
$footnote->addText('The reference for this is wrapped in its own line');
|
||||
|
||||
// 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__));
|
||||
// Save file
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
|
||||
$objWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
<?php
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s') , " Create new PHPWord object" , EOL;
|
||||
$PHPWord = new PHPWord();
|
||||
|
||||
$document = $PHPWord->loadTemplate('Sample_07_TemplateCloneRow.docx');
|
||||
$document = $PHPWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx');
|
||||
|
||||
// Simple table
|
||||
$document->cloneRow('rowValue', 10);
|
||||
|
|
@ -51,4 +56,11 @@ $document->setValue('userFirstName#3', 'Michael');
|
|||
$document->setValue('userName#3', 'Ray');
|
||||
$document->setValue('userPhone#3', '+1 428 889 775');
|
||||
|
||||
$document->saveAs('Sample_07_TemplateCloneRow_result.docx');
|
||||
$name = 'Sample_07_TemplateCloneRow_result.docx';
|
||||
echo date('H:i:s'), " Write to Word2007 format", EOL;
|
||||
$document->saveAs($name);
|
||||
rename($name, "results/{$name}");
|
||||
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
<?php
|
||||
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
define('EOL', PHP_EOL);
|
||||
}
|
||||
else {
|
||||
define('EOL', '<br />');
|
||||
}
|
||||
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// New Word document
|
||||
|
|
@ -55,22 +48,16 @@ $section->addText('Paragraph with pageBreakBefore = true (default: false). ' .
|
|||
'heading styles.',
|
||||
null, array('pageBreakBefore' => true));
|
||||
|
||||
// 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__));
|
||||
// Save file
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
|
||||
$objWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
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;
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
<?php
|
||||
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
define('EOL', PHP_EOL);
|
||||
} else {
|
||||
define('EOL', '<br />');
|
||||
}
|
||||
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// New Word Document
|
||||
|
|
@ -82,21 +76,16 @@ $table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered);
|
|||
$table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered);
|
||||
$table->addCell(null, $cellRowContinue);
|
||||
|
||||
// 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__));
|
||||
// Save file
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
|
||||
$objWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
// 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;
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
|
|
@ -1,33 +1,24 @@
|
|||
<?php
|
||||
// error_reporting(E_ALL );
|
||||
|
||||
// Init
|
||||
error_reporting(E_ALL);
|
||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||
|
||||
require_once '../Classes/PHPWord.php';
|
||||
|
||||
// Read contents
|
||||
$sample = 'Sample_10_ReadWord2007';
|
||||
$source = "resources/{$sample}.docx";
|
||||
$target = "results/{$sample}";
|
||||
echo '<p><strong>', date('H:i:s'), " Reading contents from `{$source}`</strong></p>";
|
||||
$name = basename(__FILE__, '.php');
|
||||
$source = "resources/{$name}.docx";
|
||||
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
|
||||
$PHPWord = PHPWord_IOFactory::load($source);
|
||||
|
||||
// Rewrite contents
|
||||
echo date('H:i:s') , " Write to Word2007 format" , EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
|
||||
$objWriter->save("{$sample}.docx");
|
||||
rename("{$sample}.docx", "{$target}.docx");
|
||||
// (Re)write contents
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
|
||||
$objWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText');
|
||||
$objWriter->save("{$sample}.odt");
|
||||
rename("{$sample}.odt", "{$target}.odt");
|
||||
|
||||
echo date('H:i:s') , ' Write to RTF format' , EOL;
|
||||
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF');
|
||||
$objWriter->save("{$sample}.rtf");
|
||||
rename("{$sample}.rtf", "{$target}.rtf");
|
||||
|
||||
// Echo memory peak usage
|
||||
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
|
||||
echo date('H:i:s') , " Done writing file" , EOL;
|
||||
// Done
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
|
|
|
|||
Loading…
Reference in New Issue