116 public function __construct($isSupervisor = FALSE, $isConditional = FALSE)
119 parent::__construct($isSupervisor);
121 if ($isConditional) {
122 $this->_formatCode = NULL;
123 $this->_builtInFormatCode = FALSE;
135 return $this->_parent->getSharedComponent()->getNumberFormat();
146 return array(
'numberformat' => $array);
166 if (is_array($pStyles)) {
167 if ($this->_isSupervisor) {
170 if (array_key_exists(
'code', $pStyles)) {
187 if ($this->_isSupervisor) {
190 if ($this->_builtInFormatCode !==
false)
192 return self::builtInFormatCode($this->_builtInFormatCode);
208 if ($this->_isSupervisor) {
212 $this->_formatCode = $pValue;
213 $this->_builtInFormatCode = self::builtInFormatCodeIndex($pValue);
225 if ($this->_isSupervisor) {
240 if ($this->_isSupervisor) {
241 $styleArray = $this->
getStyleArray(
array(
'code' => self::builtInFormatCode($pValue)));
244 $this->_builtInFormatCode = $pValue;
245 $this->_formatCode = self::builtInFormatCode($pValue);
256 if (is_null(self::$_builtInFormats)) {
257 self::$_builtInFormats =
array();
261 self::$_builtInFormats[1] =
'0';
262 self::$_builtInFormats[2] =
'0.00';
263 self::$_builtInFormats[3] =
'#,##0';
264 self::$_builtInFormats[4] =
'#,##0.00';
266 self::$_builtInFormats[9] =
'0%';
267 self::$_builtInFormats[10] =
'0.00%';
268 self::$_builtInFormats[11] =
'0.00E+00';
269 self::$_builtInFormats[12] =
'# ?/?';
270 self::$_builtInFormats[13] =
'# ??/??';
271 self::$_builtInFormats[14] =
'mm-dd-yy';
272 self::$_builtInFormats[15] =
'd-mmm-yy';
273 self::$_builtInFormats[16] =
'd-mmm';
274 self::$_builtInFormats[17] =
'mmm-yy';
275 self::$_builtInFormats[18] =
'h:mm AM/PM';
276 self::$_builtInFormats[19] =
'h:mm:ss AM/PM';
277 self::$_builtInFormats[20] =
'h:mm';
278 self::$_builtInFormats[21] =
'h:mm:ss';
279 self::$_builtInFormats[22] =
'm/d/yy h:mm';
281 self::$_builtInFormats[37] =
'#,##0 ;(#,##0)';
282 self::$_builtInFormats[38] =
'#,##0 ;[Red](#,##0)';
283 self::$_builtInFormats[39] =
'#,##0.00;(#,##0.00)';
284 self::$_builtInFormats[40] =
'#,##0.00;[Red](#,##0.00)';
286 self::$_builtInFormats[44] =
'_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)';
287 self::$_builtInFormats[45] =
'mm:ss';
288 self::$_builtInFormats[46] =
'[h]:mm:ss';
289 self::$_builtInFormats[47] =
'mmss.0';
290 self::$_builtInFormats[48] =
'##0.0E+0';
291 self::$_builtInFormats[49] =
'@';
294 self::$_builtInFormats[27] =
'[$-404]e/m/d';
295 self::$_builtInFormats[30] =
'm/d/yy';
296 self::$_builtInFormats[36] =
'[$-404]e/m/d';
297 self::$_builtInFormats[50] =
'[$-404]e/m/d';
298 self::$_builtInFormats[57] =
'[$-404]e/m/d';
301 self::$_builtInFormats[59] =
't0';
302 self::$_builtInFormats[60] =
't0.00';
303 self::$_builtInFormats[61] =
't#,##0';
304 self::$_builtInFormats[62] =
't#,##0.00';
305 self::$_builtInFormats[67] =
't0%';
306 self::$_builtInFormats[68] =
't0.00%';
307 self::$_builtInFormats[69] =
't# ?/?';
308 self::$_builtInFormats[70] =
't# ??/??';
311 self::$_flippedBuiltInFormats = array_flip(self::$_builtInFormats);
324 $pIndex = intval($pIndex);
327 self::fillBuiltInFormatCodes();
330 if (isset(self::$_builtInFormats[$pIndex])) {
331 return self::$_builtInFormats[$pIndex];
346 self::fillBuiltInFormatCodes();
349 if (isset(self::$_flippedBuiltInFormats[$formatCode])) {
350 return self::$_flippedBuiltInFormats[$formatCode];
363 if ($this->_isSupervisor) {
368 . $this->_builtInFormatCode
442 $format = preg_replace(
'/^(\[\$[A-Z]*-[0-9A-F]*\])/i',
'',
$format);
455 $value = $dateObj->format(
$format);
460 if (
$format === self::FORMAT_PERCENTAGE) {
461 $value = round( (100 * $value), 0) .
'%';
463 if (preg_match(
'/\.[#0]+/i',
$format,
$m)) {
464 $s = substr(
$m[0], 0, 1) . (strlen(
$m[0]) - 1);
467 if (preg_match(
'/^[#0]+/',
$format,
$m)) {
472 $value = sprintf(
$format, 100 * $value);
478 $sign = ($value < 0) ?
'-' :
'';
480 $integerPart = floor(abs($value));
481 $decimalPart = trim(fmod(abs($value),1),
'0.');
482 $decimalLength = strlen($decimalPart);
483 $decimalDivisor = pow(10,$decimalLength);
487 $adjustedDecimalPart = $decimalPart/$GCD;
488 $adjustedDecimalDivisor = $decimalDivisor/$GCD;
490 if ((strpos(
$format,
'0') !==
false) || (strpos(
$format,
'#') !==
false) || (substr(
$format,0,3) ==
'? ?')) {
491 if ($integerPart == 0) {
494 $value =
"$sign$integerPart $adjustedDecimalPart/$adjustedDecimalDivisor";
496 $adjustedDecimalPart += $integerPart * $adjustedDecimalDivisor;
497 $value =
"$sign$adjustedDecimalPart/$adjustedDecimalDivisor";
502 $sign = ($number < 0.0);
503 $number = abs($number);
504 if (strpos(
$mask,
'.') !==
false) {
505 $numbers = explode(
'.', $number .
'.0');
506 $masks = explode(
'.',
$mask .
'.0');
507 $result1 = self::_complexNumberFormatMask($numbers[0], $masks[0], 1);
508 $result2 = strrev(self::_complexNumberFormatMask(strrev($numbers[1]), strrev($masks[1]), 1));
509 return (($sign) ?
'-' :
'') . $result1 .
'.' . $result2;
517 $divisor = 1 . $block[0];
518 $size = strlen($block[0]);
521 $blockValue = sprintf(
523 fmod($number, $divisor)
525 $number = floor($number / $divisor);
529 $mask = substr_replace(
$mask, $number, $offset, 0);
536 return (($sign) ?
'-' :
'') .
$result;
550 if (!is_numeric($value))
return $value;
559 $sections = explode(
';',
$format);
568 switch (count($sections)) {
574 $format = ($value >= 0) ? $sections[0] : $sections[1];
575 $value = abs($value);
580 $sections[0] : ( ($value < 0) ?
581 $sections[1] : $sections[2]);
582 $value = abs($value);
587 $sections[0] : ( ($value < 0) ?
588 $sections[1] : $sections[2]);
589 $value = abs($value);
602 $color_regex =
'/^\\[[a-zA-Z]+\\]/';
606 if (preg_match(
'/^(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy]/i',
$format)) {
607 self::_formatAsDate($value,
$format);
608 }
else if (preg_match(
'/%$/',
$format)) {
609 self::_formatAsPercentage($value,
$format);
611 if (
$format === self::FORMAT_CURRENCY_EUR_SIMPLE) {
612 $value =
'EUR ' . sprintf(
'%1.2f', $value);
629 $useThousands = preg_match(
'/(#,#|0,0)/',
$format);
640 if (preg_match(
'/(#|0)(,+)/',
$format, $matches)) {
641 $scale = pow(1000, strlen($matches[2]));
648 if (preg_match(
'/#?.*\?\/\?/',
$format,
$m)) {
650 if ($value != (
int)$value) {
651 self::_formatAsFraction($value,
$format);
658 $value = $value / $scale;
665 $number_regex =
"/(0+)(\.?)(0*)/";
666 if (preg_match($number_regex,
$m, $matches)) {
669 $right = $matches[3];
672 $minWidth = strlen($left) + strlen($dec) + strlen($right);
674 $value = number_format(
680 $value = preg_replace($number_regex, $value,
$format);
682 if (preg_match(
'/[0#]E[+-]0/i',
$format)) {
684 $value = sprintf(
'%5.2E', $value);
685 } elseif (preg_match(
'/0([^\d\.]+)0/',
$format)) {
686 $value = self::_complexNumberFormatMask($value,
$format);
688 $sprintf_pattern =
"%0$minWidth." . strlen($right) .
"f";
689 $value = sprintf($sprintf_pattern, $value);
690 $value = preg_replace($number_regex, $value,
$format);
695 if (preg_match(
'/\[\$(.*)\]/u',
$format,
$m)) {
697 $currencyFormat =
$m[0];
698 $currencyCode =
$m[1];
699 list($currencyCode) = explode(
'-',$currencyCode);
700 if ($currencyCode ==
'') {
703 $value = preg_replace(
'/\[\$([^\]]*)\]/u',$currencyCode,$value);
709 if ($callBack !== null) {
710 list($writerInstance,
$function) = $callBack;
711 $value = $writerInstance->$function($value, $formatColor);
static getCurrencyCode()
Get the currency code.
static ExcelToPHPObject($dateValue=0)
Convert a date from Excel to a PHP Date/Time object.
getSelectedCells()
Get the currently active cell coordinate in currently active sheet.
static getThousandsSeparator()
Get the thousands separator.
Create styles array
The data for the language used.
static getDecimalSeparator()
Get the decimal separator.
getActiveSheet()
Get the currently active sheet.