<?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