mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-22 21:36:05 +03:00
Minor performance tweaks when working with alternating blocks in a string
git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@68309 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
parent
8218d04b0f
commit
0fd77aa397
@ -1960,9 +1960,10 @@ class PHPExcel_Calculation {
|
||||
// So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
|
||||
// the formula
|
||||
$temp = explode('"',$formula);
|
||||
foreach($temp as $i => &$value) {
|
||||
// Only count/replace in alternate array entries
|
||||
if (($i % 2) == 0) {
|
||||
$i = false;
|
||||
foreach($temp as &$value) {
|
||||
// Only count/replace in alternating array entries
|
||||
if ($i = !$i) {
|
||||
$value = preg_replace($from,$to,$value);
|
||||
$value = self::_translateSeparator($fromSeparator,$toSeparator,$value,$inBraces);
|
||||
}
|
||||
@ -2553,9 +2554,10 @@ class PHPExcel_Calculation {
|
||||
$temp = explode('"',$formula);
|
||||
// Open and Closed counts used for trapping mismatched braces in the formula
|
||||
$openCount = $closeCount = 0;
|
||||
foreach($temp as $i => &$value) {
|
||||
// Only count/replace in alternate array entries
|
||||
if (($i % 2) == 0) {
|
||||
$i = false;
|
||||
foreach($temp as &$value) {
|
||||
// Only count/replace in alternating array entries
|
||||
if ($i = !$i) {
|
||||
$openCount += substr_count($value,'{');
|
||||
$closeCount += substr_count($value,'}');
|
||||
$value = str_replace($matrixReplaceFrom,$matrixReplaceTo,$value);
|
||||
|
@ -663,9 +663,10 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
|
||||
$columnNumber = PHPExcel_Cell::columnIndexFromString($columnID);
|
||||
// Convert R1C1 style references to A1 style references (but only when not quoted)
|
||||
$temp = explode('"',$cellDataFormula);
|
||||
foreach($temp as $key => &$value) {
|
||||
$key = false;
|
||||
foreach($temp as &$value) {
|
||||
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
||||
if (($key % 2) == 0) {
|
||||
if ($key = !$key) {
|
||||
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
|
||||
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
|
||||
// through the formula from left to right. Reversing means that we work right to left.through
|
||||
|
@ -493,9 +493,10 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
|
||||
// echo 'Formula: '.$cellDataFormula.'<br />';
|
||||
$cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
|
||||
$temp = explode('"',$cellDataFormula);
|
||||
foreach($temp as $key => &$value) {
|
||||
$tKey = false;
|
||||
foreach($temp as &$value) {
|
||||
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
||||
if (($key % 2) == 0) {
|
||||
if ($tKey = !$tKey) {
|
||||
$value = preg_replace('/\[\.(.*):\.(.*)\]/Ui','$1:$2',$value);
|
||||
$value = preg_replace('/\[\.(.*)\]/Ui','$1',$value);
|
||||
$value = PHPExcel_Calculation::_translateSeparator(';',',',$value,$inBraces);
|
||||
|
@ -270,9 +270,10 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
|
||||
case 'E' : $cellDataFormula = '='.substr($rowDatum,1);
|
||||
// Convert R1C1 style references to A1 style references (but only when not quoted)
|
||||
$temp = explode('"',$cellDataFormula);
|
||||
foreach($temp as $key => &$value) {
|
||||
$key = false;
|
||||
foreach($temp as &$value) {
|
||||
// Only count/replace in alternate array entries
|
||||
if (($key % 2) == 0) {
|
||||
if ($key = !$key) {
|
||||
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
|
||||
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
|
||||
// through the formula from left to right. Reversing means that we work right to left.through
|
||||
|
@ -348,9 +348,10 @@ class PHPExcel_ReferenceHelper
|
||||
public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, $sheetName = '') {
|
||||
// Update cell references in the formula
|
||||
$formulaBlocks = explode('"',$pFormula);
|
||||
foreach($formulaBlocks as $i => &$formulaBlock) {
|
||||
// Ignore blocks that were enclosed in quotes (even entries in the $formulaBlocks array after the explode)
|
||||
if (($i % 2) == 0) {
|
||||
$i = false;
|
||||
foreach($formulaBlocks as &$formulaBlock) {
|
||||
// Ignore blocks that were enclosed in quotes (alternating entries in the $formulaBlocks array after the explode)
|
||||
if ($i = !$i) {
|
||||
$adjustCount = 0;
|
||||
$newCellTokens = $cellTokens = array();
|
||||
// Search for row ranges (e.g. 'Sheet1'!3:5 or 3:5) with or without $ absolutes (e.g. $3:5)
|
||||
|
Loading…
Reference in New Issue
Block a user