Resolve Issue with float values losing their decimal when read from SpreadsheetML
This commit is contained in:
parent
e6a4442d9a
commit
60ade80c0f
|
|
@ -49,6 +49,22 @@ class AddressHelper
|
|||
return $A1CellReference;
|
||||
}
|
||||
|
||||
protected static function convertSpreadsheetMLFormula(string $formula): string
|
||||
{
|
||||
$formula = substr($formula, 3);
|
||||
$temp = explode('"', $formula);
|
||||
$key = false;
|
||||
foreach ($temp as &$value) {
|
||||
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
||||
if ($key = !$key) {
|
||||
$value = str_replace(['[.', ':.', ']'], ['', ':', ''], $value);
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
|
||||
return implode('"', $temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a formula that uses R1C1/SpreadsheetXML format cell address to an A1 format cell address.
|
||||
*/
|
||||
|
|
@ -58,15 +74,8 @@ class AddressHelper
|
|||
int $currentColumnNumber = 1
|
||||
): string {
|
||||
if (substr($formula, 0, 3) == 'of:') {
|
||||
$formula = substr($formula, 3);
|
||||
$temp = explode('"', $formula);
|
||||
$key = false;
|
||||
foreach ($temp as &$value) {
|
||||
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
||||
if ($key = !$key) {
|
||||
$value = str_replace(['[.', '.', ']'], '', $value);
|
||||
}
|
||||
}
|
||||
// We have a SpreasheetML Formula
|
||||
return self::convertSpreadsheetMLFormula($formula);
|
||||
} else {
|
||||
// Convert R1C1 style references to A1 style references (but only when not quoted)
|
||||
$temp = explode('"', $formula);
|
||||
|
|
@ -87,8 +96,9 @@ class AddressHelper
|
|||
}
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
}
|
||||
unset($value);
|
||||
|
||||
// Then rebuild the formula string
|
||||
$formula = implode('"', $temp);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,4 +10,6 @@ return [
|
|||
'Formula arithmetic' => ['=SUM(E1:E5, D5)-C5', 'of:=SUM([.E1:.E5], [.D5])-[.C5]'],
|
||||
'Formula with comparison' => ['=IF(E1>E2, E3, E4)', 'of:=IF([.E1]>[.E2], [.E3], [.E4])'],
|
||||
'String literal' => ['=CONCAT("Result of formula expression =[.C3]+[.C4] is: ", C3+C4)', 'of:=CONCAT("Result of formula expression =[.C3]+[.C4] is: ", [.C3]+[.C4])'],
|
||||
'Simple numeric addition' => ['=1.23+2.34', 'of:=1.23+2.34'],
|
||||
'More complex formula with cells and numeric literals' => ['=D3+F7+G4+C6+5.67', 'of:=[.D3]+[.F7]+[.G4]+[.C6]+5.67'],
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue