]> _ Git - cubeextranet.git/commitdiff
done #3040 @1
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 13 Sep 2019 08:01:19 +0000 (08:01 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 13 Sep 2019 08:01:19 +0000 (08:01 +0000)
inc/commons/class.common.tools.php

index 332589ed7ace1fabf4a7281cb56ae8093b0f1503..b73abc5710d097b2e642c3a7ae668188f64a1aa7 100644 (file)
@@ -1358,4 +1358,42 @@ class commonTools
         return $fname;
     }
 
+
+    public static function xlsxToJson($args)
+    {
+        global $core;
+        $res = commonPage::barre();
+        $res .= commonPage::tMain();
+        $res .= commonPage::bh();
+        $res .= '<form action="' . SITE_PATH . 'tools/convertXlsxToJson" method="post" class="notajax" enctype="multipart/form-data">';
+        $res .= '<table class="liste">';
+        $res .= '<tr><th><strong>' . __('Convertir un xlsx en json') . '</strong></th></tr>';
+        $res .= '<tr><td>' . __('Charger un fichier excel') . '</td></tr>';
+        $res .= '<tr class="odd"><td><input type="file" name="file" /></td></tr>';
+        $res .= '<tr><td class="right"><a href="#" class="submit">' . $core->typo->BoutonOK(__('Convertion')) . '</a></td></td>';
+        $res .= '</table>';
+        $res .= '</form>';
+        $res .= '</div>';
+        $res .= commonPage::bf();
+        $res .= commonPage::bMain();
+        return $res;
+    }
+
+    public static function convertXlsxToJson($args)
+    {
+        new PHPExcel();
+
+        $reader = new PHPExcel_Reader_Excel2007();
+        $xls = $reader->load($_FILES['file']['tmp_name']);
+
+        $res = [];
+        foreach ($xls->getAllSheets() as $sheet) {
+            $res[$sheet->getTitle()]=$sheet->toArray();
+        }
+
+        ob_end_clean();
+
+        header('Content-Type: application/json');
+        die(json_encode($res));
+    }
 }