Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zhil authored Jun 28, 2019
1 parent 30705f2 commit 1c8a6a3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,24 @@ If you are migrating from Symfony Serializer component + CSV encoder - you can u
```
$spreadsheet = $this->get('phpoffice.spreadsheet')->createSpreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle($this->filterVars['wareCategory']->getTitle());
$columnsMap = [];
$lineIndex = 1;
$lineIndex = 2;
foreach ($data as $line) {
foreach ($line as $columnName=>$columnValue) {
if (!$columnIndex = array_search($columnName, $columnsMap)) {
if (is_int($columnIndex = array_search($columnName, $columnsMap))) {
$columnIndex++;
} else {
$columnsMap[] = $columnName;
$columnIndex = count($columnsMap);
}
$sheet->getCellByColumnAndRow($columnIndex, $lineIndex)->setValue($columnValue);
}
$lineIndex++;
}
foreach ($columnsMap as $columnMapId=>$columnTitle) {
$sheet->getCellByColumnAndRow($columnMapId+1, 1)->setValue($columnTitle);
}
$writer = $this->get('phpoffice.spreadsheet')->createWriter($spreadsheet, 'Xlsx');
ob_start();
$writer->save('php://output');
Expand Down

0 comments on commit 1c8a6a3

Please sign in to comment.