]> _ Git - sandvik-apps.git/commitdiff
wip #4164 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 21 Jan 2021 16:25:51 +0000 (17:25 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 21 Jan 2021 16:25:51 +0000 (17:25 +0100)
WearParts/_doc/data.xlsx [new file with mode: 0644]
WearParts/tools/convertclientdata.php

diff --git a/WearParts/_doc/data.xlsx b/WearParts/_doc/data.xlsx
new file mode 100644 (file)
index 0000000..2766eee
Binary files /dev/null and b/WearParts/_doc/data.xlsx differ
index 18292fd1a0ee58240b3b89998298f872258b4a49..522a43d271b2740a53da3f69efcb761a5dd8f86e 100644 (file)
@@ -1,2 +1,58 @@
 <?php
-require_once __DIR__ . '/../vendor/autoload.php';
\ No newline at end of file
+
+use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
+
+error_reporting(E_ALL);
+ini_set('display_errors', true);
+require_once __DIR__ . '/../vendor/autoload.php';
+$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
+$xls = $reader->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