1、创建一个简单的Excel文件:
$config = ['path' => '/home/viest/'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->fileName('test.xlsx')
->header(['Item', 'Cost'])
->data([
['Rent', 1000],
['Gas', 100],
['Food', 300],
['Gym', 50],
])
->output();
2、插入图片
insertImage(int $row, int $column, string $localImagePath)
$excel = new \Vtiful\Kernel\Excel($config);
$freeFile = $excel->fileName("free.xlsx");
$freeFile->insertImage(5, 0, '/vagrant/ASW-G-66.jpg');
$freeFile->output();
3、定义一个公式
insertFormula(int $row, int $column, string $formula)
$excel = new \Vtiful\Kernel\Excel($config);
$freeFile = $excel->fileName("free.xlsx")
->header(['name', 'money']);
for($index = 0; $index < 10; $index++) {
$textFile->insertText($index+1, 0, 'vikin');
$textFile->insertText($index+1, 1, 10);
}
$textFile->insertText(12, 0, "Total");
$textFile->insertFormula(12, 1, '=SUM(B2:B11)');
$freeFile->output();
4、性能如何?
测试脚本
for($index = 0 ; $index < 10000 ; $index++){
$data[$index] = ['viest', 23, 666666666666666666, '银河市地球区程序村PHP组菜鸟湾66号', 15666666666];
}
$timeStart = microtime(true);
$config = [
'path' => '/vagrant/',
];
$excel = new \Vtiful\Kernel\Excel($config);
$textFile = $excel->fileName("test.xlsx")
->header(['name', 'age', 'id_card', 'address', 'phone'])
->data($data)
->outPut();
$timeEnd = microtime(true);
$time = $timeEnd - $timeStart;
echo "导出Excel花费: $time seconds\n";
结果
5、最后附上Github地址
bowtie: