Skip to content

Commit

Permalink
Fix color from CSS when reading from HTML
Browse files Browse the repository at this point in the history
In case we generate Spreadsheet from html file and the code
in file have text color in css "color:#FF00FF" it will showing
as black color because it will render like rgb content with } "FF00FF}"
So, we fix it by adding missing bracket "{".

Closes #831
  • Loading branch information
vipmaa authored and PowerKiKi committed Jan 2, 2019
1 parent 0f8292f commit 86c635b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Improved memory usage and performance when loading large spreadsheets - [#822](https://github.com/PHPOffice/PhpSpreadsheet/pull/822)
- Improved performance when loading large spreadsheets - [#825](https://github.com/PHPOffice/PhpSpreadsheet/pull/825)
- Improved performance when loading large spreadsheets - [#824](https://github.com/PHPOffice/PhpSpreadsheet/pull/824)
- Fix color from CSS when reading from HTML - [#831](https://github.com/PHPOffice/PhpSpreadsheet/pull/831)

## [1.5.2] - 2018-11-25

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ private function applyInlineStyle(&$sheet, $row, $column, $attributeArray)

break;
case 'color':
$sheet->getStyle($column . $row)->applyFromArray(['font' => ['color' => ['rgb' => "$style_color}"]]]);
$sheet->getStyle($column . $row)->applyFromArray(['font' => ['color' => ['rgb' => "{$style_color}"]]]);

break;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,22 @@ public function testCanReadVerySmallFile($expected, $content)

self::assertSame($expected, $actual);
}

public function testBackgroundColorInRanding()
{
$html = '<table>
<tr>
<td style="background-color: #000000;color: #FFFFFF">Blue background</td>
</tr>
</table>';
$filename = tempnam(sys_get_temp_dir(), 'html');
file_put_contents($filename, $html);
$reader = new Html();
$spreadsheet = $reader->load($filename);
$firstSheet = $spreadsheet->getSheet(0);
$style = $firstSheet->getCell('A1')->getStyle();

self::assertEquals('FFFFFF', $style->getFont()->getColor()->getRGB());
unlink($filename);
}
}

0 comments on commit 86c635b

Please sign in to comment.