From 088caa2d3606c04d540e8ac2f4f858d3a87c9ffb Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Fri, 14 Mar 2014 20:56:27 +0700 Subject: [PATCH 1/2] @codeCoverageIgnore for some legacy (unused yet) code --- Classes/PHPWord/HashTable.php | 2 ++ Classes/PHPWord/Shared/ZipStreamWrapper.php | 5 ++--- Classes/PHPWord/Writer/ODText.php | 3 ++- Classes/PHPWord/Writer/ODText/Manifest.php | 2 ++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Classes/PHPWord/HashTable.php b/Classes/PHPWord/HashTable.php index f2ef3148..22c602b8 100755 --- a/Classes/PHPWord/HashTable.php +++ b/Classes/PHPWord/HashTable.php @@ -27,6 +27,8 @@ /** * PHPWord_HashTable + * + * @codeCoverageIgnore Legacy from PHPExcel */ class PHPWord_HashTable { diff --git a/Classes/PHPWord/Shared/ZipStreamWrapper.php b/Classes/PHPWord/Shared/ZipStreamWrapper.php index ee346921..bfdc791b 100755 --- a/Classes/PHPWord/Shared/ZipStreamWrapper.php +++ b/Classes/PHPWord/Shared/ZipStreamWrapper.php @@ -25,11 +25,10 @@ * @version 0.7.0 */ -/** Register new zip wrapper */ -PHPWord_Shared_ZipStreamWrapper::register(); - /** * Class PHPWord_Shared_ZipStreamWrapper + * + * @codeCoverageIgnore Legacy from PHPExcel */ class PHPWord_Shared_ZipStreamWrapper { diff --git a/Classes/PHPWord/Writer/ODText.php b/Classes/PHPWord/Writer/ODText.php index 71775630..97e8f29b 100755 --- a/Classes/PHPWord/Writer/ODText.php +++ b/Classes/PHPWord/Writer/ODText.php @@ -141,7 +141,8 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter // Add META-INF/manifest.xml $objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->_document)); - // Add media + // Add media. Has not used yet. Legacy from PHPExcel. + // @codeCoverageIgnoreStart for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) { if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) { $imageContents = null; diff --git a/Classes/PHPWord/Writer/ODText/Manifest.php b/Classes/PHPWord/Writer/ODText/Manifest.php index 4b1c6b26..266bf24f 100755 --- a/Classes/PHPWord/Writer/ODText/Manifest.php +++ b/Classes/PHPWord/Writer/ODText/Manifest.php @@ -77,6 +77,8 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart $objWriter->writeAttribute('manifest:full-path', 'styles.xml'); $objWriter->endElement(); + // Not used yet. Legacy from PHPExcel + // @codeCoverageIgnoreStart for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) { if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) { $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension()); From 44d2501293407e9535b08c9ac9527c07d4a196f2 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Fri, 14 Mar 2014 22:03:19 +0700 Subject: [PATCH 2/2] TextBreak: Allow font/paragraph styling for text break --- Classes/PHPWord/Section.php | 8 +- Classes/PHPWord/Section/Footer.php | 10 ++- Classes/PHPWord/Section/Header.php | 10 ++- Classes/PHPWord/Section/Table/Cell.php | 12 ++- Classes/PHPWord/Section/TextBreak.php | 82 +++++++++++++++++++- Classes/PHPWord/Section/TextRun.php | 12 +-- Classes/PHPWord/Writer/Word2007/Base.php | 47 ++++++++++- Classes/PHPWord/Writer/Word2007/Document.php | 2 +- Classes/PHPWord/Writer/Word2007/Footer.php | 2 +- Classes/PHPWord/Writer/Word2007/Header.php | 2 +- Tests/PHPWord/Section/TextBreakTest.php | 50 +++++++++++- Tests/PHPWord/Writer/Word2007/BaseTest.php | 25 ++++++ changelog.txt | 11 ++- samples/Sample_19_TextBreak.php | 49 ++++++++++++ 14 files changed, 288 insertions(+), 34 deletions(-) create mode 100644 samples/Sample_19_TextBreak.php diff --git a/Classes/PHPWord/Section.php b/Classes/PHPWord/Section.php index bdf37f81..95bb9db0 100755 --- a/Classes/PHPWord/Section.php +++ b/Classes/PHPWord/Section.php @@ -156,12 +156,14 @@ class PHPWord_Section /** * Add a TextBreak Element * - * @param int $count + * @param int $count + * @param null|string|array|PHPWord_Style_Font $fontStyle + * @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle */ - public function addTextBreak($count = 1) + public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) { for ($i = 1; $i <= $count; $i++) { - $this->_elementCollection[] = new PHPWord_Section_TextBreak(); + $this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); } } diff --git a/Classes/PHPWord/Section/Footer.php b/Classes/PHPWord/Section/Footer.php index 3455adc9..ae2e2119 100755 --- a/Classes/PHPWord/Section/Footer.php +++ b/Classes/PHPWord/Section/Footer.php @@ -79,14 +79,16 @@ class PHPWord_Section_Footer } /** - * Add a TextBreak Element + * Add TextBreak * - * @param int $count + * @param int $count + * @param null|string|array|PHPWord_Style_Font $fontStyle + * @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle */ - public function addTextBreak($count = 1) + public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) { for ($i = 1; $i <= $count; $i++) { - $this->_elementCollection[] = new PHPWord_Section_TextBreak(); + $this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); } } diff --git a/Classes/PHPWord/Section/Header.php b/Classes/PHPWord/Section/Header.php index 83c82c49..e2f5b2be 100755 --- a/Classes/PHPWord/Section/Header.php +++ b/Classes/PHPWord/Section/Header.php @@ -108,14 +108,16 @@ class PHPWord_Section_Header } /** - * Add a TextBreak Element + * Add TextBreak * - * @param int $count + * @param int $count + * @param null|string|array|PHPWord_Style_Font $fontStyle + * @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle */ - public function addTextBreak($count = 1) + public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) { for ($i = 1; $i <= $count; $i++) { - $this->_elementCollection[] = new PHPWord_Section_TextBreak(); + $this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); } } diff --git a/Classes/PHPWord/Section/Table/Cell.php b/Classes/PHPWord/Section/Table/Cell.php index 898c6bf2..983f4a24 100755 --- a/Classes/PHPWord/Section/Table/Cell.php +++ b/Classes/PHPWord/Section/Table/Cell.php @@ -146,13 +146,17 @@ class PHPWord_Section_Table_Cell } /** - * Add a TextBreak Element + * Add TextBreak * - * @param int $count + * @param int $count + * @param null|string|array|PHPWord_Style_Font $fontStyle + * @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle */ - public function addTextBreak() + public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) { - $this->_elementCollection[] = new PHPWord_Section_TextBreak(); + for ($i = 1; $i <= $count; $i++) { + $this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); + } } /** diff --git a/Classes/PHPWord/Section/TextBreak.php b/Classes/PHPWord/Section/TextBreak.php index eca56705..0438bd4f 100755 --- a/Classes/PHPWord/Section/TextBreak.php +++ b/Classes/PHPWord/Section/TextBreak.php @@ -30,11 +30,91 @@ */ class PHPWord_Section_TextBreak { + /** + * Paragraph style + * + * @var PHPWord_Style_Pagaraph + */ + private $paragraphStyle = null; + + /** + * Text style + * + * @var PHPWord_Style_Font + */ + private $fontStyle = null; /** * Create a new TextBreak Element */ - public function __construct() + public function __construct($fontStyle = null, $paragraphStyle = null) { + if (!is_null($paragraphStyle)) { + $paragraphStyle = $this->setParagraphStyle($paragraphStyle); + } + if (!is_null($fontStyle)) { + $this->setFontStyle($fontStyle, $paragraphStyle); + } + } + + /** + * Set Text style + * + * @param null|array|\PHPWord_Style_Font $style + * @param null|array|\PHPWord_Style_Paragraph $paragraphStyle + * @return PHPWord_Style_Font + */ + public function setFontStyle($style = null, $paragraphStyle = null) + { + if ($style instanceof PHPWord_Style_Font) { + $this->fontStyle = $style; + $this->setParagraphStyle($paragraphStyle); + } elseif (is_array($style)) { + $this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle); + $this->fontStyle->setArrayStyle($style); + } else { + $this->fontStyle = $style; + $this->setParagraphStyle($paragraphStyle); + } + return $this->fontStyle; + } + + /** + * Get Text style + * + * @return PHPWord_Style_Font + */ + public function getFontStyle() + { + return $this->fontStyle; + } + + /** + * Set Paragraph style + * + * @param null|array|\PHPWord_Style_Paragraph $style + * @return null|\PHPWord_Style_Paragraph + */ + public function setParagraphStyle($style = null) + { + if (is_array($style)) { + $this->paragraphStyle = new PHPWord_Style_Paragraph; + $this->paragraphStyle->setArrayStyle($style); + } elseif ($style instanceof PHPWord_Style_Paragraph) { + $this->paragraphStyle = $style; + } else { + $this->paragraphStyle = $style; + } + return $this->paragraphStyle; + } + + /** + * Get Paragraph style + * + * @return PHPWord_Style_Paragraph + */ + public function getParagraphStyle() + { + return $this->paragraphStyle; } } diff --git a/Classes/PHPWord/Section/TextRun.php b/Classes/PHPWord/Section/TextRun.php index eeb936a0..a708a119 100755 --- a/Classes/PHPWord/Section/TextRun.php +++ b/Classes/PHPWord/Section/TextRun.php @@ -132,14 +132,16 @@ class PHPWord_Section_TextRun } /** - * Add a Text Break + * Add TextBreak * - * @param int $count + * @param int $count + * @param null|string|array|PHPWord_Style_Font $fontStyle + * @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle */ - public function addTextBreak($count = 1) + public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) { - for ($i=1; $i<=$count; $i++) { - $this->_elementCollection[] = new PHPWord_Section_TextBreak(); + for ($i = 1; $i <= $count; $i++) { + $this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); } } diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 0168a649..4bb8908d 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -477,10 +477,51 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart /** * Write text break + * + * @param PHPWord_Shared_XMLWriter $objWriter + * @param PHPWord_Section_TextBreak $element */ - protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) + protected function _writeTextBreak($objWriter, $element = null) { - $objWriter->writeElement('w:p', null); + $hasStyle = false; + if (!is_null($element)) { + $fontStyle = $element->getFontStyle(); + $sfIsObject = ($fontStyle instanceof PHPWord_Style_Font) ? true : false; + $paragraphStyle = $element->getParagraphStyle(); + $spIsObject = ($paragraphStyle instanceof PHPWord_Style_Paragraph) ? true : false; + $hasStyle = !is_null($fontStyle) || !is_null($paragraphStyle); + } + if ($hasStyle) { + // Paragraph style + $objWriter->startElement('w:p'); + if ($spIsObject) { + $this->_writeParagraphStyle($objWriter, $paragraphStyle); + } elseif (!$spIsObject && !is_null($paragraphStyle)) { + $objWriter->startElement('w:pPr'); + $objWriter->startElement('w:pStyle'); + $objWriter->writeAttribute('w:val', $paragraphStyle); + $objWriter->endElement(); // w:pStyle + $objWriter->endElement(); // w:pPr + } + // Font style + if (!is_null($fontStyle)) { + $objWriter->startElement('w:pPr'); + if ($sfIsObject) { + $this->_writeTextStyle($objWriter, $fontStyle); + } elseif (!$sfIsObject && !is_null($fontStyle)) { + $objWriter->startElement('w:rPr'); + $objWriter->startElement('w:rStyle'); + $objWriter->writeAttribute('w:val', $fontStyle); + $objWriter->endElement(); // w:rStyle + $objWriter->endElement(); // w:rPr + } + $objWriter->endElement(); // w:pPr + } + $objWriter->endElement(); // w:p + } else { + // Null element. No paragraph nor font style + $objWriter->writeElement('w:p', null); + } } /** @@ -570,7 +611,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart } elseif ($element instanceof PHPWord_Section_Link) { $this->_writeLink($objWriter, $element); } elseif ($element instanceof PHPWord_Section_TextBreak) { - $this->_writeTextBreak($objWriter); + $this->_writeTextBreak($objWriter, $element); } elseif ($element instanceof PHPWord_Section_ListItem) { $this->_writeListItem($objWriter, $element); } elseif ($element instanceof PHPWord_Section_Image || diff --git a/Classes/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php index 558fa72f..9991179d 100755 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ b/Classes/PHPWord/Writer/Word2007/Document.php @@ -79,7 +79,7 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base } elseif ($element instanceof PHPWord_Section_Title) { $this->_writeTitle($objWriter, $element); } elseif ($element instanceof PHPWord_Section_TextBreak) { - $this->_writeTextBreak($objWriter); + $this->_writeTextBreak($objWriter, $element); } elseif ($element instanceof PHPWord_Section_PageBreak) { $this->_writePageBreak($objWriter); } elseif ($element instanceof PHPWord_Section_Table) { diff --git a/Classes/PHPWord/Writer/Word2007/Footer.php b/Classes/PHPWord/Writer/Word2007/Footer.php index 1cd49771..f9b4763e 100755 --- a/Classes/PHPWord/Writer/Word2007/Footer.php +++ b/Classes/PHPWord/Writer/Word2007/Footer.php @@ -63,7 +63,7 @@ class PHPWord_Writer_Word2007_Footer extends PHPWord_Writer_Word2007_Base } elseif ($element instanceof PHPWord_Section_TextRun) { $this->_writeTextRun($objWriter, $element); } elseif ($element instanceof PHPWord_Section_TextBreak) { - $this->_writeTextBreak($objWriter); + $this->_writeTextBreak($objWriter, $element); } elseif ($element instanceof PHPWord_Section_Table) { $this->_writeTable($objWriter, $element); } elseif ($element instanceof PHPWord_Section_Image || diff --git a/Classes/PHPWord/Writer/Word2007/Header.php b/Classes/PHPWord/Writer/Word2007/Header.php index 4106d197..6bb6f784 100755 --- a/Classes/PHPWord/Writer/Word2007/Header.php +++ b/Classes/PHPWord/Writer/Word2007/Header.php @@ -63,7 +63,7 @@ class PHPWord_Writer_Word2007_Header extends PHPWord_Writer_Word2007_Base } elseif ($element instanceof PHPWord_Section_TextRun) { $this->_writeTextRun($objWriter, $element); } elseif ($element instanceof PHPWord_Section_TextBreak) { - $this->_writeTextBreak($objWriter); + $this->_writeTextBreak($objWriter, $element); } elseif ($element instanceof PHPWord_Section_Table) { $this->_writeTable($objWriter, $element); } elseif ($element instanceof PHPWord_Section_Image || diff --git a/Tests/PHPWord/Section/TextBreakTest.php b/Tests/PHPWord/Section/TextBreakTest.php index 6334f5a9..761c04a3 100644 --- a/Tests/PHPWord/Section/TextBreakTest.php +++ b/Tests/PHPWord/Section/TextBreakTest.php @@ -2,17 +2,59 @@ namespace PHPWord\Tests\Section; use PHPWord_Section_TextBreak; +use PHPWord_Style_Paragraph; +use PHPWord_Style_Font; +/** + * @package PHPWord\Tests + * @coversDefaultClass PHPWord_Section_TextBreak + * @runTestsInSeparateProcesses + */ class TextBreakTest extends \PHPUnit_Framework_TestCase { /** - * Executed before each method of the class + * Construct with empty value */ public function testConstruct() { - // Section Settings - $oTextBreak = new PHPWord_Section_TextBreak(); + $object = new PHPWord_Section_TextBreak(); + $this->assertNull($object->getFontStyle()); + $this->assertNull($object->getParagraphStyle()); + } - $this->assertInstanceOf('PHPWord_Section_TextBreak', $oTextBreak); + /** + * Construct with style object + */ + public function testConstructWithStyleObject() + { + $fStyle = new PHPWord_Style_Font(); + $pStyle = new PHPWord_Style_Paragraph(); + $object = new PHPWord_Section_TextBreak($fStyle, $pStyle); + $this->assertEquals($fStyle, $object->getFontStyle()); + $this->assertEquals($pStyle, $object->getParagraphStyle()); + } + + /** + * Construct with style array + */ + public function testConstructWithStyleArray() + { + $fStyle = array('size' => 12); + $pStyle = array('spacing' => 240); + $object = new PHPWord_Section_TextBreak($fStyle, $pStyle); + $this->assertInstanceOf('PHPWord_Style_Font', $object->getFontStyle()); + $this->assertInstanceOf('PHPWord_Style_Paragraph', $object->getParagraphStyle()); + } + + /** + * Construct with style name + */ + public function testConstructWithStyleName() + { + $fStyle = 'fStyle'; + $pStyle = 'pStyle'; + $object = new PHPWord_Section_TextBreak($fStyle, $pStyle); + $this->assertEquals($fStyle, $object->getFontStyle()); + $this->assertEquals($pStyle, $object->getParagraphStyle()); } } diff --git a/Tests/PHPWord/Writer/Word2007/BaseTest.php b/Tests/PHPWord/Writer/Word2007/BaseTest.php index 6aafce93..fde6e30b 100644 --- a/Tests/PHPWord/Writer/Word2007/BaseTest.php +++ b/Tests/PHPWord/Writer/Word2007/BaseTest.php @@ -2,6 +2,7 @@ namespace PHPWord\Tests\Writer\Word2007; use PHPWord; +use PHPWord_Style; use PHPWord\Tests\TestHelperDOCX; /** @@ -103,6 +104,30 @@ class BaseTest extends \PHPUnit_Framework_TestCase $this->assertEquals('PAGE', $preserve->nodeValue); $this->assertEquals('preserve', $preserve->getAttribute('xml:space')); } + /** + * covers ::_writeTextBreak + */ + public function testWriteTextBreak() + { + $fArray = array('size' => 12); + $pArray = array('spacing' => 240); + $fName = 'fStyle'; + $pName = 'pStyle'; + + $PHPWord = new PHPWord(); + $PHPWord->addFontStyle($fName, $fArray); + $PHPWord->addParagraphStyle($pName, $pArray); + $section = $PHPWord->createSection(); + $section->addTextBreak(); + $section->addTextBreak(1, $fArray, $pArray); + $section->addTextBreak(1, $fName, $pName); + $doc = TestHelperDOCX::getDocument($PHPWord); + + $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:rPr/w:rStyle'); + $this->assertEquals($fName, $element->getAttribute('w:val')); + $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:pStyle'); + $this->assertEquals($pName, $element->getAttribute('w:val')); + } /** * covers ::_writeParagraphStyle diff --git a/changelog.txt b/changelog.txt index 9f3d2bee..83d127ea 100755 --- a/changelog.txt +++ b/changelog.txt @@ -50,9 +50,14 @@ Changes in branch for release 0.8.0 : - Bugfix: (ivanlanin) GH-94 - General: PHPWord_Shared_Drawing::centimetersToPixels() conversion - Feature: (ivanlanin) - Paragraph: setTabs() function - Feature: (ivanlanin) GH-99 - General: Basic support for TextRun on ODT and RTF -- Feature: (ivanlanin) - Reader: Initial effort for Word2007 -- Feature: (ivanlanin) - MemoryImage: Allow remote image when allow_url_open = on -- Bugfix: (ivanlanin) - Footnote: Corrupt DOCX reported by MS Word when sections > 1 and not every sections have footnote +- Feature: (ivanlanin) GH-104 - Reader: Basic Reader for Word2007 +- Feature: (bskrtich ) GH-109 - TextRun: Allow Text Break in Text Run +- Feature: (jhfangying) GH-111 GH-118 - General: Support for East Asian fontstyle +- Feature: (gabrielbull) GH-114 - Image: Use exif_imagetype to check image format instead of extension name +- Feature: (bskrtich ) GH-103 - General: Setting for XMLWriter Compatibility option +- Feature: (ivanlanin) GH-122 - MemoryImage: Allow remote image when allow_url_open = on +- Bugfix: (ivanlanin) GH-125 - Footnote: Corrupt DOCX reported by MS Word when sections > 1 and not every sections have footnote +- Feature: (ivanlanin) GH-18 - TextBreak: Allow style for font break - QA: (Progi1984) - UnitTests Changes in branch for release 0.7.0 : diff --git a/samples/Sample_19_TextBreak.php b/samples/Sample_19_TextBreak.php new file mode 100644 index 00000000..17299601 --- /dev/null +++ b/samples/Sample_19_TextBreak.php @@ -0,0 +1,49 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; +$PHPWord = new PHPWord(); + +// Begin code +$fontStyle = array('size' => 24); +$paragraphStyle = array('spacing' => 240, 'size' => 24); +$PHPWord->addFontStyle('fontStyle', array('size' => 9)); +$PHPWord->addParagraphStyle('paragraphStyle', array('spacing' => 480)); +$fontStyle = array('size' => 24); + +$section = $PHPWord->createSection(); +$section->addText('Text break with no style:'); +$section->addTextBreak(); +$section->addText('Text break with defined font style:'); +$section->addTextBreak(1, 'fontStyle'); +$section->addText('Text break with defined paragraph style:'); +$section->addTextBreak(1, null, 'paragraphStyle'); +$section->addText('Text break with inline font style:'); +$section->addTextBreak(1, $fontStyle); +$section->addText('Text break with inline paragraph style:'); +$section->addTextBreak(1, null, $paragraphStyle); +$section->addText('Done.'); + +// End code + +// 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}"); +} + +// 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;