Experimental - Added getHighestDataColumn(), getHighestDataRow(), getHighestRowAndColumn() and calculateWorksheetDataDimension() methods for the worksheet that return the highest row and column that have cell records

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@83932 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2011-12-16 16:01:21 +00:00
parent 0924d0a4ca
commit b235c531a7
3 changed files with 96 additions and 15 deletions

View File

@ -155,6 +155,56 @@ class PHPExcel_CachedObjectStorage_CacheBase {
} // function sortCellList()
/**
* Get highest worksheet column and highest row that have cell records
*
* @return array Highest column name and highest row number
*/
public function getHighestRowAndColumn()
{
// Lookup highest column and highest row
$col = array('A' => '1A');
$row = array(1);
foreach ($this->getCellList() as $coord) {
list($c,$r) = sscanf($coord,'%[A-Z]%d');
$row[$r] = $r;
$col[$c] = strlen($c).$c;
}
if (count($row) > 0) {
// Determine highest column and row
$highestRow = max($row);
$highestColumn = substr(max($col),1);
}
return array( 'row' => $highestRow,
'column' => $highestColumn
);
}
/**
* Get highest worksheet column
*
* @return string Highest column name
*/
public function getHighestColumn()
{
$colRow = $this->getHighestRowAndColumn();
return $colRow['column'];
}
/**
* Get highest worksheet row
*
* @return int Highest row number
*/
public function getHighestRow()
{
$colRow = $this->getHighestRowAndColumn();
return $colRow['row'];
}
protected function _getUniqueID() {
if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid();

View File

@ -539,6 +539,17 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
return 'A1' . ':' . $this->getHighestColumn() . $this->getHighestRow();
}
/**
* Calculate worksheet data dimension
*
* @return string String containing the dimension of this worksheet that actually contain data
*/
public function calculateWorksheetDataDimension()
{
// Return
return 'A1' . ':' . $this->getHighestDataColumn() . $this->getHighestDataRow();
}
/**
* Calculate widths for auto-size columns
*
@ -843,6 +854,16 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
return $this->_cachedHighestColumn;
}
/**
* Get highest worksheet column that contains data
*
* @return string Highest column name that contains data
*/
public function getHighestDataColumn()
{
return $this->_cellCollection->getHighestColumn();
}
/**
* Get highest worksheet row
*
@ -853,6 +874,26 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
return $this->_cachedHighestRow;
}
/**
* Get highest worksheet row that contains data
*
* @return string Highest row number that contains data
*/
public function getHighestDataRow()
{
return $this->_cellCollection->getHighestRow();
}
/**
* Get highest worksheet column and highest row that have cell records
*
* @return array Highest column name and highest row number
*/
public function getHighestRowAndColumn()
{
return $this->_cellCollection->getHighestRowAndColumn();
}
/**
* Set a cell value
*
@ -2297,21 +2338,9 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// }
//
// Lookup highest column and highest row if cells are cleaned
$highestColumn = -1;
$highestRow = 1;
// Find cells that can be cleaned
$col = $row = array();
foreach ($this->_cellCollection->getCellList() as $coord) {
list($c,$r) = sscanf($coord,'%[A-Z]%d');
$row[$r] = $r;
$col[$c] = strlen($c).$c;
}
if (count($row) > 0) {
// Determine highest column and row
$highestRow = max($row);
$highestColumn = PHPExcel_Cell::columnIndexFromString(substr(max($col),1));
}
$colRow = $this->_cellCollection->getHighestRowAndColumn();
$highestRow = $colRow['row'];
$highestColumn = PHPExcel_Cell::columnIndexFromString($colRow['column']);
// Loop through column dimensions
foreach ($this->_columnDimensions as $dimension) {

View File

@ -29,6 +29,8 @@ Fixed in SVN:
- General: (MBaker) Reduce cell caching overhead using dirty flag to ensure that cells are only rewritten to the cache if they have actually been changed
- General: (MBaker) Improved memory usage in CSV Writer
- General: (MBaker) Improved speed and memory usage in Excel5 Writer
- General: (MBaker) Experimental -
Added getHighestDataColumn(), getHighestDataRow(), getHighestRowAndColumn() and calculateWorksheetDataDimension() methods for the worksheet that return the highest row and column that have cell records
- Bugfix: (MBaker) Work item 15459 - Invalid cell coordinate in Autofilter for Excel2007 Writer
- Bugfix: (MBaker) Work item 15518 - PCLZip library issue
- Bugfix: (MBaker) Work item 15537 - Excel2007 Reader canRead function bug