Merge pull request #2853 from PHPOffice/Gnumeric-Reader-Worksheet-Visibility
Add support for reading Worksheet Visibility for Gnumeric
This commit is contained in:
commit
13e1b9a939
|
|
@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
|
||||
Note that a ChartSheet is still only written as a normal Worksheet containing a single chart, not as an actual ChartSheet.
|
||||
|
||||
- Added Worksheet visibility in Ods Reader [PR #2851](https://github.com/PHPOffice/PhpSpreadsheet/pull/2851)
|
||||
- Added Worksheet visibility in Ods Reader [PR #2851](https://github.com/PHPOffice/PhpSpreadsheet/pull/2851) and Gnumeric Reader [PR #2853](https://github.com/PHPOffice/PhpSpreadsheet/pull/2853)
|
||||
- Added Worksheet visibility in Ods Writer [PR #2850](https://github.com/PHPOffice/PhpSpreadsheet/pull/2850)
|
||||
|
||||
### Changed
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<th></th>
|
||||
<th>XLS</th>
|
||||
<th>XLSX</th>
|
||||
<th>Excel2003XML</th>
|
||||
<th>XML (Excel2003XML)</th>
|
||||
<th>Ods</th>
|
||||
<th>Gnumeric</th>
|
||||
<th>CSV</th>
|
||||
|
|
@ -732,12 +732,32 @@
|
|||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding-left: 1em;">Hidden Worksheets</td>
|
||||
<td style="text-align: center; color: green;">✔</td>
|
||||
<td style="text-align: center; color: green;">✔</td>
|
||||
<td></td>
|
||||
<td style="text-align: center; color: green;">✔</td>
|
||||
<td style="text-align: center; color: green;">✔</td>
|
||||
<td style="text-align: center;">N/A</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding-left: 1em;">Coloured Tabs</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td style="text-align: center;">N/A</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
|
|
|
|||
|
|
@ -272,6 +272,11 @@ class Gnumeric extends BaseReader
|
|||
// name in line with the formula, not the reverse
|
||||
$this->spreadsheet->getActiveSheet()->setTitle($worksheetName, false, false);
|
||||
|
||||
$visibility = $sheetOrNull->attributes()['Visibility'] ?? 'GNM_SHEET_VISIBILITY_VISIBLE';
|
||||
if ((string) $visibility !== 'GNM_SHEET_VISIBILITY_VISIBLE') {
|
||||
$this->spreadsheet->getActiveSheet()->setSheetState(Worksheet::SHEETSTATE_HIDDEN);
|
||||
}
|
||||
|
||||
if (!$this->readDataOnly) {
|
||||
(new PageSetup($this->spreadsheet))
|
||||
->printInformation($sheet)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HiddenWorksheetTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Spreadsheet
|
||||
*/
|
||||
private $spreadsheet;
|
||||
|
||||
protected function setup(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/Gnumeric/HiddenSheet.gnumeric';
|
||||
$reader = new Gnumeric();
|
||||
$this->spreadsheet = $reader->load($filename);
|
||||
}
|
||||
|
||||
public function testPageSetup(): void
|
||||
{
|
||||
$assertions = $this->worksheetAssertions();
|
||||
|
||||
foreach ($this->spreadsheet->getAllSheets() as $worksheet) {
|
||||
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sheetAssertions = $assertions[$worksheet->getTitle()];
|
||||
foreach ($sheetAssertions as $test => $expectedResult) {
|
||||
$actualResult = $worksheet->getSheetState();
|
||||
self::assertSame(
|
||||
$expectedResult,
|
||||
$actualResult,
|
||||
"Failed asserting sheet state {$expectedResult} for Worksheet '{$worksheet->getTitle()}' {$test}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function worksheetAssertions(): array
|
||||
{
|
||||
return [
|
||||
'Sheet1' => [
|
||||
'sheetState' => Worksheet::SHEETSTATE_VISIBLE,
|
||||
],
|
||||
'Sheet2' => [
|
||||
'sheetState' => Worksheet::SHEETSTATE_HIDDEN,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,6 @@ class HiddenWorksheetTest extends TestCase
|
|||
|
||||
$sheetAssertions = $assertions[$worksheet->getTitle()];
|
||||
foreach ($sheetAssertions as $test => $expectedResult) {
|
||||
$testMethodName = 'get' . ucfirst($test);
|
||||
$actualResult = $worksheet->getSheetState();
|
||||
self::assertSame(
|
||||
$expectedResult,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HiddenWorksheetTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Spreadsheet
|
||||
*/
|
||||
private $spreadsheet;
|
||||
|
||||
protected function setup(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLS/HiddenSheet.xls';
|
||||
$reader = new Xls();
|
||||
$this->spreadsheet = $reader->load($filename);
|
||||
}
|
||||
|
||||
public function testPageSetup(): void
|
||||
{
|
||||
$assertions = $this->worksheetAssertions();
|
||||
|
||||
foreach ($this->spreadsheet->getAllSheets() as $worksheet) {
|
||||
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sheetAssertions = $assertions[$worksheet->getTitle()];
|
||||
foreach ($sheetAssertions as $test => $expectedResult) {
|
||||
$actualResult = $worksheet->getSheetState();
|
||||
self::assertSame(
|
||||
$expectedResult,
|
||||
$actualResult,
|
||||
"Failed asserting sheet state {$expectedResult} for Worksheet '{$worksheet->getTitle()}' {$test}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function worksheetAssertions(): array
|
||||
{
|
||||
return [
|
||||
'Sheet1' => [
|
||||
'sheetState' => Worksheet::SHEETSTATE_VISIBLE,
|
||||
],
|
||||
'Sheet2' => [
|
||||
'sheetState' => Worksheet::SHEETSTATE_HIDDEN,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HiddenWorksheetTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Spreadsheet
|
||||
*/
|
||||
private $spreadsheet;
|
||||
|
||||
protected function setup(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLSX/HiddenSheet.xlsx';
|
||||
$reader = new Xlsx();
|
||||
$this->spreadsheet = $reader->load($filename);
|
||||
}
|
||||
|
||||
public function testPageSetup(): void
|
||||
{
|
||||
$assertions = $this->worksheetAssertions();
|
||||
|
||||
foreach ($this->spreadsheet->getAllSheets() as $worksheet) {
|
||||
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sheetAssertions = $assertions[$worksheet->getTitle()];
|
||||
foreach ($sheetAssertions as $test => $expectedResult) {
|
||||
$actualResult = $worksheet->getSheetState();
|
||||
self::assertSame(
|
||||
$expectedResult,
|
||||
$actualResult,
|
||||
"Failed asserting sheet state {$expectedResult} for Worksheet '{$worksheet->getTitle()}' {$test}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function worksheetAssertions(): array
|
||||
{
|
||||
return [
|
||||
'Sheet1' => [
|
||||
'sheetState' => Worksheet::SHEETSTATE_VISIBLE,
|
||||
],
|
||||
'Sheet2' => [
|
||||
'sheetState' => Worksheet::SHEETSTATE_HIDDEN,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue