mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-26 07:16:03 +03:00
Minor work on Excel2003XML Reader (not yet complete)
git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@69208 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
parent
bba779bfc3
commit
5b71914eea
@ -659,40 +659,56 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($hasCalculatedValue) {
|
if ($hasCalculatedValue) {
|
||||||
|
// echo 'FORMULA<br />';
|
||||||
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
|
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
|
||||||
$columnNumber = PHPExcel_Cell::columnIndexFromString($columnID);
|
$columnNumber = PHPExcel_Cell::columnIndexFromString($columnID);
|
||||||
// Convert R1C1 style references to A1 style references (but only when not quoted)
|
if (substr($cellDataFormula,0,3) == 'of:') {
|
||||||
$temp = explode('"',$cellDataFormula);
|
$cellDataFormula = substr($cellDataFormula,3);
|
||||||
$key = false;
|
// echo 'Before: ',$cellDataFormula,'<br />';
|
||||||
foreach($temp as &$value) {
|
$temp = explode('"',$cellDataFormula);
|
||||||
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
$key = false;
|
||||||
if ($key = !$key) {
|
foreach($temp as &$value) {
|
||||||
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
|
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
||||||
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
|
if ($key = !$key) {
|
||||||
// through the formula from left to right. Reversing means that we work right to left.through
|
$value = str_replace(array('[.','.',']'),'',$value);
|
||||||
// the formula
|
}
|
||||||
$cellReferences = array_reverse($cellReferences);
|
}
|
||||||
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
|
} else {
|
||||||
// then modify the formula to use that new reference
|
// Convert R1C1 style references to A1 style references (but only when not quoted)
|
||||||
foreach($cellReferences as $cellReference) {
|
// echo 'Before: ',$cellDataFormula,'<br />';
|
||||||
$rowReference = $cellReference[2][0];
|
$temp = explode('"',$cellDataFormula);
|
||||||
// Empty R reference is the current row
|
$key = false;
|
||||||
if ($rowReference == '') $rowReference = $rowID;
|
foreach($temp as &$value) {
|
||||||
// Bracketed R references are relative to the current row
|
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
||||||
if ($rowReference{0} == '[') $rowReference = $rowID + trim($rowReference,'[]');
|
if ($key = !$key) {
|
||||||
$columnReference = $cellReference[4][0];
|
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
|
||||||
// Empty C reference is the current column
|
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
|
||||||
if ($columnReference == '') $columnReference = $columnNumber;
|
// through the formula from left to right. Reversing means that we work right to left.through
|
||||||
// Bracketed C references are relative to the current column
|
// the formula
|
||||||
if ($columnReference{0} == '[') $columnReference = $columnNumber + trim($columnReference,'[]');
|
$cellReferences = array_reverse($cellReferences);
|
||||||
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
|
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
|
||||||
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
|
// then modify the formula to use that new reference
|
||||||
|
foreach($cellReferences as $cellReference) {
|
||||||
|
$rowReference = $cellReference[2][0];
|
||||||
|
// Empty R reference is the current row
|
||||||
|
if ($rowReference == '') $rowReference = $rowID;
|
||||||
|
// Bracketed R references are relative to the current row
|
||||||
|
if ($rowReference{0} == '[') $rowReference = $rowID + trim($rowReference,'[]');
|
||||||
|
$columnReference = $cellReference[4][0];
|
||||||
|
// Empty C reference is the current column
|
||||||
|
if ($columnReference == '') $columnReference = $columnNumber;
|
||||||
|
// Bracketed C references are relative to the current column
|
||||||
|
if ($columnReference{0} == '[') $columnReference = $columnNumber + trim($columnReference,'[]');
|
||||||
|
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
|
||||||
|
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($value);
|
unset($value);
|
||||||
// Then rebuild the formula string
|
// Then rebuild the formula string
|
||||||
$cellDataFormula = implode('"',$temp);
|
$cellDataFormula = implode('"',$temp);
|
||||||
|
// echo 'After: ',$cellDataFormula,'<br />';
|
||||||
}
|
}
|
||||||
|
|
||||||
// echo 'Cell '.$columnID.$rowID.' is a '.$type.' with a value of '.(($hasCalculatedValue) ? $cellDataFormula : $cellValue).'<br />';
|
// echo 'Cell '.$columnID.$rowID.' is a '.$type.' with a value of '.(($hasCalculatedValue) ? $cellDataFormula : $cellValue).'<br />';
|
||||||
|
@ -35,7 +35,16 @@ require_once '../Classes/PHPExcel/IOFactory.php';
|
|||||||
|
|
||||||
|
|
||||||
echo date('H:i:s') . " Load from XML file\n";
|
echo date('H:i:s') . " Load from XML file\n";
|
||||||
$objPHPExcel = PHPExcel_IOFactory::load("XMLTest.xml");
|
$inputFileName = "XMLTest.xml";
|
||||||
|
|
||||||
|
/** Identify the type of $inputFileName **/
|
||||||
|
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
|
||||||
|
echo 'Loading ',$inputFileName,' using ',$inputFileType," Reader\n";
|
||||||
|
|
||||||
|
/** Create a new Reader of the type that has been identified **/
|
||||||
|
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||||
|
/** Load $inputFileName to a PHPExcel Object **/
|
||||||
|
$objPHPExcel = $objReader->load($inputFileName);
|
||||||
|
|
||||||
echo date('H:i:s') . " Write to Excel2007 format\n";
|
echo date('H:i:s') . " Write to Excel2007 format\n";
|
||||||
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
|
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
|
||||||
|
Loading…
Reference in New Issue
Block a user