Skip to content

Commit 1642ee4

Browse files
authored
Merge pull request #2702 from PHPOffice/Xls-Reader-CF-Styling
Support fill style and color for reading CF Formats
2 parents be734cf + 0a9d154 commit 1642ee4

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2020
- Support for two cell anchor drawing of images. [#2532](https://github.com/PHPOffice/PhpSpreadsheet/pull/2532)
2121
- Limited support for Xls Reader to handle Conditional Formatting:
2222

23-
Ranges and Rules are read, but style is currently limited to font size, weight and color.
23+
Ranges and Rules are read, but style is currently limited to font size, weight and color; and to fill style and color.
2424

2525
### Changed
2626

src/PhpSpreadsheet/Reader/Xls.php

+21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpOffice\PhpSpreadsheet\NamedRange;
1010
use PhpOffice\PhpSpreadsheet\Reader\Xls\ConditionalFormatting;
1111
use PhpOffice\PhpSpreadsheet\Reader\Xls\Style\CellFont;
12+
use PhpOffice\PhpSpreadsheet\Reader\Xls\Style\FillPattern;
1213
use PhpOffice\PhpSpreadsheet\RichText\RichText;
1314
use PhpOffice\PhpSpreadsheet\Shared\CodePage;
1415
use PhpOffice\PhpSpreadsheet\Shared\Date;
@@ -23,6 +24,7 @@
2324
use PhpOffice\PhpSpreadsheet\Style\Alignment;
2425
use PhpOffice\PhpSpreadsheet\Style\Borders;
2526
use PhpOffice\PhpSpreadsheet\Style\Conditional;
27+
use PhpOffice\PhpSpreadsheet\Style\Fill;
2628
use PhpOffice\PhpSpreadsheet\Style\Font;
2729
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
2830
use PhpOffice\PhpSpreadsheet\Style\Protection;
@@ -8013,6 +8015,25 @@ private function getCFBorderStyle(string $options, Style $style): void
80138015

80148016
private function getCFFillStyle(string $options, Style $style): void
80158017
{
8018+
$fillPattern = self::getUInt2d($options, 0);
8019+
// bit: 10-15; mask: 0xFC00; type
8020+
$fillPattern = (0xFC00 & $fillPattern) >> 10;
8021+
$fillPattern = FillPattern::lookup($fillPattern);
8022+
$fillPattern = $fillPattern === Fill::FILL_NONE ? Fill::FILL_SOLID : $fillPattern;
8023+
8024+
if ($fillPattern !== Fill::FILL_NONE) {
8025+
$style->getFill()->setFillType($fillPattern);
8026+
8027+
$fillColors = self::getUInt2d($options, 2);
8028+
8029+
// bit: 0-6; mask: 0x007F; type
8030+
$color1 = (0x007F & $fillColors) >> 0;
8031+
$style->getFill()->getStartColor()->setRGB(Xls\Color::map($color1, $this->palette, $this->version)['rgb']);
8032+
8033+
// bit: 7-13; mask: 0x3F80; type
8034+
$color2 = (0x3F80 & $fillColors) >> 7;
8035+
$style->getFill()->getEndColor()->setRGB(Xls\Color::map($color2, $this->palette, $this->version)['rgb']);
8036+
}
80168037
}
80178038

80188039
private function getCFProtectionStyle(string $options, Style $style): void
512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)