From d87fa2aa8bcff7936b870276db207142fa9ac946 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Fri, 14 Mar 2014 14:53:45 +0700 Subject: [PATCH] MS Word report corrupted DOCX when there's more than 1 section and footnote applied not on the first section. OO is fine. Bug source: [Content-Types].xml entry is different with document.xml.rels --- Classes/PHPWord/Section.php | 3 +++ Classes/PHPWord/Writer/Word2007.php | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Classes/PHPWord/Section.php b/Classes/PHPWord/Section.php index bdf37f81..63eeaf03 100755 --- a/Classes/PHPWord/Section.php +++ b/Classes/PHPWord/Section.php @@ -422,6 +422,9 @@ class PHPWord_Section */ public function getFooter() { + if (!($this->_footer instanceOf PHPWord_Section_Footer)) { + $this->_footer = new PHPWord_Section_Footer($this->_sectionCount); + } return $this->_footer; } diff --git a/Classes/PHPWord/Writer/Word2007.php b/Classes/PHPWord/Writer/Word2007.php index 8d112d47..8d2e5e28 100755 --- a/Classes/PHPWord/Writer/Word2007.php +++ b/Classes/PHPWord/Writer/Word2007.php @@ -139,14 +139,12 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter } $_footer = $section->getFooter(); - if (!is_null($_footer)) { - $_cFtrs++; - $_footer->setRelationId(++$rID); - $_footerCount = $_footer->getFooterCount(); - $_footerFile = 'footer' . $_footerCount . '.xml'; - $sectionElements[] = array('target' => $_footerFile, 'type' => 'footer', 'rID' => $rID); - $objZip->addFromString('word/' . $_footerFile, $this->getWriterPart('footer')->writeFooter($_footer)); - } + $_cFtrs++; + $_footer->setRelationId(++$rID); + $_footerCount = $_footer->getFooterCount(); + $_footerFile = 'footer' . $_footerCount . '.xml'; + $sectionElements[] = array('target' => $_footerFile, 'type' => 'footer', 'rID' => $rID); + $objZip->addFromString('word/' . $_footerFile, $this->getWriterPart('footer')->writeFooter($_footer)); } if (PHPWord_Footnote::countFootnoteElements() > 0) {