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