Skip to content

Commit 98d6743

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

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use PhpOffice\PhpWord\PhpWord;
3030
use PhpOffice\PhpWord\Reader\Word2007;
3131
use PhpOffice\PhpWord\Style\Font;
32+
use PhpOffice\PhpWord\Style\Paragraph;
3233
use PhpOffice\PhpWordTests\TestHelperDOCX;
3334

3435
/**
@@ -82,6 +83,41 @@ public function testLoad(): void
8283
self::assertEquals('0', $doc->getElementAttribute('/w:document/w:body/w:p/w:r[w:t/node()="italics"]/w:rPr/w:b', 'w:val'));
8384
}
8485

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

0 commit comments

Comments
 (0)