Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ protected static function parseInlineStyle($node, $styles = [])
$attributeClass = $attributes->getNamedItem('class');
if ($attributeClass && self::$css) {
$styles = self::parseStyleDeclarations(self::$css->getStyle('.' . $attributeClass->value), $styles);
$styles['className'] = $attributeClass->value;
}

$attributeStyle = $attributes->getNamedItem('style');
Expand Down Expand Up @@ -411,6 +412,11 @@ protected static function parseTable($node, $element, &$styles)

$newElement = $element->addTable($elementStyles);

// Add style name from CSS Class
if (isset($elementStyles['className'])) {
$newElement->getStyle()->setStyleName($elementStyles['className']);
}

$attributes = $node->attributes;
if ($attributes->getNamedItem('border') !== null) {
$border = (int) $attributes->getNamedItem('border')->value;
Expand Down
12 changes: 12 additions & 0 deletions tests/PhpWordTests/Shared/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Exception;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Html;
use PhpOffice\PhpWord\SimpleType\Jc;
Expand Down Expand Up @@ -134,6 +135,17 @@ public function testParseStyle(): void
self::assertEquals('22.5', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:r/w:rPr/w:sz', 'w:val'));
}

public function testParseStyleTableClassName(): void
{
$html = '<style type="text/css">.pStyle { font-size:15px; }</style><table class="pStyle"><tr><td></td></tr></table>';
$phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, $html);

self::assertInstanceOf(Table::class, $section->getElement(0));
self::assertEquals('pStyle', $section->getElement(0)->getStyle()->getStyleName());
}

/**
* Test underline.
*/
Expand Down