mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-22 05:16:06 +03:00
Start work on implementing an option to ignore "empty" cells when reading a file
This commit is contained in:
parent
7eb10adb3b
commit
2058c8468a
@ -36,6 +36,15 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
|
||||
*/
|
||||
protected $readDataOnly = false;
|
||||
|
||||
/**
|
||||
* Read empty cells?
|
||||
* Identifies whether the Reader should read data values for cells all cells, or should ignore cells containing
|
||||
* null value or empty string
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $readEmptyCells = true;
|
||||
|
||||
/**
|
||||
* Read charts that are defined in the workbook?
|
||||
* Identifies whether the Reader should read the definitions for any charts that exist in the workbook;
|
||||
@ -89,6 +98,33 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read empty cells?
|
||||
* If this is true (the default), then the Reader will read data values for all cells, irrespective of value.
|
||||
* If false it will not read data for cells containing a null value or an empty string.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getReadEmptyCells()
|
||||
{
|
||||
return $this->readEmptyCells;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set read empty cells
|
||||
* Set to true (the default) to advise the Reader read data values for all cells, irrespective of value.
|
||||
* Set to false to advise the Reader to ignore cells containing a null value or an empty string.
|
||||
*
|
||||
* @param boolean $pValue
|
||||
*
|
||||
* @return PHPExcel_Reader_IReader
|
||||
*/
|
||||
public function setReadEmptyCells($pValue = true)
|
||||
{
|
||||
$this->readEmptyCells = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read charts in workbook?
|
||||
* If this is true, then the Reader will include any charts that exist in the workbook.
|
||||
|
@ -3687,6 +3687,7 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
|
||||
$column = self::getInt2d($recordData, 2);
|
||||
$columnString = PHPExcel_Cell::stringFromColumnIndex($column);
|
||||
|
||||
$emptyCell = true;
|
||||
// Read cell?
|
||||
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
|
||||
// offset: 4; size: 2; index to XF record
|
||||
@ -3727,14 +3728,20 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
|
||||
}
|
||||
}
|
||||
}
|
||||
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
||||
$cell->setValueExplicit($richText, PHPExcel_Cell_DataType::TYPE_STRING);
|
||||
if ($this->readEmptyCells || trim($richText->getPlainText()) !== '') {
|
||||
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
||||
$cell->setValueExplicit($richText, PHPExcel_Cell_DataType::TYPE_STRING);
|
||||
$emptyCell = false;
|
||||
}
|
||||
} else {
|
||||
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
||||
$cell->setValueExplicit($this->sst[$index]['value'], PHPExcel_Cell_DataType::TYPE_STRING);
|
||||
if ($this->readEmptyCells || trim($this->sst[$index]['value']) !== '') {
|
||||
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
||||
$cell->setValueExplicit($this->sst[$index]['value'], PHPExcel_Cell_DataType::TYPE_STRING);
|
||||
$emptyCell = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->readDataOnly) {
|
||||
if (!$this->readDataOnly && !$emptyCell) {
|
||||
// add style information
|
||||
$cell->setXfIndex($this->mapCellXfIndex[$xfIndex]);
|
||||
}
|
||||
@ -4108,7 +4115,7 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
|
||||
|
||||
// offset: 4; size: 2 x nc; list of indexes to XF records
|
||||
// add style information
|
||||
if (!$this->readDataOnly) {
|
||||
if (!$this->readDataOnly && $this->readEmptyCells) {
|
||||
for ($i = 0; $i < $length / 2 - 3; ++$i) {
|
||||
$columnString = PHPExcel_Cell::stringFromColumnIndex($fc + $i);
|
||||
|
||||
@ -4163,12 +4170,14 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
|
||||
$string = $this->readByteStringLong(substr($recordData, 6));
|
||||
$value = $string['value'];
|
||||
}
|
||||
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
||||
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
|
||||
if ($this->readEmptyCells || trim($value) !== '') {
|
||||
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
||||
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
|
||||
|
||||
if (!$this->readDataOnly) {
|
||||
// add cell style
|
||||
$cell->setXfIndex($this->mapCellXfIndex[$xfIndex]);
|
||||
if (!$this->readDataOnly) {
|
||||
// add cell style
|
||||
$cell->setXfIndex($this->mapCellXfIndex[$xfIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4198,11 +4207,10 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
|
||||
$xfIndex = self::getInt2d($recordData, 4);
|
||||
|
||||
// add style information
|
||||
if (!$this->readDataOnly) {
|
||||
if (!$this->readDataOnly && $this->readEmptyCells) {
|
||||
$this->phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->mapCellXfIndex[$xfIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user