mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-31 04:28:51 +00:00
f3c3aba618
TOCOL and TOROW were introduced to Excel in 2024, and will now be supported by PhpSpreadsheet. The documentation says that, under certain circumstances, "blanks" will be ignored. This seems demonstrably wrong. In the right circumstance, Excel will ignore nulls, not blanks. Further, when it decides to not ignore the nulls, it changes them to 0, which also seems insufficiently documented. PhpSpreadsheet will behave as Excel does. I discovered some minor problems and some missing test conditions for the TRANSPOSE function while testing these. Those are now fixed.
108 lines
3.0 KiB
PHP
108 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AllSetupTeardown extends TestCase
|
|
{
|
|
protected string $compatibilityMode;
|
|
|
|
protected string $arrayReturnType;
|
|
|
|
protected ?Spreadsheet $spreadsheet = null;
|
|
|
|
private ?Worksheet $sheet = null;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->compatibilityMode = Functions::getCompatibilityMode();
|
|
$this->arrayReturnType = Calculation::getArrayReturnType();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Functions::setCompatibilityMode($this->compatibilityMode);
|
|
Calculation::setArrayReturnType($this->arrayReturnType);
|
|
$this->sheet = null;
|
|
if ($this->spreadsheet !== null) {
|
|
$this->spreadsheet->disconnectWorksheets();
|
|
$this->spreadsheet = null;
|
|
}
|
|
}
|
|
|
|
protected static function setOpenOffice(): void
|
|
{
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
|
}
|
|
|
|
protected static function setGnumeric(): void
|
|
{
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
|
|
}
|
|
|
|
protected function mightHaveException(mixed $expectedResult): void
|
|
{
|
|
if ($expectedResult === 'exception') {
|
|
$this->expectException(CalcException::class);
|
|
}
|
|
}
|
|
|
|
protected function setCell(string $cell, mixed $value): void
|
|
{
|
|
if ($value !== null) {
|
|
if (is_string($value) && is_numeric($value)) {
|
|
$this->getSheet()->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
|
|
} else {
|
|
$this->getSheet()->getCell($cell)->setValue($value);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function getSpreadsheet(): Spreadsheet
|
|
{
|
|
if ($this->spreadsheet !== null) {
|
|
return $this->spreadsheet;
|
|
}
|
|
$this->spreadsheet = new Spreadsheet();
|
|
|
|
return $this->spreadsheet;
|
|
}
|
|
|
|
protected function getSheet(): Worksheet
|
|
{
|
|
if ($this->sheet !== null) {
|
|
return $this->sheet;
|
|
}
|
|
$this->sheet = $this->getSpreadsheet()->getActiveSheet();
|
|
|
|
return $this->sheet;
|
|
}
|
|
|
|
protected function setArrayAsValue(): void
|
|
{
|
|
$spreadsheet = $this->getSpreadsheet();
|
|
$calculation = Calculation::getInstance($spreadsheet);
|
|
$calculation->setInstanceArrayReturnType(
|
|
Calculation::RETURN_ARRAY_AS_VALUE
|
|
);
|
|
}
|
|
|
|
protected function setArrayAsArray(): void
|
|
{
|
|
$spreadsheet = $this->getSpreadsheet();
|
|
$calculation = Calculation::getInstance($spreadsheet);
|
|
$calculation->setInstanceArrayReturnType(
|
|
Calculation::RETURN_ARRAY_AS_ARRAY
|
|
);
|
|
}
|
|
}
|