Performance tweaks

This commit is contained in:
Mark Baker 2013-06-16 21:35:35 +01:00
parent 333c811c5e
commit 6216d2855c
1 changed files with 12 additions and 11 deletions

View File

@ -1142,18 +1142,15 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
$this->_cachedHighestRow = max($this->_cachedHighestRow,$aCoordinates[1]); $this->_cachedHighestRow = max($this->_cachedHighestRow,$aCoordinates[1]);
// Cell needs appropriate xfIndex // Cell needs appropriate xfIndex
$rowDimensions = $this->getRowDimensions(); $rowDimension = $this->getRowDimension($aCoordinates[1], FALSE);
$columnDimensions = $this->getColumnDimensions(); $columnDimension = $this->getColumnDimension($aCoordinates[0], FALSE);
if ( isset($rowDimensions[$aCoordinates[1]]) && $rowDimensions[$aCoordinates[1]]->getXfIndex() !== null ) { if ($rowDimension !== NULL && $rowDimension->getXfIndex() > 0) {
// then there is a row dimension with explicit style, assign it to the cell // then there is a row dimension with explicit style, assign it to the cell
$cell->setXfIndex($rowDimensions[$aCoordinates[1]]->getXfIndex()); $cell->setXfIndex($rowDimension->getXfIndex());
} else if ( isset($columnDimensions[$aCoordinates[0]]) ) { } elseif ($columnDimension !== NULL && $columnDimension->getXfIndex() > 0) {
// then there is a column dimension, assign it to the cell // then there is a column dimension, assign it to the cell
$cell->setXfIndex($columnDimensions[$aCoordinates[0]]->getXfIndex()); $cell->setXfIndex($columnDimension->getXfIndex());
} else {
// set to default index
$cell->setXfIndex(0);
} }
return $cell; return $cell;
@ -1253,13 +1250,15 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param int $pRow Numeric index of the row * @param int $pRow Numeric index of the row
* @return PHPExcel_Worksheet_RowDimension * @return PHPExcel_Worksheet_RowDimension
*/ */
public function getRowDimension($pRow = 1) public function getRowDimension($pRow = 1, $create = TRUE)
{ {
// Found // Found
$found = null; $found = null;
// Get row dimension // Get row dimension
if (!isset($this->_rowDimensions[$pRow])) { if (!isset($this->_rowDimensions[$pRow])) {
if (!$create)
return NULL;
$this->_rowDimensions[$pRow] = new PHPExcel_Worksheet_RowDimension($pRow); $this->_rowDimensions[$pRow] = new PHPExcel_Worksheet_RowDimension($pRow);
$this->_cachedHighestRow = max($this->_cachedHighestRow,$pRow); $this->_cachedHighestRow = max($this->_cachedHighestRow,$pRow);
@ -1273,13 +1272,15 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* @param string $pColumn String index of the column * @param string $pColumn String index of the column
* @return PHPExcel_Worksheet_ColumnDimension * @return PHPExcel_Worksheet_ColumnDimension
*/ */
public function getColumnDimension($pColumn = 'A') public function getColumnDimension($pColumn = 'A', $create = TRUE)
{ {
// Uppercase coordinate // Uppercase coordinate
$pColumn = strtoupper($pColumn); $pColumn = strtoupper($pColumn);
// Fetch dimensions // Fetch dimensions
if (!isset($this->_columnDimensions[$pColumn])) { if (!isset($this->_columnDimensions[$pColumn])) {
if (!$create)
return NULL;
$this->_columnDimensions[$pColumn] = new PHPExcel_Worksheet_ColumnDimension($pColumn); $this->_columnDimensions[$pColumn] = new PHPExcel_Worksheet_ColumnDimension($pColumn);
if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($pColumn)) if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($pColumn))