/
autofilter.php
87 lines (78 loc) · 2.92 KB
/
autofilter.php
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* @see http://libxlsxwriter.github.io/autofilter_8c-example.html
* @noinspection PhpUnhandledExceptionInspection
*/
use FFILibXlsxWriter\FFILibXlsxWriter;
use FFILibXlsxWriter\Workbook;
require_once __DIR__ . '/../vendor/autoload.php';
FFILibXlsxWriter::init();
$workbook = new Workbook(__DIR__ . '/output/autofilter.xlsx');
$worksheet = $workbook->addWorksheet();
$data = [
["East", "Apple", 9000, "July"],
["East", "Apple", 5000, "July"],
["South", "Orange", 9000, "September"],
["North", "Apple", 2000, "November"],
["West", "Apple", 9000, "November"],
["South", "Pear", 7000, "October"],
["North", "Pear", 9000, "August"],
["West", "Orange", 1000, "December"],
["West", "Grape", 1000, "November"],
["South", "Pear", 10000, "April"],
["West", "Grape", 6000, "January"],
["South", "Orange", 3000, "May"],
["North", "Apple", 3000, "December"],
["South", "Apple", 7000, "February"],
["West", "Grape", 1000, "December"],
["East", "Grape", 8000, "February"],
["South", "Grape", 10000, "June"],
["West", "Pear", 7000, "December"],
["South", "Apple", 2000, "October"],
["East", "Grape", 7000, "December"],
["North", "Grape", 6000, "April"],
["East", "Pear", 8000, "February"],
["North", "Apple", 7000, "August"],
["North", "Orange", 7000, "July"],
["North", "Apple", 6000, "June"],
["South", "Grape", 8000, "September"],
["West", "Apple", 3000, "October"],
["South", "Orange", 10000, "November"],
["West", "Grape", 4000, "July"],
["North", "Orange", 5000, "August"],
["East", "Orange", 1000, "November"],
["East", "Orange", 4000, "October"],
["North", "Grape", 5000, "August"],
["East", "Apple", 1000, "December"],
["South", "Apple", 10000, "March"],
["East", "Grape", 7000, "October"],
["West", "Grape", 1000, "September"],
["East", "Grape", 10000, "October"],
["South", "Orange", 8000, "March"],
["North", "Apple", 4000, "July"],
["South", "Orange", 5000, "July"],
["West", "Apple", 4000, "June"],
["East", "Apple", 5000, "April"],
["North", "Pear", 3000, "August"],
["East", "Grape", 9000, "November"],
["North", "Orange", 8000, "October"],
["East", "Apple", 10000, "June"],
["South", "Pear", 1000, "December"],
["North", "Grape", 10000, "July"],
["East", "Grape", 6000, "February"]
];
/* Write the column headers. */
$worksheet->writeString([0, 0], "Region");
$worksheet->writeString([0, 1], "Item");
$worksheet->writeString([0, 2], "Volume");
$worksheet->writeString([0, 3], "Month");
/* Write the row data. */
for ($i = 0; $i < count($data); $i++) {
$worksheet->writeString([$i + 1, 0], $data[$i][0]);
$worksheet->writeString([$i + 1, 1], $data[$i][1]);
$worksheet->writeNumber([$i + 1, 2], $data[$i][2]);
$worksheet->writeString([$i + 1, 3], $data[$i][3]);
}
/* Add the autofilter. */
$worksheet->autofilter([0, 0, 50, 3]);
$workbook->close();