diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
commit | 75160b12821f7f4299cce7f0b69c83c1502ae071 (patch) | |
tree | 27e25e4ccaef45f0c58b22831164050d1af1d4db /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/DocumentGenerator.php | |
parent | prvi-commit (diff) | |
download | 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.gz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.bz2 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.lz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.xz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.zst 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.zip |
Diffstat (limited to '')
-rw-r--r-- | vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/DocumentGenerator.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/DocumentGenerator.php b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/DocumentGenerator.php new file mode 100644 index 0000000..91b4650 --- /dev/null +++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/DocumentGenerator.php @@ -0,0 +1,97 @@ +<?php
+
+namespace PhpOffice\PhpSpreadsheet;
+
+use PhpOffice\PhpSpreadsheet\Calculation\Category;
+use PhpOffice\PhpSpreadsheet\Calculation\Functions;
+use ReflectionClass;
+use UnexpectedValueException;
+
+class DocumentGenerator
+{
+ /**
+ * @param array[] $phpSpreadsheetFunctions
+ */
+ public static function generateFunctionListByCategory(array $phpSpreadsheetFunctions): string
+ {
+ $result = "# Function list by category\n";
+ foreach (self::getCategories() as $categoryConstant => $category) {
+ $result .= "\n";
+ $result .= "## {$categoryConstant}\n";
+ $result .= "\n";
+ $lengths = [20, 42];
+ $result .= self::tableRow($lengths, ['Excel Function', 'PhpSpreadsheet Function']) . "\n";
+ $result .= self::tableRow($lengths, null) . "\n";
+ foreach ($phpSpreadsheetFunctions as $excelFunction => $functionInfo) {
+ if ($category === $functionInfo['category']) {
+ $phpFunction = self::getPhpSpreadsheetFunctionText($functionInfo['functionCall']);
+ $result .= self::tableRow($lengths, [$excelFunction, $phpFunction]) . "\n";
+ }
+ }
+ }
+
+ return $result;
+ }
+
+ private static function getCategories(): array
+ {
+ return (new ReflectionClass(Category::class))->getConstants();
+ }
+
+ private static function tableRow(array $lengths, ?array $values = null): string
+ {
+ $result = '';
+ foreach (array_map(null, $lengths, $values ?? []) as $i => [$length, $value]) {
+ $pad = $value === null ? '-' : ' ';
+ if ($i > 0) {
+ $result .= '|' . $pad;
+ }
+ $result .= str_pad($value ?? '', $length, $pad);
+ }
+
+ return rtrim($result, ' ');
+ }
+
+ private static function getPhpSpreadsheetFunctionText($functionCall): string
+ {
+ if (is_string($functionCall)) {
+ return $functionCall;
+ }
+ if ($functionCall === [Functions::class, 'DUMMY']) {
+ return '**Not yet Implemented**';
+ }
+ if (is_array($functionCall)) {
+ return "\\{$functionCall[0]}::{$functionCall[1]}";
+ }
+
+ throw new UnexpectedValueException(
+ '$functionCall is of type ' . gettype($functionCall) . '. string or array expected'
+ );
+ }
+
+ /**
+ * @param array[] $phpSpreadsheetFunctions
+ */
+ public static function generateFunctionListByName(array $phpSpreadsheetFunctions): string
+ {
+ $categoryConstants = array_flip(self::getCategories());
+ $result = "# Function list by name\n";
+ $lastAlphabet = null;
+ foreach ($phpSpreadsheetFunctions as $excelFunction => $functionInfo) {
+ $lengths = [20, 31, 42];
+ if ($lastAlphabet !== $excelFunction[0]) {
+ $lastAlphabet = $excelFunction[0];
+ $result .= "\n";
+ $result .= "## {$lastAlphabet}\n";
+ $result .= "\n";
+ $result .= self::tableRow($lengths, ['Excel Function', 'Category', 'PhpSpreadsheet Function']) . "\n";
+ $result .= self::tableRow($lengths, null) . "\n";
+ }
+ $category = $categoryConstants[$functionInfo['category']];
+ $phpFunction = self::getPhpSpreadsheetFunctionText($functionInfo['functionCall']);
+ $result .= self::tableRow($lengths, [$excelFunction, $category, $phpFunction]) . "\n";
+ }
+
+ return $result;
+ }
+}
|