]> _ Git - cubeextranet.git/commitdiff
wait #3879 @0.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 8 Sep 2020 16:48:17 +0000 (16:48 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 8 Sep 2020 16:48:17 +0000 (16:48 +0000)
inc/commons/class.common.tools.php

index 71f3829ea44188274971543fa3a970cfce136b47..157dbc2339ceeed0cf9e3eacb082193cca40ee13 100644 (file)
@@ -1420,6 +1420,36 @@ class commonTools
         die(json_encode($res));
     }
 
+    public static function convertXlsxToKeyValueJson($args)
+    {
+        new PHPExcel();
+
+        $reader = new PHPExcel_Reader_Excel2007();
+        $xls = $reader->load($_FILES['file']['tmp_name']);
+
+        $res = [];
+        foreach ($xls->getAllSheets() as $sheet) {
+            $lines = $sheet->toArray();
+            foreach ($lines as $line) {
+                if (null === $line[0]) {
+                    continue;
+                }
+                $k = trim($line[0]);
+                if (!$k) {
+                    continue;
+                }
+                $v = trim($line[1]);
+                $res[$k] = $v;
+            }
+            break;
+        }
+
+        ob_end_clean();
+
+        header('Content-Type: application/json');
+        die(json_encode($res));
+    }
+
     public static function excelTranslation($args)
     {
         $name = $_REQUEST['name'] ?? 'translations';
@@ -1443,6 +1473,7 @@ class commonTools
         exit;
     }
 
+
     public static function articles($args)
     {
         global $core;