mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-29 08:46:03 +03:00
Bugfix: Remove cells cleanly when calling RemoveRow() or RemoveColumn()
This commit is contained in:
parent
538fbcd2e8
commit
a95e3f6607
@ -333,6 +333,35 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
|
|||||||
}
|
}
|
||||||
} // function copyCellCollection()
|
} // function copyCellCollection()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a row, deleting all cells in that row
|
||||||
|
*
|
||||||
|
* @param string $row Row number to remove
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function removeRow($row) {
|
||||||
|
foreach ($this->getCellList() as $coord) {
|
||||||
|
sscanf($coord,'%[A-Z]%d', $c, $r);
|
||||||
|
if ($r == $row) {
|
||||||
|
$this->deleteCacheData($coord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a column, deleting all cells in that column
|
||||||
|
*
|
||||||
|
* @param string $column Column ID to remove
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function removeColumn($column) {
|
||||||
|
foreach ($this->getCellList() as $coord) {
|
||||||
|
sscanf($coord,'%[A-Z]%d', $c, $r);
|
||||||
|
if ($c == $column) {
|
||||||
|
$this->deleteCacheData($coord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identify whether the caching method is currently available
|
* Identify whether the caching method is currently available
|
||||||
|
@ -2064,8 +2064,13 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
|
|||||||
*/
|
*/
|
||||||
public function removeRow($pRow = 1, $pNumRows = 1) {
|
public function removeRow($pRow = 1, $pNumRows = 1) {
|
||||||
if ($pRow >= 1) {
|
if ($pRow >= 1) {
|
||||||
|
$highestRow = $this->getHighestDataRow();
|
||||||
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
|
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
|
||||||
$objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, -$pNumRows, $this);
|
$objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, -$pNumRows, $this);
|
||||||
|
for($r = 0; $r < $pNumRows; ++$r) {
|
||||||
|
$this->getCellCacheController()->removeRow($highestRow);
|
||||||
|
--$highestRow;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new PHPExcel_Exception("Rows to be deleted should at least start from row 1.");
|
throw new PHPExcel_Exception("Rows to be deleted should at least start from row 1.");
|
||||||
}
|
}
|
||||||
@ -2075,16 +2080,21 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
|
|||||||
/**
|
/**
|
||||||
* Remove a column, updating all possible related data
|
* Remove a column, updating all possible related data
|
||||||
*
|
*
|
||||||
* @param int $pColumn Remove starting with this one
|
* @param string $pColumn Remove starting with this one
|
||||||
* @param int $pNumCols Number of columns to remove
|
* @param int $pNumCols Number of columns to remove
|
||||||
* @throws PHPExcel_Exception
|
* @throws PHPExcel_Exception
|
||||||
* @return PHPExcel_Worksheet
|
* @return PHPExcel_Worksheet
|
||||||
*/
|
*/
|
||||||
public function removeColumn($pColumn = 'A', $pNumCols = 1) {
|
public function removeColumn($pColumn = 'A', $pNumCols = 1) {
|
||||||
if (!is_numeric($pColumn)) {
|
if (!is_numeric($pColumn)) {
|
||||||
|
$highestColumn = $this->getHighestDataColumn();
|
||||||
$pColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($pColumn) - 1 + $pNumCols);
|
$pColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($pColumn) - 1 + $pNumCols);
|
||||||
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
|
$objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
|
||||||
$objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this);
|
$objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this);
|
||||||
|
for($c = 0; $c < $pNumCols; ++$c) {
|
||||||
|
$this->getCellCacheController()->removeColumn($highestColumn);
|
||||||
|
$highestColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($highestColumn) - 2);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new PHPExcel_Exception("Column references should not be numeric.");
|
throw new PHPExcel_Exception("Column references should not be numeric.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user