php-xlswrite
https://github.com/viest/php-ext-xlswriter
100万数据,导出数据列较小的情况下,仅需几秒导出
time usage 3.9795 seconds memory usage 429.06633758545 MB
<?php
$export = isset($_GET['export']) ? true : false;
if ($export) {
ini_set('memory_limit', '1024M');
$starttime = microtime(true);
$config = ['path' => './execl-export'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->constMemory('tutorial01.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$boldStyle = $format->bold()->toResource();
$count = 1000000;
for ($i=0; $i < $count; $i++) {
$list[] = ['name' . $i , 1];
}
$fileObject->setRow('A1', 10, $boldStyle) // 写入数据前设置行样式
->header(['name', 'age'])
->data($list)
->output();
$endtime = microtime(true);
$times = $endtime - $starttime;
echo 'time usage ' . sprintf('%.4f' , $times) . ' seconds' . "\n";
echo 'memory usage ' . (memory_get_usage() / 1024 / 1024) . ' MB' . "\n";
}
?>
<meta charset="utf8"/>
<form method="get" action="">
<button name="export">导出</button>
</form>
导出数据在7列或以上时间就会增加
time usage 11.9661 seconds memory usage 429.06133270264 MB
<?php
$export = isset($_GET['export']) ? true : false;
if ($export) {
ini_set('memory_limit', '1024M');
$starttime = microtime(true);
$config = ['path' => './execl-export'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->constMemory('tutorial01.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$boldStyle = $format->bold()->toResource();
$count = 1000000;
for ($i=0; $i < $count; $i++) {
$list[] = ['name' . $i , 1 , 'sss' , 'ddd' , 'ffff' , 'eeee' , 'sddd'];
}
$fileObject->setRow('A1', 10, $boldStyle) // 写入数据前设置行样式
->header(['name', 'age' , 'school' , 'hobby' , 'number' , '222' , '3333'])
->data($list)
->output();
$endtime = microtime(true);
$times = $endtime - $starttime;
echo 'time usage ' . sprintf('%.4f' , $times) . ' seconds' . "\n";
echo 'memory usage ' . (memory_get_usage() / 1024 / 1024) . ' MB' . "\n";
}
?>
<meta charset="utf8"/>
<form method="get" action="">
<button name="export">导出</button>
</form>
phpExcel测试效果,请看 https://blog.csdn.net/szulilin/article/details/90722808?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-3