Feature: Added "Quote Prefix" to style settings (Excel2007 Reader and Writer only)

This commit is contained in:
Mark Baker 2013-06-25 23:13:13 +01:00
parent 6cea3bbf7b
commit 39953ff49f
6 changed files with 90 additions and 2 deletions

View File

@ -496,6 +496,10 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE
$numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]); $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('mm', 'i', $numFmt);
//$numFmt = str_replace('h', 'H', $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"])], "border" => $xmlStyles->borders->border[intval($xf["borderId"])],
"alignment" => $xf->alignment, "alignment" => $xf->alignment,
"protection" => $xf->protection, "protection" => $xf->protection,
"quotePrefix" => $quotePrefix,
); );
$styles[] = $style; $styles[] = $style;
@ -533,6 +538,7 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE
"border" => $xmlStyles->borders->border[intval($xf["borderId"])], "border" => $xmlStyles->borders->border[intval($xf["borderId"])],
"alignment" => $xf->alignment, "alignment" => $xf->alignment,
"protection" => $xf->protection, "protection" => $xf->protection,
"quotePrefix" => $quotePrefix,
); );
$cellStyles[] = $cellStyle; $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);
}
} }

View File

@ -91,6 +91,13 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp
*/ */
protected $_index; 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 * Create a new PHPExcel_Style
* *
@ -156,6 +163,17 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp
return $this->_parent; 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 * Apply styles from array
* *
@ -185,7 +203,8 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp
* 'rgb' => '808080' * 'rgb' => '808080'
* ) * )
* ) * )
* ) * ),
* 'quotePrefix' => true
* ) * )
* ); * );
* </code> * </code>
@ -463,6 +482,9 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp
if (array_key_exists('protection', $pStyles)) { if (array_key_exists('protection', $pStyles)) {
$this->getProtection()->applyFromArray($pStyles['protection']); $this->getProtection()->applyFromArray($pStyles['protection']);
} }
if (array_key_exists('quotePrefix', $pStyles)) {
$this->_quotePrefix = $pStyles['quotePrefix'];
}
} }
} else { } else {
throw new PHPExcel_Exception("Invalid style array passed."); 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; 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 * Get hash code
* *
@ -586,6 +640,7 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp
. $this->_numberFormat->getHashCode() . $this->_numberFormat->getHashCode()
. $hashConditionals . $hashConditionals
. $this->_protection->getHashCode() . $this->_protection->getHashCode()
. ($this->_quotePrefix ? 't' : 'f')
. __CLASS__ . __CLASS__
); );
} }

View File

@ -70,6 +70,13 @@ class PHPExcel_Writer_Excel2007 extends PHPExcel_Writer_Abstract implements PHPE
*/ */
private $_stylesConditionalHashTable; private $_stylesConditionalHashTable;
/**
* Private unique PHPExcel_Style HashTable
*
* @var PHPExcel_HashTable
*/
private $_styleHashTable;
/** /**
* Private unique PHPExcel_Style_Fill HashTable * 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', $hashTablesArray = array( '_stylesConditionalHashTable', '_fillHashTable', '_fontHashTable',
'_bordersHashTable', '_numFmtHashTable', '_drawingHashTable' '_bordersHashTable', '_numFmtHashTable', '_drawingHashTable',
'_styleHashTable'
); );
// Set HashTable variables // Set HashTable variables
@ -191,6 +199,7 @@ class PHPExcel_Writer_Excel2007 extends PHPExcel_Writer_Abstract implements PHPE
} }
// Create styles dictionaries // Create styles dictionaries
$this->_styleHashTable->addFromSource( $this->getWriterPart('Style')->allStyles($this->_spreadSheet) );
$this->_stylesConditionalHashTable->addFromSource( $this->getWriterPart('Style')->allConditionalStyles($this->_spreadSheet) ); $this->_stylesConditionalHashTable->addFromSource( $this->getWriterPart('Style')->allConditionalStyles($this->_spreadSheet) );
$this->_fillHashTable->addFromSource( $this->getWriterPart('Style')->allFills($this->_spreadSheet) ); $this->_fillHashTable->addFromSource( $this->getWriterPart('Style')->allFills($this->_spreadSheet) );
$this->_fontHashTable->addFromSource( $this->getWriterPart('Style')->allFonts($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; return $this->_stringTable;
} }
/**
* Get PHPExcel_Style HashTable
*
* @return PHPExcel_HashTable
*/
public function getStyleHashTable() {
return $this->_styleHashTable;
}
/** /**
* Get PHPExcel_Style_Conditional HashTable * Get PHPExcel_Style_Conditional HashTable
* *

View File

@ -397,6 +397,9 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
$objWriter->startElement('xf'); $objWriter->startElement('xf');
$objWriter->writeAttribute('xfId', 0); $objWriter->writeAttribute('xfId', 0);
$objWriter->writeAttribute('fontId', (int)$this->getParentWriter()->getFontHashTable()->getIndexForHashCode($pStyle->getFont()->getHashCode())); $objWriter->writeAttribute('fontId', (int)$this->getParentWriter()->getFontHashTable()->getIndexForHashCode($pStyle->getFont()->getHashCode()));
if ($pStyle->getQuotePrefix()) {
$objWriter->writeAttribute('quotePrefix', 1);
}
if ($pStyle->getNumberFormat()->getBuiltInFormatCode() === false) { if ($pStyle->getNumberFormat()->getBuiltInFormatCode() === false) {
$objWriter->writeAttribute('numFmtId', (int)($this->getParentWriter()->getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) + 164) ); $objWriter->writeAttribute('numFmtId', (int)($this->getParentWriter()->getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) + 164) );

View File

@ -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) - Style error with merged cells in PDF Writer
- Bugfix: (MBaker) - Problem with cloning worksheets - Bugfix: (MBaker) - Problem with cloning worksheets
- Feature: (amerov) - Implementation of the Excel HLOOKUP() function - 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: Fixed in develop branch for release v1.7.9:
- Feature: (MBaker) Include charts option for HTML Writer - Feature: (MBaker) Include charts option for HTML Writer