123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- require_once(__DIR__ . '/../vendor/autoload.php');
- use Pxlswrite\DB\DB;
- use Pxlswrite\Pxlswrite;
- use Pxlswrite\WebSocket\WebSocketClient;
- $time = time();
- $fileObj = new Pxlswrite(['path' => __DIR__ . '/uploads']);
- $pushHandle = new WebSocketClient('ws://192.168.18.192:9502', $_GET['fd']);
- $fileObj->fileName('123.xlsx');
- $style = [
- 'align' => [Pxlswrite::FORMAT_ALIGN_CENTER, Pxlswrite::FORMAT_ALIGN_VERTICAL_CENTER],
- 'border' => Pxlswrite::BORDER_SLANT_DASH_DOT,
- 'background' => Pxlswrite::COLOR_RED,
- 'fontColor' => Pxlswrite::COLOR_BLUE,
- 'fontSize' => 30,
- 'font' => 'FontName',
- 'number' => '#,##0',
- 'bold' => true,
- 'strikeout' => false,
- 'wrap' => true,
- 'italic' => true,
- ];
- $field = [
- 'id' => ['name' => 'title'],
- 'c1' => ['name' => 'age'],
- 'c2' => ['name' => 'year'],
- 'c3' => ['name' => 'kk'],
- 'c4' => ['name' => 'll'],
- 'c5' => ['name' => 'aa', 'callback' => 'myFormat']
- ];
- $filePath = $fileObj->field($field)
- ->setDataByGenerator('generateData', $pushHandle)
- ->setRow('A1:A3', 80, $style)
- ->setColumn('A:F', 20, ['background' => Pxlswrite::COLOR_GRAY])
- ->setRow('A1', 50, ['background' => Pxlswrite::COLOR_PINK, 'align' => [Pxlswrite::FORMAT_ALIGN_CENTER, Pxlswrite::FORMAT_ALIGN_VERTICAL_CENTER]])
- ->setColumn('F:F', 60, ['background' => Pxlswrite::COLOR_YELLOW])
- ->defaultFormat(['background' => Pxlswrite::COLOR_GREEN])
- ->mergeCells('A1:C1', 'Merge cells', ['align' => [Pxlswrite::FORMAT_ALIGN_CENTER, Pxlswrite::FORMAT_ALIGN_VERTICAL_CENTER]])
- ->output();
- $memory = floor((memory_get_peak_usage()) / 1024 / 1024) . "MB";
- $execute_time = time() - $time . 's';
- echo json_encode(['code' => 1, 'msg' => '导出完毕', 'url' => '/download.php?file=' . $filePath, 'data' => ['memory' => $memory, 'excute_time' => $execute_time]]);
- function generateData()
- {
- $db = DB::getInstance();
- $step = 10000;
- for ($i = 0; $i < 100000; $i = $i + $step) {
- yield $db->get_records_sql("select * from sheet1 limit {$i},{$step}", null, PDO::FETCH_ASSOC);
- }
- }
- function myFormat($v, $values)
- {
- return $v . '自定义格式化-' . $values['id'];
- }
|