diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index af796f6c..0b78f569 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -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'])])) { diff --git a/Classes/PHPExcel/Style.php b/Classes/PHPExcel/Style.php index ae508081..6afd1577 100644 --- a/Classes/PHPExcel/Style.php +++ b/Classes/PHPExcel/Style.php @@ -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) { diff --git a/Classes/PHPExcel/Style/Alignment.php b/Classes/PHPExcel/Style/Alignment.php index 5ccd9302..fe85cb8b 100644 --- a/Classes/PHPExcel/Style/Alignment.php +++ b/Classes/PHPExcel/Style/Alignment.php @@ -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; + } } /** diff --git a/Classes/PHPExcel/Style/Border.php b/Classes/PHPExcel/Style/Border.php index 6ad3e780..a409e1c7 100644 --- a/Classes/PHPExcel/Style/Border.php +++ b/Classes/PHPExcel/Style/Border.php @@ -90,14 +90,19 @@ 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; // Initialise values - $this->_color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor); + $this->_color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor); // bind parent if we are a supervisor if ($isSupervisor) { diff --git a/Classes/PHPExcel/Style/Borders.php b/Classes/PHPExcel/Style/Borders.php index 77dea7e3..295daa21 100644 --- a/Classes/PHPExcel/Style/Borders.php +++ b/Classes/PHPExcel/Style/Borders.php @@ -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 diff --git a/Classes/PHPExcel/Style/Color.php b/Classes/PHPExcel/Style/Color.php index 7e225b66..a94a0eda 100644 --- a/Classes/PHPExcel/Style/Color.php +++ b/Classes/PHPExcel/Style/Color.php @@ -59,7 +59,7 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable * * @var string */ - private $_argb; + private $_argb = NULL; /** * Supervisor? @@ -88,14 +88,21 @@ 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 - $this->_argb = $pARGB; + if (!$isConditional) { + $this->_argb = $pARGB; + } } /** @@ -131,17 +138,12 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable public function getSharedComponent() { switch ($this->_parentPropertyName) { - case '_endColor': - return $this->_parent->getSharedComponent()->getEndColor(); - break; - - case '_color': - return $this->_parent->getSharedComponent()->getColor(); - break; - - case '_startColor': - return $this->_parent->getSharedComponent()->getStartColor(); - break; + case '_endColor': + return $this->_parent->getSharedComponent()->getEndColor(); break; + case '_color': + return $this->_parent->getSharedComponent()->getColor(); break; + case '_startColor': + return $this->_parent->getSharedComponent()->getStartColor(); break; } } @@ -186,17 +188,15 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable public function getStyleArray($array) { switch ($this->_parentPropertyName) { - case '_endColor': - $key = 'endcolor'; - break; - - case '_color': - $key = 'color'; - break; - - case '_startColor': - $key = 'startcolor'; - break; + case '_endColor': + $key = 'endcolor'; + break; + case '_color': + $key = 'color'; + break; + case '_startColor': + $key = 'startcolor'; + break; } return $this->_parent->getStyleArray(array($key => $array)); diff --git a/Classes/PHPExcel/Style/Conditional.php b/Classes/PHPExcel/Style/Conditional.php index f631996d..ff365d1b 100644 --- a/Classes/PHPExcel/Style/Conditional.php +++ b/Classes/PHPExcel/Style/Conditional.php @@ -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); } /** diff --git a/Classes/PHPExcel/Style/Fill.php b/Classes/PHPExcel/Style/Fill.php index d58d633a..5817a43a 100644 --- a/Classes/PHPExcel/Style/Fill.php +++ b/Classes/PHPExcel/Style/Fill.php @@ -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) { diff --git a/Classes/PHPExcel/Style/Font.php b/Classes/PHPExcel/Style/Font.php index 10ef154c..becc69f4 100644 --- a/Classes/PHPExcel/Style/Font.php +++ b/Classes/PHPExcel/Style/Font.php @@ -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 - $this->_color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor); - + 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'); diff --git a/Classes/PHPExcel/Style/NumberFormat.php b/Classes/PHPExcel/Style/NumberFormat.php index 1b57959e..613dcae1 100644 --- a/Classes/PHPExcel/Style/NumberFormat.php +++ b/Classes/PHPExcel/Style/NumberFormat.php @@ -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; + } } /** diff --git a/Classes/PHPExcel/Style/Protection.php b/Classes/PHPExcel/Style/Protection.php index 153b37bc..477742bd 100644 --- a/Classes/PHPExcel/Style/Protection.php +++ b/Classes/PHPExcel/Style/Protection.php @@ -79,15 +79,22 @@ 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 - $this->_locked = self::PROTECTION_INHERIT; - $this->_hidden = self::PROTECTION_INHERIT; + if (!$isConditional) { + $this->_locked = self::PROTECTION_INHERIT; + $this->_hidden = self::PROTECTION_INHERIT; + } } /** diff --git a/Classes/PHPExcel/Writer/Excel2007/Style.php b/Classes/PHPExcel/Writer/Excel2007/Style.php index f16c950b..daf9f3ef 100644 --- a/Classes/PHPExcel/Writer/Excel2007/Style.php +++ b/Classes/PHPExcel/Writer/Excel2007/Style.php @@ -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,14 +247,18 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) { // fgColor - $objWriter->startElement('fgColor'); - $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB()); - $objWriter->endElement(); + if ($pFill->getStartColor()->getARGB()) { + $objWriter->startElement('fgColor'); + $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB()); + $objWriter->endElement(); + } // bgColor - $objWriter->startElement('bgColor'); - $objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB()); - $objWriter->endElement(); + 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 - $objWriter->startElement('name'); - $objWriter->writeAttribute('val', $pFont->getName()); - $objWriter->endElement(); + if ($pFont->getName() !== NULL) { + $objWriter->startElement('name'); + $objWriter->writeAttribute('val', $pFont->getName()); + $objWriter->endElement(); + } // Size - $objWriter->startElement('sz'); - $objWriter->writeAttribute('val', $pFont->getSize()); - $objWriter->endElement(); + 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 - $objWriter->startElement('b'); - $objWriter->writeAttribute('val', $pFont->getBold() ? '1' : '0'); - $objWriter->endElement(); + if ($pFont->getBold() !== NULL) { + $objWriter->startElement('b'); + $objWriter->writeAttribute('val', $pFont->getBold() ? '1' : '0'); + $objWriter->endElement(); + } // Italic - $objWriter->startElement('i'); - $objWriter->writeAttribute('val', $pFont->getItalic() ? '1' : '0'); - $objWriter->endElement(); + 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 - $objWriter->startElement('u'); - $objWriter->writeAttribute('val', $pFont->getUnderline()); - $objWriter->endElement(); + if ($pFont->getUnderline() !== NULL) { + $objWriter->startElement('u'); + $objWriter->writeAttribute('val', $pFont->getUnderline()); + $objWriter->endElement(); + } // Strikethrough - $objWriter->startElement('strike'); - $objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0'); - $objWriter->endElement(); + if ($pFont->getStrikethrough() !== NULL) { + $objWriter->startElement('strike'); + $objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0'); + $objWriter->endElement(); + } // Foreground color - $objWriter->startElement('color'); - $objWriter->writeAttribute('rgb', $pFont->getColor()->getARGB()); - $objWriter->endElement(); + if ($pFont->getColor()->getARGB() !== NULL) { + $objWriter->startElement('color'); + $objWriter->writeAttribute('rgb', $pFont->getColor()->getARGB()); + $objWriter->endElement(); + } $objWriter->endElement(); } @@ -353,11 +371,11 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa } // BorderPr - $this->_writeBorderPr($objWriter, 'left', $pBorders->getLeft()); - $this->_writeBorderPr($objWriter, 'right', $pBorders->getRight()); - $this->_writeBorderPr($objWriter, 'top', $pBorders->getTop()); - $this->_writeBorderPr($objWriter, 'bottom', $pBorders->getBottom()); - $this->_writeBorderPr($objWriter, 'diagonal', $pBorders->getDiagonal()); + $this->_writeBorderPr($objWriter, 'left', $pBorders->getLeft()); + $this->_writeBorderPr($objWriter, 'right', $pBorders->getRight()); + $this->_writeBorderPr($objWriter, 'top', $pBorders->getTop()); + $this->_writeBorderPr($objWriter, 'bottom', $pBorders->getBottom()); + $this->_writeBorderPr($objWriter, 'diagonal', $pBorders->getDiagonal()); $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,32 +472,43 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa // alignment $objWriter->startElement('alignment'); - $objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal()); - $objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical()); - - $textRotation = 0; - if ($pStyle->getAlignment()->getTextRotation() >= 0) { - $textRotation = $pStyle->getAlignment()->getTextRotation(); - } else if ($pStyle->getAlignment()->getTextRotation() < 0) { - $textRotation = 90 - $pStyle->getAlignment()->getTextRotation(); + if ($pStyle->getAlignment()->getHorizontal() !== NULL) { + $objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal()); + } + if ($pStyle->getAlignment()->getVertical() !== NULL) { + $objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical()); } - $objWriter->writeAttribute('textRotation', $textRotation); + 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) { - $objWriter->startElement('protection'); - if ($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) { - $objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false')); - } - $objWriter->endElement(); + 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() !== 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() !== 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,10 +552,12 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa $formatCode = $pNumberFormat->getFormatCode(); // numFmt - $objWriter->startElement('numFmt'); - $objWriter->writeAttribute('numFmtId', ($pId + 164)); - $objWriter->writeAttribute('formatCode', $formatCode); - $objWriter->endElement(); + if ($formatCode !== NULL) { + $objWriter->startElement('numFmt'); + $objWriter->writeAttribute('numFmtId', ($pId + 164)); + $objWriter->writeAttribute('formatCode', $formatCode); + $objWriter->endElement(); + } } /** diff --git a/changelog.txt b/changelog.txt index c258055f..c2556b65 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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):