3
3
namespace PhpOffice \PhpSpreadsheet \Calculation \TextData ;
4
4
5
5
use DateTimeInterface ;
6
+ use PhpOffice \PhpSpreadsheet \Calculation \ArrayEnabled ;
6
7
use PhpOffice \PhpSpreadsheet \Calculation \DateTimeExcel ;
7
8
use PhpOffice \PhpSpreadsheet \Calculation \Exception as CalcExp ;
8
9
use PhpOffice \PhpSpreadsheet \Calculation \Functions ;
13
14
14
15
class Format
15
16
{
17
+ use ArrayEnabled;
18
+
16
19
/**
17
20
* DOLLAR.
18
21
*
19
22
* This function converts a number to text using currency format, with the decimals rounded to the specified place.
20
23
* The format used is $#,##0.00_);($#,##0.00)..
21
24
*
22
25
* @param mixed $value The value to format
26
+ * Or can be an array of values
23
27
* @param mixed $decimals The number of digits to display to the right of the decimal point (as an integer).
24
28
* If decimals is negative, number is rounded to the left of the decimal point.
25
29
* If you omit decimals, it is assumed to be 2
30
+ * Or can be an array of values
31
+ *
32
+ * @return array|string
33
+ * If an array of values is passed for either of the arguments, then the returned result
34
+ * will also be an array with matching dimensions
26
35
*/
27
- public static function DOLLAR ($ value = 0 , $ decimals = 2 ): string
36
+ public static function DOLLAR ($ value = 0 , $ decimals = 2 )
28
37
{
38
+ if (is_array ($ value ) || is_array ($ decimals )) {
39
+ return self ::evaluateArrayArguments ([self ::class, __FUNCTION__ ], $ value , $ decimals );
40
+ }
41
+
29
42
try {
30
43
$ value = Helpers::extractFloat ($ value );
31
44
$ decimals = Helpers::extractInt ($ decimals , -100 , 0 , true );
@@ -52,11 +65,22 @@ public static function DOLLAR($value = 0, $decimals = 2): string
52
65
* FIXED.
53
66
*
54
67
* @param mixed $value The value to format
68
+ * Or can be an array of values
55
69
* @param mixed $decimals Integer value for the number of decimal places that should be formatted
70
+ * Or can be an array of values
56
71
* @param mixed $noCommas Boolean value indicating whether the value should have thousands separators or not
72
+ * Or can be an array of values
73
+ *
74
+ * @return array|string
75
+ * If an array of values is passed for either of the arguments, then the returned result
76
+ * will also be an array with matching dimensions
57
77
*/
58
- public static function FIXEDFORMAT ($ value , $ decimals = 2 , $ noCommas = false ): string
78
+ public static function FIXEDFORMAT ($ value , $ decimals = 2 , $ noCommas = false )
59
79
{
80
+ if (is_array ($ value ) || is_array ($ decimals ) || is_array ($ noCommas )) {
81
+ return self ::evaluateArrayArguments ([self ::class, __FUNCTION__ ], $ value , $ decimals , $ noCommas );
82
+ }
83
+
60
84
try {
61
85
$ value = Helpers::extractFloat ($ value );
62
86
$ decimals = Helpers::extractInt ($ decimals , -100 , 0 , true );
@@ -85,10 +109,20 @@ public static function FIXEDFORMAT($value, $decimals = 2, $noCommas = false): st
85
109
* TEXT.
86
110
*
87
111
* @param mixed $value The value to format
112
+ * Or can be an array of values
88
113
* @param mixed $format A string with the Format mask that should be used
114
+ * Or can be an array of values
115
+ *
116
+ * @return array|string
117
+ * If an array of values is passed for either of the arguments, then the returned result
118
+ * will also be an array with matching dimensions
89
119
*/
90
- public static function TEXTFORMAT ($ value , $ format ): string
120
+ public static function TEXTFORMAT ($ value , $ format )
91
121
{
122
+ if (is_array ($ value ) || is_array ($ format )) {
123
+ return self ::evaluateArrayArguments ([self ::class, __FUNCTION__ ], $ value , $ format );
124
+ }
125
+
92
126
$ value = Helpers::extractString ($ value );
93
127
$ format = Helpers::extractString ($ format );
94
128
@@ -122,11 +156,18 @@ private static function convertValue($value)
122
156
* VALUE.
123
157
*
124
158
* @param mixed $value Value to check
159
+ * Or can be an array of values
125
160
*
126
- * @return DateTimeInterface|float|int|string A string if arguments are invalid
161
+ * @return array|DateTimeInterface|float|int|string A string if arguments are invalid
162
+ * If an array of values is passed for the argument, then the returned result
163
+ * will also be an array with matching dimensions
127
164
*/
128
165
public static function VALUE ($ value = '' )
129
166
{
167
+ if (is_array ($ value )) {
168
+ return self ::evaluateSingleArgumentArray ([self ::class, __FUNCTION__ ], $ value );
169
+ }
170
+
130
171
try {
131
172
$ value = self ::convertValue ($ value );
132
173
} catch (CalcExp $ e ) {
@@ -191,13 +232,20 @@ private static function getGroupSeparator($groupSeparator): string
191
232
* NUMBERVALUE.
192
233
*
193
234
* @param mixed $value The value to format
235
+ * Or can be an array of values
194
236
* @param mixed $decimalSeparator A string with the decimal separator to use, defaults to locale defined value
237
+ * Or can be an array of values
195
238
* @param mixed $groupSeparator A string with the group/thousands separator to use, defaults to locale defined value
239
+ * Or can be an array of values
196
240
*
197
- * @return float|string
241
+ * @return array| float|string
198
242
*/
199
243
public static function NUMBERVALUE ($ value = '' , $ decimalSeparator = null , $ groupSeparator = null )
200
244
{
245
+ if (is_array ($ value ) || is_array ($ decimalSeparator ) || is_array ($ groupSeparator )) {
246
+ return self ::evaluateArrayArguments ([self ::class, __FUNCTION__ ], $ value , $ decimalSeparator , $ groupSeparator );
247
+ }
248
+
201
249
try {
202
250
$ value = self ::convertValue ($ value );
203
251
$ decimalSeparator = self ::getDecimalSeparator ($ decimalSeparator );
0 commit comments