Files
oleibman a15091737f Html Writer Conditional Formatting Inline Css
Fix #4539. Conditional Formatting was recently added to Html Writer. It works fine when not using inline Css. However, when using inline Css, the code inadvertently added 2 different `style` attributes (one for the unconditional style and one for the conditional style) to the same cell. This is not valid html, and results in losing the conditional styling. This PR combines the two `style` attributes into one, which will now come after the `class`, `colspan`, and `rowspan` attributes.

Aside from the new tests, this PR changes an unusually large number of existing tests. While this might normally be considered a red flag, it is not a problem here. All of the changes involve merely changing the order of attributes within html tags; none of them affect how the generated html would appear in a browser.
2025-07-15 22:22:34 -07:00

39 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Writer\Tcpdf;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf;
use PHPUnit\Framework\TestCase;
class MergedBorderTest extends TestCase
{
public static function testMergedBorder(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$target = 'A2:B5';
$sheet->mergeCells($target);
$sheet->setCellValue('A2', 'Planning');
$sheet->getStyle($target)->applyFromArray([
'borders' => [
'outline' => [
'borderStyle' => Border::BORDER_HAIR,
'color' => ['rgb' => 'FF0000'],
],
],
]);
$sheet->setSelectedCells('D1');
$sheet->setCellValue('D1', 'Edge');
$sheet->setCellValue('D5', 'Edge');
$sheet->setShowGridlines(false);
$writer = new Tcpdf($spreadsheet);
$html = $writer->generateHtmlAll();
self::assertSame(1, preg_match('/ colspan="2" rowspan="4" style="vertical-align:bottom; border-bottom:1px solid #FF0000 !important; border-top:1px solid #FF0000 !important; border-left:1px solid #FF0000 !important; border-right:1px solid #FF0000 !important; color:#000000;[^>]+/', $html));
$spreadsheet->disconnectWorksheets();
}
}