Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Reader/Csv/CsvLoadFromStringTest.php
oleibman 35530502d2 Allow Csv Reader to Treat String as Contents of File (#2792)
See #1285, which went stale and was closed, but recently received some positive feeback. It seems easy to implement, and the only other plaintext file format, Html, allows loading from a string. Those two reasons combined suggest that we should do it.
2022-05-07 08:24:53 -07:00

27 lines
666 B
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PHPUnit\Framework\TestCase;
class CsvLoadFromStringTest extends TestCase
{
public function testLoadFromString(): void
{
$data = <<<EOF
1,2,3
4,2+3,6
"7 , 8", 9, 10
11,"12
13",14
EOF;
$reader = new Csv();
$spreadsheet = $reader->loadSpreadsheetFromString($data);
$sheet = $spreadsheet->getActiveSheet();
self::AssertSame('2+3', $sheet->getCell('B2')->getValue());
self::AssertSame('7 , 8', $sheet->getCell('A3')->getValue());
self::AssertSame("12\n13", $sheet->getCell('B4')->getValue());
}
}