mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-03 05:57:46 +00:00
4a8f2a8f0c
It currently always uses PHP_EOL, which, of course, works, but you get slightly different results in Windows and Unix. User can now set line ending to `\n` or `\r\n` to ensure consistent results regardless of environment. Default remains PHP_EOL. We already do this for CSV.
58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Dompdf;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf as DompdfWriter;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class PrintAreaTest extends TestCase
|
|
{
|
|
public function testPrintArea(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$inArray = [
|
|
[1, 2, 3, 4, 5],
|
|
[6, 7, 8, 9, 10],
|
|
[11, 12, 13, 14, 15],
|
|
[16, 17, 18, 19, 20],
|
|
[21, 22, 23, 24, 25],
|
|
[26, 27, 28, 29, 30],
|
|
];
|
|
$sheet->fromArray($inArray);
|
|
$sheet->getPageSetup()->setPrintArea('B2:D4');
|
|
$writer = new DompdfWriter($spreadsheet);
|
|
$eol = $writer->getLineEnding();
|
|
$html = $writer->generateHtmlAll();
|
|
$html = preg_replace('/^ +/m', '', $html) ?? $html;
|
|
$expectedArray = [
|
|
'<tbody>',
|
|
'<tr class="row1">',
|
|
'<td class="column0 style0 n" style="width:42pt">7</td>',
|
|
'<td class="column1 style0 n" style="width:42pt">8</td>',
|
|
'<td class="column2 style0 n" style="width:42pt">9</td>',
|
|
'</tr>',
|
|
'<tr class="row2">',
|
|
'<td class="column0 style0 n" style="width:42pt">12</td>',
|
|
'<td class="column1 style0 n" style="width:42pt">13</td>',
|
|
'<td class="column2 style0 n" style="width:42pt">14</td>',
|
|
'</tr>',
|
|
'<tr class="row3">',
|
|
'<td class="column0 style0 n" style="width:42pt">17</td>',
|
|
'<td class="column1 style0 n" style="width:42pt">18</td>',
|
|
'<td class="column2 style0 n" style="width:42pt">19</td>',
|
|
'</tr>',
|
|
'</tbody>',
|
|
];
|
|
$expectedString = implode($eol, $expectedArray);
|
|
self::assertStringContainsString(
|
|
$expectedString,
|
|
$html
|
|
);
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|