Skip to content

Commit 23ce219

Browse files
author
MarkBaker
committed
Add support for reading Worksheet Visibility for Gnumeric
1 parent 7fff764 commit 23ce219

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/PhpSpreadsheet/Reader/Gnumeric.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
272272
// name in line with the formula, not the reverse
273273
$this->spreadsheet->getActiveSheet()->setTitle($worksheetName, false, false);
274274

275+
$visibility = $sheetOrNull->attributes()['Visibility'] ?? 'GNM_SHEET_VISIBILITY_VISIBLE';
276+
if ((string) $visibility !== 'GNM_SHEET_VISIBILITY_VISIBLE') {
277+
$this->spreadsheet->getActiveSheet()->setSheetState(Worksheet::SHEETSTATE_HIDDEN);
278+
}
279+
275280
if (!$this->readDataOnly) {
276281
(new PageSetup($this->spreadsheet))
277282
->printInformation($sheet)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
4+
5+
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
6+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
7+
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class HiddenWorksheetTest extends TestCase
11+
{
12+
/**
13+
* @var Spreadsheet
14+
*/
15+
private $spreadsheet;
16+
17+
protected function setup(): void
18+
{
19+
$filename = 'tests/data/Reader/Gnumeric/HiddenSheet.gnumeric';
20+
$reader = new Gnumeric();
21+
$this->spreadsheet = $reader->load($filename);
22+
}
23+
24+
public function testPageSetup(): void
25+
{
26+
$assertions = $this->worksheetAssertions();
27+
28+
foreach ($this->spreadsheet->getAllSheets() as $worksheet) {
29+
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
30+
continue;
31+
}
32+
33+
$sheetAssertions = $assertions[$worksheet->getTitle()];
34+
foreach ($sheetAssertions as $test => $expectedResult) {
35+
$actualResult = $worksheet->getSheetState();
36+
self::assertSame(
37+
$expectedResult,
38+
$actualResult,
39+
"Failed asserting sheet state {$expectedResult} for Worksheet '{$worksheet->getTitle()}' {$test}"
40+
);
41+
}
42+
}
43+
}
44+
45+
private function worksheetAssertions(): array
46+
{
47+
return [
48+
'Sheet1' => [
49+
'sheetState' => Worksheet::SHEETSTATE_VISIBLE,
50+
],
51+
'Sheet2' => [
52+
'sheetState' => Worksheet::SHEETSTATE_HIDDEN,
53+
],
54+
];
55+
}
56+
}
1.83 KB
Binary file not shown.

0 commit comments

Comments
 (0)