General - merged (with some localisation mods) from a pull request by alexgann - Add Currency detection to the Advanced Value Binder
This commit is contained in:
parent
b7dfeb9bb7
commit
013c18b859
|
@ -88,6 +88,26 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for currency
|
||||||
|
$currencyCode = PHPExcel_Shared_String::getCurrencyCode();
|
||||||
|
if (preg_match('/^'.preg_quote($currencyCode).' ?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/', $value)) {
|
||||||
|
// Convert value to number
|
||||||
|
$cell->setValueExplicit( trim(str_replace($currencyCode, '', $value)), PHPExcel_Cell_DataType::TYPE_NUMERIC);
|
||||||
|
// Set style
|
||||||
|
$cell->getParent()->getStyle( $cell->getCoordinate() )
|
||||||
|
->getNumberFormat()->setFormatCode(
|
||||||
|
str_replace('$', $currencyCode, PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE )
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
} elseif (preg_match('/^\$ ?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/', $value)) {
|
||||||
|
// Convert value to number
|
||||||
|
$cell->setValueExplicit( trim(str_replace('$', '', $value)), PHPExcel_Cell_DataType::TYPE_NUMERIC);
|
||||||
|
// Set style
|
||||||
|
$cell->getParent()->getStyle( $cell->getCoordinate() )
|
||||||
|
->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for time without seconds e.g. '9:45', '09:45'
|
// Check for time without seconds e.g. '9:45', '09:45'
|
||||||
if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d$/', $value)) {
|
if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d$/', $value)) {
|
||||||
list($h, $m) = explode(':', $value);
|
list($h, $m) = explode(':', $value);
|
||||||
|
|
|
@ -612,7 +612,7 @@ class PHPExcel_Shared_String
|
||||||
{
|
{
|
||||||
if (!isset(self::$_decimalSeparator)) {
|
if (!isset(self::$_decimalSeparator)) {
|
||||||
$localeconv = localeconv();
|
$localeconv = localeconv();
|
||||||
self::$_decimalSeparator = $localeconv['decimal_point'] != ''
|
self::$_decimalSeparator = ($localeconv['decimal_point'] != '')
|
||||||
? $localeconv['decimal_point'] : $localeconv['mon_decimal_point'];
|
? $localeconv['decimal_point'] : $localeconv['mon_decimal_point'];
|
||||||
|
|
||||||
if (self::$_decimalSeparator == '') {
|
if (self::$_decimalSeparator == '') {
|
||||||
|
@ -644,7 +644,7 @@ class PHPExcel_Shared_String
|
||||||
{
|
{
|
||||||
if (!isset(self::$_thousandsSeparator)) {
|
if (!isset(self::$_thousandsSeparator)) {
|
||||||
$localeconv = localeconv();
|
$localeconv = localeconv();
|
||||||
self::$_thousandsSeparator = $localeconv['thousands_sep'] != ''
|
self::$_thousandsSeparator = ($localeconv['thousands_sep'] != '')
|
||||||
? $localeconv['thousands_sep'] : $localeconv['mon_thousands_sep'];
|
? $localeconv['thousands_sep'] : $localeconv['mon_thousands_sep'];
|
||||||
}
|
}
|
||||||
return self::$_thousandsSeparator;
|
return self::$_thousandsSeparator;
|
||||||
|
@ -671,7 +671,7 @@ class PHPExcel_Shared_String
|
||||||
{
|
{
|
||||||
if (!isset(self::$_currencyCode)) {
|
if (!isset(self::$_currencyCode)) {
|
||||||
$localeconv = localeconv();
|
$localeconv = localeconv();
|
||||||
self::$_currencyCode = $localeconv['currency_symbol'] != ''
|
self::$_currencyCode = ($localeconv['currency_symbol'] != '')
|
||||||
? $localeconv['currency_symbol'] : $localeconv['int_curr_symbol'];
|
? $localeconv['currency_symbol'] : $localeconv['int_curr_symbol'];
|
||||||
|
|
||||||
if (self::$_currencyCode == '') {
|
if (self::$_currencyCode == '') {
|
||||||
|
|
|
@ -104,32 +104,35 @@ $objPHPExcel->getActiveSheet()->setCellValue('B11', '10%');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A12', 'Percentage value #2:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A12', 'Percentage value #2:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B12', '12.5%');
|
$objPHPExcel->getActiveSheet()->setCellValue('B12', '12.5%');
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Date value #1:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Currency value:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B13', '21 December 1983');
|
$objPHPExcel->getActiveSheet()->setCellValue('B13', '$12345');
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A14', 'Date value #2:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A14', 'Date value #1:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B14', '19-Dec-1960');
|
$objPHPExcel->getActiveSheet()->setCellValue('B14', '21 December 1983');
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A15', 'Date value #3:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A15', 'Date value #2:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B15', '19/12/1960');
|
$objPHPExcel->getActiveSheet()->setCellValue('B15', '19-Dec-1960');
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A16', 'Date value #4:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A16', 'Date value #3:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B16', '19-12-1960');
|
$objPHPExcel->getActiveSheet()->setCellValue('B16', '19/12/1960');
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A17', 'Date value #5:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A17', 'Date value #4:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B17', '1-Jan');
|
$objPHPExcel->getActiveSheet()->setCellValue('B17', '19-12-1960');
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A18', 'Time value #1:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A18', 'Date value #5:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B18', '01:30');
|
$objPHPExcel->getActiveSheet()->setCellValue('B18', '1-Jan');
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A19', 'Time value #2:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A19', 'Time value #1:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B19', '01:30:15');
|
$objPHPExcel->getActiveSheet()->setCellValue('B19', '01:30');
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A20', 'Date/Time value:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A20', 'Time value #2:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B20', '19-Dec-1960 01:30');
|
$objPHPExcel->getActiveSheet()->setCellValue('B20', '01:30:15');
|
||||||
|
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A21', 'Formula:');
|
$objPHPExcel->getActiveSheet()->setCellValue('A21', 'Date/Time value:');
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('B21', '=SUM(B2:B9)');
|
$objPHPExcel->getActiveSheet()->setCellValue('B21', '19-Dec-1960 01:30');
|
||||||
|
|
||||||
|
$objPHPExcel->getActiveSheet()->setCellValue('A22', 'Formula:');
|
||||||
|
$objPHPExcel->getActiveSheet()->setCellValue('B22', '=SUM(B2:B9)');
|
||||||
|
|
||||||
// Rename worksheet
|
// Rename worksheet
|
||||||
echo date('H:i:s') , " Rename worksheet" , PHP_EOL;
|
echo date('H:i:s') , " Rename worksheet" , PHP_EOL;
|
||||||
|
|
|
@ -79,6 +79,7 @@ Fixed in develop branch:
|
||||||
- Feature: (MBaker) Initial version of HTML Reader
|
- Feature: (MBaker) Initial version of HTML Reader
|
||||||
- Feature: (Progi1984) & (blazzy) Work items 9605 - Implement support for AutoFilter in PHPExcel_Writer_Excel5
|
- Feature: (Progi1984) & (blazzy) Work items 9605 - Implement support for AutoFilter in PHPExcel_Writer_Excel5
|
||||||
- Feature: (MBaker) Modified ERF and ERFC Engineering functions to accept Excel 2010's modified acceptance of negative arguments
|
- Feature: (MBaker) Modified ERF and ERFC Engineering functions to accept Excel 2010's modified acceptance of negative arguments
|
||||||
|
- General: (alexgann) Add Currency detection to the Advanced Value Binder
|
||||||
- Bugfix: (cyberconte) Patch 12318 - OOCalc cells containing <text:span> inside the <text:p> tag
|
- Bugfix: (cyberconte) Patch 12318 - OOCalc cells containing <text:span> inside the <text:p> tag
|
||||||
- Bugfix: (schir1964) Fix to listWorksheetInfo() method for OOCalc Reader
|
- Bugfix: (schir1964) Fix to listWorksheetInfo() method for OOCalc Reader
|
||||||
- Bugfix: (MBaker) Support for "e" (epoch) date format mask
|
- Bugfix: (MBaker) Support for "e" (epoch) date format mask
|
||||||
|
|
Loading…
Reference in New Issue