Fix for the BIFF-8 Xls colour mappings in the Reader (#2156)

* Fix for the BIFF-8 Xls colour mappings in the Reader
* Unit test for reading colours, writing hen rereading and ensuring that the RGB values have not changed
This commit is contained in:
Mark Baker 2021-06-13 21:46:49 +02:00 committed by GitHub
parent b98b9c761c
commit 74b02fb31c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 98 additions and 56 deletions

View File

@ -5,62 +5,62 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls\Color;
class BIFF8 class BIFF8
{ {
protected static $map = [ protected static $map = [
'000000' => 0x08, 0x08 => '000000',
'FFFFFF' => 0x09, 0x09 => 'FFFFFF',
'FF0000' => 0x0A, 0x0A => 'FF0000',
'00FF00' => 0x0B, 0x0B => '00FF00',
'0000FF' => 0x0C, 0x0C => '0000FF',
'FFFF00' => 0x0D, 0x0D => 'FFFF00',
'FF00FF' => 0x0E, 0x0E => 'FF00FF',
'00FFFF' => 0x0F, 0x0F => '00FFFF',
'800000' => 0x10, 0x10 => '800000',
'008000' => 0x11, 0x11 => '008000',
'000080' => 0x12, 0x12 => '000080',
'808000' => 0x13, 0x13 => '808000',
'800080' => 0x14, 0x14 => '800080',
'008080' => 0x15, 0x15 => '008080',
'C0C0C0' => 0x16, 0x16 => 'C0C0C0',
'808080' => 0x17, 0x17 => '808080',
'9999FF' => 0x18, 0x18 => '9999FF',
'993366' => 0x19, 0x19 => '993366',
'FFFFCC' => 0x1A, 0x1A => 'FFFFCC',
'CCFFFF' => 0x1B, 0x1B => 'CCFFFF',
'660066' => 0x1C, 0x1C => '660066',
'FF8080' => 0x1D, 0x1D => 'FF8080',
'0066CC' => 0x1E, 0x1E => '0066CC',
'CCCCFF' => 0x1F, 0x1F => 'CCCCFF',
// '000080' => 0x20, 0x20 => '000080',
// 'FF00FF' => 0x21, 0x21 => 'FF00FF',
// 'FFFF00' => 0x22, 0x22 => 'FFFF00',
// '00FFFF' => 0x23, 0x23 => '00FFFF',
// '800080' => 0x24, 0x24 => '800080',
// '800000' => 0x25, 0x25 => '800000',
// '008080' => 0x26, 0x26 => '008080',
// '0000FF' => 0x27, 0x27 => '0000FF',
'00CCFF' => 0x28, 0x28 => '00CCFF',
// 'CCFFFF' => 0x29, 0x29 => 'CCFFFF',
'CCFFCC' => 0x2A, 0x2A => 'CCFFCC',
'FFFF99' => 0x2B, 0x2B => 'FFFF99',
'99CCFF' => 0x2C, 0x2C => '99CCFF',
'FF99CC' => 0x2D, 0x2D => 'FF99CC',
'CC99FF' => 0x2E, 0x2E => 'CC99FF',
'FFCC99' => 0x2F, 0x2F => 'FFCC99',
'3366FF' => 0x30, 0x30 => '3366FF',
'33CCCC' => 0x31, 0x31 => '33CCCC',
'99CC00' => 0x32, 0x32 => '99CC00',
'FFCC00' => 0x33, 0x33 => 'FFCC00',
'FF9900' => 0x34, 0x34 => 'FF9900',
'FF6600' => 0x35, 0x35 => 'FF6600',
'666699' => 0x36, 0x36 => '666699',
'969696' => 0x37, 0x37 => '969696',
'003366' => 0x38, 0x38 => '003366',
'339966' => 0x39, 0x39 => '339966',
'003300' => 0x3A, 0x3A => '003300',
'333300' => 0x3B, 0x3B => '333300',
'993300' => 0x3C, 0x3C => '993300',
// '993366' => 0x3D, 0x3D => '993366',
'333399' => 0x3E, 0x3E => '333399',
'333333' => 0x3F, 0x3F => '333333',
]; ];
/** /**

View File

@ -0,0 +1,42 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class ColourTest extends AbstractFunctional
{
/**
* @var Spreadsheet
*/
private $spreadsheet;
protected function setup(): void
{
$filename = 'tests/data/Reader/XLS/Colours.xls';
$reader = new Xls();
$this->spreadsheet = $reader->load($filename);
}
public function testColours(): void
{
$colours = [];
$worksheet = $this->spreadsheet->getActiveSheet();
for ($row = 1; $row <= 7; ++$row) {
for ($column = 'A'; $column !== 'J'; ++$column) {
$cellAddress = "{$column}{$row}";
$colours[$cellAddress] = $worksheet->getStyle($cellAddress)->getFill()->getStartColor()->getRGB();
}
}
$newSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Xls');
$newWorksheet = $newSpreadsheet->getActiveSheet();
foreach ($colours as $cellAddress => $expectedColourValue) {
$actualColourValue = $newWorksheet->getStyle($cellAddress)->getFill()->getStartColor()->getRGB();
self::assertSame($expectedColourValue, $actualColourValue);
}
}
}

Binary file not shown.