Files
oleibman 1b64b42481 Add Dynamic valueBinder Property to Spreadsheet and Readers
Fix #1395, a 2020 issue which had been marked stale and is now re-opened. Static valueBinder property of Cell isn't ideal. It would be more flexible to make it a dynamic property of the spreadsheet. Static property will continue to be used, but dynamic property will be used first if it is set. Readers will also be changed to add a valueBinder property which they pass to the spreadsheet; however, it will make a difference only for Csv/Html/Slk, since the other readers use setValueExplicit which ignores valueBinder.

Documentation is updated in several places to note that dynamic property is preferred over static.
2024-10-05 23:59:44 -07:00

31 lines
1004 B
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Slk;
use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder;
use PhpOffice\PhpSpreadsheet\Reader\Slk;
use PHPUnit\Framework\TestCase;
class BinderTest extends TestCase
{
public function testBinder(): void
{
$infile = 'tests/data/Reader/Slk/issue.2276.slk';
$reader = new Slk();
$spreadsheet = $reader->load($infile);
$sheet = $spreadsheet->getActiveSheet();
$expected1 = [[1, 2], [3, '']];
self::assertSame($expected1, $sheet->toArray(null, false, false));
$reader2 = new Slk();
$reader2->setValueBinder(new StringValueBinder());
$spreadsheet2 = $reader2->load($infile);
$sheet2 = $spreadsheet2->getActiveSheet();
$expected2 = [['1', '2'], ['3', '']];
self::assertSame($expected2, $sheet2->toArray(null, false, false));
$spreadsheet->disconnectWorksheets();
$spreadsheet2->disconnectWorksheets();
}
}