1234567891011121314151617181920212223242526272829 |
- <?php
- require_once(__DIR__ . '/../vendor/autoload.php');
- use Pxlswrite\Pxlswrite;
- $fileObj = new Pxlswrite(['path' => __DIR__. '/uploads']);
- $filePath = $fileObj
- ->fileName('simple.xlsx','sheet1')
- ->field([
- 'username'=>['name'=>'用户名'],
- 'age'=>['name'=>'年龄']
- ])
- ->setGeneralData('generateData')
- ->output();
- $fileObj->download($filePath);
- function generateData(){
- for($i=0;$i<10000;$i++){
- yield [
- [
- 'username' => '匿名用户'.rand(1,9999),
- 'age' => rand(1,100),
- ]
- ];
- }
- }
|