From: vincent@cubedesigners.com Date: Mon, 22 Nov 2021 16:29:22 +0000 (+0000) Subject: wip #4740 @4 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=3d37d3ac6d30110f757d818fcb274da8ec677973;p=cubeextranet.git wip #4740 @4 --- diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index dec4504d9..feed2161d 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1717,6 +1717,92 @@ class wsMaintenance exit; } + public static function wescogroups() + { + CubeIT_Library::PHPExcel(); + $reader = new PHPExcel_Reader_Excel2007(); + $file = '/home/wesco/groups.xlsx'; + if (!file_exists($file)) { + die(':('); + } + $xlsx = $reader->load('/home/wesco/groups.xlsx'); + + ob_end_clean(); + $allgroups = []; + foreach ($xlsx->getAllSheets() as $s) { + if ($s->getTitle() === 'Lexique' || $s->getSheetState() !== PHPExcel_Worksheet::SHEETSTATE_VISIBLE) { + continue; + } + $groups = []; + $subgroups = []; + foreach ($s->getRowIterator() as $row) { + $rowIndex = $row->getRowIndex(); + foreach ($row->getCellIterator() as $cell) { + $v = trim($cell->getValue()); + $colIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn()); + + if (isset($groups[$colIndex])) { + $groupname = $groups[$colIndex]; + } else { + $groupname = ''; + } + + if (isset($subgroups[$colIndex])) { + $subgroupname = $subgroups[$colIndex]; + } else { + $subgroupname = ''; + } + + if (!$v) { + continue; + } + if ($cell->getMergeRange()) { + + $e = explode(':', $cell->getMergeRange(), 2); + $start = PHPExcel_Cell::columnIndexFromString(substr($e[0], 0, 1)); + $end = PHPExcel_Cell::columnIndexFromString(substr($e[1], 0, 1)); + + for ($i = $start; $i <= $end; $i++) { + $groups[$i] = $v; + } + } else if (preg_match('/^(\d{1,5})$/', $v, $matches)) { + $grouplabel = $s->getTitle() . ' - ' . $groupname . ' - ' . $subgroupname; + if (!isset($allgroups[$grouplabel])) { + $allgroups[$grouplabel] = []; + } + $allgroups[$grouplabel][] = $v; + } else { + $subgroups[$colIndex] = $v; + } + } + } + + } + + $res = []; + foreach ($allgroups as $k => $allgroup) { + $res[$k] = array_unique($allgroup); + } + + $p = new PHPExcel(); + $s = $p->getActiveSheet(); + $s->setTitle('Groupes'); + $s->setCellValueByColumnAndRow(0, 1, 'Onglet'); + $s->setCellValueByColumnAndRow(1, 1, 'Références'); + $rowIndex = 2; + foreach ($res as $groupName => $references) { + $s->setCellValueByColumnAndRow(0, $rowIndex, $groupName); + foreach ($references as $k => $reference) { + $s->setCellValueByColumnAndRow(1 + $k, $rowIndex, $reference); + } + $rowIndex++; + } + $writer = new PHPExcel_Writer_Excel2007($p); + $writer->save('/home/wesco/groups1.xlsx'); + + exit; + } + }