Issues (5)

example.php (1 issue)

Labels
Severity
1
<?php
2
3
require __DIR__ . '/vendor/autoload.php';
4
5
use Zhaqq\Xlsx\XlsxWriter;
0 ignored issues
show
The type Zhaqq\Xlsx\XlsxWriter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Zhaqq\Xlsx\Writer\Builder;
7
8
date_default_timezone_set('PRC');
9
$start = microtime(true);
10
ini_set('memory_limit', '20M');
11
12
times($start);
13
14
try {
15
    $writer = new Builder();
16
17
    $fileName = __DIR__ . '/data/xlsx_writer' . date('Ymd-His') . '.xlsx';
18
    $writer->buildHeader('sheet_name_1', otherHead());
19
    $writer->buildHeader('sheet_name_2', clothingHead());
20
21
    foreach (rows() as $row) {
22
        $writer->writeSheetRow($row[0], $row[1]);
23
    }
24
    times($start);
25
26
    $writer->writeToFile($fileName);
27
28
    times($start);
29
30
} catch (\Exception $exception) {
31
    var_dump($exception->getMessage());
32
}
33
34
35
function rows()
36
{
37
    for ($i = 0; $i < 20; $i++) {
38
        if ($i % 2) {
39
            yield ['sheet_name_1', [
40
                'SKU' . $i,
41
                '尺码' . $i,
42
                '净重' . $i,
43
                '单价' . $i,
44
            ]];
45
        } else {
46
            yield ['sheet_name_2', [
47
                'SKU' . $i,
48
                '尺码' . $i,
49
                '净重' . $i,
50
                '单价' . $i,
51
52
            ]];
53
        }
54
    }
55
}
56
57
function rowsE()
58
{
59
    for ($i = 0; $i < 100; $i++) {
60
        if ($i % 2) {
61
            yield ['非服装', [
62
                'sku' => 'SKU' . $i,
63
                'skc' => 'SKC' . $i,
64
                'size' => '尺码' . $i,
65
                'real_weight' => '净重' . $i,
66
                'us_cost' => '单价' . $i,
67
            ]];
68
        } else {
69
            yield ['服装', [
70
                'sku' => 'SKU' . $i,
71
                'size' => '尺码' . $i,
72
                'real_weight' => '净重' . $i,
73
                'us_cost' => '单价' . $i,
74
            ]];
75
        }
76
    }
77
}
78
79
function times($start, $object = 'XlsxWriter')
80
{
81
    echo $object, PHP_EOL;
82
    echo microtime(true) - $start, PHP_EOL;
83
    echo '#', floor((memory_get_peak_usage(true)) / 1024 / 1024), "MB", PHP_EOL;
84
    echo '#', floor((memory_get_usage(true)) / 1024 / 1024), "MB", PHP_EOL, PHP_EOL;
85
}
86
87
88
function clothingHead()
89
{
90
    return [
91
        'SKU' => 'string',
92
        '尺码' => 'string',
93
        '净重' => 'string',
94
        '单价' => 'float3',
95
    ];
96
}
97
98
function otherHead()
99
{
100
    return [
101
        'SKU' => 'string',
102
        '尺码' => 'string',  // sku
103
        '净重' => 'string',  // sku
104
        '单价' => 'prices',  // sku
105
    ];
106
}
107
108
function word($i)
109
{
110
    return [
111
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'Q', 'O', 'P', 'Q', 'R', 'S'
112
    ][$i];
113
}
114