diff --git a/CHANGELOG.md b/CHANGELOG.md index 6508250927..877e335d7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/references/function-list-by-category.md b/docs/references/function-list-by-category.md index 22c5222ad1..c8aa192e28 100644 --- a/docs/references/function-list-by-category.md +++ b/docs/references/function-list-by-category.md @@ -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 diff --git a/docs/references/function-list-by-name-compact.md b/docs/references/function-list-by-name-compact.md index 4df84d2935..e137d63486 100644 --- a/docs/references/function-list-by-name-compact.md +++ b/docs/references/function-list-by-name-compact.md @@ -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 diff --git a/docs/references/function-list-by-name.md b/docs/references/function-list-by-name.md index 35594a7109..1f6683b337 100644 --- a/docs/references/function-list-by-name.md +++ b/docs/references/function-list-by-name.md @@ -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 diff --git a/src/PhpSpreadsheet/Calculation/FunctionArray.php b/src/PhpSpreadsheet/Calculation/FunctionArray.php index 68c2ecd1cd..74e778fda2 100644 --- a/src/PhpSpreadsheet/Calculation/FunctionArray.php +++ b/src/PhpSpreadsheet/Calculation/FunctionArray.php @@ -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, diff --git a/src/PhpSpreadsheet/Calculation/Information/Info.php b/src/PhpSpreadsheet/Calculation/Information/Info.php new file mode 100644 index 0000000000..61138fe1ea --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/Information/Info.php @@ -0,0 +1,44 @@ + '/', + '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(), + }; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Information/InfoTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Information/InfoTest.php new file mode 100644 index 0000000000..966cedc9fc --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Information/InfoTest.php @@ -0,0 +1,43 @@ +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(); + } +} diff --git a/tests/PhpSpreadsheetTests/Functional/TypeAttributePreservationTest.php b/tests/PhpSpreadsheetTests/Functional/TypeAttributePreservationTest.php index ea6397f94f..0c4a99a608 100644 --- a/tests/PhpSpreadsheetTests/Functional/TypeAttributePreservationTest.php +++ b/tests/PhpSpreadsheetTests/Functional/TypeAttributePreservationTest.php @@ -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; @@ -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']; diff --git a/tests/data/Calculation/Information/INFO.php b/tests/data/Calculation/Information/INFO.php new file mode 100644 index 0000000000..9b46d7e313 --- /dev/null +++ b/tests/data/Calculation/Information/INFO.php @@ -0,0 +1,62 @@ +