From 8a83e847cdab6c991c9312d3028c92f3a2c05a8d Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 8 Feb 2011 12:55:45 +0000 Subject: [PATCH] Bugfix: Work item 15121 - Column reference rather than cell reference in Print Area definition Fixed Excel2007 Writer to handle print areas that are defined as row or column ranges rather than just as cell ranges... added a static absoluteReference() method to PHPExcel_Cell that will return an absolute row, column or cell reference, and modified the _writeDefinedNameForPrintArea() method of the Excel2007 Workbook Writer to call that rather than absoluteCoordinate() git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@68176 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Cell.php | 26 +++++++++++++++++-- .../PHPExcel/Writer/Excel2007/Workbook.php | 4 +-- changelog.txt | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Classes/PHPExcel/Cell.php b/Classes/PHPExcel/Cell.php index 4a588a26..4d2678af 100644 --- a/Classes/PHPExcel/Cell.php +++ b/Classes/PHPExcel/Cell.php @@ -509,11 +509,33 @@ class PHPExcel_Cell } } + /** + * Make string row, column or cell coordinate absolute + * + * @param string $pCoordinateString e.g. 'A' or '1' or 'A1' + * @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1' + * @throws Exception + */ + public static function absoluteReference($pCoordinateString = 'A1') + { + if (strpos($pCoordinateString,':') === false && strpos($pCoordinateString,',') === false) { + // Create absolute coordinate + if (ctype_digit($pCoordinateString)) { + return '$'.$pCoordinateString; + } elseif (ctype_alpha($pCoordinateString)) { + return '$'.strtoupper($pCoordinateString); + } + return self::absoluteCoordinate($pCoordinateString); + } else { + throw new Exception("Coordinate string should not be a cell range."); + } + } + /** * Make string coordinate absolute * - * @param string $pCoordinateString - * @return string Absolute coordinate + * @param string $pCoordinateString e.g. 'A1' + * @return string Absolute coordinate e.g. '$A$1' * @throws Exception */ public static function absoluteCoordinate($pCoordinateString = 'A1') diff --git a/Classes/PHPExcel/Writer/Excel2007/Workbook.php b/Classes/PHPExcel/Writer/Excel2007/Workbook.php index d1c125fb..83414581 100644 --- a/Classes/PHPExcel/Writer/Excel2007/Workbook.php +++ b/Classes/PHPExcel/Writer/Excel2007/Workbook.php @@ -430,8 +430,8 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write $chunks = array(); foreach ($printArea as $printAreaRect) { - $printAreaRect[0] = PHPExcel_Cell::absoluteCoordinate($printAreaRect[0]); - $printAreaRect[1] = PHPExcel_Cell::absoluteCoordinate($printAreaRect[1]); + $printAreaRect[0] = PHPExcel_Cell::absoluteReference($printAreaRect[0]); + $printAreaRect[1] = PHPExcel_Cell::absoluteReference($printAreaRect[1]); $chunks[] = '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . implode(':', $printAreaRect); } diff --git a/changelog.txt b/changelog.txt index 71538080..db70fcd5 100644 --- a/changelog.txt +++ b/changelog.txt @@ -56,6 +56,8 @@ Fixed in SVN: - Bugfix: (MBaker) Fix Excel5 Writer so that it only writes column dimensions for columns that are actually used rather than the full range (A to IV) - Bugfix: (MBaker) The freezePaneByColumnAndRow() method row argument should default to 1 rather than 0. Default row argument for all __ByColumnAndRow() methods should be 1 +- Bugfix: (MBaker) Work item 15121 - Column reference rather than cell reference in Print Area definition + Fix Excel2007 Writer to handle print areas that are defined as row or column ranges rather than just as cell ranges - General: (MBaker) Improved performance (speed), for building the Shared Strings table in the Excel2007 Writer. - General: (MBaker) Enhanced SheetViews element structures in the Excel2007 Writer for frozen panes.