From f8f1d27a1e531be49135e6e45b0f91e869e0ff39 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sat, 12 Jun 2021 15:08:47 +0200 Subject: [PATCH 1/2] Fix for the BIFF-8 Xls colour mappings in the Reader --- src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php b/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php index 5d8b5ab87a..5c109fb071 100644 --- a/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php +++ b/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php @@ -5,62 +5,62 @@ class BIFF8 { protected static $map = [ - '000000' => 0x08, - 'FFFFFF' => 0x09, - 'FF0000' => 0x0A, - '00FF00' => 0x0B, - '0000FF' => 0x0C, - 'FFFF00' => 0x0D, - 'FF00FF' => 0x0E, - '00FFFF' => 0x0F, - '800000' => 0x10, - '008000' => 0x11, - '000080' => 0x12, - '808000' => 0x13, - '800080' => 0x14, - '008080' => 0x15, - 'C0C0C0' => 0x16, - '808080' => 0x17, - '9999FF' => 0x18, - '993366' => 0x19, - 'FFFFCC' => 0x1A, - 'CCFFFF' => 0x1B, - '660066' => 0x1C, - 'FF8080' => 0x1D, - '0066CC' => 0x1E, - 'CCCCFF' => 0x1F, - // '000080' => 0x20, - // 'FF00FF' => 0x21, - // 'FFFF00' => 0x22, - // '00FFFF' => 0x23, - // '800080' => 0x24, - // '800000' => 0x25, - // '008080' => 0x26, - // '0000FF' => 0x27, - '00CCFF' => 0x28, - // 'CCFFFF' => 0x29, - 'CCFFCC' => 0x2A, - 'FFFF99' => 0x2B, - '99CCFF' => 0x2C, - 'FF99CC' => 0x2D, - 'CC99FF' => 0x2E, - 'FFCC99' => 0x2F, - '3366FF' => 0x30, - '33CCCC' => 0x31, - '99CC00' => 0x32, - 'FFCC00' => 0x33, - 'FF9900' => 0x34, - 'FF6600' => 0x35, - '666699' => 0x36, - '969696' => 0x37, - '003366' => 0x38, - '339966' => 0x39, - '003300' => 0x3A, - '333300' => 0x3B, - '993300' => 0x3C, - // '993366' => 0x3D, - '333399' => 0x3E, - '333333' => 0x3F, + 0x08 => '000000', + 0x09 => 'FFFFFF', + 0x0A => 'FF0000', + 0x0B => '00FF00', + 0x0C => '0000FF', + 0x0D => 'FFFF00', + 0x0E => 'FF00FF', + 0x0F => '00FFFF', + 0x10 => '800000', + 0x11 => '008000', + 0x12 => '000080', + 0x13 => '808000', + 0x14 => '800080', + 0x15 => '008080', + 0x16 => 'C0C0C0', + 0x17 => '808080', + 0x18 => '9999FF', + 0x19 => '993366', + 0x1A => 'FFFFCC', + 0x1B => 'CCFFFF', + 0x1C => '660066', + 0x1D => 'FF8080', + 0x1E => '0066CC', + 0x1F => 'CCCCFF', + 0x20 => '000080', + 0x21 => 'FF00FF', + 0x22 => 'FFFF00', + 0x23 => '00FFFF', + 0x24 => '800080', + 0x25 => '800000', + 0x26 => '008080', + 0x27 => '0000FF', + 0x28 => '00CCFF', + 0x29 => 'CCFFFF', + 0x2A => 'CCFFCC', + 0x2B => 'FFFF99', + 0x2C => '99CCFF', + 0x2D => 'FF99CC', + 0x2E => 'CC99FF', + 0x2F => 'FFCC99', + 0x30 => '3366FF', + 0x31 => '33CCCC', + 0x32 => '99CC00', + 0x33 => 'FFCC00', + 0x34 => 'FF9900', + 0x35 => 'FF6600', + 0x36 => '666699', + 0x37 => '969696', + 0x38 => '003366', + 0x39 => '339966', + 0x3A => '003300', + 0x3B => '333300', + 0x3C => '993300', + 0x3D => '993366', + 0x3E => '333399', + 0x3F => '333333', ]; /** From 716124ca6012e0642f6d768c0a5009c3fc4e3c07 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 13 Jun 2021 21:34:55 +0200 Subject: [PATCH 2/2] Unit test for reading colours, writing hen rereading and ensuring that the RGB values have not changed --- .../Reader/Xls/ColourTest.php | 42 ++++++++++++++++++ tests/data/Reader/XLS/Colours.xls | Bin 0 -> 31232 bytes 2 files changed, 42 insertions(+) create mode 100644 tests/PhpSpreadsheetTests/Reader/Xls/ColourTest.php create mode 100644 tests/data/Reader/XLS/Colours.xls diff --git a/tests/PhpSpreadsheetTests/Reader/Xls/ColourTest.php b/tests/PhpSpreadsheetTests/Reader/Xls/ColourTest.php new file mode 100644 index 0000000000..d17e7e167d --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xls/ColourTest.php @@ -0,0 +1,42 @@ +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); + } + } +} diff --git a/tests/data/Reader/XLS/Colours.xls b/tests/data/Reader/XLS/Colours.xls new file mode 100644 index 0000000000000000000000000000000000000000..c3aa05926d95098e98ef370ad0e654d131631d31 GIT binary patch literal 31232 zcmeHQ30M@zv+w0x6yy{{RF*>pIpy?1E)^9J#5*2{xC;n^uAmqt5XC5JJW%6B;uRI| z`@##4U{F+4(7zfLyrS`l8Y3}@*;h5g!tAg!%)bBof8TrGWB7V@rl$K>)z#HKT{S&J z`Bl@Z4f|SG6V}#~Xp?^w21JiR7r}9N<+%xg>k0*)Du27dF_45|W) zF6*BmT0~DwNHzTK)xk4D9zq&LCXr@@M8?UJB_VOiQn}AmMdS!o z<_<;aOxls3AitO_L5tTS$Mr>_B#xwzBr=Z3VgJ7;M<S7 zDXCpWBFKFLwaQU1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