133 $this->_isSupervisor = $isSupervisor;
144 $this->_parent = $parent;
165 return $this->_parent->getSharedComponent()->getNumberFormat();
175 return $this->_parent->getActiveSheet();
208 return array(
'numberformat' => $array);
228 if (is_array($pStyles)) {
229 if ($this->_isSupervisor) {
232 if (array_key_exists(
'code', $pStyles)) {
237 throw new Exception(
"Invalid style array passed.");
249 if ($this->_isSupervisor) {
252 if ($this->_builtInFormatCode !==
false)
270 if ($this->_isSupervisor) {
271 $styleArray = $this->
getStyleArray(array(
'code' => $pValue));
274 $this->_formatCode = $pValue;
287 if ($this->_isSupervisor) {
302 if ($this->_isSupervisor) {
303 $styleArray = $this->
getStyleArray(array(
'code' => self::builtInFormatCode($pValue)));
306 $this->_builtInFormatCode = $pValue;
318 if (is_null(self::$_builtInFormats)) {
319 self::$_builtInFormats = array();
323 self::$_builtInFormats[1] =
'0';
324 self::$_builtInFormats[2] =
'0.00';
325 self::$_builtInFormats[3] =
'#,##0';
326 self::$_builtInFormats[4] =
'#,##0.00';
328 self::$_builtInFormats[9] =
'0%';
329 self::$_builtInFormats[10] =
'0.00%';
330 self::$_builtInFormats[11] =
'0.00E+00';
331 self::$_builtInFormats[12] =
'# ?/?';
332 self::$_builtInFormats[13] =
'# ??/??';
333 self::$_builtInFormats[14] =
'mm-dd-yy';
334 self::$_builtInFormats[15] =
'd-mmm-yy';
335 self::$_builtInFormats[16] =
'd-mmm';
336 self::$_builtInFormats[17] =
'mmm-yy';
337 self::$_builtInFormats[18] =
'h:mm AM/PM';
338 self::$_builtInFormats[19] =
'h:mm:ss AM/PM';
339 self::$_builtInFormats[20] =
'h:mm';
340 self::$_builtInFormats[21] =
'h:mm:ss';
341 self::$_builtInFormats[22] =
'm/d/yy h:mm';
343 self::$_builtInFormats[37] =
'#,##0 ;(#,##0)';
344 self::$_builtInFormats[38] =
'#,##0 ;[Red](#,##0)';
345 self::$_builtInFormats[39] =
'#,##0.00;(#,##0.00)';
346 self::$_builtInFormats[40] =
'#,##0.00;[Red](#,##0.00)';
348 self::$_builtInFormats[44] =
'_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)';
349 self::$_builtInFormats[45] =
'mm:ss';
350 self::$_builtInFormats[46] =
'[h]:mm:ss';
351 self::$_builtInFormats[47] =
'mmss.0';
352 self::$_builtInFormats[48] =
'##0.0E+0';
353 self::$_builtInFormats[49] =
'@';
356 self::$_builtInFormats[27] =
'[$-404]e/m/d';
357 self::$_builtInFormats[30] =
'm/d/yy';
358 self::$_builtInFormats[36] =
'[$-404]e/m/d';
359 self::$_builtInFormats[50] =
'[$-404]e/m/d';
360 self::$_builtInFormats[57] =
'[$-404]e/m/d';
363 self::$_builtInFormats[59] =
't0';
364 self::$_builtInFormats[60] =
't0.00';
365 self::$_builtInFormats[61] =
't#,##0';
366 self::$_builtInFormats[62] =
't#,##0.00';
367 self::$_builtInFormats[67] =
't0%';
368 self::$_builtInFormats[68] =
't0.00%';
369 self::$_builtInFormats[69] =
't# ?/?';
370 self::$_builtInFormats[70] =
't# ??/??';
373 self::$_flippedBuiltInFormats = array_flip(self::$_builtInFormats);
386 $pIndex = intval($pIndex);
392 if (isset(self::$_builtInFormats[$pIndex])) {
393 return self::$_builtInFormats[$pIndex];
411 if (isset(self::$_flippedBuiltInFormats[$formatCode])) {
412 return self::$_flippedBuiltInFormats[$formatCode];
425 if ($this->_isSupervisor) {
430 . $this->_builtInFormatCode
440 $vars = get_object_vars($this);
441 foreach ($vars as $key => $value) {
442 if ((is_object($value)) && ($key !=
'_parent')) {
443 $this->$key = clone $value;
445 $this->$key = $value;
504 if (!is_numeric($value))
return $value;
513 $sections = explode(
';', $format);
522 switch (count($sections)) {
524 $format = $sections[0];
528 $format = ($value >= 0) ? $sections[0] : $sections[1];
529 $value = abs($value);
533 $format = ($value > 0) ?
534 $sections[0] : ( ($value < 0) ?
535 $sections[1] : $sections[2]);
536 $value = abs($value);
540 $format = ($value > 0) ?
541 $sections[0] : ( ($value < 0) ?
542 $sections[1] : $sections[2]);
543 $value = abs($value);
548 $format = $sections[0];
553 $formatColor = $format;
556 $color_regex =
'/^\\[[a-zA-Z]+\\]/';
557 $format = preg_replace($color_regex,
'', $format);
560 if (preg_match(
'/^(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy]/i', $format)) {
566 $format = preg_replace(
'/^(\[\$[A-Z]*-[0-9A-F]*\])/i',
'', $format);
569 $format = strtolower($format);
571 $format = strtr($format,self::$_dateFormatReplacements);
572 if (!strpos($format,
'A')) {
573 $format = strtr($format,self::$_dateFormatReplacements24);
575 $format = strtr($format,self::$_dateFormatReplacements12);
579 $value = $dateObj->format($format);
581 }
else if (preg_match(
'/%$/', $format)) {
582 if ($format === self::FORMAT_PERCENTAGE) {
583 $value = round( (100 * $value), 0) .
'%';
585 if (preg_match(
'/\.[#0]+/i', $format, $m)) {
586 $s = substr($m[0], 0, 1) . (strlen($m[0]) - 1);
587 $format = str_replace($m[0], $s, $format);
589 if (preg_match(
'/^[#0]+/', $format, $m)) {
590 $format = str_replace($m[0], strlen($m[0]), $format);
592 $format =
'%' . str_replace(
'%',
'f%%', $format);
594 $value = sprintf($format, 100 * $value);
598 if ($format === self::FORMAT_CURRENCY_EUR_SIMPLE) {
599 $value =
'EUR ' . sprintf(
'%1.2f', $value);
603 $format = preg_replace(
'/_./',
'', $format);
606 $format = preg_replace(
"/\\\\/",
'', $format);
609 $format = str_replace(array(
'"',
'*'),
'', $format);
614 $useThousands = preg_match(
'/(#,#|0,0)/', $format);
616 $format = preg_replace(
'/0,0/',
'00', $format);
617 $format = preg_replace(
'/#,#/',
'##', $format);
625 if (preg_match(
'/(#|0)(,+)/', $format, $matches)) {
626 $scale = pow(1000, strlen($matches[2]));
629 $format = preg_replace(
'/0,+/',
'0', $format);
630 $format = preg_replace(
'/#,+/',
'#', $format);
633 if (preg_match(
'/#?.*\?\/\?/', $format, $m)) {
635 if ($value != (
int)$value) {
636 $sign = ($value < 0) ?
'-' :
'';
638 $integerPart = floor(abs($value));
639 $decimalPart = trim(fmod(abs($value),1),
'0.');
640 $decimalLength = strlen($decimalPart);
641 $decimalDivisor = pow(10,$decimalLength);
645 $adjustedDecimalPart = $decimalPart/$GCD;
646 $adjustedDecimalDivisor = $decimalDivisor/$GCD;
648 if ((strpos($format,
'0') !==
false) || (strpos($format,
'#') !==
false) || (substr($format,0,3) ==
'? ?')) {
649 if ($integerPart == 0) { $integerPart =
''; }
650 $value =
"$sign$integerPart $adjustedDecimalPart/$adjustedDecimalDivisor";
652 $adjustedDecimalPart += $integerPart * $adjustedDecimalDivisor;
653 $value =
"$sign$adjustedDecimalPart/$adjustedDecimalDivisor";
661 $value = $value / $scale;
664 $format = preg_replace(
'/\\#/',
'', $format);
667 $m = preg_replace($n,
'', $format);
668 $number_regex =
"/(0+)(\.?)(0*)/";
669 if (preg_match($number_regex, $m, $matches)) {
672 $right = $matches[3];
675 $minWidth = strlen($left) + strlen($dec) + strlen($right);
678 $value = number_format(
685 $sprintf_pattern =
"%0$minWidth." . strlen($right) .
"f";
686 $value = sprintf($sprintf_pattern, $value);
689 $value = preg_replace($number_regex, $value, $format);
692 if (preg_match(
'/\[\$(.*)\]/u', $format, $m)) {
694 $currencyFormat = $m[0];
695 $currencyCode = $m[1];
696 list($currencyCode) = explode(
'-',$currencyCode);
697 if ($currencyCode ==
'') {
700 $value = preg_replace(
'/\[\$([^\]]*)\]/u',$currencyCode,$value);
706 if ($callBack !== null) {
707 list($writerInstance, $function) = $callBack;
708 $value = $writerInstance->$function($value, $formatColor);