Skip to content

Commit 965e51c

Browse files
authored
Merge branch 'master' into simplify-code
2 parents ee062e4 + f6f3daa commit 965e51c

File tree

9 files changed

+166
-4
lines changed

9 files changed

+166
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). Thia is a
3434
- Add missing Dutch translation to translation file. [PR #4707](https://github.com/PHPOffice/PhpSpreadsheet/pull/4707)
3535
- Fix lots of typos throughout codebase. [PR #4705](https://github.com/PHPOffice/PhpSpreadsheet/pull/4705)
3636
- Apply small code style improvements. [PR #4708](https://github.com/PHPOffice/PhpSpreadsheet/pull/4708)
37+
- Implement missing `INFO` function. [PR #4709](https://github.com/PHPOffice/PhpSpreadsheet/pull/4709)
3738

3839
## 2025-10-25 - 5.2.0
3940

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Excel Function | PhpSpreadsheet Function
189189
-------------------------|--------------------------------------
190190
CELL | **Not yet Implemented**
191191
ERROR.TYPE | \PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError::type
192-
INFO | **Not yet Implemented**
192+
INFO | \PhpOffice\PhpSpreadsheet\Calculation\Information\Info::getInfo
193193
ISBLANK | \PhpOffice\PhpSpreadsheet\Calculation\Information\Value::isBlank
194194
ISERR | \PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue::isErr
195195
ISERROR | \PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue::isError

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ IMSUM | ENGINEERING | Engineering\ComplexOperations
299299
IMTAN | ENGINEERING | Engineering\ComplexFunctions::IMTAN
300300
INDEX | LOOKUP_AND_REFERENCE | LookupRef\Matrix::index
301301
INDIRECT | LOOKUP_AND_REFERENCE | LookupRef\Indirect::INDIRECT
302-
INFO | INFORMATION | **Not yet Implemented**
302+
INFO | INFORMATION | Information\Info::getInfo
303303
INT | MATH_AND_TRIG | MathTrig\IntClass::evaluate
304304
INTERCEPT | STATISTICAL | Statistical\Trends::INTERCEPT
305305
INTRATE | FINANCIAL | Financial\Securities\Rates::interest

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ IMSUM | CATEGORY_ENGINEERING | \PhpOffice\PhpSpread
295295
IMTAN | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions::IMTAN
296296
INDEX | CATEGORY_LOOKUP_AND_REFERENCE | \PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Matrix::index
297297
INDIRECT | CATEGORY_LOOKUP_AND_REFERENCE | \PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Indirect::INDIRECT
298-
INFO | CATEGORY_INFORMATION | **Not yet Implemented**
298+
INFO | CATEGORY_INFORMATION | \PhpOffice\PhpSpreadsheet\Calculation\Information\Info::getInfo
299299
INT | CATEGORY_MATH_AND_TRIG | \PhpOffice\PhpSpreadsheet\Calculation\MathTrig\IntClass::evaluate
300300
INTERCEPT | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical\Trends::INTERCEPT
301301
INTRATE | CATEGORY_FINANCIAL | \PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities\Rates::interest

src/PhpSpreadsheet/Calculation/FunctionArray.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,8 +1284,9 @@ class FunctionArray extends CalculationBase
12841284
],
12851285
'INFO' => [
12861286
'category' => Category::CATEGORY_INFORMATION,
1287-
'functionCall' => [Functions::class, 'DUMMY'],
1287+
'functionCall' => [Information\Info::class, 'getInfo'],
12881288
'argumentCount' => '1',
1289+
'passCellReference' => true,
12891290
],
12901291
'INT' => [
12911292
'category' => Category::CATEGORY_MATH_AND_TRIG,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheet\Calculation\Information;
4+
5+
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6+
use PhpOffice\PhpSpreadsheet\Cell\Cell;
7+
8+
class Info
9+
{
10+
/**
11+
* @internal
12+
*/
13+
public static bool $infoSupported = true;
14+
15+
/**
16+
* INFO.
17+
*
18+
* Excel Function:
19+
* =INFO(type_text)
20+
*
21+
* @param mixed $typeText String specifying the type of information to be returned
22+
* @param ?Cell $cell Cell from which spreadsheet information is retrieved
23+
*
24+
* @return int|string The requested information about the current operating environment
25+
*/
26+
public static function getInfo(mixed $typeText = '', ?Cell $cell = null): int|string
27+
{
28+
if (!self::$infoSupported) {
29+
return Functions::DUMMY();
30+
}
31+
32+
return match (is_string($typeText) ? strtolower($typeText) : $typeText) {
33+
'directory' => '/',
34+
'numfile' => $cell?->getWorksheetOrNull()?->getParent()?->getSheetCount() ?? 1,
35+
'origin' => '$A:$A$1',
36+
'osversion' => 'PHP ' . PHP_VERSION,
37+
'recalc' => 'Automatic',
38+
'release' => PHP_VERSION,
39+
'system' => 'PHP',
40+
'memavail', 'memused', 'totmem' => ExcelError::NA(),
41+
default => ExcelError::VALUE(),
42+
};
43+
}
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information;
6+
7+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class InfoTest extends TestCase
11+
{
12+
#[\PHPUnit\Framework\Attributes\DataProvider('providerINFO')]
13+
public function testINFO(mixed $expectedResult, string $typeText): void
14+
{
15+
$spreadsheet = new Spreadsheet();
16+
$sheet = $spreadsheet->getActiveSheet();
17+
18+
$sheet->getCell('A1')->setValue('=INFO("' . $typeText . '")');
19+
$result = $sheet->getCell('A1')->getCalculatedValue();
20+
21+
self::assertSame($expectedResult, $result);
22+
$spreadsheet->disconnectWorksheets();
23+
}
24+
25+
public static function providerINFO(): array
26+
{
27+
return require 'tests/data/Calculation/Information/INFO.php';
28+
}
29+
30+
public function testINFONumfileWithThreeSheets(): void
31+
{
32+
$spreadsheet = new Spreadsheet();
33+
$spreadsheet->createSheet();
34+
$spreadsheet->createSheet();
35+
$sheet = $spreadsheet->getActiveSheet();
36+
37+
$sheet->getCell('A1')->setValue('=INFO("numfile")');
38+
$result = $sheet->getCell('A1')->getCalculatedValue();
39+
40+
self::assertSame(3, $result);
41+
$spreadsheet->disconnectWorksheets();
42+
}
43+
}

tests/PhpSpreadsheetTests/Functional/TypeAttributePreservationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpOffice\PhpSpreadsheetTests\Functional;
66

7+
use PhpOffice\PhpSpreadsheet\Calculation\Information\Info;
78
use PhpOffice\PhpSpreadsheet\Reader\Ods as ReaderOds;
89
use PhpOffice\PhpSpreadsheet\Reader\Slk as ReaderSlk;
910
use PhpOffice\PhpSpreadsheet\Reader\Xls as ReaderXls;
@@ -15,6 +16,16 @@
1516

1617
class TypeAttributePreservationTest extends AbstractFunctional
1718
{
19+
protected function setUp(): void
20+
{
21+
Info::$infoSupported = false;
22+
}
23+
24+
protected function tearDown(): void
25+
{
26+
Info::$infoSupported = true;
27+
}
28+
1829
public static function providerFormulae(): array
1930
{
2031
$formats = ['Xlsx'];
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
[
7+
'/',
8+
'directory',
9+
],
10+
[
11+
1,
12+
'numfile',
13+
],
14+
[
15+
'$A:$A$1',
16+
'origin',
17+
],
18+
[
19+
'PHP ' . PHP_VERSION,
20+
'osversion',
21+
],
22+
[
23+
'Automatic',
24+
'recalc',
25+
],
26+
[
27+
'Automatic',
28+
'RECALC',
29+
],
30+
[
31+
PHP_VERSION,
32+
'release',
33+
],
34+
[
35+
'PHP',
36+
'system',
37+
],
38+
[
39+
'#N/A',
40+
'memavail',
41+
],
42+
[
43+
'#N/A',
44+
'memused',
45+
],
46+
[
47+
'#N/A',
48+
'totmem',
49+
],
50+
[
51+
'#VALUE!',
52+
'1',
53+
],
54+
[
55+
'#VALUE!',
56+
'A',
57+
],
58+
[
59+
'#VALUE!',
60+
'#VALUE!',
61+
],
62+
];

0 commit comments

Comments
 (0)