From 39953ff49fc8781a33d126e81c733aefc5f7bba1 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 25 Jun 2013 23:13:13 +0100 Subject: [PATCH] Feature: Added "Quote Prefix" to style settings (Excel2007 Reader and Writer only) --- Classes/PHPExcel/Reader/Excel2007.php | 11 ++++ Classes/PHPExcel/Style.php | 57 +++++++++++++++++- Classes/PHPExcel/Writer/Excel2007.php | 20 +++++- Classes/PHPExcel/Writer/Excel2007/Style.php | 3 + .../PHPExcel developer documentation.doc | Bin 818688 -> 819200 bytes changelog.txt | 1 + 6 files changed, 90 insertions(+), 2 deletions(-) diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 410025b7..678d837c 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 7669b695..64618261 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 9c78dff4..3d67b3db 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 887b5ab9..bd246fcd 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 b6c1f4d273daa2cd68cf43f86403caa3d741c6ca..a3542c9a04c2d407ad1f24302959d7d6c6d86214 100644 GIT binary patch delta 4183 zcma*qdsJ0b9tZHf&)M7u``{I>Vkih0BB1y{(ZC0UTr@HV)O_Qr@dds>gjs6k^$|5| z3PrEFo3hjytu^H;7#&X2I4vqCr%XyqqDiO)j?0{xbSlgez4QHX?@jQ|ADz2C=j^@D zK6~%;+vjo5=FU-@H>cH%?4My_zNI%~6OiV}-ST?9jP0DBrrl#vUtX8b?5w%GON-{M zo)~QecY7Yt{-$k-^Yqd49yk)qnTA7N#g>+zvrRy~F9vZ|j|2A%=4==8XK{RqXQyy_ z-q5qPv$38|eQe_RIL;!m^Q#7|u-v(QXD(x_GCgy}pa>dA_vNbw6@Nk-JDjS}61?A6 zPEGa_j9qhZc1fdS^4)EHeQo7U^wmK$5Dv!5=IVs4vPGcmtTd<{NxRbMEIQJomzWl^m#(rt@7zRKiab?m-uHlG4O*)#E zOR>Ifb0lXCIP&S)jQt8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