blob: 625283e45a0f205c5fcd08c3aef8098ffb28d90a (
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
44
45
|
<?php
require_once '%PWD%vendor/autoload.php';
require_once '%PWD%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"]);
$path = "%PWD%imgs/" . $d["thumbnail"];
if(file_exists($path)) {
$drawing = new Drawing();
$drawing->setName($d["name"]);
$drawing->setPath($path);
$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();
|