Start work on implementing an option to ignore "empty" cells when reading a file
This commit is contained in:
parent
28d3b97d0d
commit
6518b75796
|
@ -3672,6 +3672,7 @@ class Excel5 extends BaseReader implements IReader
|
||||||
$column = self::getInt2d($recordData, 2);
|
$column = self::getInt2d($recordData, 2);
|
||||||
$columnString = \PHPExcel\Cell::stringFromColumnIndex($column);
|
$columnString = \PHPExcel\Cell::stringFromColumnIndex($column);
|
||||||
|
|
||||||
|
$emptyCell = true;
|
||||||
// Read cell?
|
// Read cell?
|
||||||
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
|
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
|
||||||
// offset: 4; size: 2; index to XF record
|
// offset: 4; size: 2; index to XF record
|
||||||
|
@ -3712,14 +3713,20 @@ class Excel5 extends BaseReader implements IReader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($this->readEmptyCells || trim($richText->getPlainText()) !== '') {
|
||||||
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
||||||
$cell->setValueExplicit($richText, \PHPExcel\Cell\DataType::TYPE_STRING);
|
$cell->setValueExplicit($richText, \PHPExcel\Cell\DataType::TYPE_STRING);
|
||||||
|
$emptyCell = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if ($this->readEmptyCells || trim($this->sst[$index]['value']) !== '') {
|
||||||
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
||||||
$cell->setValueExplicit($this->sst[$index]['value'], \PHPExcel\Cell\DataType::TYPE_STRING);
|
$cell->setValueExplicit($this->sst[$index]['value'], \PHPExcel\Cell\DataType::TYPE_STRING);
|
||||||
|
$emptyCell = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->readDataOnly) {
|
if (!$this->readDataOnly && !$emptyCell) {
|
||||||
// add style information
|
// add style information
|
||||||
$cell->setXfIndex($this->mapCellXfIndex[$xfIndex]);
|
$cell->setXfIndex($this->mapCellXfIndex[$xfIndex]);
|
||||||
}
|
}
|
||||||
|
@ -4093,7 +4100,7 @@ class Excel5 extends BaseReader implements IReader
|
||||||
|
|
||||||
// offset: 4; size: 2 x nc; list of indexes to XF records
|
// offset: 4; size: 2 x nc; list of indexes to XF records
|
||||||
// add style information
|
// add style information
|
||||||
if (!$this->readDataOnly) {
|
if (!$this->readDataOnly && $this->readEmptyCells) {
|
||||||
for ($i = 0; $i < $length / 2 - 3; ++$i) {
|
for ($i = 0; $i < $length / 2 - 3; ++$i) {
|
||||||
$columnString = \PHPExcel\Cell::stringFromColumnIndex($fc + $i);
|
$columnString = \PHPExcel\Cell::stringFromColumnIndex($fc + $i);
|
||||||
|
|
||||||
|
@ -4148,6 +4155,7 @@ class Excel5 extends BaseReader implements IReader
|
||||||
$string = $this->readByteStringLong(substr($recordData, 6));
|
$string = $this->readByteStringLong(substr($recordData, 6));
|
||||||
$value = $string['value'];
|
$value = $string['value'];
|
||||||
}
|
}
|
||||||
|
if ($this->readEmptyCells || trim($value) !== '') {
|
||||||
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
|
||||||
$cell->setValueExplicit($value, \PHPExcel\Cell\DataType::TYPE_STRING);
|
$cell->setValueExplicit($value, \PHPExcel\Cell\DataType::TYPE_STRING);
|
||||||
|
|
||||||
|
@ -4157,6 +4165,7 @@ class Excel5 extends BaseReader implements IReader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4183,11 +4192,10 @@ class Excel5 extends BaseReader implements IReader
|
||||||
$xfIndex = self::getInt2d($recordData, 4);
|
$xfIndex = self::getInt2d($recordData, 4);
|
||||||
|
|
||||||
// add style information
|
// add style information
|
||||||
if (!$this->readDataOnly) {
|
if (!$this->readDataOnly && $this->readEmptyCells) {
|
||||||
$this->phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->mapCellXfIndex[$xfIndex]);
|
$this->phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->mapCellXfIndex[$xfIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue