diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-03-16 23:20:59 +0100 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-03-16 23:20:59 +0100 |
| commit | bf7852bccce954aff2d7c94161f4d301a0f29684 (patch) | |
| tree | fc3f2aac4f843990b02992e02903df22857a1928 /api/export.php | |
| download | mlos-bf7852bccce954aff2d7c94161f4d301a0f29684.tar.gz mlos-bf7852bccce954aff2d7c94161f4d301a0f29684.tar.zst mlos-bf7852bccce954aff2d7c94161f4d301a0f29684.zip | |
Initial commit w/ v1.0.0
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(); |
