summaryrefslogtreecommitdiffstats
path: root/api/export.php
blob: 77e36a236dc103855814826e21857378983f5781 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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();