Added Conditional Formatting: ColorScale for Xlsx (#3738)

* Added Conditional Formatting: ColorScale for Xlsx

* Add Reader Support, Tests, Sample

Also correct Phpstan and phpcs problems.

* Update cond08_colorscale.php

* Improve Coverage

* More Coverage Improvements

* Use StyleReader for Colors for ColorScale and DataBar

The implementation of DataBar looks for an rgb attribute, but the color may be provided via theme attribute instead. The initial implementation for ColorScale did the same. Change both to use the existing code in Reader\Xlsx\Styles to parse the color.

* Change Some Doc Blocks to Type Declarations

---------

Co-authored-by: oleibman <10341515+oleibman@users.noreply.github.com>
This commit is contained in:
redtailmatt
2023-09-30 10:23:42 -04:00
committed by GitHub
parent 7328e1ed61
commit a713e153aa
10 changed files with 339 additions and 78 deletions
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class ConditionalColorScaleTest extends AbstractFunctional
{
public function testColorScale(): void
{
$filename = 'tests/data/Reader/XLSX/colorscale.xlsx';
$reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filename);
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
$spreadsheet->disconnectWorksheets();
$worksheet = $reloadedSpreadsheet->getActiveSheet();
$styles = $worksheet->getConditionalStyles('A1:A10');
self::assertCount(1, $styles);
$colorScale = $styles[0]->getColorScale();
self::assertNotNull($colorScale);
self::assertNotNull($colorScale->getMinimumConditionalFormatValueObject());
self::assertNotNull($colorScale->getMidpointConditionalFormatValueObject());
self::assertSame('50', $colorScale->getMidpointConditionalFormatValueObject()->getValue());
self::assertNotNull($colorScale->getMaximumConditionalFormatValueObject());
self::assertSame('FFF8696B', $colorScale->getMinimumColor()?->getARGB());
self::assertSame('FFFFEB84', $colorScale->getMidpointColor()?->getARGB());
self::assertSame('FF63BE7B', $colorScale->getMaximumColor()?->getARGB());
$reloadedSpreadsheet->disconnectWorksheets();
}
}