diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 410025b..678d837 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -496,6 +496,10 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE $numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]); } } + $quotePrefix = false; + if (isset($xf["quotePrefix"])) { + $quotePrefix = (boolean) $xf["quotePrefix"]; + } //$numFmt = str_replace('mm', 'i', $numFmt); //$numFmt = str_replace('h', 'H', $numFmt); @@ -506,6 +510,7 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE "border" => $xmlStyles->borders->border[intval($xf["borderId"])], "alignment" => $xf->alignment, "protection" => $xf->protection, + "quotePrefix" => $quotePrefix, ); $styles[] = $style; @@ -533,6 +538,7 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE "border" => $xmlStyles->borders->border[intval($xf["borderId"])], "alignment" => $xf->alignment, "protection" => $xf->protection, + "quotePrefix" => $quotePrefix, ); $cellStyles[] = $cellStyle; @@ -1856,6 +1862,11 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE } } } + + // top-level style settings + if (isset($style->quotePrefix)) { + $docStyle->setQuotePrefix($style->quotePrefix); + } } diff --git a/Classes/PHPExcel/Style.php b/Classes/PHPExcel/Style.php index 7669b69..6461826 100644 --- a/Classes/PHPExcel/Style.php +++ b/Classes/PHPExcel/Style.php @@ -91,6 +91,13 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp */ protected $_index; + /** + * Use Quote Prefix when displaying in cell editor. Only used for real style. + * + * @var boolean + */ + protected $_quotePrefix = false; + /** * Create a new PHPExcel_Style * @@ -156,6 +163,17 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp return $this->_parent; } + /** + * Build style array from subcomponents + * + * @param array $array + * @return array + */ + public function getStyleArray($array) + { + return array('quotePrefix' => $array); + } + /** * Apply styles from array * @@ -185,7 +203,8 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp * 'rgb' => '808080' * ) * ) - * ) + * ), + * 'quotePrefix' => true * ) * ); * @@ -463,6 +482,9 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp if (array_key_exists('protection', $pStyles)) { $this->getProtection()->applyFromArray($pStyles['protection']); } + if (array_key_exists('quotePrefix', $pStyles)) { + $this->_quotePrefix = $pStyles['quotePrefix']; + } } } else { throw new PHPExcel_Exception("Invalid style array passed."); @@ -566,6 +588,38 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp return $this->_protection; } + /** + * Get quote prefix + * + * @return boolean + */ + public function getQuotePrefix() + { + if ($this->_isSupervisor) { + return $this->getSharedComponent()->getQuotePrefix(); + } + return $this->_quotePrefix; + } + + /** + * Set quote prefix + * + * @param boolean $pValue + */ + public function setQuotePrefix($pValue) + { + if ($pValue == '') { + $pValue = false; + } + if ($this->_isSupervisor) { + $styleArray = array('quotePrefix' => $pValue); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); + } else { + $this->_quotePrefix = (boolean) $pValue; + } + return $this; + } + /** * Get hash code * @@ -586,6 +640,7 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp . $this->_numberFormat->getHashCode() . $hashConditionals . $this->_protection->getHashCode() + . ($this->_quotePrefix ? 't' : 'f') . __CLASS__ ); } diff --git a/Classes/PHPExcel/Writer/Excel2007.php b/Classes/PHPExcel/Writer/Excel2007.php index 9c78dff..3d67b3d 100644 --- a/Classes/PHPExcel/Writer/Excel2007.php +++ b/Classes/PHPExcel/Writer/Excel2007.php @@ -70,6 +70,13 @@ class PHPExcel_Writer_Excel2007 extends PHPExcel_Writer_Abstract implements PHPE */ private $_stylesConditionalHashTable; + /** + * Private unique PHPExcel_Style HashTable + * + * @var PHPExcel_HashTable + */ + private $_styleHashTable; + /** * Private unique PHPExcel_Style_Fill HashTable * @@ -135,7 +142,8 @@ class PHPExcel_Writer_Excel2007 extends PHPExcel_Writer_Abstract implements PHPE } $hashTablesArray = array( '_stylesConditionalHashTable', '_fillHashTable', '_fontHashTable', - '_bordersHashTable', '_numFmtHashTable', '_drawingHashTable' + '_bordersHashTable', '_numFmtHashTable', '_drawingHashTable', + '_styleHashTable' ); // Set HashTable variables @@ -191,6 +199,7 @@ class PHPExcel_Writer_Excel2007 extends PHPExcel_Writer_Abstract implements PHPE } // Create styles dictionaries + $this->_styleHashTable->addFromSource( $this->getWriterPart('Style')->allStyles($this->_spreadSheet) ); $this->_stylesConditionalHashTable->addFromSource( $this->getWriterPart('Style')->allConditionalStyles($this->_spreadSheet) ); $this->_fillHashTable->addFromSource( $this->getWriterPart('Style')->allFills($this->_spreadSheet) ); $this->_fontHashTable->addFromSource( $this->getWriterPart('Style')->allFonts($this->_spreadSheet) ); @@ -395,6 +404,15 @@ class PHPExcel_Writer_Excel2007 extends PHPExcel_Writer_Abstract implements PHPE return $this->_stringTable; } + /** + * Get PHPExcel_Style HashTable + * + * @return PHPExcel_HashTable + */ + public function getStyleHashTable() { + return $this->_styleHashTable; + } + /** * Get PHPExcel_Style_Conditional HashTable * diff --git a/Classes/PHPExcel/Writer/Excel2007/Style.php b/Classes/PHPExcel/Writer/Excel2007/Style.php index 887b5ab..bd246fc 100644 --- a/Classes/PHPExcel/Writer/Excel2007/Style.php +++ b/Classes/PHPExcel/Writer/Excel2007/Style.php @@ -397,6 +397,9 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa $objWriter->startElement('xf'); $objWriter->writeAttribute('xfId', 0); $objWriter->writeAttribute('fontId', (int)$this->getParentWriter()->getFontHashTable()->getIndexForHashCode($pStyle->getFont()->getHashCode())); + if ($pStyle->getQuotePrefix()) { + $objWriter->writeAttribute('quotePrefix', 1); + } if ($pStyle->getNumberFormat()->getBuiltInFormatCode() === false) { $objWriter->writeAttribute('numFmtId', (int)($this->getParentWriter()->getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) + 164) ); diff --git a/Documentation/PHPExcel developer documentation.doc b/Documentation/PHPExcel developer documentation.doc index b6c1f4d..a3542c9 100644 Binary files a/Documentation/PHPExcel developer documentation.doc and b/Documentation/PHPExcel developer documentation.doc differ diff --git a/changelog.txt b/changelog.txt index 3c27a1b..f7b7767 100644 --- a/changelog.txt +++ b/changelog.txt @@ -28,6 +28,7 @@ Fixed in develop branch for release v1.7.9a: - Bugfix: (MBaker) - Style error with merged cells in PDF Writer - Bugfix: (MBaker) - Problem with cloning worksheets - Feature: (amerov) - Implementation of the Excel HLOOKUP() function +- Feature: (MBaker) - Added "Quote Prefix" to style settings (Excel2007 Reader and Writer only) Fixed in develop branch for release v1.7.9: - Feature: (MBaker) Include charts option for HTML Writer