Skip to content

Commit a33be2b

Browse files
kernusrProgi1984
authored andcommitted
Word2007 Reader : Support for table cell borders and margins
1 parent c17c4c7 commit a33be2b

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1313
- Improved TextDirection for styling a cell by @terryzwt in #2429
1414
- Word2007 Reader : Added option to disable loading images by @aelliott1485 in #2450
1515
- HTML Writer : Added border-spacing to default styles for table by @kernusr in #2451
16+
- Word2007 Reader : Support for table cell borders and margins by @kernusr in #2454
1617

1718
### Bug fixes
1819

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,8 @@ protected function readTable(XMLReader $xmlReader, DOMElement $domNode, $parent,
385385
} elseif ('w:tc' == $rowNode->nodeName) { // Cell
386386
$cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW');
387387
$cellStyle = null;
388-
$cellStyleNode = $xmlReader->getElement('w:tcPr', $rowNode);
389-
if (null !== $cellStyleNode) {
390-
$cellStyle = $this->readCellStyle($xmlReader, $cellStyleNode);
388+
if ($xmlReader->elementExists('w:tcPr', $rowNode)) {
389+
$cellStyle = $this->readCellStyle($xmlReader, $rowNode);
391390
}
392391

393392
$cell = $row->addCell($cellWidth, $cellStyle);
@@ -573,7 +572,7 @@ private function readTableIndent(XMLReader $xmlReader, DOMElement $domNode)
573572
/**
574573
* Read w:tcPr.
575574
*
576-
* @return array
575+
* @return null|array
577576
*/
578577
private function readCellStyle(XMLReader $xmlReader, DOMElement $domNode)
579578
{
@@ -585,8 +584,30 @@ private function readCellStyle(XMLReader $xmlReader, DOMElement $domNode)
585584
'bgColor' => [self::READ_VALUE, 'w:shd', 'w:fill'],
586585
'noWrap' => [self::READ_VALUE, 'w:noWrap', null, null, true],
587586
];
587+
$style = null;
588588

589-
return $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
589+
if ($xmlReader->elementExists('w:tcPr', $domNode)) {
590+
$styleNode = $xmlReader->getElement('w:tcPr', $domNode);
591+
592+
$margins = ['top', 'left', 'bottom', 'right'];
593+
foreach ($margins as $side) {
594+
$ucfSide = ucfirst($side);
595+
$styleDefs['cellMargin' . $ucfSide] = [self::READ_VALUE, 'w:tcMar/w:' . $side, 'w:w'];
596+
}
597+
598+
$borders = array_merge($margins, ['insideH', 'insideV']);
599+
foreach ($borders as $side) {
600+
$ucfSide = ucfirst($side);
601+
602+
$styleDefs['border' . $ucfSide . 'Size'] = [self::READ_VALUE, 'w:tcBorders/w:' . $side, 'w:sz'];
603+
$styleDefs['border' . $ucfSide . 'Color'] = [self::READ_VALUE, 'w:tcBorders/w:' . $side, 'w:color'];
604+
$styleDefs['border' . $ucfSide . 'Style'] = [self::READ_VALUE, 'w:tcBorders/w:' . $side, 'w:val'];
605+
}
606+
607+
$style = $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
608+
}
609+
610+
return $style;
590611
}
591612

592613
/**

0 commit comments

Comments
 (0)