Skip to content
Open
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
109 changes: 99 additions & 10 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@

protected static $options;

protected static $rowIndex = 0;

Check failure on line 50 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Property PhpOffice\PhpWord\Shared\Html::$rowIndex has no type specified.

Check failure on line 50 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.0)

Property PhpOffice\PhpWord\Shared\Html::$rowIndex has no type specified.

Check failure on line 50 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Property PhpOffice\PhpWord\Shared\Html::$rowIndex has no type specified.

Check failure on line 50 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Property PhpOffice\PhpWord\Shared\Html::$rowIndex has no type specified.

Check failure on line 50 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.2)

Property PhpOffice\PhpWord\Shared\Html::$rowIndex has no type specified.

Check failure on line 50 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.4)

Property PhpOffice\PhpWord\Shared\Html::$rowIndex has no type specified.

Check failure on line 50 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.3)

Property PhpOffice\PhpWord\Shared\Html::$rowIndex has no type specified.

Check failure on line 50 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.4)

Property PhpOffice\PhpWord\Shared\Html::$rowIndex has no type specified.

protected static $columnIndex = 0;

Check failure on line 52 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Property PhpOffice\PhpWord\Shared\Html::$columnIndex has no type specified.

Check failure on line 52 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.0)

Property PhpOffice\PhpWord\Shared\Html::$columnIndex has no type specified.

Check failure on line 52 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Property PhpOffice\PhpWord\Shared\Html::$columnIndex has no type specified.

Check failure on line 52 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Property PhpOffice\PhpWord\Shared\Html::$columnIndex has no type specified.

Check failure on line 52 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.2)

Property PhpOffice\PhpWord\Shared\Html::$columnIndex has no type specified.

Check failure on line 52 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.4)

Property PhpOffice\PhpWord\Shared\Html::$columnIndex has no type specified.

Check failure on line 52 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.3)

Property PhpOffice\PhpWord\Shared\Html::$columnIndex has no type specified.

Check failure on line 52 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.4)

Property PhpOffice\PhpWord\Shared\Html::$columnIndex has no type specified.

protected static $rowSpanArray = [];

Check failure on line 54 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Property PhpOffice\PhpWord\Shared\Html::$rowSpanArray has no type specified.

Check failure on line 54 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.0)

Property PhpOffice\PhpWord\Shared\Html::$rowSpanArray has no type specified.

Check failure on line 54 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Property PhpOffice\PhpWord\Shared\Html::$rowSpanArray has no type specified.

Check failure on line 54 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Property PhpOffice\PhpWord\Shared\Html::$rowSpanArray has no type specified.

Check failure on line 54 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.2)

Property PhpOffice\PhpWord\Shared\Html::$rowSpanArray has no type specified.

Check failure on line 54 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.4)

Property PhpOffice\PhpWord\Shared\Html::$rowSpanArray has no type specified.

Check failure on line 54 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.3)

Property PhpOffice\PhpWord\Shared\Html::$rowSpanArray has no type specified.

Check failure on line 54 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.4)

Property PhpOffice\PhpWord\Shared\Html::$rowSpanArray has no type specified.

/**
* @var Css
*/
Expand Down Expand Up @@ -424,6 +430,9 @@
$newElement->getStyle()->setStyleName($elementStyles['className']);
}

self::$rowIndex = 0;
self::$rowSpanArray = [];

$attributes = $node->attributes;
if ($attributes->getNamedItem('border')) {
$border = (int) $attributes->getNamedItem('border')->nodeValue;
Expand Down Expand Up @@ -453,6 +462,9 @@
$height = $rowStyles['height'] ?? null;
unset($rowStyles['height']); // would not apply

self::$columnIndex = 0;
self::$rowIndex = self::$rowIndex + 1;

return $element->addRow($height, $rowStyles);
}

Expand All @@ -468,22 +480,99 @@
protected static function parseCell($node, $element, &$styles)
{
$cellStyles = self::recursiveParseStylesInHierarchy($node, $styles['cell']);
$vMergeStyle = self::recursiveParseStylesInHierarchy($node, $styles['cell']);
self::$columnIndex = self::$columnIndex + 1;
$search_row_items = ["rowIndex" => self::$rowIndex];
$rowSpanCell = array_filter(self::$rowSpanArray, function ($item) use ($search_row_items) {
return count(array_intersect_assoc($search_row_items, $item)) == count($search_row_items);
});

$colspan = $node->getAttribute('colspan');

Check failure on line 490 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Ignored error pattern #^Call to an undefined method DOMNode\:\:getAttribute\(\)\.$# in path /home/runner/work/PHPWord/PHPWord/src/PhpWord/Shared/Html.php is expected to occur 1 time, but occurred 2 times.

Check failure on line 490 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.0)

Ignored error pattern #^Call to an undefined method DOMNode\:\:getAttribute\(\)\.$# in path /home/runner/work/PHPWord/PHPWord/src/PhpWord/Shared/Html.php is expected to occur 1 time, but occurred 2 times.

Check failure on line 490 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Ignored error pattern #^Call to an undefined method DOMNode\:\:getAttribute\(\)\.$# in path /home/runner/work/PHPWord/PHPWord/src/PhpWord/Shared/Html.php is expected to occur 1 time, but occurred 2 times.

Check failure on line 490 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Ignored error pattern #^Call to an undefined method DOMNode\:\:getAttribute\(\)\.$# in path /home/runner/work/PHPWord/PHPWord/src/PhpWord/Shared/Html.php is expected to occur 1 time, but occurred 2 times.

Check failure on line 490 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.2)

Ignored error pattern #^Call to an undefined method DOMNode\:\:getAttribute\(\)\.$# in path /home/runner/work/PHPWord/PHPWord/src/PhpWord/Shared/Html.php is expected to occur 1 time, but occurred 2 times.

Check failure on line 490 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.4)

Ignored error pattern #^Call to an undefined method DOMNode\:\:getAttribute\(\)\.$# in path /home/runner/work/PHPWord/PHPWord/src/PhpWord/Shared/Html.php is expected to occur 1 time, but occurred 2 times.

Check failure on line 490 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.3)

Ignored error pattern #^Call to an undefined method DOMNode\:\:getAttribute\(\)\.$# in path /home/runner/work/PHPWord/PHPWord/src/PhpWord/Shared/Html.php is expected to occur 1 time, but occurred 2 times.

Check failure on line 490 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.4)

Ignored error pattern #^Call to an undefined method DOMNode\:\:getAttribute\(\)\.$# in path /home/runner/work/PHPWord/PHPWord/src/PhpWord/Shared/Html.php is expected to occur 1 time, but occurred 2 times.
if (!empty($colspan)) {
$cellStyles['gridSpan'] = $colspan - 0;
self::$columnIndex = self::$columnIndex + $colspan - 1;
}

// set cell width to control column widths
$width = $cellStyles['width'] ?? null;
unset($cellStyles['width']); // would not apply
$cell = $element->addCell($width, $cellStyles);

if (self::shouldAddTextRun($node)) {
return $cell->addTextRun(self::filterOutNonInheritedStyles(self::parseInlineStyle($node, $styles['paragraph'])));
}

return $cell;
$rowspan = $node->getAttribute('rowspan');

Check failure on line 496 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Call to an undefined method DOMNode::getAttribute().

Check failure on line 496 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.0)

Call to an undefined method DOMNode::getAttribute().

Check failure on line 496 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Call to an undefined method DOMNode::getAttribute().

Check failure on line 496 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Call to an undefined method DOMNode::getAttribute().

Check failure on line 496 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.2)

Call to an undefined method DOMNode::getAttribute().

Check failure on line 496 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.4)

Call to an undefined method DOMNode::getAttribute().

Check failure on line 496 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.3)

Call to an undefined method DOMNode::getAttribute().

Check failure on line 496 in src/PhpWord/Shared/Html.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.4)

Call to an undefined method DOMNode::getAttribute().
if (!empty($rowspan)) {
$cellStyles['vMerge'] = 'restart';
$gridSpan = 0;
$colIndex = self::$columnIndex;
if (!empty($colspan)){
$gridSpan = $colspan;
$colIndex = self::$columnIndex - $colspan + 1;
}
for ($x = 1; $x < $rowspan; $x++) {
array_push(self::$rowSpanArray, ['columnIndex'=>$colIndex, 'rowIndex'=>self::$rowIndex + $x, 'colspan'=>$gridSpan]);
}
}

$search_column_item = ["columnIndex" => self::$columnIndex];
$currentColumnRowSpan = array_filter($rowSpanCell, function ($item) use ($search_column_item) {
return count(array_intersect_assoc($search_column_item, $item)) == count($search_column_item);
});

// set cell width to control column widths
$width = $cellStyles['width'] ?? null;
unset($cellStyles['width']); // would not apply
$loop_check = self::$columnIndex;
if (count($currentColumnRowSpan) == 0){
$cell = $element->addCell($width, $cellStyles);
$loop_check = self::$columnIndex + 1;
}

if (count($rowSpanCell) > 0) {
unset($vMergeStyle['width']);
foreach($rowSpanCell as $row) {
if($row['columnIndex'] == $loop_check){
$loop_check = $row['columnIndex'] + 1;

if ($row['colspan'] > 0) {
$vMergeStyle['gridSpan'] = $row['colspan'];
self::$columnIndex = self::$columnIndex + $row['colspan'] + 1;
} else {
unset($vMergeStyle['gridSpan']);
self::$columnIndex = self::$columnIndex + 1;
}
$vMergeStyle['vMerge'] = 'continue';
$element->addCell($width, $vMergeStyle);
}
}
}

if (count($currentColumnRowSpan) > 0){
$cell = $element->addCell($width, $cellStyles);
}

$search_item = ["columnIndex" => self::$columnIndex + 1];
$nextColumnRowSpan = array_filter($rowSpanCell, function ($item) use ($search_item) {
return count(array_intersect_assoc($search_item, $item)) == count($search_item);
});

if (count($nextColumnRowSpan) > 0) {
unset($vMergeStyle['width']);
$loop_check = self::$columnIndex + 1;
foreach($rowSpanCell as $row) {
if($row['columnIndex'] == $loop_check){
$loop_check = $row['columnIndex'] + 1;
if ($row['colspan'] > 0) {
$vMergeStyle['gridSpan'] = $row['colspan'];
self::$columnIndex = self::$columnIndex + $row['colspan'] + 1;
} else {
unset($vMergeStyle['gridSpan']);
self::$columnIndex = self::$columnIndex + 1;
}
$vMergeStyle['vMerge'] = 'continue';
$element->addCell($width, $vMergeStyle);
}
}
}

if (self::shouldAddTextRun($node)) {
return $cell->addTextRun(self::filterOutNonInheritedStyles(self::parseInlineStyle($node, $styles['paragraph'])));
}

return $cell;
}

/**
Expand Down
Loading