Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). Thia is a
- Unexpected Exception in Php DateTime. [Issue #4696](https://github.com/PHPOffice/PhpSpreadsheet/issues/4696) [Issue #917](https://github.com/PHPOffice/PhpSpreadsheet/issues/917) [PR #4697](https://github.com/PHPOffice/PhpSpreadsheet/pull/4697)
- Add missing Dutch translation to translation file. [PR #4707](https://github.com/PHPOffice/PhpSpreadsheet/pull/4707)
- Fix lots of typos throughout codebase. [PR #4705](https://github.com/PHPOffice/PhpSpreadsheet/pull/4705)
- Implement missing `INFO` function. [PR #4709](https://github.com/PHPOffice/PhpSpreadsheet/pull/4709)

## 2025-10-25 - 5.2.0

Expand Down
2 changes: 1 addition & 1 deletion docs/references/function-list-by-category.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
CELL | **Not yet Implemented**
ERROR.TYPE | \PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError::type
INFO | **Not yet Implemented**
INFO | \PhpOffice\PhpSpreadsheet\Calculation\Information\Info::getInfo
ISBLANK | \PhpOffice\PhpSpreadsheet\Calculation\Information\Value::isBlank
ISERR | \PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue::isErr
ISERROR | \PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue::isError
Expand Down
2 changes: 1 addition & 1 deletion docs/references/function-list-by-name-compact.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ IMSUM | ENGINEERING | Engineering\ComplexOperations
IMTAN | ENGINEERING | Engineering\ComplexFunctions::IMTAN
INDEX | LOOKUP_AND_REFERENCE | LookupRef\Matrix::index
INDIRECT | LOOKUP_AND_REFERENCE | LookupRef\Indirect::INDIRECT
INFO | INFORMATION | **Not yet Implemented**
INFO | INFORMATION | Information\Info::getInfo
INT | MATH_AND_TRIG | MathTrig\IntClass::evaluate
INTERCEPT | STATISTICAL | Statistical\Trends::INTERCEPT
INTRATE | FINANCIAL | Financial\Securities\Rates::interest
Expand Down
2 changes: 1 addition & 1 deletion docs/references/function-list-by-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ IMSUM | CATEGORY_ENGINEERING | \PhpOffice\PhpSpread
IMTAN | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions::IMTAN
INDEX | CATEGORY_LOOKUP_AND_REFERENCE | \PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Matrix::index
INDIRECT | CATEGORY_LOOKUP_AND_REFERENCE | \PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Indirect::INDIRECT
INFO | CATEGORY_INFORMATION | **Not yet Implemented**
INFO | CATEGORY_INFORMATION | \PhpOffice\PhpSpreadsheet\Calculation\Information\Info::getInfo
INT | CATEGORY_MATH_AND_TRIG | \PhpOffice\PhpSpreadsheet\Calculation\MathTrig\IntClass::evaluate
INTERCEPT | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical\Trends::INTERCEPT
INTRATE | CATEGORY_FINANCIAL | \PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities\Rates::interest
Expand Down
3 changes: 2 additions & 1 deletion src/PhpSpreadsheet/Calculation/FunctionArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,9 @@ class FunctionArray extends CalculationBase
],
'INFO' => [
'category' => Category::CATEGORY_INFORMATION,
'functionCall' => [Functions::class, 'DUMMY'],
'functionCall' => [Information\Info::class, 'getInfo'],
'argumentCount' => '1',
'passCellReference' => true,
],
'INT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
Expand Down
44 changes: 44 additions & 0 deletions src/PhpSpreadsheet/Calculation/Information/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace PhpOffice\PhpSpreadsheet\Calculation\Information;

use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Cell\Cell;

class Info
{
/**
* @internal
*/
public static bool $infoSupported = true;

/**
* INFO.
*
* Excel Function:
* =INFO(type_text)
*
* @param mixed $typeText String specifying the type of information to be returned
* @param ?Cell $cell Cell from which spreadsheet information is retrieved
*
* @return int|string The requested information about the current operating environment
*/
public static function getInfo(mixed $typeText = '', ?Cell $cell = null): int|string
{
if (!self::$infoSupported) {
return Functions::DUMMY();
}

return match (is_string($typeText) ? strtolower($typeText) : $typeText) {
'directory' => '/',
'numfile' => $cell?->getWorksheetOrNull()?->getParent()?->getSheetCount() ?? 1,
'origin' => '$A:$A$1',
'osversion' => 'PHP ' . PHP_VERSION,
'recalc' => 'Automatic',
'release' => PHP_VERSION,
'system' => 'PHP',
'memavail', 'memused', 'totmem' => ExcelError::NA(),
default => ExcelError::VALUE(),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information;

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;

class InfoTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerINFO')]
public function testINFO(mixed $expectedResult, string $typeText): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

$sheet->getCell('A1')->setValue('=INFO("' . $typeText . '")');
$result = $sheet->getCell('A1')->getCalculatedValue();

self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}

public static function providerINFO(): array
{
return require 'tests/data/Calculation/Information/INFO.php';
}

public function testINFONumfileWithThreeSheets(): void
{
$spreadsheet = new Spreadsheet();
$spreadsheet->createSheet();
$spreadsheet->createSheet();
$sheet = $spreadsheet->getActiveSheet();

$sheet->getCell('A1')->setValue('=INFO("numfile")');
$result = $sheet->getCell('A1')->getCalculatedValue();

self::assertSame(3, $result);
$spreadsheet->disconnectWorksheets();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpOffice\PhpSpreadsheetTests\Functional;

use PhpOffice\PhpSpreadsheet\Calculation\Information\Info;
use PhpOffice\PhpSpreadsheet\Reader\Ods as ReaderOds;
use PhpOffice\PhpSpreadsheet\Reader\Slk as ReaderSlk;
use PhpOffice\PhpSpreadsheet\Reader\Xls as ReaderXls;
Expand All @@ -15,6 +16,16 @@

class TypeAttributePreservationTest extends AbstractFunctional
{
protected function setUp(): void
{
Info::$infoSupported = false;
}

protected function tearDown(): void
{
Info::$infoSupported = true;
}

public static function providerFormulae(): array
{
$formats = ['Xlsx'];
Expand Down
62 changes: 62 additions & 0 deletions tests/data/Calculation/Information/INFO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

return [
[
'/',
'directory',
],
[
1,
'numfile',
],
[
'$A:$A$1',
'origin',
],
[
'PHP ' . PHP_VERSION,
'osversion',
],
[
'Automatic',
'recalc',
],
[
'Automatic',
'RECALC',
],
[
PHP_VERSION,
'release',
],
[
'PHP',
'system',
],
[
'#N/A',
'memavail',
],
[
'#N/A',
'memused',
],
[
'#N/A',
'totmem',
],
[
'#VALUE!',
'1',
],
[
'#VALUE!',
'A',
],
[
'#VALUE!',
'#VALUE!',
],
];