Merge changes from the 1.7.9 develop branch since 1.7.9 release

This commit is contained in:
Mark Baker 2013-07-12 22:19:40 +01:00
parent a453d68430
commit 46a5fd4c13
10 changed files with 168 additions and 67 deletions

View File

@ -307,9 +307,9 @@ class Calculation_LookupRef {
if (strpos($cellAddress,'!') !== false) { if (strpos($cellAddress,'!') !== false) {
list($sheetName, $cellAddress) = explode('!',$cellAddress); list($sheetName, $cellAddress) = explode('!',$cellAddress);
$sheetName = trim($sheetName, "'"); $sheetName = trim($sheetName, "'");
$pSheet = $pCell->getParent()->getParent()->getSheetByName($sheetName); $pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
} else { } else {
$pSheet = $pCell->getParent(); $pSheet = $pCell->getWorksheet();
} }
return Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, false); return Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, false);
@ -318,9 +318,9 @@ class Calculation_LookupRef {
if (strpos($cellAddress,'!') !== false) { if (strpos($cellAddress,'!') !== false) {
list($sheetName,$cellAddress) = explode('!',$cellAddress); list($sheetName,$cellAddress) = explode('!',$cellAddress);
$sheetName = trim($sheetName, "'"); $sheetName = trim($sheetName, "'");
$pSheet = $pCell->getParent()->getParent()->getSheetByName($sheetName); $pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
} else { } else {
$pSheet = $pCell->getParent(); $pSheet = $pCell->getWorksheet();
} }
return Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false); return Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false);
@ -412,9 +412,9 @@ class Calculation_LookupRef {
} }
if ($sheetName !== null) { if ($sheetName !== null) {
$pSheet = $pCell->getParent()->getParent()->getSheetByName($sheetName); $pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
} else { } else {
$pSheet = $pCell->getParent(); $pSheet = $pCell->getWorksheet();
} }
return Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, False); return Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, False);

View File

@ -471,7 +471,7 @@ class Cell
/** /**
* Get parent worksheet * Get parent worksheet
* *
* @return PHPExcel\Worksheet * @return PHPExcel\CachedObjectStorage_CacheBase
*/ */
public function getParent() { public function getParent() {
return $this->_parent; return $this->_parent;

View File

@ -492,6 +492,10 @@ class Reader_Excel2007 extends Reader_Abstract implements Reader_IReader
//$numFmt = str_replace('mm', 'i', $numFmt); //$numFmt = str_replace('mm', 'i', $numFmt);
//$numFmt = str_replace('h', 'H', $numFmt); //$numFmt = str_replace('h', 'H', $numFmt);
$quotePrefix = false;
if (isset($xf["quotePrefix"])) {
$quotePrefix = (boolean) $xf["quotePrefix"];
}
$style = (object) array( $style = (object) array(
"numFmt" => $numFmt, "numFmt" => $numFmt,
"font" => $xmlStyles->fonts->font[intval($xf["fontId"])], "font" => $xmlStyles->fonts->font[intval($xf["fontId"])],
@ -499,6 +503,7 @@ class Reader_Excel2007 extends Reader_Abstract implements Reader_IReader
"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;
@ -526,6 +531,7 @@ class Reader_Excel2007 extends Reader_Abstract implements Reader_IReader
"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;
@ -1848,6 +1854,11 @@ class Reader_Excel2007 extends Reader_Abstract implements Reader_IReader
$docStyle->getProtection()->setHidden(Style_Protection::PROTECTION_UNPROTECTED); $docStyle->getProtection()->setHidden(Style_Protection::PROTECTION_UNPROTECTED);
} }
} }
}
// top-level style settings
if (isset($style->quotePrefix)) {
$docStyle->setQuotePrefix($style->quotePrefix);
} }
} }

View File

@ -1562,11 +1562,15 @@ class Reader_Excel5 extends Reader_Abstract implements Reader_IReader
private function _readFilepass() private function _readFilepass()
{ {
$length = self::_GetInt2d($this->_data, $this->_pos + 2); $length = self::_GetInt2d($this->_data, $this->_pos + 2);
// $recordData = substr($this->_data, $this->_pos + 4, $length); $recordData = substr($this->_data, $this->_pos + 4, $length);
// move stream pointer to next record // move stream pointer to next record
$this->_pos += 4 + $length; $this->_pos += 4 + $length;
if (!$this->_readDataOnly) {
// offset: 0; size: 2; 16-bit hash value of password
$password = strtoupper(dechex(self::_GetInt2d($recordData, 0))); // the hashed password
}
throw new Reader_Exception('Cannot read encrypted file'); throw new Reader_Exception('Cannot read encrypted file');
} }
@ -1829,6 +1833,9 @@ class Reader_Excel5 extends Reader_Abstract implements Reader_IReader
case 3: case 3:
$objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_RIGHT); $objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_RIGHT);
break; break;
case 4:
$objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_FILL);
break;
case 5: case 5:
$objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_JUSTIFY); $objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_JUSTIFY);
break; break;

View File

@ -86,6 +86,13 @@ class Style extends Style_Supervisor implements IComparable
*/ */
protected $_protection; protected $_protection;
/**
* Use Quote Prefix when displaying in cell editor. Only used for real style.
*
* @var boolean
*/
protected $_quotePrefix = false;
/** /**
* Index of style in collection. Only used for real style. * Index of style in collection. Only used for real style.
* *
@ -158,6 +165,17 @@ class Style extends Style_Supervisor implements IComparable
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
* *
@ -187,7 +205,8 @@ class Style extends Style_Supervisor implements IComparable
* 'rgb' => '808080' * 'rgb' => '808080'
* ) * )
* ) * )
* ) * ),
* 'quotePrefix' => true
* ) * )
* ); * );
* </code> * </code>
@ -465,6 +484,9 @@ class Style extends Style_Supervisor implements IComparable
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 Exception("Invalid style array passed."); throw new Exception("Invalid style array passed.");
@ -568,6 +590,38 @@ class Style extends Style_Supervisor implements IComparable
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
* *
@ -588,6 +642,7 @@ class Style extends Style_Supervisor implements IComparable
. $this->_numberFormat->getHashCode() . $this->_numberFormat->getHashCode()
. $hashConditionals . $hashConditionals
. $this->_protection->getHashCode() . $this->_protection->getHashCode()
. ($this->_quotePrefix ? 't' : 'f')
. __CLASS__ . __CLASS__
); );
} }

View File

@ -44,12 +44,15 @@ class Style_Alignment extends Style_Supervisor implements IComparable
const HORIZONTAL_CENTER = 'center'; const HORIZONTAL_CENTER = 'center';
const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous'; const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous';
const HORIZONTAL_JUSTIFY = 'justify'; const HORIZONTAL_JUSTIFY = 'justify';
const HORIZONTAL_FILL = 'fill';
const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only
/* Vertical alignment styles */ /* Vertical alignment styles */
const VERTICAL_BOTTOM = 'bottom'; const VERTICAL_BOTTOM = 'bottom';
const VERTICAL_TOP = 'top'; const VERTICAL_TOP = 'top';
const VERTICAL_CENTER = 'center'; const VERTICAL_CENTER = 'center';
const VERTICAL_JUSTIFY = 'justify'; const VERTICAL_JUSTIFY = 'justify';
const VERTICAL_DISTRIBUTED = 'distributed'; // Excel2007 only
/** /**
* Horizontal * Horizontal

View File

@ -65,6 +65,13 @@ class Writer_Excel2007 extends Writer_Abstract implements Writer_IWriter
*/ */
private $_stringTable = array(); private $_stringTable = array();
/**
* Private unique PHPExcel_Style HashTable
*
* @var PHPExcel_HashTable
*/
private $_styleHashTable;
/** /**
* Private unique PHPExcel\Style_Conditional HashTable * Private unique PHPExcel\Style_Conditional HashTable
* *
@ -117,7 +124,8 @@ class Writer_Excel2007 extends Writer_Abstract implements Writer_IWriter
// Assign PHPExcel // Assign PHPExcel
$this->setPHPExcel($pPHPExcel); $this->setPHPExcel($pPHPExcel);
$writerPartsArray = array( 'stringtable' => __NAMESPACE__ . '\Writer_Excel2007_StringTable', $writerPartsArray = array(
'stringtable' => __NAMESPACE__ . '\Writer_Excel2007_StringTable',
'contenttypes' => __NAMESPACE__ . '\Writer_Excel2007_ContentTypes', 'contenttypes' => __NAMESPACE__ . '\Writer_Excel2007_ContentTypes',
'docprops' => __NAMESPACE__ . '\Writer_Excel2007_DocProps', 'docprops' => __NAMESPACE__ . '\Writer_Excel2007_DocProps',
'rels' => __NAMESPACE__ . '\Writer_Excel2007_Rels', 'rels' => __NAMESPACE__ . '\Writer_Excel2007_Rels',
@ -137,7 +145,8 @@ class Writer_Excel2007 extends Writer_Abstract implements Writer_IWriter
} }
$hashTablesArray = array( '_stylesConditionalHashTable', '_fillHashTable', '_fontHashTable', $hashTablesArray = array( '_stylesConditionalHashTable', '_fillHashTable', '_fontHashTable',
'_bordersHashTable', '_numFmtHashTable', '_drawingHashTable' '_bordersHashTable', '_numFmtHashTable', '_drawingHashTable',
'_styleHashTable'
); );
// Set HashTable variables // Set HashTable variables
@ -193,6 +202,7 @@ class Writer_Excel2007 extends Writer_Abstract implements Writer_IWriter
} }
// 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) );
@ -397,6 +407,15 @@ class Writer_Excel2007 extends Writer_Abstract implements Writer_IWriter
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

@ -400,6 +400,9 @@ class Writer_Excel2007_Style extends Writer_Excel2007_WriterPart
$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) );
} else { } else {

View File

@ -416,7 +416,8 @@ class Writer_Excel5_Xf
* @static array of int * @static array of int
* *
*/ */
private static $_mapFillType = array( Style_Fill::FILL_NONE => 0x00, private static $_mapFillType = array(
Style_Fill::FILL_NONE => 0x00,
Style_Fill::FILL_SOLID => 0x01, Style_Fill::FILL_SOLID => 0x01,
Style_Fill::FILL_PATTERN_MEDIUMGRAY => 0x02, Style_Fill::FILL_PATTERN_MEDIUMGRAY => 0x02,
Style_Fill::FILL_PATTERN_DARKGRAY => 0x03, Style_Fill::FILL_PATTERN_DARKGRAY => 0x03,
@ -455,13 +456,16 @@ class Writer_Excel5_Xf
* @static array of int * @static array of int
* *
*/ */
private static $_mapHAlign = array( Style_Alignment::HORIZONTAL_GENERAL => 0, private static $_mapHAlign = array(
Style_Alignment::HORIZONTAL_GENERAL => 0,
Style_Alignment::HORIZONTAL_LEFT => 1, Style_Alignment::HORIZONTAL_LEFT => 1,
Style_Alignment::HORIZONTAL_CENTER => 2, Style_Alignment::HORIZONTAL_CENTER => 2,
Style_Alignment::HORIZONTAL_RIGHT => 3, Style_Alignment::HORIZONTAL_RIGHT => 3,
Style_Alignment::HORIZONTAL_FILL => 4,
Style_Alignment::HORIZONTAL_JUSTIFY => 5, Style_Alignment::HORIZONTAL_JUSTIFY => 5,
Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6, Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6,
); );
/** /**
* Map to BIFF2-BIFF8 codes for horizontal alignment * Map to BIFF2-BIFF8 codes for horizontal alignment
* *

View File

@ -34,9 +34,8 @@ define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London'); date_default_timezone_set('Europe/London');
/** Include PHPExcel */ /** Include PHPExcel Bootstrap */
require_once '../Classes/PHPExcel.php'; require_once '../Classes/Bootstrap.php';
/* /*
After doing some test, I've got these results benchmarked After doing some test, I've got these results benchmarked
@ -52,9 +51,9 @@ for writing to Excel2007:
15000 465 15000 465
*/ */
// Create new PHPExcel object // Create new PHPExcel Workbook object
echo date('H:i:s') , " Create new PHPExcel object" , EOL; echo date('H:i:s') , " Create new PHPExcel Workbook object" , EOL;
$objPHPExcel = new PHPExcel(); $objPHPExcel = new PHPExcel\Workbook();
// Set document properties // Set document properties
echo date('H:i:s') , " Set properties" , EOL; echo date('H:i:s') , " Set properties" , EOL;
@ -117,7 +116,7 @@ $objPHPExcel->setActiveSheetIndex(0);
echo date('H:i:s') , " Write to Excel5 format" , EOL; echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter = PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__)); $objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime; $callTime = $callEndTime - $callStartTime;