PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Calculation / LookupRef / TorowTocol.php

TorowTocol.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/TorowTocol.php

101 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
8
9 class TorowTocol
10 {
11 /**
12 * Excel function TOCOL.
13 *
14 * @return mixed[]|string
15 * @param mixed $array
16 * @param mixed $ignore
17 * @param mixed $byColumn
18 */
19 public static function tocol($array, $ignore = 0, $byColumn = false)
20 {
21 $result = self::torow($array, $ignore, $byColumn);
22 if (is_array($result)) {
23 return array_map((fn ($x) => [$x]), $result);
24 }
25
26 return $result;
27 }
28
29 /**
30 * Excel function TOROW.
31 *
32 * @return mixed[]|string
33 * @param mixed $array
34 * @param mixed $ignore
35 * @param mixed $byColumn
36 */
37 public static function torow($array, $ignore = 0, $byColumn = false)
38 {
39 if (!is_numeric($ignore)) {
40 return ExcelError::VALUE();
41 }
42 $ignore = (int) $ignore;
43 if ($ignore < 0 || $ignore > 3) {
44 return ExcelError::VALUE();
45 }
46 if (is_int($byColumn) || is_float($byColumn)) {
47 $byColumn = (bool) $byColumn;
48 }
49 if (!is_bool($byColumn)) {
50 return ExcelError::VALUE();
51 }
52 if (!is_array($array)) {
53 $array = [$array];
54 }
55 if ($byColumn) {
56 $temp = [];
57 foreach ($array as $row) {
58 if (!is_array($row)) {
59 $row = [$row];
60 }
61 $temp[] = Functions::flattenArray($row);
62 }
63 $array = ChooseRowsEtc::transpose($temp);
64 } else {
65 $array = Functions::flattenArray($array);
66 }
67
68 return self::byRow($array, $ignore);
69 }
70
71 /**
72 * @param mixed[] $array
73 *
74 * @return mixed[]
75 */
76 private static function byRow(array $array, int $ignore): array
77 {
78 $returnMatrix = [];
79 foreach ($array as $row) {
80 if (!is_array($row)) {
81 $row = [$row];
82 }
83 foreach ($row as $cell) {
84 if ($cell === null) {
85 if ($ignore === 1 || $ignore === 3) {
86 continue;
87 }
88 $cell = 0;
89 } elseif (ErrorValue::isError($cell, true)) {
90 if ($ignore === 2 || $ignore === 3) {
91 continue;
92 }
93 }
94 $returnMatrix[] = $cell;
95 }
96 }
97
98 return $returnMatrix;
99 }
100 }
101