1. 规定导出字段
$title = array(
'id' => '序号',
'finishTime' => '运单完成时间',
'business_name' => '负责商家',
'site_name' => '站点名称',
'waybill_number' => '运单号',
'order_total_price' => '订单金额',
'income' => '商家实收',
);
$info = array();
$info['title'] = $title;
$info['creator'] = $nickname;
$info['sheetName'] = '商家账单';
得到$info
2.获取数据源,二维数组,数组需包含$info中的title字段,字段顺序也需一致;得到$data
3.调用类的方法:
~~~
$objWriter = PHPExcelToolkit::export($data, $info);
~~~
4.设置头部
~~~
$this->_setHeader($filename);
protected function _setHeader($filename)
{
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename={$filename}");
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
}
~~~
5.定义文件名,保存
~~~
$filename = '骑手账单'. $start .'-'.$end .'.xls';
$objWriter->save('php://output');
~~~