diff options
Diffstat (limited to 'api/export.php')
| -rw-r--r-- | api/export.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/api/export.php b/api/export.php new file mode 100644 index 0000000..77e36a2 --- /dev/null +++ b/api/export.php @@ -0,0 +1,43 @@ +<?php +require_once '../vendor/autoload.php'; +require_once '../src/data.php'; + +[$data, $count] = get_data(); + +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; + +header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); +header('Content-Disposition: attachment;filename="mlos-data.xlsx"'); +header('Cache-Control: max-age=0'); + +$spreadsheet = new Spreadsheet(); +$active_sheet = $spreadsheet->getActiveSheet(); + +$active_sheet->setCellValue('A1', "Name"); +$active_sheet->setCellValue('B1', "Author"); +$active_sheet->setCellValue('C1', "Magazine"); +$row = 2; +foreach ($data as $d) { + $active_sheet->setCellValue('A' . $row, $d["name"]); + + $drawing = new Drawing(); + $drawing->setName($d["name"]); + $drawing->setPath("../imgs/" . $d["thumbnail"]); + $drawing->setHeight(200); + + $comment = $active_sheet->getComment('A' . $row); + $comment->setBackgroundImage($drawing); + $comment->setSizeAsBackgroundImage(); + + + $active_sheet->setCellValue('B' . $row, $d["author"]); + $active_sheet->setCellValue('C' . $row, $d["magazine"]); + $row++; +} + +$writer = new Xlsx($spreadsheet); +$writer->save('php://output'); + +$spreadsheet->disconnectWorksheets(); |
