Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 148 lines (137 sloc) 5.313 kB
9b0565a @shimondoodkin firt commit
authored
1 diff -upr orig/Classes/PHPExcel/Style/NumberFormat.php phpexcel/Classes/PHPExcel/Style/NumberFormat.php
2 --- orig/Classes/PHPExcel/Style/NumberFormat.php 2010-08-26 17:47:10.000000000 +0300
3 +++ phpexcel/Classes/PHPExcel/Style/NumberFormat.php 2010-10-11 00:48:41.427561891 +0200
4 @@ -502,14 +502,59 @@ class PHPExcel_Style_NumberFormat implem
5 * @param array $callBack Callback function for additional formatting of string
6 * @return string Formatted string
7 */
8 - public static function toFormattedString($value = '', $format = '', $callBack = null)
9 +
10 +/*
11 + // Pre-defined formats
12 + const FORMAT_GENERAL = 'General';
13 +
14 + const FORMAT_TEXT = '@';
15 +
16 + const FORMAT_NUMBER = '0';
17 + const FORMAT_NUMBER_00 = '0.00';
18 + const FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00';
19 + const FORMAT_NUMBER_COMMA_SEPARATED2 = '#,##0.00_-';
20 +
21 + const FORMAT_PERCENTAGE = '0%';
22 + const FORMAT_PERCENTAGE_00 = '0.00%';
23 +
24 + const FORMAT_DATE_YYYYMMDD2 = 'yyyy-mm-dd';
25 + const FORMAT_DATE_YYYYMMDD = 'yy-mm-dd';
26 + const FORMAT_DATE_DDMMYYYY = 'dd/mm/yy';
27 + const FORMAT_DATE_DMYSLASH = 'd/m/y';
28 + const FORMAT_DATE_DMYMINUS = 'd-m-y';
29 + const FORMAT_DATE_DMMINUS = 'd-m';
30 + const FORMAT_DATE_MYMINUS = 'm-y';
31 + const FORMAT_DATE_XLSX14 = 'mm-dd-yy';
32 + const FORMAT_DATE_XLSX15 = 'd-mmm-yy';
33 + const FORMAT_DATE_XLSX16 = 'd-mmm';
34 + const FORMAT_DATE_XLSX17 = 'mmm-yy';
35 + const FORMAT_DATE_XLSX22 = 'm/d/yy h:mm';
36 + const FORMAT_DATE_DATETIME = 'd/m/y h:mm';
37 + const FORMAT_DATE_TIME1 = 'h:mm AM/PM';
38 + const FORMAT_DATE_TIME2 = 'h:mm:ss AM/PM';
39 + const FORMAT_DATE_TIME3 = 'h:mm';
40 + const FORMAT_DATE_TIME4 = 'h:mm:ss';
41 + const FORMAT_DATE_TIME5 = 'mm:ss';
42 + const FORMAT_DATE_TIME6 = 'h:mm:ss';
43 + const FORMAT_DATE_TIME7 = 'i:s.S';
44 + const FORMAT_DATE_TIME8 = 'h:mm:ss;@';
45 + const FORMAT_DATE_YYYYMMDDSLASH = 'yy/mm/dd;@';
46 +
47 + const FORMAT_CURRENCY_USD_SIMPLE = '"$"#,##0.00_-';
48 + const FORMAT_CURRENCY_USD = '$#,##0_-';
49 + const FORMAT_CURRENCY_EUR_SIMPLE = '[$EUR ]#,##0.00_-';
50 +*/
51 +
52 + public static function toFormattedString($value = '', $format = '', $callBack = null, $toArrayDateFormat = false)
53 {
54 // For now we do not treat strings although section 4 of a format code affects strings
55 if (!is_numeric($value)) return $value;
56
57 // For 'General' format code, we just pass the value although this is not entirely the way Excel does it,
58 // it seems to round numbers to a total of 10 digits.
59 - if ($format === 'General') {
60 + if ($format === 'General'
61 + ||$format === '@'// added this, without it, it was braking phone numbers like 054-12345678
62 + ) {
63 return $value;
64 }
65
66 @@ -580,7 +625,12 @@ class PHPExcel_Style_NumberFormat implem
67 }
68
69 $dateObj = PHPExcel_Shared_Date::ExcelToPHPObject($value);
70 - $value = $dateObj->format($format);
71 +
72 + if($toArrayDateFormat!==false)
73 + $value = $dateObj->format($toArrayDateFormat);
74 + else
75 + $value = $dateObj->format($format);
76 +
77
78 } else if (preg_match('/%$/', $format)) { // % number format
79 if ($format === self::FORMAT_PERCENTAGE) {
80 diff -upr orig/Classes/PHPExcel/Worksheet.php phpexcel/Classes/PHPExcel/Worksheet.php
81 --- orig/Classes/PHPExcel/Worksheet.php 2010-08-26 17:47:10.000000000 +0300
82 +++ phpexcel/Classes/PHPExcel/Worksheet.php 2010-10-11 00:51:46.658977263 +0200
83 @@ -303,6 +303,13 @@ class PHPExcel_Worksheet implements PHPE
84 * @var PHPExcel_Style_Color
85 */
86 private $_tabColor;
87 +
88 + /**
89 + * to Array Date Format
90 + *
91 + * @var PHPExcel_Style_Color
92 + */
93 + private $_toArrayDateFormat = false;
94
95 /**
96 * Create a new worksheet
97 @@ -350,6 +357,7 @@ class PHPExcel_Worksheet implements PHPE
98
99 // Default column dimension
100 $this->_defaultColumnDimension = new PHPExcel_Worksheet_ColumnDimension(null);
101 +
102 }
103
104
105 @@ -624,6 +632,20 @@ class PHPExcel_Worksheet implements PHPE
106 return $this;
107 }
108
109 + /**
110 + * Set toArray date format
111 + *
112 + * @param string $pValue String containing the date format for PHPDateObject->format(...)
113 + */
114 + public function setToArrayDateFormat($pValue = false)
115 + {
116 + $this->_toArrayDateFormat=$pValue;
117 + }
118 + public function getToArrayDateFormat()
119 + {
120 + return $this->_toArrayDateFormat;
121 + }
122 +
123 /**
124 * Get title
125 *
126 @@ -638,7 +660,7 @@ class PHPExcel_Worksheet implements PHPE
127 * Set title
128 *
129 * @param string $pValue String containing the dimension of this worksheet
130 - * @return PHPExcel_Worksheet
131 + * @return PHPExcel_Worksheet
132 */
133 public function setTitle($pValue = 'Worksheet')
134 {
135 @@ -2137,10 +2159,9 @@ class PHPExcel_Worksheet implements PHPE
136 $returnValue[$row][$column] = $cell->getValue();
137 }
138 }
139 -
140 $style = $this->_parent->getCellXfByIndex($cell->getXfIndex());
141
142 - $returnValue[$row][$column] = PHPExcel_Style_NumberFormat::toFormattedString($returnValue[$row][$column], $style->getNumberFormat()->getFormatCode());
143 + $returnValue[$row][$column] = PHPExcel_Style_NumberFormat::toFormattedString($returnValue[$row][$column], $style->getNumberFormat()->getFormatCode(),null,$this->_toArrayDateFormat);
144 } else {
145 $returnValue[$row][$column] = $nullValue;
146 }
147 Only in phpexcel/Classes/PHPExcel/Writer: JSON.php
Something went wrong with that request. Please try again.