Merge pull request #2702 from PHPOffice/Xls-Reader-CF-Styling

Support fill style and color for reading CF Formats
This commit is contained in:
Mark Baker 2022-03-19 19:57:52 +01:00 committed by GitHub
commit 1642ee4eb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Support for two cell anchor drawing of images. [#2532](https://github.com/PHPOffice/PhpSpreadsheet/pull/2532) - Support for two cell anchor drawing of images. [#2532](https://github.com/PHPOffice/PhpSpreadsheet/pull/2532)
- Limited support for Xls Reader to handle Conditional Formatting: - Limited support for Xls Reader to handle Conditional Formatting:
Ranges and Rules are read, but style is currently limited to font size, weight and color. Ranges and Rules are read, but style is currently limited to font size, weight and color; and to fill style and color.
### Changed ### Changed

View File

@ -9,6 +9,7 @@ use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Reader\Xls\ConditionalFormatting; use PhpOffice\PhpSpreadsheet\Reader\Xls\ConditionalFormatting;
use PhpOffice\PhpSpreadsheet\Reader\Xls\Style\CellFont; use PhpOffice\PhpSpreadsheet\Reader\Xls\Style\CellFont;
use PhpOffice\PhpSpreadsheet\Reader\Xls\Style\FillPattern;
use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\CodePage; use PhpOffice\PhpSpreadsheet\Shared\CodePage;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date;
@ -23,6 +24,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Borders; use PhpOffice\PhpSpreadsheet\Style\Borders;
use PhpOffice\PhpSpreadsheet\Style\Conditional; use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Style\Font;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\Protection; use PhpOffice\PhpSpreadsheet\Style\Protection;
@ -8013,6 +8015,25 @@ class Xls extends BaseReader
private function getCFFillStyle(string $options, Style $style): void private function getCFFillStyle(string $options, Style $style): void
{ {
$fillPattern = self::getUInt2d($options, 0);
// bit: 10-15; mask: 0xFC00; type
$fillPattern = (0xFC00 & $fillPattern) >> 10;
$fillPattern = FillPattern::lookup($fillPattern);
$fillPattern = $fillPattern === Fill::FILL_NONE ? Fill::FILL_SOLID : $fillPattern;
if ($fillPattern !== Fill::FILL_NONE) {
$style->getFill()->setFillType($fillPattern);
$fillColors = self::getUInt2d($options, 2);
// bit: 0-6; mask: 0x007F; type
$color1 = (0x007F & $fillColors) >> 0;
$style->getFill()->getStartColor()->setRGB(Xls\Color::map($color1, $this->palette, $this->version)['rgb']);
// bit: 7-13; mask: 0x3F80; type
$color2 = (0x3F80 & $fillColors) >> 7;
$style->getFill()->getEndColor()->setRGB(Xls\Color::map($color2, $this->palette, $this->version)['rgb']);
}
} }
private function getCFProtectionStyle(string $options, Style $style): void private function getCFProtectionStyle(string $options, Style $style): void