Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 56 additions & 56 deletions src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

/**
Expand Down
42 changes: 42 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xls/ColourTest.php
Original file line number Diff line number Diff line change
@@ -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 added tests/data/Reader/XLS/Colours.xls
Binary file not shown.