load($file);
$writer = new HtmlWriter($spreadsheet);
$writer->setConditionalFormatting(true);
$this->data = $writer->generateHtmlAll();
$spreadsheet->disconnectWorksheets();
}
private function extractCell(string $coordinate): string
{
[$column, $row] = Coordinate::indexesFromString($coordinate);
--$column;
--$row;
// extract row into $matches
$match = preg_match('~
~s', $this->data, $matches);
if ($match !== 1) {
return 'unable to match row';
}
$rowData = $matches[0];
// extract cell into $matches
$match = preg_match('~| Jan<', 'no conditional styling for B1'],
['F2', 'background-color:#C6EFCE;">120<', 'conditional style for F2'],
['H2', 'background-color:#FFEB9C;">90<', 'conditional style for H2'],
['F3', 'background-color:#C6EFCE;">70<', 'conditional style for cell F3'],
['H3', 'background-color:#FFEB9C;">60<', 'conditional style for cell H3'],
['F4', 'background-color:#C6EFCE;">1<', 'conditional style for cell F4'],
['L4', 'background-color:#FFC7CE;">5<', 'conditional style for cell L4'],
['F5', 'class="column5 style1 n">0<', 'no conditional styling for F5'],
];
foreach ($expectedMatches as $expected) {
[$coordinate, $expectedString, $message] = $expected;
$string = $this->extractCell($coordinate);
self::assertStringContainsString($expectedString, $string, $message);
}
}
}
|