Final fix that satisfies both MS Word and OpenOffice

This commit is contained in:
Ivan Lanin 2014-03-14 15:26:17 +07:00
parent d87fa2aa8b
commit c8a1e2e0eb
4 changed files with 28 additions and 17 deletions

View File

@ -422,9 +422,6 @@ class PHPWord_Section
*/
public function getFooter()
{
if (!($this->_footer instanceOf PHPWord_Section_Footer)) {
$this->_footer = new PHPWord_Section_Footer($this->_sectionCount);
}
return $this->_footer;
}

View File

@ -128,6 +128,7 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$rID = PHPWord_Media::countSectionMediaElements() + 6;
$_sections = $this->_document->getSections();
$footers = array();
foreach ($_sections as $section) {
$_headers = $section->getHeaders();
foreach ($_headers as $index => &$_header) {
@ -139,13 +140,15 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
}
$_footer = $section->getFooter();
$_cFtrs++;
$footers[++$_cFtrs] = $_footer;
if (!is_null($_footer)) {
$_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) {
$_allFootnotesCollection = PHPWord_Footnote::getFootnoteElements();
@ -159,7 +162,15 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
// build docx file
// Write dynamic files
$objZip->addFromString('[Content_Types].xml', $this->getWriterPart('contenttypes')->writeContentTypes($this->_imageTypes, $this->_objectTypes, $_cHdrs, $_cFtrs));
$objZip->addFromString(
'[Content_Types].xml',
$this->getWriterPart('contenttypes')->writeContentTypes(
$this->_imageTypes,
$this->_objectTypes,
$_cHdrs,
$footers
)
);
$objZip->addFromString('_rels/.rels', $this->getWriterPart('rels')->writeRelationships($this->_document));
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('docprops')->writeDocPropsApp($this->_document));
$objZip->addFromString('docProps/core.xml', $this->getWriterPart('docprops')->writeDocPropsCore($this->_document));

View File

@ -31,7 +31,7 @@
class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_WriterPart
{
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $_cFtrs)
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers)
{
// Create XML writer
$objWriter = null;
@ -153,13 +153,15 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
);
}
for ($i = 1; $i <= $_cFtrs; $i++) {
for ($i = 1; $i <= count($footers); $i++) {
if (!is_null($footers[$i])) {
$this->_writeOverrideContentType(
$objWriter,
'/word/footer' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
);
}
}
$objWriter->endElement();

View File

@ -52,6 +52,7 @@ Changes in branch for release 0.7.1 :
- 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
- QA: (Progi1984) - UnitTests
Changes in branch for release 0.7.0 :