Skip to content

Commit 53aab72

Browse files
author
MarkBaker
committed
Merge branch 'master' into CalculationEngine-Array-Formulae-Initial-Work
# Conflicts: # src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
2 parents be57361 + 1801f58 commit 53aab72

File tree

20 files changed

+365
-80
lines changed

20 files changed

+365
-80
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1616

1717
This functionality is locale-aware, using the server's locale settings to identify the thousands and decimal separators.
1818

19+
- Support for two cell anchor drawing of images. [#2532](https://github.com/PHPOffice/PhpSpreadsheet/pull/2532)
20+
1921
### Changed
2022

2123
- Gnumeric Reader now loads number formatting for cells.
@@ -75,10 +77,10 @@ and this project adheres to [Semantic Versioning](https://semver.org).
7577
- Full support of the above CF Rules for the Xlsx Reader and Writer; even when the file being loaded has CF rules listed in the `<extLst><ext><ConditionalFormattings>` element for the worksheet rather than the `<ConditionalFormatting>` element.
7678
- Provision of a CellMatcher to identify if rules are matched for a cell, and which matching style will be applied.
7779
- Improved documentation and examples, covering all supported CF rule types.
78-
- Add support for one digit decimals (FORMAT_NUMBER_0, FORMAT_PERCENTAGE_0). [PR #2525](https://github.com/PHPOffice/PhpSpreadsheet/pull/2525)
79-
- Initial work enabling Excel function implementations for handling arrays as arguments when used in "array formulae" [#2562](https://github.com/PHPOffice/PhpSpreadsheet/issues/2562)
80-
- Enable most of the Date/Time functions to accept array arguments [#2573](https://github.com/PHPOffice/PhpSpreadsheet/issues/2573)
81-
- Array ready functions - Text, Math/Trig, Statistical, Engineering and Logical [#2580](https://github.com/PHPOffice/PhpSpreadsheet/issues/2580)
80+
- Add support for one digit decimals (FORMAT_NUMBER_0, FORMAT_PERCENTAGE_0). [PR #2525](https://github.com/PHPOffice/PhpSpreadsheet/pull/2525)
81+
- Initial work enabling Excel function implementations for handling arrays as arguments when used in "array formulae" [#2562](https://github.com/PHPOffice/PhpSpreadsheet/issues/2562)
82+
- Enable most of the Date/Time functions to accept array arguments [#2573](https://github.com/PHPOffice/PhpSpreadsheet/issues/2573)
83+
- Array ready functions - Text, Math/Trig, Statistical, Engineering and Logical [#2580](https://github.com/PHPOffice/PhpSpreadsheet/issues/2580)
8284

8385
### Changed
8486

phpstan-baseline.neon

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4170,16 +4170,6 @@ parameters:
41704170
count: 1
41714171
path: src/PhpSpreadsheet/Spreadsheet.php
41724172

4173-
-
4174-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Conditional\\:\\:\\$condition \\(array\\<string\\>\\) does not accept array\\<bool\\|float\\|int\\|string\\>\\.$#"
4175-
count: 1
4176-
path: src/PhpSpreadsheet/Style/Conditional.php
4177-
4178-
-
4179-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Conditional\\:\\:\\$style \\(PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Style\\) does not accept PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Style\\|null\\.$#"
4180-
count: 1
4181-
path: src/PhpSpreadsheet/Style/Conditional.php
4182-
41834173
-
41844174
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\ConditionalDataBar\\:\\:setConditionalFormattingRuleExt\\(\\) has no return type specified\\.$#"
41854175
count: 1
@@ -4340,11 +4330,6 @@ parameters:
43404330
count: 1
43414331
path: src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php
43424332

4343-
-
4344-
message: "#^Parameter \\#1 \\$conditions of method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Conditional\\:\\:setConditions\\(\\) expects array\\<string\\>\\|bool\\|float\\|int\\|string, array\\<int, float\\|int\\|string\\> given\\.$#"
4345-
count: 1
4346-
path: src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/CellValue.php
4347-
43484333
-
43494334
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\NumberFormat\\\\DateFormatter\\:\\:escapeQuotesCallback\\(\\) has parameter \\$matches with no type specified\\.$#"
43504335
count: 1
@@ -5560,6 +5545,11 @@ parameters:
55605545
count: 2
55615546
path: src/PhpSpreadsheet/Writer/Xlsx/DocProps.php
55625547

5548+
-
5549+
message: "#^Parameter \\#1 \\$coordinates of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:indexesFromString\\(\\) expects string, string\\|null given\\.$#"
5550+
count: 1
5551+
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php
5552+
55635553
-
55645554
message: "#^Parameter \\#1 \\$index of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getChartByIndex\\(\\) expects string, int\\<0, max\\> given\\.$#"
55655555
count: 1
@@ -5572,12 +5562,12 @@ parameters:
55725562

55735563
-
55745564
message: "#^Parameter \\#2 \\$content of method XMLWriter\\:\\:writeElement\\(\\) expects string\\|null, int given\\.$#"
5575-
count: 12
5565+
count: 20
55765566
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php
55775567

55785568
-
55795569
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int given\\.$#"
5580-
count: 8
5570+
count: 10
55815571
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php
55825572

55835573
-
@@ -5875,11 +5865,6 @@ parameters:
58755865
count: 1
58765866
path: tests/PhpSpreadsheetTests/Functional/CommentsTest.php
58775867

5878-
-
5879-
message: "#^Parameter \\#1 \\$condition of method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Conditional\\:\\:addCondition\\(\\) expects string, float given\\.$#"
5880-
count: 2
5881-
path: tests/PhpSpreadsheetTests/Functional/ConditionalStopIfTrueTest.php
5882-
58835868
-
58845869
message: "#^Cannot call method getPageSetup\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
58855870
count: 5
@@ -6025,16 +6010,6 @@ parameters:
60256010
count: 1
60266011
path: tests/PhpSpreadsheetTests/SpreadsheetTest.php
60276012

6028-
-
6029-
message: "#^Parameter \\#1 \\$condition of method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Conditional\\:\\:addCondition\\(\\) expects string, float given\\.$#"
6030-
count: 2
6031-
path: tests/PhpSpreadsheetTests/Style/ConditionalTest.php
6032-
6033-
-
6034-
message: "#^Parameter \\#1 \\$conditions of method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Conditional\\:\\:setConditions\\(\\) expects array\\<string\\>\\|bool\\|float\\|int\\|string, array\\<int, float\\> given\\.$#"
6035-
count: 1
6036-
path: tests/PhpSpreadsheetTests/Style/ConditionalTest.php
6037-
60386013
-
60396014
message: "#^Parameter \\#2 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter\\\\Column\\:\\:setAttribute\\(\\) expects string, int given\\.$#"
60406015
count: 1
@@ -6104,4 +6079,3 @@ parameters:
61046079
message: "#^Cannot call method getExtension\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\BaseDrawing\\|null\\.$#"
61056080
count: 2
61066081
path: tests/PhpSpreadsheetTests/Writer/Xlsx/WmfTest.php
6107-

samples/Basic/39_Dropdown.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function transpose($value)
4646
new NamedRange(
4747
$continent,
4848
$spreadsheet->getActiveSheet(),
49-
$column . '1:' . $column . $countryCount
49+
'$' . $column . '$1:$' . $column . '$' . $countryCount
5050
)
5151
);
5252
$spreadsheet->getActiveSheet()
@@ -68,7 +68,7 @@ function transpose($value)
6868
new NamedRange(
6969
'Continents',
7070
$spreadsheet->getActiveSheet(),
71-
$continentColumn . '1:' . $continentColumn . count($continents)
71+
'$' . $continentColumn . '$1:$' . $continentColumn . '$' . count($continents)
7272
)
7373
);
7474

@@ -126,4 +126,5 @@ function transpose($value)
126126
$spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(30);
127127

128128
// Save
129-
$helper->write($spreadsheet, __FILE__);
129+
$helper->log('Not writing to Xls - formulae with defined names not yet supported');
130+
$helper->write($spreadsheet, __FILE__, ['Xlsx']);

src/PhpSpreadsheet/Calculation/ArrayEnabled.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ trait ArrayEnabled
1212
*/
1313
private static $arrayArgumentHelper;
1414

15-
private static function initialiseHelper(array $arguments): void
15+
/**
16+
* @param array|false $arguments Can be changed to array for Php8.1+
17+
*/
18+
private static function initialiseHelper($arguments): void
1619
{
1720
if (self::$arrayArgumentHelper === null) {
1821
self::$arrayArgumentHelper = new ArrayArgumentHelper();
1922
}
20-
self::$arrayArgumentHelper->initialise($arguments);
23+
self::$arrayArgumentHelper->initialise($arguments ?: []);
2124
}
2225

2326
/**
@@ -70,6 +73,14 @@ protected static function evaluateArrayArgumentsSubset(callable $method, int $li
7073
return ArrayArgumentProcessor::processArguments(self::$arrayArgumentHelper, $method, ...$arguments);
7174
}
7275

76+
/**
77+
* @param mixed $value
78+
*/
79+
private static function testFalse($value): bool
80+
{
81+
return $value === false;
82+
}
83+
7384
/**
7485
* Handles array argument processing when the function accepts multiple arguments,
7586
* but only the last few (from start) can be an array arguments.
@@ -85,7 +96,7 @@ protected static function evaluateArrayArgumentsSubsetFrom(callable $method, int
8596
range($start, count($arguments) - $start),
8697
array_slice($arguments, $start)
8798
);
88-
if ($arrayArgumentsSubset === false) {
99+
if (self::testFalse($arrayArgumentsSubset)) {
89100
return ['#VALUE!'];
90101
}
91102

src/PhpSpreadsheet/Calculation/Information/Value.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static function isEven($value = null)
8787
return ExcelError::VALUE();
8888
}
8989

90-
return $value % 2 == 0;
90+
return ((int) fmod($value, 2)) === 0;
9191
}
9292

9393
/**
@@ -112,7 +112,7 @@ public static function isOdd($value = null)
112112
return ExcelError::VALUE();
113113
}
114114

115-
return abs($value) % 2 == 1;
115+
return ((int) fmod($value, 2)) !== 0;
116116
}
117117

118118
/**

src/PhpSpreadsheet/Cell/Coordinate.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public static function absoluteReference($cellAddress)
9292
}
9393

9494
// Create absolute coordinate
95+
$cellAddress = "$cellAddress";
9596
if (ctype_digit($cellAddress)) {
9697
return $worksheet . '$' . $cellAddress;
9798
} elseif (ctype_alpha($cellAddress)) {

src/PhpSpreadsheet/Helper/Dimension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Dimension
5858
public function __construct(string $dimension)
5959
{
6060
[$size, $unit] = sscanf($dimension, '%[1234567890.]%s');
61-
$unit = strtolower(trim($unit));
61+
$unit = strtolower(trim($unit ?? ''));
6262

6363
// If a UoM is specified, then convert the size to pixels for internal storage
6464
if (isset(self::ABSOLUTE_UNITS[$unit])) {

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ protected function parseTextNode(DOMText $textNode): void
794794
$domText = preg_replace(
795795
'/\s+/u',
796796
' ',
797-
str_replace(["\r", "\n"], ' ', $textNode->nodeValue)
797+
str_replace(["\r", "\n"], ' ', $textNode->nodeValue ?: '')
798798
);
799799
$this->stringData .= $domText;
800800
$this->buildTextRun();

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ protected function processDomElement(DOMNode $element, Worksheet $sheet, int &$r
619619
{
620620
foreach ($element->childNodes as $child) {
621621
if ($child instanceof DOMText) {
622-
$domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue));
622+
$domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue ?: ''));
623623
if (is_string($cellContent)) {
624624
// simply append the text if the cell content is a plain text string
625625
$cellContent .= $domText;

src/PhpSpreadsheet/Reader/Ods.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ private function activeSheet(DOMElement $settings, Spreadsheet $spreadsheet, str
631631
foreach ($settings->getElementsByTagNameNS($configNs, 'config-item') as $t) {
632632
if ($t->getAttributeNs($configNs, 'name') === 'ActiveTable') {
633633
try {
634-
$spreadsheet->setActiveSheetIndexByName($t->nodeValue);
634+
$spreadsheet->setActiveSheetIndexByName($t->nodeValue ?: '');
635635
} catch (Throwable $e) {
636636
// do nothing
637637
}

0 commit comments

Comments
 (0)