Fix color from CSS when reading from HTML

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
This commit is contained in:
Mahmoud Abdo 2018-12-22 22:32:02 +03:00 committed by Adrien Crivelli
parent 0f8292fc0b
commit 86c635b3f5
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
3 changed files with 20 additions and 1 deletions

View File

@ -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

View File

@ -634,7 +634,7 @@ class Html extends BaseReader
break;
case 'color':
$sheet->getStyle($column . $row)->applyFromArray(['font' => ['color' => ['rgb' => "$style_color}"]]]);
$sheet->getStyle($column . $row)->applyFromArray(['font' => ['color' => ['rgb' => "{$style_color}"]]]);
break;
}

View File

@ -43,4 +43,22 @@ class HtmlTest extends TestCase
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);
}
}