Skip to content

Commit 8e9ade5

Browse files
damienfaProgi1984
authored andcommitted
Word2007 Reader: Support for Paragraph Border Style
1 parent fbe52dc commit 8e9ade5

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

docs/changes/2.x/2.0.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- IOFactory : Added extractVariables method to extract variables from a document [@sibalonat](https://github.com/sibalonat) in [#2515](https://github.com/PHPOffice/PHPWord/pull/2515)
88
- PDF Writer : Documented how to specify a PDF renderer, when working with the PDF writer, as well as the three available choices by [@settermjd](https://github.com/settermjd) in [#2642](https://github.com/PHPOffice/PHPWord/pull/2642)
9+
- Word2007 Reader: Support for Paragraph Border Style by [@damienfa](https://github.com/damienfa) in [#2651](https://github.com/PHPOffice/PHPWord/pull/2651)
910

1011
### Bug fixes
1112

src/PhpWord/Element/TextRun.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class TextRun extends AbstractContainer
3232
/**
3333
* Paragraph style.
3434
*
35-
* @var \PhpOffice\PhpWord\Style\Paragraph|string
35+
* @var Paragraph|string
3636
*/
3737
protected $paragraphStyle;
3838

3939
/**
4040
* Create new instance.
4141
*
42-
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $paragraphStyle
42+
* @param array|Paragraph|string $paragraphStyle
4343
*/
4444
public function __construct($paragraphStyle = null)
4545
{
@@ -49,7 +49,7 @@ public function __construct($paragraphStyle = null)
4949
/**
5050
* Get Paragraph style.
5151
*
52-
* @return \PhpOffice\PhpWord\Style\Paragraph|string
52+
* @return Paragraph|string
5353
*/
5454
public function getParagraphStyle()
5555
{
@@ -59,9 +59,9 @@ public function getParagraphStyle()
5959
/**
6060
* Set Paragraph style.
6161
*
62-
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $style
62+
* @param array|Paragraph|string $style
6363
*
64-
* @return \PhpOffice\PhpWord\Style\Paragraph|string
64+
* @return Paragraph|string
6565
*/
6666
public function setParagraphStyle($style = null)
6767
{

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,18 @@ protected function readParagraphStyle(XMLReader $xmlReader, DOMElement $domNode)
529529
'contextualSpacing' => [self::READ_TRUE, 'w:contextualSpacing'],
530530
'bidi' => [self::READ_TRUE, 'w:bidi'],
531531
'suppressAutoHyphens' => [self::READ_TRUE, 'w:suppressAutoHyphens'],
532+
'borderTopStyle' => [self::READ_VALUE, 'w:pBdr/w:top'],
533+
'borderTopColor' => [self::READ_VALUE, 'w:pBdr/w:top', 'w:color'],
534+
'borderTopSize' => [self::READ_VALUE, 'w:pBdr/w:top', 'w:sz'],
535+
'borderRightStyle' => [self::READ_VALUE, 'w:pBdr/w:right'],
536+
'borderRightColor' => [self::READ_VALUE, 'w:pBdr/w:right', 'w:color'],
537+
'borderRightSize' => [self::READ_VALUE, 'w:pBdr/w:right', 'w:sz'],
538+
'borderBottomStyle' => [self::READ_VALUE, 'w:pBdr/w:bottom'],
539+
'borderBottomColor' => [self::READ_VALUE, 'w:pBdr/w:bottom', 'w:color'],
540+
'borderBottomSize' => [self::READ_VALUE, 'w:pBdr/w:bottom', 'w:sz'],
541+
'borderLeftStyle' => [self::READ_VALUE, 'w:pBdr/w:left'],
542+
'borderLeftColor' => [self::READ_VALUE, 'w:pBdr/w:left', 'w:color'],
543+
'borderLeftSize' => [self::READ_VALUE, 'w:pBdr/w:left', 'w:sz'],
532544
];
533545

534546
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);

tests/PhpWordTests/Reader/Word2007Test.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,35 @@ public function testLoad(): void
8282
self::assertEquals('0', $doc->getElementAttribute('/w:document/w:body/w:p/w:r[w:t/node()="italics"]/w:rPr/w:b', 'w:val'));
8383
}
8484

85+
public function testLoadStyles(): void
86+
{
87+
$phpWord = IOFactory::load(dirname(__DIR__, 1) . '/_files/documents/reader-styles.docx', 'Word2007');
88+
89+
self::assertInstanceOf(PhpWord::class, $phpWord);
90+
91+
$section2 = $phpWord->getSection(2);
92+
self::assertInstanceOf(Section::class, $section2);
93+
$element2_31 = $section2->getElement(31);
94+
self::assertInstanceOf(TextRun::class, $element2_31);
95+
self::assertEquals('This is a paragraph with border differents', $element2_31->getText());
96+
// Top
97+
self::assertEquals('FFFF00', $element2_31->getParagraphStyle()->getBorderTopColor());
98+
self::assertEquals('10', $element2_31->getParagraphStyle()->getBorderTopSize());
99+
self::assertEquals('dotted', $element2_31->getParagraphStyle()->getBorderTopStyle());
100+
// Right
101+
self::assertEquals('00A933', $element2_31->getParagraphStyle()->getBorderRightColor());
102+
self::assertEquals('4', $element2_31->getParagraphStyle()->getBorderRightSize());
103+
self::assertEquals('dashed', $element2_31->getParagraphStyle()->getBorderRightStyle());
104+
// Bottom
105+
self::assertEquals('F10D0C', $element2_31->getParagraphStyle()->getBorderBottomColor());
106+
self::assertEquals('8', $element2_31->getParagraphStyle()->getBorderBottomSize());
107+
self::assertEquals('dashSmallGap', $element2_31->getParagraphStyle()->getBorderBottomStyle());
108+
// Left
109+
self::assertEquals('3465A4', $element2_31->getParagraphStyle()->getBorderLeftColor());
110+
self::assertEquals('8', $element2_31->getParagraphStyle()->getBorderLeftSize());
111+
self::assertEquals('dashed', $element2_31->getParagraphStyle()->getBorderLeftStyle());
112+
}
113+
85114
/**
86115
* Load a Word 2011 file.
87116
*/
Binary file not shown.

0 commit comments

Comments
 (0)