Skip to content
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

Xls Reader Conditional Styles #3400

Merged
merged 1 commit into from
Feb 25, 2023
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
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xls.php
Original file line number Diff line number Diff line change
Expand Up @@ -7921,7 +7921,7 @@ private function readCFRule(array $cellRangeAddresses): void
// offset: 6; size: 4; Options
$options = self::getInt4d($recordData, 6);

$style = new Style();
$style = new Style(false, true); // non-supervisor, conditional
$this->getCFStyleOptions($options, $style);

$hasFontRecord = (bool) ((0x04000000 & $options) >> 26);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;

use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -146,4 +147,59 @@ public function conditionalFormattingProvider(): array
],
];
}

public function testReadConditionalFormattingStyles(): void
{
$filename = 'tests/data/Reader/XLS/CF_Basic_Comparisons.xls';
$reader = new Xls();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
$expectedRange = 'A2:E5';
$hasConditionalStyles = $sheet->conditionalStylesExists($expectedRange);
self::assertTrue($hasConditionalStyles);

$conditionalStyles = $sheet->getConditionalStyles($expectedRange);
self::assertCount(3, $conditionalStyles);

$style = $conditionalStyles[0]->getStyle();
$font = $style->getFont();
self::assertSame('FF0000FF', $font->getColor()->getArgb());
self::assertNull($font->getItalic());
self::assertNull($font->getStrikethrough());
// Fill not handled correctly - forget for now
$borders = $style->getBorders();
self::assertSame(Border::BORDER_OMIT, $borders->getLeft()->getBorderStyle());
self::assertSame(Border::BORDER_OMIT, $borders->getRight()->getBorderStyle());
self::assertSame(Border::BORDER_OMIT, $borders->getTop()->getBorderStyle());
self::assertSame(Border::BORDER_OMIT, $borders->getBottom()->getBorderStyle());
self::assertNull($style->getNumberFormat()->getFormatCode());

$style = $conditionalStyles[1]->getStyle();
$font = $style->getFont();
self::assertSame('FF800000', $font->getColor()->getArgb());
self::assertNull($font->getItalic());
self::assertNull($font->getStrikethrough());
// Fill not handled correctly - forget for now
$borders = $style->getBorders();
self::assertSame(Border::BORDER_OMIT, $borders->getLeft()->getBorderStyle());
self::assertSame(Border::BORDER_OMIT, $borders->getRight()->getBorderStyle());
self::assertSame(Border::BORDER_OMIT, $borders->getTop()->getBorderStyle());
self::assertSame(Border::BORDER_OMIT, $borders->getBottom()->getBorderStyle());
self::assertNull($style->getNumberFormat()->getFormatCode());

$style = $conditionalStyles[2]->getStyle();
$font = $style->getFont();
self::assertSame('FF00FF00', $font->getColor()->getArgb());
self::assertNull($font->getItalic());
self::assertNull($font->getStrikethrough());
// Fill not handled correctly - forget for now
$borders = $style->getBorders();
self::assertSame(Border::BORDER_OMIT, $borders->getLeft()->getBorderStyle());
self::assertSame(Border::BORDER_OMIT, $borders->getRight()->getBorderStyle());
self::assertSame(Border::BORDER_OMIT, $borders->getTop()->getBorderStyle());
self::assertSame(Border::BORDER_OMIT, $borders->getBottom()->getBorderStyle());
self::assertNull($style->getNumberFormat()->getFormatCode());

$spreadsheet->disconnectWorksheets();
}
}