2018-02-25 18:38:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Functional;
|
|
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\BaseReader;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
|
|
|
|
class PrintAreaTest extends AbstractFunctional
|
|
|
|
{
|
|
|
|
public function providerFormats()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['Xls'],
|
|
|
|
['Xlsx'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerFormats
|
|
|
|
*
|
|
|
|
* @param string $format
|
|
|
|
*/
|
|
|
|
public function testPageSetup($format)
|
|
|
|
{
|
|
|
|
// Create new workbook with 3 sheets and different print areas
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
|
$worksheet1 = $spreadsheet->getActiveSheet()->setTitle('Sheet 1');
|
|
|
|
$worksheet1->getPageSetup()->setPrintArea('A1:B1');
|
|
|
|
|
|
|
|
for ($i = 2; $i < 4; ++$i) {
|
|
|
|
$sheet = $spreadsheet->createSheet()->setTitle("Sheet $i");
|
|
|
|
$sheet->getPageSetup()->setPrintArea("A$i:B$i");
|
|
|
|
}
|
|
|
|
|
2018-10-23 09:29:09 +00:00
|
|
|
$worksheet4 = $spreadsheet->createSheet()->setTitle('Sheet 4');
|
|
|
|
$worksheet4->getPageSetup()->setPrintArea('A4:B4,D1:E4');
|
|
|
|
|
2018-02-25 18:38:53 +00:00
|
|
|
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format, function (BaseReader $reader) {
|
2018-10-23 09:29:09 +00:00
|
|
|
$reader->setLoadSheetsOnly(['Sheet 1', 'Sheet 3', 'Sheet 4']);
|
2018-02-25 18:38:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$actual1 = $reloadedSpreadsheet->getSheetByName('Sheet 1')->getPageSetup()->getPrintArea();
|
|
|
|
$actual3 = $reloadedSpreadsheet->getSheetByName('Sheet 3')->getPageSetup()->getPrintArea();
|
2018-10-23 09:29:09 +00:00
|
|
|
$actual4 = $reloadedSpreadsheet->getSheetByName('Sheet 4')->getPageSetup()->getPrintArea();
|
2018-02-25 18:38:53 +00:00
|
|
|
self::assertSame('A1:B1', $actual1, 'should be able to write and read normal page setup');
|
|
|
|
self::assertSame('A3:B3', $actual3, 'should be able to write and read page setup even when skipping sheets');
|
2018-10-23 09:29:09 +00:00
|
|
|
self::assertSame('A4:B4,D1:E4', $actual4, 'should be able to write and read page setup with multiple print areas');
|
2018-02-25 18:38:53 +00:00
|
|
|
}
|
|
|
|
}
|