Files
oleibman 4be300865c Writer Mpdf and Tcpdf Borders on Merged Cells
Fix #3557. Borders around merged cells are not handled correctly for Mpdf. Although a perfectly acceptable workaround is suggested in the issue, it would be better if things just worked without the workaround. Html and Dompdf work with the existing code. As it turns out, Tcpdf does not work, but for a different reason than Mpdf.

Mpdf was not working because Mpdf does not honor the `!important` attribute in Css. We can get it working almost perfectly by suppressing `border*:none`; the exception is fairly Byzantine, and I'll be glad to discuss the matter should anyone report a problem with it. At any rate, it's not working now in the exception case, so we won't be any worse off.

Tcpdf was not working because the merging of attributes happened only when `useInlineCss` was not being used, but Tcpdf does use it. Merging of border attributes is now added for useInlineCss.
2024-05-27 16:38:04 -07:00

43 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Writer\Mpdf;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
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 Mpdf($spreadsheet);
$html = $writer->generateHtmlAll();
self::assertSame(0, preg_match('/border-(top|bottom|right|left):none #000000;/', $html));
self::assertSame(1, preg_match('/border-top:1px solid #FF0000 !important; border-left:1px solid #FF0000 !important;/', $html));
self::assertSame(1, preg_match('/border-bottom:1px solid #FF0000 !important; border-left:1px solid #FF0000 !important;/', $html));
self::assertSame(1, preg_match('/border-top:1px solid #FF0000 !important; border-right:1px solid #FF0000 !important;/', $html));
self::assertSame(1, preg_match('/border-bottom:1px solid #FF0000 !important; border-right:1px solid #FF0000 !important;/', $html));
$spreadsheet->disconnectWorksheets();
}
}