Skip to content

Commit 2735c40

Browse files
committed
StyleMerger Use Copy Of baseStyle
Using baseStyle directly can lead to the by-reference problems associated with Cell and Style.
1 parent ffeaa42 commit 2735c40

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/PhpSpreadsheet/Style/ConditionalFormatting/StyleMerger.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ class StyleMerger
1414

1515
public function __construct(Style $baseStyle)
1616
{
17-
$this->baseStyle = $baseStyle;
17+
// Setting to $baseStyle sometimes causes problems later on.
18+
$array = $baseStyle->exportArray();
19+
$this->baseStyle = new Style();
20+
$this->baseStyle->applyFromArray($array);
1821
}
1922

2023
public function getStyle(): Style

tests/PhpSpreadsheetTests/Writer/Html/Issue4539Test.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,29 @@ public function testInlineAndNot(): void
1919
$writer->setConditionalFormatting(true);
2020
$writer->setUseInlineCss(true);
2121
$html = $writer->generateHtmlAll();
22-
$expected = '<td class="gridlines" style="vertical-align:bottom; color:#000000; font-family:\'Aptos Narrow\'; font-size:12pt; text-align:right; width:102pt; color:#000000;background-color:#5A8AC6;">5</td>';
22+
$expected = '<td style="vertical-align:bottom; color:#000000; font-family:\'Aptos Narrow\'; font-size:12pt; text-align:right; width:102pt; color:#000000;background-color:#5A8AC6;">5</td>';
2323
self::assertStringContainsString($expected, $html, 'inline conditional style');
24-
$expected = '<td class="gridlines" style="vertical-align:bottom; font-weight:bold; color:#000000; font-family:\'Aptos Narrow\'; font-size:12pt; text-align:left; width:102pt">Column Heading</td>';
24+
$expected = '<td style="vertical-align:bottom; font-weight:bold; color:#000000; font-family:\'Aptos Narrow\'; font-size:12pt; text-align:left; width:102pt">Column Heading</td>';
2525
self::assertStringContainsString($expected, $html, 'inline no conditional style');
26+
$expected = '<td style="vertical-align:bottom; color:#000000; font-family:\'Aptos Narrow\'; font-size:12pt; text-align:right; width:102pt; border-top:1px solid #92D050 !important;color:#000000;">1</td>';
27+
self::assertStringContainsString($expected, $html, 'inline border-top');
28+
$expected = '<td style="vertical-align:bottom; color:#000000; font-family:\'Aptos Narrow\'; font-size:12pt; text-align:right; width:102pt; border-top:1px solid #FF0000 !important;font-weight:bold;color:#000000;">2</td>';
29+
self::assertStringContainsString($expected, $html, 'inline border-top and bold');
30+
$expected = '<td style="vertical-align:bottom; color:#000000; font-family:\'Aptos Narrow\'; font-size:12pt; text-align:right; width:102pt">3</td>';
31+
self::assertStringContainsString($expected, $html, 'inline nomatch');
2632

2733
$writer->setUseInlineCss(false);
2834
$html = $writer->generateHtmlAll();
29-
$expected = '<td class="column0 style2 n" style="color:#000000;background-color:#5A8AC6;">5</td>';
35+
$expected = '<td class="column0 style0 n" style="color:#000000;background-color:#5A8AC6;">5</td>';
3036
self::assertStringContainsString($expected, $html, 'notinline conditional style');
3137
$expected = '<td class="column0 style1 s">Column Heading</td>';
3238
self::assertStringContainsString($expected, $html, 'notinline no conditional style');
39+
$expected = '<td class="column0 style0 n" style="border-top:1px solid #92D050 !important;color:#000000;">1</td>';
40+
self::assertStringContainsString($expected, $html, 'notinline border-top');
41+
$expected = '<td class="column0 style0 n" style="border-top:1px solid #FF0000 !important;font-weight:bold;color:#000000;">2</td>';
42+
self::assertStringContainsString($expected, $html, 'notinline border-top bold');
43+
$expected = '<td class="column0 style0 n">3</td>';
44+
self::assertStringContainsString($expected, $html, 'notinline nomatch');
3345

3446
$spreadsheet->disconnectWorksheets();
3547
}
618 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)