Skip to content

Commit

Permalink
Word2007 Writer : Fixed first footnote appearing as separator (#2635)
Browse files Browse the repository at this point in the history
* Fix first footnote appearing as separator

* Add test

* Update changelog

* Fixed changelog

---------

Co-authored-by: Progi1984 <[email protected]>
  • Loading branch information
jacksleight and Progi1984 authored Aug 14, 2024
1 parent 1691301 commit dbf0a3e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changes/2.x/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Documentation : Updated Comment element by [@laminga](https://github.com/laminga) in [#2650](https://github.com/PHPOffice/PHPWord/pull/2650)
- HTML Reader : Read width & height attributes in points fixing [#2589](https://github.com/PHPOffice/PHPWord/issues/2589) by [@Progi1984](https://github.com/Progi1984) in [#2654](https://github.com/PHPOffice/PHPWord/pull/2654)
- Template Processor : Fixed bad naming of variables fixing [#2586](https://github.com/PHPOffice/PHPWord/issues/2586) by [@Progi1984](https://github.com/Progi1984) in [#2655](https://github.com/PHPOffice/PHPWord/pull/2655)
- Word2007 Writer : Fix first footnote appearing as separator [#2634](https://github.com/PHPOffice/PHPWord/issues/2634) by [@jacksleight](https://github.com/jacksleight) in [#2635](https://github.com/PHPOffice/PHPWord/pull/2635)

### Miscellaneous

Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/Word2007/Element/Footnote.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function write(): void
$xmlWriter->endElement(); // w:rStyle
$xmlWriter->endElement(); // w:rPr
$xmlWriter->startElement("w:{$this->referenceType}");
$xmlWriter->writeAttribute('w:id', $element->getRelationId());
$xmlWriter->writeAttribute('w:id', $element->getRelationId() + 1);
$xmlWriter->endElement(); // w:$referenceType
$xmlWriter->endElement(); // w:r

Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/Word2007/Part/Footnotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function setElements($elements)
protected function writeNote(XMLWriter $xmlWriter, $element): void
{
$xmlWriter->startElement($this->elementNode);
$xmlWriter->writeAttribute('w:id', $element->getRelationId());
$xmlWriter->writeAttribute('w:id', $element->getRelationId() + 1);
$xmlWriter->startElement('w:p');

// Paragraph style
Expand Down
3 changes: 3 additions & 0 deletions tests/PhpWordTests/Writer/Word2007/Part/FootnotesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ public function testWriteFootnotes(): void

self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference'));
self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:endnoteReference'));

self::assertFalse($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference[@w:id="0"]'));
self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference[@w:id="1"]'));
}
}

0 comments on commit dbf0a3e

Please sign in to comment.