From: Vincent Vanwaelscappel Date: Thu, 21 Jan 2021 16:25:51 +0000 (+0100) Subject: wip #4164 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=3de0fe398c4aa134866362d7f0b79a7cf7f4ce61;p=sandvik-apps.git wip #4164 @1.5 --- diff --git a/WearParts/_doc/data.xlsx b/WearParts/_doc/data.xlsx new file mode 100644 index 0000000..2766eee Binary files /dev/null and b/WearParts/_doc/data.xlsx differ diff --git a/WearParts/tools/convertclientdata.php b/WearParts/tools/convertclientdata.php index 18292fd..522a43d 100644 --- a/WearParts/tools/convertclientdata.php +++ b/WearParts/tools/convertclientdata.php @@ -1,2 +1,58 @@ load(__DIR__ . '/../_doc/client.xlsx'); +$res = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$wsr = $res->getActiveSheet(); +$ws = $xls->getActiveSheet(); + +$questionByCol = []; +$answerByCol = []; + +foreach ($ws->getColumnIterator('F') as $col) { + $colIndex = Coordinate::columnIndexFromString($col->getColumnIndex()); + $questionByCol[$colIndex] = $ws->getCellByColumnAndRow($colIndex, 1)->getValue(); + $answerByCol[$colIndex] = str_replace("\n", ' ', $ws->getCellByColumnAndRow($colIndex, 2)->getValue()); +} + +print_r($questionByCol); +print_r($answerByCol); + +foreach ($ws->getRowIterator(3) as $row) { + $questions = []; + foreach ($row->getCellIterator('F') as $cell) { + $colIndex = Coordinate::columnIndexFromString($cell->getColumn()); + $question = $questionByCol[$colIndex]; + if (!isset($questions[$question])) { + $questions[$question] = []; + } + if ($cell->getValue() == 'Y') { + $questions[$question][] = $answerByCol[$colIndex]; + } + } + + $rcol = 1; + foreach ($questions as $question => $answers) { + $wsr->getCellByColumnAndRow($rcol, $row->getRowIndex())->setValue(implode("\n", $answers)); + $wsr->getStyleByColumnAndRow($rcol, $row->getRowIndex())->getAlignment()->setWrapText(true); + $rcol++; + } + foreach ($row->getCellIterator('A', 'E') as $cell) { + $wsr->getCellByColumnAndRow($rcol, $row->getRowIndex())->setValue($cell->getValue()); + + $rcol++; + } +} +$rcol = 1; +foreach ($questions as $question => $answers) { + $wsr->getCellByColumnAndRow($rcol, 2)->setValue($question); + $rcol++; +} + +$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($res); +$writer->save(__DIR__ . '/../_doc/data.xlsx'); \ No newline at end of file