Skip to content

Commit 99f0e6a

Browse files
authored
Merge branch 'master' into hyperlinkstyle
2 parents 31b4cad + e65bc8b commit 99f0e6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1114
-112
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).
3434
- Print Area and Row Break. [Issue #1275](https://github.com/PHPOffice/PhpSpreadsheet/issues/1275) [PR #4450](https://github.com/PHPOffice/PhpSpreadsheet/pull/4450)
3535
- Copy Styles after insertNewColumnBefore. [Issue #1425](https://github.com/PHPOffice/PhpSpreadsheet/issues/1425) [PR #4468](https://github.com/PHPOffice/PhpSpreadsheet/pull/4468)
3636
- Xls Writer Treat Hyperlink Starting with # as Internal. [Issue #56](https://github.com/PHPOffice/PhpSpreadsheet/issues/56) [PR #4453](https://github.com/PHPOffice/PhpSpreadsheet/pull/4453)
37-
- ODS Handling of Ceiling and Floor. [Issue #407](https://github.com/PHPOffice/PhpSpreadsheet/issues/407) [PR #4466](https://github.com/PHPOffice/PhpSpreadsheet/pull/4466)
3837
- Hyperlink Styles. [Issue #1632](https://github.com/PHPOffice/PhpSpreadsheet/issues/1632) [PR #4478](https://github.com/PHPOffice/PhpSpreadsheet/pull/4478)
38+
- ODS Handling of Ceiling and Floor. [Issue #477](https://github.com/PHPOffice/PhpSpreadsheet/issues/407) [PR #4466](https://github.com/PHPOffice/PhpSpreadsheet/pull/4466)
39+
- Xlsx Reader Do Not Process Printer Settings for Dataonly. [Issue #4477](https://github.com/PHPOffice/PhpSpreadsheet/issues/4477) [PR #4480](https://github.com/PHPOffice/PhpSpreadsheet/pull/4480)
3940

4041
## 2025-04-16 - 4.2.0
4142

bin/generate-document.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@
1111

1212
file_put_contents(
1313
__DIR__ . '/../docs/references/function-list-by-category.md',
14-
DocumentGenerator::generateFunctionListByCategory($phpSpreadsheetFunctions)
14+
DocumentGenerator::generateFunctionListByCategory(
15+
$phpSpreadsheetFunctions
16+
)
1517
);
1618
file_put_contents(
1719
__DIR__ . '/../docs/references/function-list-by-name.md',
18-
DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions)
20+
DocumentGenerator::generateFunctionListByName(
21+
$phpSpreadsheetFunctions
22+
)
23+
);
24+
file_put_contents(
25+
__DIR__ . '/../docs/references/function-list-by-name-compact.md',
26+
DocumentGenerator::generateFunctionListByName(
27+
$phpSpreadsheetFunctions,
28+
true
29+
)
1930
);

docs/references/function-list-by-name-compact.md

Lines changed: 663 additions & 0 deletions
Large diffs are not rendered by default.

docs/references/function-list-by-name.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Function list by name
22

3+
A more compact list can be found [here](./function-list-by-name-compact.md)
4+
5+
36
## A
47

58
Excel Function | Category | PhpSpreadsheet Function

infra/DocumentGenerator.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,30 @@ private static function getPhpSpreadsheetFunctionText(mixed $functionCall): stri
9191
/**
9292
* @param array<string, array{category: string, functionCall: string|string[], argumentCount: string, passCellReference?: bool, passByReference?: bool[], custom?: bool}> $phpSpreadsheetFunctions
9393
*/
94-
public static function generateFunctionListByName(array $phpSpreadsheetFunctions): string
94+
public static function generateFunctionListByName(array $phpSpreadsheetFunctions, bool $compact = false): string
9595
{
9696
$categoryConstants = array_flip(self::getCategories());
97-
$result = "# Function list by name\n";
97+
if ($compact) {
98+
$result = "# Function list by name compact\n";
99+
$result .= "\n";
100+
$result .= 'Category should be prefixed by `CATEGORY_` to match the values in \PhpOffice\PhpSpreadsheet\Calculation\Category';
101+
$result .= "\n\n";
102+
$result .= 'Function should be prefixed by `PhpOffice\PhpSpreadsheet\Calculation\`';
103+
$result .= "\n\n";
104+
$result .= 'A less compact list can be found [here](./function-list-by-name.md)';
105+
$result .= "\n\n";
106+
} else {
107+
$result = "# Function list by name\n";
108+
$result .= "\n";
109+
$result .= 'A more compact list can be found [here](./function-list-by-name-compact.md)';
110+
$result .= "\n\n";
111+
}
98112
$lastAlphabet = null;
113+
$lengths = $compact ? [25, 22, 37] : [25, 31, 37];
99114
foreach ($phpSpreadsheetFunctions as $excelFunction => $functionInfo) {
100115
if (in_array($excelFunction, self::EXCLUDED_FUNCTIONS, true)) {
101116
continue;
102117
}
103-
$lengths = [25, 31, 37];
104118
if ($lastAlphabet !== $excelFunction[0]) {
105119
$lastAlphabet = $excelFunction[0];
106120
$result .= "\n";
@@ -111,6 +125,14 @@ public static function generateFunctionListByName(array $phpSpreadsheetFunctions
111125
}
112126
$category = $categoryConstants[$functionInfo['category']];
113127
$phpFunction = self::getPhpSpreadsheetFunctionText($functionInfo['functionCall']);
128+
if ($compact) {
129+
$category = str_replace('CATEGORY_', '', $category);
130+
$phpFunction = str_replace(
131+
'\PhpOffice\PhpSpreadsheet\Calculation\\',
132+
'',
133+
$phpFunction
134+
);
135+
}
114136
$result .= self::tableRow($lengths, [$excelFunction, $category, $phpFunction]) . "\n";
115137
}
116138

src/PhpSpreadsheet/Calculation/Engine/FormattedNumber.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,18 @@ class FormattedNumber
1616
// preg_quoted string for major currency symbols, with a %s for locale currency
1717
private const CURRENCY_CONVERSION_LIST = '\$€£¥%s';
1818

19-
private const STRING_CONVERSION_LIST = [
20-
[self::class, 'convertToNumberIfNumeric'],
21-
[self::class, 'convertToNumberIfFraction'],
22-
[self::class, 'convertToNumberIfPercent'],
23-
[self::class, 'convertToNumberIfCurrency'],
24-
];
25-
2619
/**
2720
* Identify whether a string contains a formatted numeric value,
2821
* and convert it to a numeric if it is.
2922
*
30-
* @param string $operand string value to test
23+
* @param float|string $operand string value to test
3124
*/
32-
public static function convertToNumberIfFormatted(string &$operand): bool
25+
public static function convertToNumberIfFormatted(float|string &$operand): bool
3326
{
34-
foreach (self::STRING_CONVERSION_LIST as $conversionMethod) {
35-
if ($conversionMethod($operand) === true) {
36-
return true;
37-
}
38-
}
39-
40-
return false;
27+
return self::convertToNumberIfNumeric($operand)
28+
|| self::convertToNumberIfFraction($operand)
29+
|| self::convertToNumberIfPercent($operand)
30+
|| self::convertToNumberIfCurrency($operand);
4131
}
4232

4333
/**
@@ -68,9 +58,9 @@ public static function convertToNumberIfNumeric(float|string &$operand): bool
6858
*
6959
* @param string $operand string value to test
7060
*/
71-
public static function convertToNumberIfFraction(string &$operand): bool
61+
public static function convertToNumberIfFraction(float|string &$operand): bool
7262
{
73-
if (preg_match(self::STRING_REGEXP_FRACTION, $operand, $match)) {
63+
if (is_string($operand) && preg_match(self::STRING_REGEXP_FRACTION, $operand, $match)) {
7464
$sign = ($match[1] === '-') ? '-' : '+';
7565
$wholePart = ($match[3] === '') ? '' : ($sign . $match[3]);
7666
$fractionFormula = '=' . $wholePart . $sign . $match[4];

src/PhpSpreadsheet/Calculation/Engine/Operands/StructuredReference.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ final class StructuredReference implements Operand, Stringable
4747

4848
private ?int $totalsRow;
4949

50+
/** @var mixed[] */
5051
private array $columns;
5152

5253
public function __construct(string $structuredReference)
5354
{
5455
$this->value = $structuredReference;
5556
}
5657

58+
/** @param string[] $matches */
5759
public static function fromParser(string $formula, int $index, array $matches): self
5860
{
5961
$val = $matches[0];
@@ -171,6 +173,11 @@ private function getTableByName(Cell $cell): Table
171173
return $table;
172174
}
173175

176+
/**
177+
* @param array<array<int|string>> $tableRange
178+
*
179+
* @return mixed[]
180+
*/
174181
private function getColumns(Cell $cell, array $tableRange): array
175182
{
176183
$worksheet = $cell->getWorksheet();
@@ -179,6 +186,7 @@ private function getColumns(Cell $cell, array $tableRange): array
179186
$columns = [];
180187
$lastColumn = ++$tableRange[1][0];
181188
for ($column = $tableRange[0][0]; $column !== $lastColumn; ++$column) {
189+
/** @var string $column */
182190
$columns[$column] = $worksheet
183191
->getCell($column . ($this->headersRow ?? ($this->firstDataRow - 1)))
184192
->getCalculatedValue();
@@ -196,7 +204,7 @@ private function getRowReference(Cell $cell): string
196204
$reference = str_replace('[' . self::ITEM_SPECIFIER_THIS_ROW . '],', '', $reference);
197205

198206
foreach ($this->columns as $columnId => $columnName) {
199-
$columnName = str_replace("\u{a0}", ' ', $columnName);
207+
$columnName = str_replace("\u{a0}", ' ', $columnName); //* @phpstan-ignore-line
200208
$reference = $this->adjustRowReference($columnName, $reference, $cell, $columnId);
201209
}
202210

@@ -330,7 +338,7 @@ private function getColumnsForColumnReference(string $reference, int $startRow,
330338
{
331339
$columnsSelected = false;
332340
foreach ($this->columns as $columnId => $columnName) {
333-
$columnName = str_replace("\u{a0}", ' ', $columnName ?? '');
341+
$columnName = str_replace("\u{a0}", ' ', $columnName ?? ''); //* @phpstan-ignore-line
334342
$cellFrom = "{$columnId}{$startRow}";
335343
$cellTo = "{$columnId}{$endRow}";
336344
$cellReference = ($cellFrom === $cellTo) ? $cellFrom : "{$cellFrom}:{$cellTo}";

src/PhpSpreadsheet/Calculation/Logical/Operations.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ public static function NOT(mixed $logical = false): array|bool|string
130130
return !$logical;
131131
}
132132

133-
/** @param mixed[] $args */
133+
/**
134+
* @param mixed[] $args
135+
* @param callable(int, int): bool $func
136+
*/
134137
private static function countTrueValues(array $args, callable $func): bool|string
135138
{
136139
$trueValueCount = 0;

src/PhpSpreadsheet/Calculation/LookupRef/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Address
4545
* @param mixed $sheetName Optional Name of worksheet to use
4646
* Or can be an array of values
4747
*
48-
* @return array|string If an array of values is passed as the $testValue argument, then the returned result will also be
48+
* @return mixed[]|string If an array of values is passed as the $testValue argument, then the returned result will also be
4949
* an array with the same dimensions
5050
*/
5151
public static function cell(mixed $row, mixed $column, mixed $relativity = 1, mixed $referenceStyle = true, mixed $sheetName = ''): array|string

src/PhpSpreadsheet/Calculation/LookupRef/ChooseRowsEtc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ public static function chooseRows(mixed $input, mixed ...$args): array|string
8080
return $outputArray;
8181
}
8282

83+
/**
84+
* @param mixed[] $array
85+
*
86+
* @return mixed[]|string
87+
*/
8388
private static function dropRows(array $array, mixed $offset): array|string
8489
{
8590
if ($offset === null) {
@@ -134,6 +139,11 @@ public static function drop(mixed $input, mixed $rows = null, mixed $columns = n
134139
return self::transpose($outputArray3);
135140
}
136141

142+
/**
143+
* @param mixed[] $array
144+
*
145+
* @return mixed[]|string
146+
*/
137147
private static function takeRows(array $array, mixed $offset): array|string
138148
{
139149
if ($offset === null) {

0 commit comments

Comments
 (0)