Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
4
 
5
use Composer\Pcre\Preg;
6
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
7
 
8
class FunctionPrefix
9
{
10
    const XLFNREGEXP = '/(?:_xlfn\.)?((?:_xlws\.)?\b('
11
        // functions added with Excel 2010
12
        . 'beta[.]dist'
13
        . '|beta[.]inv'
14
        . '|binom[.]dist'
15
        . '|binom[.]inv'
16
        . '|ceiling[.]precise'
17
        . '|chisq[.]dist'
18
        . '|chisq[.]dist[.]rt'
19
        . '|chisq[.]inv'
20
        . '|chisq[.]inv[.]rt'
21
        . '|chisq[.]test'
22
        . '|confidence[.]norm'
23
        . '|confidence[.]t'
24
        . '|covariance[.]p'
25
        . '|covariance[.]s'
26
        . '|erf[.]precise'
27
        . '|erfc[.]precise'
28
        . '|expon[.]dist'
29
        . '|f[.]dist'
30
        . '|f[.]dist[.]rt'
31
        . '|f[.]inv'
32
        . '|f[.]inv[.]rt'
33
        . '|f[.]test'
34
        . '|floor[.]precise'
35
        . '|gamma[.]dist'
36
        . '|gamma[.]inv'
37
        . '|gammaln[.]precise'
38
        . '|lognorm[.]dist'
39
        . '|lognorm[.]inv'
40
        . '|mode[.]mult'
41
        . '|mode[.]sngl'
42
        . '|negbinom[.]dist'
43
        . '|networkdays[.]intl'
44
        . '|norm[.]dist'
45
        . '|norm[.]inv'
46
        . '|norm[.]s[.]dist'
47
        . '|norm[.]s[.]inv'
48
        . '|percentile[.]exc'
49
        . '|percentile[.]inc'
50
        . '|percentrank[.]exc'
51
        . '|percentrank[.]inc'
52
        . '|poisson[.]dist'
53
        . '|quartile[.]exc'
54
        . '|quartile[.]inc'
55
        . '|rank[.]avg'
56
        . '|rank[.]eq'
57
        . '|stdev[.]p'
58
        . '|stdev[.]s'
59
        . '|t[.]dist'
60
        . '|t[.]dist[.]2t'
61
        . '|t[.]dist[.]rt'
62
        . '|t[.]inv'
63
        . '|t[.]inv[.]2t'
64
        . '|t[.]test'
65
        . '|var[.]p'
66
        . '|var[.]s'
67
        . '|weibull[.]dist'
68
        . '|z[.]test'
69
        // functions added with Excel 2013
70
        . '|acot'
71
        . '|acoth'
72
        . '|arabic'
73
        . '|averageifs'
74
        . '|binom[.]dist[.]range'
75
        . '|bitand'
76
        . '|bitlshift'
77
        . '|bitor'
78
        . '|bitrshift'
79
        . '|bitxor'
80
        . '|ceiling[.]math'
81
        . '|combina'
82
        . '|cot'
83
        . '|coth'
84
        . '|csc'
85
        . '|csch'
86
        . '|days'
87
        . '|dbcs'
88
        . '|decimal'
89
        . '|encodeurl'
90
        . '|filterxml'
91
        . '|floor[.]math'
92
        . '|formulatext'
93
        . '|gamma'
94
        . '|gauss'
95
        . '|ifna'
96
        . '|imcosh'
97
        . '|imcot'
98
        . '|imcsc'
99
        . '|imcsch'
100
        . '|imsec'
101
        . '|imsech'
102
        . '|imsinh'
103
        . '|imtan'
104
        . '|isformula'
105
        . '|iso[.]ceiling'
106
        . '|isoweeknum'
107
        . '|munit'
108
        . '|numbervalue'
109
        . '|pduration'
110
        . '|permutationa'
111
        . '|phi'
112
        . '|rri'
113
        . '|sec'
114
        . '|sech'
115
        . '|sheet'
116
        . '|sheets'
117
        . '|skew[.]p'
118
        . '|unichar'
119
        . '|unicode'
120
        . '|webservice'
121
        . '|xor'
122
        // functions added with Excel 2016
123
        . '|forecast[.]et2'
124
        . '|forecast[.]ets[.]confint'
125
        . '|forecast[.]ets[.]seasonality'
126
        . '|forecast[.]ets[.]stat'
127
        . '|forecast[.]linear'
128
        . '|switch'
129
        // functions added with Excel 2019
130
        . '|concat'
131
        . '|ifs'
132
        . '|maxifs'
133
        . '|minifs'
134
        . '|textjoin'
135
        // functions added with Excel 365
136
        . '|anchorarray'
137
        . '|arraytotext'
138
        . '|bycol'
139
        . '|byrow'
140
        . '|call'
141
        . '|choosecols'
142
        . '|chooserows'
143
        . '|drop'
144
        . '|expand'
145
        . '|filter'
146
        . '|groupby'
147
        . '|hstack'
148
        . '|isomitted'
149
        . '|lambda'
150
        . '|let'
151
        . '|makearray'
152
        . '|map'
153
        . '|randarray'
154
        . '|reduce'
155
        . '|register[.]id'
156
        . '|scan'
157
        . '|sequence'
158
        . '|single'
159
        . '|sort'
160
        . '|sortby'
161
        . '|take'
162
        . '|textafter'
163
        . '|textbefore'
164
        . '|textjoin'
165
        . '|textsplit'
166
        . '|tocol'
167
        . '|torow'
168
        . '|unique'
169
        . '|valuetotext'
170
        . '|vstack'
171
        . '|wrapcols'
172
        . '|wraprows'
173
        . '|xlookup'
174
        . '|xmatch'
175
        . '))\s*\(/Umui';
176
 
177
    const XLWSREGEXP = '/(?<!_xlws\.)('
178
        // functions added with Excel 365
179
        . 'filter'
180
        . '|sort'
181
        . ')\s*\(/mui';
182
 
183
    /**
184
     * Prefix function name in string with _xlfn. where required.
185
     */
186
    protected static function addXlfnPrefix(string $functionString): string
187
    {
188
        return Preg::replace(self::XLFNREGEXP, '_xlfn.$1(', $functionString);
189
    }
190
 
191
    /**
192
     * Prefix function name in string with _xlws. where required.
193
     */
194
    protected static function addXlwsPrefix(string $functionString): string
195
    {
196
        return Preg::replace(self::XLWSREGEXP, '_xlws.$1(', $functionString);
197
    }
198
 
199
    /**
200
     * Prefix function name in string with _xlfn. where required.
201
     */
202
    public static function addFunctionPrefix(string $functionString): string
203
    {
204
        $functionString = Preg::replaceCallback(
205
            Calculation::CALCULATION_REGEXP_CELLREF_SPILL,
206
            fn (array $matches) => 'ANCHORARRAY(' . substr((string) $matches[0], 0, -1) . ')',
207
            $functionString
208
        );
209
 
210
        return self::addXlwsPrefix(self::addXlfnPrefix($functionString));
211
    }
212
 
213
    /**
214
     * Prefix function name in string with _xlfn. where required.
215
     * Leading character, expected to be equals sign, is stripped.
216
     */
217
    public static function addFunctionPrefixStripEquals(string $functionString): string
218
    {
219
        return self::addFunctionPrefix(substr($functionString, 1));
220
    }
221
}