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><td><input type="file" name="file" /></td></tr>';
- $res .= '<tr class="odd"><td>Organisation des données</td><td><select name="dataorg">
- <option value="excelToArray">Conforme à la source</option>
- <option value="excelToArrayKeyVal">Couples Clé/Valeur</option>
- <option value="excelToArrayKeyVars">Liste nommée par le titre de colonne</option>
- </select></td></tr>';
- $res .= '<tr class=""><td>Format de sortie</td><td><select name="format"><option value="json">JSON</option><option value="js">JS</option></select></td></tr>';
- $res .= '<tr class="odd"><td class="right" colspan="2"><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;
+ header('Location: https://toolbox.fluidbook.com/opentools/excel2json', true, 308);
}
public static function convertXlsxToJson($args)
{
- require_once ROOT . '/inc/ws/Util/class.ws.util.php';
- $f = $_POST['dataorg'];
- $res = wsUtil::$f($_FILES['file']['tmp_name']);
- $json = json_encode($res);
- ob_end_clean();
-
- if ($_POST['format'] === 'json') {
- header('Content-Type: application/json');
- die($json);
- } else if ($_POST['format'] === 'js') {
- header('Content-Type: application/javascript');
- header('Content-Disposition: attachment; filename="data.js"');
- die('var DATA=' . $json . ';');
- }
- }
-
- 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));
+ header('Location: https://toolbox.fluidbook.com/opentools/doexcel2json', true, 308);
}
public static function excelTranslationM($args)