Skip to content

Commit 4f1d6d2

Browse files
authored
Merge branch 'master' into CellRange-Validation-Performance-Tweak
2 parents 8914c61 + d111522 commit 4f1d6d2

File tree

21 files changed

+652
-73
lines changed

21 files changed

+652
-73
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1414

1515
Note that a ChartSheet is still only written as a normal Worksheet containing a single chart, not as an actual ChartSheet.
1616

17+
- Added Worksheet visibility in Ods Reader [PR #2851](https://github.com/PHPOffice/PhpSpreadsheet/pull/2851)
18+
- Added Worksheet visibility in Ods Writer [PR #2850](https://github.com/PHPOffice/PhpSpreadsheet/pull/2850)
19+
1720
### Changed
1821

1922
- Memory and speed improvements, particularly for the Cell Collection, and the Writers.
@@ -32,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
3235

3336
- Xls Reader resolving absolute named ranges to relative ranges [Issue #2826](https://github.com/PHPOffice/PhpSpreadsheet/issues/2826) [PR #2827](https://github.com/PHPOffice/PhpSpreadsheet/pull/2827)
3437
- Null value handling in the Excel Math/Trig PRODUCT() function [Issue #2833](https://github.com/PHPOffice/PhpSpreadsheet/issues/2833) [PR #2834](https://github.com/PHPOffice/PhpSpreadsheet/pull/2834)
35-
38+
- Invalid Print Area defined in Xlsx corrupts internal storage of print area [Issue #2848](https://github.com/PHPOffice/PhpSpreadsheet/issues/2848) [PR #2849](https://github.com/PHPOffice/PhpSpreadsheet/pull/2849)
3639

3740
## 1.23.0 - 2022-04-24
3841

phpstan-baseline.neon

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,36 +1945,11 @@ parameters:
19451945
count: 6
19461946
path: src/PhpSpreadsheet/Reader/Ods/PageSettings.php
19471947

1948-
-
1949-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\\\PageSettings\\:\\:\\$masterPrintStylesCrossReference has no type specified\\.$#"
1950-
count: 1
1951-
path: src/PhpSpreadsheet/Reader/Ods/PageSettings.php
1952-
1953-
-
1954-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\\\PageSettings\\:\\:\\$masterStylesCrossReference has no type specified\\.$#"
1955-
count: 1
1956-
path: src/PhpSpreadsheet/Reader/Ods/PageSettings.php
1957-
1958-
-
1959-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\\\PageSettings\\:\\:\\$officeNs has no type specified\\.$#"
1960-
count: 1
1961-
path: src/PhpSpreadsheet/Reader/Ods/PageSettings.php
1962-
19631948
-
19641949
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\\\PageSettings\\:\\:\\$pageLayoutStyles has no type specified\\.$#"
19651950
count: 1
19661951
path: src/PhpSpreadsheet/Reader/Ods/PageSettings.php
19671952

1968-
-
1969-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\\\PageSettings\\:\\:\\$stylesFo has no type specified\\.$#"
1970-
count: 1
1971-
path: src/PhpSpreadsheet/Reader/Ods/PageSettings.php
1972-
1973-
-
1974-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\\\PageSettings\\:\\:\\$stylesNs has no type specified\\.$#"
1975-
count: 1
1976-
path: src/PhpSpreadsheet/Reader/Ods/PageSettings.php
1977-
19781953
-
19791954
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\\\Properties\\:\\:load\\(\\) has parameter \\$namespacesMeta with no type specified\\.$#"
19801955
count: 1
@@ -4800,26 +4775,6 @@ parameters:
48004775
count: 2
48014776
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
48024777

4803-
-
4804-
message: "#^Parameter \\#3 \\$id1 of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xlsx\\\\Chart\\:\\:writeCategoryAxis\\(\\) expects string, int\\|string given\\.$#"
4805-
count: 1
4806-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
4807-
4808-
-
4809-
message: "#^Parameter \\#4 \\$id1 of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xlsx\\\\Chart\\:\\:writeValueAxis\\(\\) expects string, int\\|string given\\.$#"
4810-
count: 2
4811-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
4812-
4813-
-
4814-
message: "#^Parameter \\#4 \\$id2 of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xlsx\\\\Chart\\:\\:writeCategoryAxis\\(\\) expects string, int\\|string given\\.$#"
4815-
count: 1
4816-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
4817-
4818-
-
4819-
message: "#^Parameter \\#5 \\$id2 of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xlsx\\\\Chart\\:\\:writeValueAxis\\(\\) expects string, int\\|string given\\.$#"
4820-
count: 2
4821-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
4822-
48234778
-
48244779
message: "#^Parameter \\#6 \\$yAxis of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xlsx\\\\Chart\\:\\:writeCategoryAxis\\(\\) expects PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Axis, PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Axis\\|null given\\.$#"
48254780
count: 1

samples/Chart/33_Chart_create_scatter2.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
['=DATEVALUE("2021-01-10")', 30.2, 32.2, 0.2],
2626
]
2727
);
28-
$worksheet->getStyle('A2:A5')->getNumberFormat()->setFormatCode('yyyy-mm-dd');
28+
$worksheet->getStyle('A2:A5')->getNumberFormat()->setFormatCode(Properties::FORMAT_CODE_DATE_ISO8601);
2929
$worksheet->getColumnDimension('A')->setAutoSize(true);
3030
$worksheet->setSelectedCells('A1');
3131

@@ -67,7 +67,7 @@
6767
// Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers
6868
$xAxis = new Axis();
6969
//$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE );
70-
$xAxis->setAxisNumberProperties('yyyy-mm-dd');
70+
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true);
7171

7272
// Build the dataseries
7373
$series = new DataSeries(
@@ -78,7 +78,7 @@
7878
$xAxisTickValues, // plotCategory
7979
$dataSeriesValues, // plotValues
8080
null, // plotDirection
81-
null, // smooth line
81+
false, // smooth line
8282
//DataSeries::STYLE_LINEMARKER // plotStyle
8383
DataSeries::STYLE_MARKER // plotStyle
8484
);
@@ -107,7 +107,7 @@
107107

108108
// Set the position where the chart should appear in the worksheet
109109
$chart->setTopLeftPosition('A7');
110-
$chart->setBottomRightPosition('N20');
110+
$chart->setBottomRightPosition('P20');
111111
// Add the chart to the worksheet
112112
$worksheet->addChart($chart);
113113

src/PhpSpreadsheet/Chart/Axis.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Axis extends Properties
1818
private $axisNumber = [
1919
'format' => self::FORMAT_CODE_GENERAL,
2020
'source_linked' => 1,
21+
'numeric' => null,
2122
];
2223

2324
/**
@@ -131,15 +132,26 @@ class Axis extends Properties
131132
'size' => null,
132133
];
133134

135+
private const NUMERIC_FORMAT = [
136+
Properties::FORMAT_CODE_NUMBER,
137+
Properties::FORMAT_CODE_DATE,
138+
];
139+
134140
/**
135141
* Get Series Data Type.
136142
*
137143
* @param mixed $format_code
138144
*/
139-
public function setAxisNumberProperties($format_code): void
145+
public function setAxisNumberProperties($format_code, ?bool $numeric = null): void
140146
{
141-
$this->axisNumber['format'] = (string) $format_code;
147+
$format = (string) $format_code;
148+
$this->axisNumber['format'] = $format;
142149
$this->axisNumber['source_linked'] = 0;
150+
if (is_bool($numeric)) {
151+
$this->axisNumber['numeric'] = $numeric;
152+
} elseif (in_array($format, self::NUMERIC_FORMAT, true)) {
153+
$this->axisNumber['numeric'] = true;
154+
}
143155
}
144156

145157
/**
@@ -162,6 +174,11 @@ public function getAxisNumberSourceLinked()
162174
return (string) $this->axisNumber['source_linked'];
163175
}
164176

177+
public function getAxisIsNumericFormat(): bool
178+
{
179+
return (bool) $this->axisNumber['numeric'];
180+
}
181+
165182
/**
166183
* Set Axis Options Properties.
167184
*

src/PhpSpreadsheet/Chart/Chart.php

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ class Chart
140140
*/
141141
private $bottomRightYOffset = 10;
142142

143+
/** @var ?int */
144+
private $rotX;
145+
146+
/** @var ?int */
147+
private $rotY;
148+
149+
/** @var ?int */
150+
private $rAngAx;
151+
152+
/** @var ?int */
153+
private $perspective;
154+
143155
/**
144156
* Create a new Chart.
145157
*
@@ -351,8 +363,9 @@ public function getChartAxisY()
351363
if ($this->yAxis !== null) {
352364
return $this->yAxis;
353365
}
366+
$this->yAxis = new Axis();
354367

355-
return new Axis();
368+
return $this->yAxis;
356369
}
357370

358371
/**
@@ -365,8 +378,9 @@ public function getChartAxisX()
365378
if ($this->xAxis !== null) {
366379
return $this->xAxis;
367380
}
381+
$this->xAxis = new Axis();
368382

369-
return new Axis();
383+
return $this->xAxis;
370384
}
371385

372386
/**
@@ -681,4 +695,52 @@ public function render($outputDestination = null)
681695

682696
return $renderer->render($outputDestination);
683697
}
698+
699+
public function getRotX(): ?int
700+
{
701+
return $this->rotX;
702+
}
703+
704+
public function setRotX(?int $rotX): self
705+
{
706+
$this->rotX = $rotX;
707+
708+
return $this;
709+
}
710+
711+
public function getRotY(): ?int
712+
{
713+
return $this->rotY;
714+
}
715+
716+
public function setRotY(?int $rotY): self
717+
{
718+
$this->rotY = $rotY;
719+
720+
return $this;
721+
}
722+
723+
public function getRAngAx(): ?int
724+
{
725+
return $this->rAngAx;
726+
}
727+
728+
public function setRAngAx(?int $rAngAx): self
729+
{
730+
$this->rAngAx = $rAngAx;
731+
732+
return $this;
733+
}
734+
735+
public function getPerspective(): ?int
736+
{
737+
return $this->perspective;
738+
}
739+
740+
public function setPerspective(?int $perspective): self
741+
{
742+
$this->perspective = $perspective;
743+
744+
return $this;
745+
}
684746
}

src/PhpSpreadsheet/Chart/Properties.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ abstract class Properties
3737
const FORMAT_CODE_CURRENCY = '$#,##0.00';
3838
const FORMAT_CODE_ACCOUNTING = '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)';
3939
const FORMAT_CODE_DATE = 'm/d/yyyy';
40+
const FORMAT_CODE_DATE_ISO8601 = 'yyyy-mm-dd';
4041
const FORMAT_CODE_TIME = '[$-F400]h:mm:ss AM/PM';
4142
const FORMAT_CODE_PERCENTAGE = '0.00%';
4243
const FORMAT_CODE_FRACTION = '# ?/?';

src/PhpSpreadsheet/Reader/Ods.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ public function loadIntoExisting($filename, Spreadsheet $spreadsheet)
588588
break;
589589
}
590590
}
591+
$pageSettings->setVisibilityForWorksheet($spreadsheet->getActiveSheet(), $worksheetStyleName);
591592
$pageSettings->setPrintSettingsForWorksheet($spreadsheet->getActiveSheet(), $worksheetStyleName);
592593
++$worksheetID;
593594
}

src/PhpSpreadsheet/Reader/Ods/PageSettings.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,41 @@
88

99
class PageSettings
1010
{
11+
/**
12+
* @var string
13+
*/
1114
private $officeNs;
1215

16+
/**
17+
* @var string
18+
*/
1319
private $stylesNs;
1420

21+
/**
22+
* @var string
23+
*/
1524
private $stylesFo;
1625

26+
/**
27+
* @var string
28+
*/
29+
private $tableNs;
30+
31+
/**
32+
* @var string[]
33+
*/
34+
private $tableStylesCrossReference = [];
35+
1736
private $pageLayoutStyles = [];
1837

38+
/**
39+
* @var string[]
40+
*/
1941
private $masterStylesCrossReference = [];
2042

43+
/**
44+
* @var string[]
45+
*/
2146
private $masterPrintStylesCrossReference = [];
2247

2348
public function __construct(DOMDocument $styleDom)
@@ -32,6 +57,7 @@ private function setDomNameSpaces(DOMDocument $styleDom): void
3257
$this->officeNs = $styleDom->lookupNamespaceUri('office');
3358
$this->stylesNs = $styleDom->lookupNamespaceUri('style');
3459
$this->stylesFo = $styleDom->lookupNamespaceUri('fo');
60+
$this->tableNs = $styleDom->lookupNamespaceUri('table');
3561
}
3662

3763
private function readPageSettingStyles(DOMDocument $styleDom): void
@@ -98,12 +124,33 @@ public function readStyleCrossReferences(DOMDocument $contentDom): void
98124
foreach ($styleXReferences as $styleXreferenceSet) {
99125
$styleXRefName = $styleXreferenceSet->getAttributeNS($this->stylesNs, 'name');
100126
$stylePageLayoutName = $styleXreferenceSet->getAttributeNS($this->stylesNs, 'master-page-name');
127+
$styleFamilyName = $styleXreferenceSet->getAttributeNS($this->stylesNs, 'family');
128+
if (!empty($styleFamilyName) && $styleFamilyName === 'table') {
129+
$styleVisibility = 'true';
130+
foreach ($styleXreferenceSet->getElementsByTagNameNS($this->stylesNs, 'table-properties') as $tableProperties) {
131+
$styleVisibility = $tableProperties->getAttributeNS($this->tableNs, 'display');
132+
}
133+
$this->tableStylesCrossReference[$styleXRefName] = $styleVisibility;
134+
}
101135
if (!empty($stylePageLayoutName)) {
102136
$this->masterStylesCrossReference[$styleXRefName] = $stylePageLayoutName;
103137
}
104138
}
105139
}
106140

141+
public function setVisibilityForWorksheet(Worksheet $worksheet, string $styleName): void
142+
{
143+
if (!array_key_exists($styleName, $this->tableStylesCrossReference)) {
144+
return;
145+
}
146+
147+
$worksheet->setSheetState(
148+
$this->tableStylesCrossReference[$styleName] === 'false'
149+
? Worksheet::SHEETSTATE_HIDDEN
150+
: Worksheet::SHEETSTATE_VISIBLE
151+
);
152+
}
153+
107154
public function setPrintSettingsForWorksheet(Worksheet $worksheet, string $styleName): void
108155
{
109156
if (!array_key_exists($styleName, $this->masterStylesCrossReference)) {

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,13 +1530,18 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
15301530
$rangeSets = preg_split("/('?(?:.*?)'?(?:![A-Z0-9]+:[A-Z0-9]+)),?/", $extractedRange, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
15311531
$newRangeSets = [];
15321532
foreach ($rangeSets as $rangeSet) {
1533-
[$sheetName, $rangeSet] = Worksheet::extractSheetTitle($rangeSet, true);
1533+
[, $rangeSet] = Worksheet::extractSheetTitle($rangeSet, true);
1534+
if (empty($rangeSet)) {
1535+
continue;
1536+
}
15341537
if (strpos($rangeSet, ':') === false) {
15351538
$rangeSet = $rangeSet . ':' . $rangeSet;
15361539
}
15371540
$newRangeSets[] = str_replace('$', '', $rangeSet);
15381541
}
1539-
$docSheet->getPageSetup()->setPrintArea(implode(',', $newRangeSets));
1542+
if (count($newRangeSets) > 0) {
1543+
$docSheet->getPageSetup()->setPrintArea(implode(',', $newRangeSets));
1544+
}
15401545

15411546
break;
15421547
default:

0 commit comments

Comments
 (0)