From f8695a74b65f605c0e1dbad3c847956dd18e806a Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Sun, 29 Nov 2009 02:02:47 +0000 Subject: [PATCH] Fixed issue #9564: Worksheet::setColumn() can only be called once per range - patch by Dan Lynn git-svn-id: https://svn.php.net/repository/pear/packages/Spreadsheet_Excel_Writer/trunk@291408 c90b9560-bf6c-de11-be94-00142212c4b1 --- Spreadsheet/Excel/Writer/Worksheet.php | 44 ++++++++++++++++++++------ 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/Spreadsheet/Excel/Writer/Worksheet.php b/Spreadsheet/Excel/Writer/Worksheet.php index 32714a1..aa20a4a 100644 --- a/Spreadsheet/Excel/Writer/Worksheet.php +++ b/Spreadsheet/Excel/Writer/Worksheet.php @@ -750,16 +750,40 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr * @param integer $hidden The optional hidden atribute * @param integer $level The optional outline level */ - function setColumn($firstcol, $lastcol, $width, $format = null, $hidden = 0, $level = 0) - { - $this->_colinfo[] = array($firstcol, $lastcol, $width, &$format, $hidden, $level); - - // Set width to zero if column is hidden - $width = ($hidden) ? 0 : $width; - - for ($col = $firstcol; $col <= $lastcol; $col++) { - $this->col_sizes[$col] = $width; - } + function setColumn($firstcol, $lastcol, $width, $format = null, $hidden = 0, $level = 0) + { // added by Dan Lynn _colinfo as $key => $colinfo) + { + $existing_start = $colinfo[0]; $existing_end = $colinfo[1]; + // if the new range starts within another range + if ($firstcol > $existing_start && $firstcol < $existing_end) + { // trim the existing range to the beginning of the new range + $this->_colinfo[$key][1] = $firstcol - 1; + // if the new range lies WITHIN the existing range + if ($lastcol < $existing_end) + { // split the existing range by adding a range after our new range + $this->_colinfo[] = array($lastcol+1, $existing_end, $colinfo[2], &$colinfo[3], $colinfo[4], $colinfo[5]); + } + } // if the new range ends inside an existing range + elseif ($lastcol > $existing_start && $lastcol < $existing_end) + { // trim the existing range to the end of the new range + $this->_colinfo[$key][0] = $lastcol + 1; + } // if the new range completely overlaps the existing range + elseif ($firstcol <= $existing_start && $lastcol >= $existing_end) + { + unset($this->_colinfo[$key]); + } + } // added by Dan Lynn _colinfo = array_values($this->_colinfo); + $this->_colinfo[] = array($firstcol, $lastcol, $width, &$format, $hidden, $level); + // Set width to zero if column is hidden + $width = ($hidden) ? 0 : $width; + for ($col = $firstcol; $col <= $lastcol; $col++) + { + $this->col_sizes[$col] = $width; + } } /**