Fix to OOCalc Reader for percentage and currency datatypes

This commit is contained in:
Mark Baker 2012-07-23 12:29:15 +01:00
parent 19dfbfe418
commit 868d14a84d

View File

@ -574,6 +574,22 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
$type = PHPExcel_Cell_DataType::TYPE_BOOL; $type = PHPExcel_Cell_DataType::TYPE_BOOL;
$dataValue = ($allCellDataText == 'TRUE') ? True : False; $dataValue = ($allCellDataText == 'TRUE') ? True : False;
break; break;
case 'percentage' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$dataValue = (float) $cellDataOfficeAttributes['value'];
if (floor($dataValue) == $dataValue) {
$dataValue = (integer) $dataValue;
}
$formatting = PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00;
break;
case 'currency' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$dataValue = (float) $cellDataOfficeAttributes['value'];
if (floor($dataValue) == $dataValue) {
$dataValue = (integer) $dataValue;
}
$formatting = PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
break;
case 'float' : case 'float' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$dataValue = (float) $cellDataOfficeAttributes['value']; $dataValue = (float) $cellDataOfficeAttributes['value'];
@ -640,8 +656,7 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
// echo 'Forumla result is '.$dataValue.'<br />'; // echo 'Forumla result is '.$dataValue.'<br />';
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($dataValue); $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($dataValue);
} }
if (($cellDataOfficeAttributes['value-type'] == 'date') || if ($formatting !== NULL) {
($cellDataOfficeAttributes['value-type'] == 'time')) {
$objPHPExcel->getActiveSheet()->getStyle($columnID.$rowID)->getNumberFormat()->setFormatCode($formatting); $objPHPExcel->getActiveSheet()->getStyle($columnID.$rowID)->getNumberFormat()->setFormatCode($formatting);
} }
if ($hyperlink !== NULL) { if ($hyperlink !== NULL) {