-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4047 from oleibman/issue3557
Writer Mpdf and Tcpdf Borders on Merged Cells
- Loading branch information
Showing
4 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/PhpSpreadsheetTests/Writer/Mpdf/MergedBorderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?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(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/PhpSpreadsheetTests/Writer/Tcpdf/MergedBorderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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('/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;[^>]+ colspan="2" rowspan="4"/', $html)); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |