Bugfix: Work items 15905 and 18183

Allow "no impact" to formats on Conditional Formatting
This commit is contained in:
Mark Baker 2012-07-02 22:38:24 +01:00
parent 6710c8a136
commit b7acf2bbe4
13 changed files with 216 additions and 117 deletions

View File

@ -689,16 +689,17 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$dxfs = array();
if (!$this->_readDataOnly && $xmlStyles) {
// Conditional Styles
if ($xmlStyles->dxfs) {
foreach ($xmlStyles->dxfs->dxf as $dxf) {
$style = new PHPExcel_Style;
$style = new PHPExcel_Style(FALSE, TRUE);
self::_readStyle($style, $dxf);
$dxfs[] = $style;
}
}
if ($xmlStyles->cellStyles)
{
// Cell Styles
if ($xmlStyles->cellStyles) {
foreach ($xmlStyles->cellStyles->cellStyle as $cellStyle) {
if (intval($cellStyle['builtinId']) == 0) {
if (isset($cellStyles[intval($cellStyle['xfId'])])) {

View File

@ -108,21 +108,26 @@ class PHPExcel_Style implements PHPExcel_IComparable
/**
* Create a new PHPExcel_Style
*
* @param boolean $isSupervisor
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
* Leave this value at default unless you understand exactly what
* its ramifications are
* @param boolean $isConditional Flag indicating if this is a conditional style or not
* Leave this value at default unless you understand exactly what
* its ramifications are
*/
public function __construct($isSupervisor = false)
public function __construct($isSupervisor = false, $isConditional = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
$this->_conditionalStyles = array();
$this->_font = new PHPExcel_Style_Font($isSupervisor);
$this->_fill = new PHPExcel_Style_Fill($isSupervisor);
$this->_borders = new PHPExcel_Style_Borders($isSupervisor);
$this->_alignment = new PHPExcel_Style_Alignment($isSupervisor);
$this->_numberFormat = new PHPExcel_Style_NumberFormat($isSupervisor);
$this->_protection = new PHPExcel_Style_Protection($isSupervisor);
$this->_font = new PHPExcel_Style_Font($isSupervisor, $isConditional);
$this->_fill = new PHPExcel_Style_Fill($isSupervisor, $isConditional);
$this->_borders = new PHPExcel_Style_Borders($isSupervisor, $isConditional);
$this->_alignment = new PHPExcel_Style_Alignment($isSupervisor, $isConditional);
$this->_numberFormat = new PHPExcel_Style_NumberFormat($isSupervisor, $isConditional);
$this->_protection = new PHPExcel_Style_Protection($isSupervisor, $isConditional);
// bind parent if we are a supervisor
if ($isSupervisor) {

View File

@ -116,11 +116,22 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
* Create a new PHPExcel_Style_Alignment
*
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
* Leave this value at default unless you understand exactly what
* its ramifications are
* @param boolean $isConditional Flag indicating if this is a conditional style or not
* Leave this value at default unless you understand exactly what
* its ramifications are
*/
public function __construct($isSupervisor = false)
public function __construct($isSupervisor = false, $isConditional = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
if ($isConditional) {
$this->_horizontal = NULL;
$this->_vertical = NULL;
$this->_textRotation = NULL;
}
}
/**

View File

@ -90,8 +90,13 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
* Create a new PHPExcel_Style_Border
*
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
* Leave this value at default unless you understand exactly what
* its ramifications are
* @param boolean $isConditional Flag indicating if this is a conditional style or not
* Leave this value at default unless you understand exactly what
* its ramifications are
*/
public function __construct($isSupervisor = false)
public function __construct($isSupervisor = false, $isConditional = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;

View File

@ -143,18 +143,23 @@ class PHPExcel_Style_Borders implements PHPExcel_IComparable
* Create a new PHPExcel_Style_Borders
*
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
* Leave this value at default unless you understand exactly what
* its ramifications are
* @param boolean $isConditional Flag indicating if this is a conditional style or not
* Leave this value at default unless you understand exactly what
* its ramifications are
*/
public function __construct($isSupervisor = false)
public function __construct($isSupervisor = false, $isConditional = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
$this->_left = new PHPExcel_Style_Border($isSupervisor);
$this->_right = new PHPExcel_Style_Border($isSupervisor);
$this->_top = new PHPExcel_Style_Border($isSupervisor);
$this->_bottom = new PHPExcel_Style_Border($isSupervisor);
$this->_diagonal = new PHPExcel_Style_Border($isSupervisor);
$this->_left = new PHPExcel_Style_Border($isSupervisor, $isConditional);
$this->_right = new PHPExcel_Style_Border($isSupervisor, $isConditional);
$this->_top = new PHPExcel_Style_Border($isSupervisor, $isConditional);
$this->_bottom = new PHPExcel_Style_Border($isSupervisor, $isConditional);
$this->_diagonal = new PHPExcel_Style_Border($isSupervisor, $isConditional);
$this->_diagonalDirection = PHPExcel_Style_Borders::DIAGONAL_NONE;
// Specially for supervisor

View File

@ -59,7 +59,7 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
*
* @var string
*/
private $_argb;
private $_argb = NULL;
/**
* Supervisor?
@ -88,15 +88,22 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
*
* @param string $pARGB ARGB value for the colour
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
* Leave this value at default unless you understand exactly what
* its ramifications are
* @param boolean $isConditional Flag indicating if this is a conditional style or not
* Leave this value at default unless you understand exactly what
* its ramifications are
*/
public function __construct($pARGB = PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor = false)
public function __construct($pARGB = PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor = false, $isConditional = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
if (!$isConditional) {
$this->_argb = $pARGB;
}
}
/**
* Bind parent. Only used for supervisor
@ -132,16 +139,11 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
{
switch ($this->_parentPropertyName) {
case '_endColor':
return $this->_parent->getSharedComponent()->getEndColor();
break;
return $this->_parent->getSharedComponent()->getEndColor(); break;
case '_color':
return $this->_parent->getSharedComponent()->getColor();
break;
return $this->_parent->getSharedComponent()->getColor(); break;
case '_startColor':
return $this->_parent->getSharedComponent()->getStartColor();
break;
return $this->_parent->getSharedComponent()->getStartColor(); break;
}
}
@ -189,11 +191,9 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
case '_endColor':
$key = 'endcolor';
break;
case '_color':
$key = 'color';
break;
case '_startColor':
$key = 'startcolor';
break;

View File

@ -100,7 +100,7 @@ class PHPExcel_Style_Conditional implements PHPExcel_IComparable
$this->_operatorType = PHPExcel_Style_Conditional::OPERATOR_NONE;
$this->_text = null;
$this->_condition = array();
$this->_style = new PHPExcel_Style();
$this->_style = new PHPExcel_Style(FALSE, TRUE);
}
/**

View File

@ -111,15 +111,23 @@ class PHPExcel_Style_Fill implements PHPExcel_IComparable
* Create a new PHPExcel_Style_Fill
*
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
* Leave this value at default unless you understand exactly what
* its ramifications are
* @param boolean $isConditional Flag indicating if this is a conditional style or not
* Leave this value at default unless you understand exactly what
* its ramifications are
*/
public function __construct($isSupervisor = false)
public function __construct($isSupervisor = false, $isConditional = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
$this->_startColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_WHITE, $isSupervisor);
$this->_endColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor);
if ($isConditional) {
$this->_fillType = NULL;
}
$this->_startColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_WHITE, $isSupervisor, $isConditional);
$this->_endColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor, $isConditional);
// bind parent if we are a supervisor
if ($isSupervisor) {

View File

@ -130,15 +130,31 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
* Create a new PHPExcel_Style_Font
*
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
* Leave this value at default unless you understand exactly what
* its ramifications are
* @param boolean $isConditional Flag indicating if this is a conditional style or not
* Leave this value at default unless you understand exactly what
* its ramifications are
*/
public function __construct($isSupervisor = false)
public function __construct($isSupervisor = false, $isConditional = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
if ($isConditional) {
$this->_name = NULL;
$this->_size = NULL;
$this->_bold = NULL;
$this->_italic = NULL;
$this->_superScript = NULL;
$this->_subScript = NULL;
$this->_underline = NULL;
$this->_strikethrough = NULL;
$this->_color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor, $isConditional);
} else {
$this->_color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor);
}
// bind parent if we are a supervisor
if ($isSupervisor) {
$this->_color->bindParent($this, '_color');

View File

@ -128,11 +128,20 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* Create a new PHPExcel_Style_NumberFormat
*
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
* Leave this value at default unless you understand exactly what
* its ramifications are
* @param boolean $isConditional Flag indicating if this is a conditional style or not
* Leave this value at default unless you understand exactly what
* its ramifications are
*/
public function __construct($isSupervisor = false)
public function __construct($isSupervisor = false, $isConditional = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
if ($isConditional) {
$this->_formatCode = NULL;
}
}
/**

View File

@ -79,16 +79,23 @@ class PHPExcel_Style_Protection implements PHPExcel_IComparable
* Create a new PHPExcel_Style_Protection
*
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
* Leave this value at default unless you understand exactly what
* its ramifications are
* @param boolean $isConditional Flag indicating if this is a conditional style or not
* Leave this value at default unless you understand exactly what
* its ramifications are
*/
public function __construct($isSupervisor = false)
public function __construct($isSupervisor = false, $isConditional = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
if (!$isConditional) {
$this->_locked = self::PROTECTION_INHERIT;
$this->_hidden = self::PROTECTION_INHERIT;
}
}
/**
* Bind parent. Only used for supervisor

View File

@ -175,11 +175,11 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
private function _writeFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null)
{
// Check if this is a pattern type or gradient type
if ($pFill->getFillType() == PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR
|| $pFill->getFillType() == PHPExcel_Style_Fill::FILL_GRADIENT_PATH) {
if ($pFill->getFillType() === PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR ||
$pFill->getFillType() === PHPExcel_Style_Fill::FILL_GRADIENT_PATH) {
// Gradient fill
$this->_writeGradientFill($objWriter, $pFill);
} else {
} elseif($pFill->getFillType() !== NULL) {
// Pattern fill
$this->_writePatternFill($objWriter, $pFill);
}
@ -247,15 +247,19 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) {
// fgColor
if ($pFill->getStartColor()->getARGB()) {
$objWriter->startElement('fgColor');
$objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB());
$objWriter->endElement();
}
// bgColor
if ($pFill->getEndColor()->getARGB()) {
$objWriter->startElement('bgColor');
$objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB());
$objWriter->endElement();
}
}
$objWriter->endElement();
@ -275,52 +279,66 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
$objWriter->startElement('font');
// Name
if ($pFont->getName() !== NULL) {
$objWriter->startElement('name');
$objWriter->writeAttribute('val', $pFont->getName());
$objWriter->endElement();
}
// Size
if ($pFont->getSize() !== NULL) {
$objWriter->startElement('sz');
$objWriter->writeAttribute('val', $pFont->getSize());
$objWriter->endElement();
}
// Bold. We explicitly write this element also when false (like MS Office Excel 2007 does
// for conditional formatting). Otherwise it will apparently not be picked up in conditional
// formatting style dialog
if ($pFont->getBold() !== NULL) {
$objWriter->startElement('b');
$objWriter->writeAttribute('val', $pFont->getBold() ? '1' : '0');
$objWriter->endElement();
}
// Italic
if ($pFont->getItalic() !== NULL) {
$objWriter->startElement('i');
$objWriter->writeAttribute('val', $pFont->getItalic() ? '1' : '0');
$objWriter->endElement();
}
// Superscript / subscript
if ($pFont->getSuperScript() || $pFont->getSubScript()) {
if ($pFont->getSuperScript() === TRUE || $pFont->getSubScript() === TRUE) {
$objWriter->startElement('vertAlign');
if ($pFont->getSuperScript()) {
if ($pFont->getSuperScript() === TRUE) {
$objWriter->writeAttribute('val', 'superscript');
} else if ($pFont->getSubScript()) {
} else if ($pFont->getSubScript() === TRUE) {
$objWriter->writeAttribute('val', 'subscript');
}
$objWriter->endElement();
}
// Underline
if ($pFont->getUnderline() !== NULL) {
$objWriter->startElement('u');
$objWriter->writeAttribute('val', $pFont->getUnderline());
$objWriter->endElement();
}
// Strikethrough
if ($pFont->getStrikethrough() !== NULL) {
$objWriter->startElement('strike');
$objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0');
$objWriter->endElement();
}
// Foreground color
if ($pFont->getColor()->getARGB() !== NULL) {
$objWriter->startElement('color');
$objWriter->writeAttribute('rgb', $pFont->getColor()->getARGB());
$objWriter->endElement();
}
$objWriter->endElement();
}
@ -406,8 +424,8 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
} else if ($pStyle->getAlignment()->getTextRotation() < 0) {
$textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
}
$objWriter->writeAttribute('textRotation', $textRotation);
$objWriter->writeAttribute('wrapText', ($pStyle->getAlignment()->getWrapText() ? 'true' : 'false'));
$objWriter->writeAttribute('shrinkToFit', ($pStyle->getAlignment()->getShrinkToFit() ? 'true' : 'false'));
@ -454,33 +472,44 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
// alignment
$objWriter->startElement('alignment');
if ($pStyle->getAlignment()->getHorizontal() !== NULL) {
$objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal());
}
if ($pStyle->getAlignment()->getVertical() !== NULL) {
$objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical());
}
if ($pStyle->getAlignment()->getTextRotation() !== NULL) {
$textRotation = 0;
if ($pStyle->getAlignment()->getTextRotation() >= 0) {
$textRotation = $pStyle->getAlignment()->getTextRotation();
} else if ($pStyle->getAlignment()->getTextRotation() < 0) {
$textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
}
$objWriter->writeAttribute('textRotation', $textRotation);
}
$objWriter->endElement();
// border
$this->_writeBorder($objWriter, $pStyle->getBorders());
// protection
if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
if (($pStyle->getProtection()->getLocked() !== NULL) ||
($pStyle->getProtection()->getHidden() !== NULL)) {
if ($pStyle->getProtection()->getLocked() !== PHPExcel_Style_Protection::PROTECTION_INHERIT ||
$pStyle->getProtection()->getHidden() !== PHPExcel_Style_Protection::PROTECTION_INHERIT) {
$objWriter->startElement('protection');
if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
if (($pStyle->getProtection()->getLocked() !== NULL) &&
($pStyle->getProtection()->getLocked() !== PHPExcel_Style_Protection::PROTECTION_INHERIT)) {
$objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false'));
}
if ($pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
if (($pStyle->getProtection()->getHidden() !== NULL) &&
($pStyle->getProtection()->getHidden() !== PHPExcel_Style_Protection::PROTECTION_INHERIT)) {
$objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false'));
}
$objWriter->endElement();
}
}
$objWriter->endElement();
}
@ -523,11 +552,13 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
$formatCode = $pNumberFormat->getFormatCode();
// numFmt
if ($formatCode !== NULL) {
$objWriter->startElement('numFmt');
$objWriter->writeAttribute('numFmtId', ($pId + 164));
$objWriter->writeAttribute('formatCode', $formatCode);
$objWriter->endElement();
}
}
/**
* Get an array of all styles

View File

@ -34,6 +34,7 @@ Fixed in develop branch:
- Bugfix: (MBaker) Support for "e" (epoch) date format mask
Rendered as a 4-digit CE year in non-Excel outputs
- Bugfix: (MBaker) Work items 15799 and 18278 - Background color cell is always black when editing cell
- Bugfix: (MBaker) Work items 15905 and 18183 - Allow "no impact" to formats on Conditional Formatting
2012-05-19 (v1.7.7):