PhpSpreadsheet/tests/PhpSpreadsheetTests/Functional/ReadBlankCellsTest.php

47 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace PhpOffice\PhpSpreadsheetTests\Functional;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class ReadBlankCellsTest extends AbstractFunctional
{
public function providerSheetFormat()
{
return [
['Xlsx'],
['Xls'],
// ['Ods'], // Broken. Requires fix in Ods reader.
// ['Csv'], // never reads blank cells
// ['Html'], // never reads blank cells
];
}
/**
2019-04-15 20:49:51 +00:00
* Test generate file with some empty cells.
*
* @dataProvider providerSheetFormat
*
* @param mixed $format
*/
2020-05-18 04:49:57 +00:00
public function testXlsxLoadWithNoBlankCells($format): void
{
$spreadsheet = new Spreadsheet();
$spreadsheet->getActiveSheet()->getCell('B2')->setValue('');
$spreadsheet->getActiveSheet()->getCell('C1')->setValue('C1');
$spreadsheet->getActiveSheet()->getCell('C3')->setValue('C3');
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format);
2020-05-18 04:49:57 +00:00
self::assertTrue($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('B2'));
self::assertFalse($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('C2'));
self::assertTrue($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('C3'));
2020-05-18 04:49:57 +00:00
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format, function ($reader): void {
$reader->setReadEmptyCells(false);
});
2020-05-18 04:49:57 +00:00
self::assertFalse($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('B2'));
self::assertFalse($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('C2'));
self::assertTrue($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('C3'));
}
}