forked from PHPOffice/PhpSpreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Xlsx Reader and Print/Show Gridlines
Fix PHPOffice#912, opened in Feb. 2019, and closed as stale in Apr. 2019, and which I have re-opened to be closed properly by this PR. Another "better late than never". Original issue says that print options should not affect ShowGridlines, which seems true enough. Aside from that, the existing code isn't quite correct anyhow. Excel looks for 2 attributes, one of which must be explicitly set to true and the other of which must not be explicitly set to false, in order to determine whether PrintGridlines should be set. PhpSpreadsheet is changed to do the same. This could be treated as a BC break for the unusual situation described in the issue, but it seems more like a bug fix to me.
- Loading branch information
Showing
2 changed files
with
54 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; | ||
|
||
class GridlinesTest extends AbstractFunctional | ||
{ | ||
/** | ||
* @dataProvider loadDataProvider | ||
*/ | ||
public function testGridlines(bool $display, bool $print): void | ||
{ | ||
$spreadsheet = new Spreadsheet(); | ||
$sheet1 = $spreadsheet->getActiveSheet(); | ||
$sheet2 = $spreadsheet->createSheet(); | ||
$sheet1->setShowGridlines($display); | ||
$sheet1->setPrintGridlines($print); | ||
$sheet1->fromArray( | ||
[ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9], | ||
] | ||
); | ||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx'); | ||
$spreadsheet->disconnectWorksheets(); | ||
$rsheet1 = $reloadedSpreadsheet->getSheet(0); | ||
$rsheet2 = $reloadedSpreadsheet->getSheet(1); | ||
self::assertSame($display, $rsheet1->getShowGridlines()); | ||
self::assertSame($print, $rsheet1->getPrintGridlines()); | ||
self::assertTrue($rsheet2->getShowGridlines()); | ||
self::assertFalse($rsheet2->getPrintGridlines()); | ||
$reloadedSpreadsheet->disconnectWorksheets(); | ||
} | ||
|
||
public static function loadDataProvider(): array | ||
{ | ||
return [ | ||
[true, true], | ||
[true, false], | ||
[false, true], | ||
[false, false], | ||
]; | ||
} | ||
} |