mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-15 12:36:32 +00:00
6083e393c1
See discussion #4202. Users can extend Spreadsheet, but the readers cannot return the extended class. This is solved pretty easily by adding a protected method in BaseReader which returns a new Spreadsheet. Users can then extend the Reader which they want, overriding that method to return the extended class.
23 lines
466 B
PHP
23 lines
466 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
class MySpreadsheet extends Spreadsheet
|
|
{
|
|
public function calcSquare(string $cellAddress): float|int|string
|
|
{
|
|
$value = $this->getActiveSheet()
|
|
->getCell($cellAddress)
|
|
->getValue();
|
|
if (is_numeric($value)) {
|
|
return $value * $value;
|
|
}
|
|
|
|
return '#VALUE!';
|
|
}
|
|
}
|