forked from lekoala/spread-compat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
60 lines (48 loc) · 1.49 KB
/
test.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
<?php
use LeKoala\SpreadCompat\Xlsx\Native;
use Shuchkin\SimpleXLSXGen;
require './vendor/autoload.php';
require './res/F.php';
use LeKoala\F;
error_log(-1);
$native = new Native();
$data = $native->readFile(__DIR__ . '/tests/data/header.xlsx');
// var_dump(iterator_to_array($data));
$native = new Native();
$data = $native->readFile(__DIR__ . '/tests/data/header.xlsx', assoc: true);
// var_dump(iterator_to_array($data));
$books = [
['ISBN', 'title', 'author', 'publisher', 'ctry', 'date', 'raw'],
[618260307, 'The Hobbit 00', 'J. R. R. Tolkien', 'Houghton Mifflin', 'USA', '2020-05-20', "\0" . '2020-10-04 16:02:00'],
[908606664, 'Slinky Malinki', 'Lynley Dodd', 'Mallinson Rendel', 'NZ', '2022-08-20', "\0" . '2020-10-04 16:02:00']
];
$xlsx = SimpleXLSXGen::fromArray($books);
// $xlsx->saveAs(__DIR__ . '/.dev/books.xlsx');
// Short style faker data
function gen($max = 100_000)
{
$i = 0;
while ($i < $max) {
$i++;
yield [
$i,
F::d(),
F::dt(),
F::i(10_000, 30_000),
$fn = F::fn(),
$sn = F::sn(),
F::em($fn . $sn),
F::uw(5, 10),
F::addr(),
$ctry = F::ctry(),
F::l($ctry),
F::b(),
F::pick('1', ''),
F::m(),
];
}
}
// Yes, you can stream the response directly
// Even if it has 1 million rows and that it creates a file of 97 mb...
$native = new Native();
$native->output(gen(), 'books.xlsx');