Bugfix: Work item 17403 - duplicateStyle() method doesn't duplicate conditional formats

Added an equivalent duplicateConditionalStyle() method for duplicating conditional styles

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@86383 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2012-02-12 18:04:22 +00:00
parent df29d7d985
commit 6f91dd9f59
2 changed files with 143 additions and 1 deletions

View File

@ -101,6 +101,13 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
*/
private $_drawingCollection = null;
/**
* Collection of Chart objects
*
* @var PHPExcel_Chart[]
*/
private $_chartCollection = array();
/**
* Worksheet title
*
@ -348,6 +355,9 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Drawing collection
$this->_drawingCollection = new ArrayObject();
// Chart collection
$this->_chartCollection = new ArrayObject();
// Protection
$this->_protection = new PHPExcel_Worksheet_Protection();
@ -490,6 +500,80 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
return $this->_drawingCollection;
}
/**
* Get collection of charts
*
* @return PHPExcel_Chart[]
*/
public function getChartCollection()
{
return $this->_chartCollection;
}
/**
* Add chart
*
* @param PHPExcel_Chart $pChart
* @param int|null $iChartIndex Index where chart should go (0,1,..., or null for last)
* @return PHPExcel_Chart
* @throws Exception
*/
public function addChart(PHPExcel_Chart $pChart = null, $iChartIndex = null)
{
if (is_null($iChartIndex)) {
$this->_chartCollection[] = $pChart;
} else {
// Insert the chart at the requested index
array_splice($this->_chartCollection, $iChartIndex, 0, array($pChart));
}
return $pChart;
}
public function getChartCount()
{
return count($this->_chartCollection);
}
public function getChartByIndex($index = null)
{
$chartCount = count($this->_chartCollection);
if ($chartCount == 0) {
return false;
}
if (is_null($index)) {
$index = --$chartCount;
}
if (!isset($this->_chartCollection[$index])) {
return false;
}
return $this->_chartCollection[$index];
}
public function getChartNames()
{
$chartNames = array();
foreach($this->_chartCollection as $chart) {
$chartNames[] = $chart->getName();
}
return $chartNames;
}
public function getChartByName($chartName = '')
{
$chartCount = count($this->_chartCollection);
if ($chartCount == 0) {
return false;
}
foreach($this->_chartCollection as $index => $chart) {
if ($chart->getName() == $chartName) {
return $this->_chartCollection[$index];
}
}
return false;
}
/**
* Refresh column dimensions
*
@ -1384,6 +1468,62 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
return $this;
}
/**
* Duplicate conditional style to a range of cells
*
* Please note that this will overwrite existing cell styles for cells in range!
*
* @param array of PHPExcel_Style_Conditional $pCellStyle Cell style to duplicate
* @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
* @throws Exception
* @return PHPExcel_Worksheet
*/
public function duplicateConditionalStyle(array $pCellStyle = null, $pRange = '')
{
foreach($pCellStyle as $cellStyle) {
if (!is_a($cellStyle,'PHPExcel_Style_Conditional')) {
throw new Exception('Style is not a conditional style');
}
}
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Is it a cell range or a single cell?
$rangeA = '';
$rangeB = '';
if (strpos($pRange, ':') === false) {
$rangeA = $pRange;
$rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
// Calculate range outer borders
$rangeStart = PHPExcel_Cell::coordinateFromString($rangeA);
$rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB);
// Translate column into index
$rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1;
$rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1;
// Make sure we can loop upwards on rows and columns
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
$tmp = $rangeStart;
$rangeStart = $rangeEnd;
$rangeEnd = $tmp;
}
// Loop through cells and apply styles
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
$this->setConditionalStyles(PHPExcel_Cell::stringFromColumnIndex($col) . $row, $pCellStyle);
}
}
return $this;
}
/**
* Duplicate cell style array to a range of cells
*

View File

@ -54,6 +54,8 @@ Fixed in SVN:
- Bugfix: (MBaker) Work item 17166 - Indexed colors do not refer to Excel's indexed colors?
- Bugfix: (MBaker) Work item 17199 - Indexed colors should be consistent with Excel and start from 1 (current index starts at 0)
- Bugfix: (MBaker) Work item 17262 - Named Range definition in .xls when sheet reeference is quote wrapped
- Bugfix: (MBaker) Work item 17403 - duplicateStyle() method doesn't duplicate conditional formats
Added an equivalent duplicateConditionalStyle() method for duplicating conditional styles
- General: (MBaker) Work item 15405 - Two easy to fix Issues concerning PHPExcel_Token_Stack (l10n/UC)
- General: (MBaker) Work item 15461 - Locale file paths not fit for windows
- General: (MBaker) Work item 16643 - Add file directory as a cache option for cache_to_discISAM