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.
Recognize 'Hidden' Attribute in Xml Spreadsheet
Fix PHPOffice#3566; PhpSpreadsheet should now handle Hidden attribute for rows and columns in Xml spreadsheets. Also added the ability to load Xml spreadsheet from string rather than file, as can be done for Csv and Html.
- Loading branch information
Showing
3 changed files
with
89 additions
and
8 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
57 changes: 57 additions & 0 deletions
57
tests/PhpSpreadsheetTests/Reader/Xml/XmlColumnRowHiddenTest.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,57 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Xml; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class XmlColumnRowHiddenTest extends TestCase | ||
{ | ||
public function testWriteThenRead(): void | ||
{ | ||
$xmldata = <<< 'EOT' | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?mso-application progid="Excel.Sheet"?> | ||
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> | ||
<Worksheet ss:Name="1"> | ||
<ss:Table> | ||
<Column ss:Hidden="1" /> | ||
<Column ss:Hidden="0" /> | ||
<Column /> | ||
<ss:Row ss:Hidden="1"> | ||
<ss:Cell> | ||
<ss:Data ss:Type="String">hidden row and hidden column</ss:Data> | ||
</ss:Cell> | ||
<ss:Cell> | ||
<ss:Data ss:Type="String">hidden row and visible column</ss:Data> | ||
</ss:Cell> | ||
</ss:Row> | ||
<ss:Row ss:Hidden="0"> | ||
<ss:Cell> | ||
<ss:Data ss:Type="String">visible row and hidden column</ss:Data> | ||
</ss:Cell> | ||
<ss:Cell> | ||
<ss:Data ss:Type="String">visible row and visible column</ss:Data> | ||
</ss:Cell> | ||
</ss:Row> | ||
<ss:Row /> | ||
</ss:Table> | ||
</Worksheet> | ||
</Workbook> | ||
EOT; | ||
$reader = new Xml(); | ||
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata); | ||
self::assertEquals(1, $spreadsheet->getSheetCount()); | ||
|
||
$sheet = $spreadsheet->getActiveSheet(); | ||
self::assertEquals('1', $sheet->getTitle()); | ||
self::assertFalse($sheet->getColumnDimension('A')->getVisible()); | ||
self::assertTrue($sheet->getColumnDimension('B')->getVisible()); | ||
self::assertTrue($sheet->getColumnDimension('C')->getVisible()); | ||
self::assertFalse($sheet->getRowDimension(1)->getVisible()); | ||
self::assertTrue($sheet->getRowDimension(2)->getVisible()); | ||
self::assertTrue($sheet->getRowDimension(3)->getVisible()); | ||
|
||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |
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