Later used many times before tossing the record for a long time
1 download phpexcel here directly under
https://github.com/PHPOffice/PHPExcel
After 2 download, unzip
New vendor directory file folder thinkphp classes phpexcel then copy the decompressed file inside the inside to phpexcel
Results shown in Figure
3 If you are using
It encapsulates a derivation function
/ * * * Direct export content production needs * @param $ Field, * @param $ List * @param String $ title * @throws \ PHPExcel_Exception * @throws \ PHPExcel_Writer_Exception * / public function phpExcelList (Field, $, $ List, $ filename = ' file ' ) { Vendor ( " PHPExcel.PHPExcel " ); $ objPHPExcel = new new \ PHPExcel (); $ objWriter = new new \ PHPExcel_Writer_Excel5 ($ objPHPExcel); // save the settings format version the foreach ($ List AS $key => $value) { foreach ($field as $k => $v) { if ($key == 0) { $objPHPExcel->getActiveSheet()->setCellValue($k . '1', $v[1]); } $i = $key + 2; //表格是从2开始的 $objPHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]); } } header("Pragma: public"); header("Expires: 0"); header("Cache-Control:must-revalidate, post-check=0, pre-check=0"); header("Content-Type:application/force-download"); header("Content-Type:application/vnd.ms-execl"); header("Content-Type:application/octet-stream"); header("Content-Type:application/download");; header('Content-Disposition:attachment;filename='.$filename.'.xls'); header("Content-Transfer-Encoding:binary"); $objWriter->save('php://output'); }
How to call 4
//导出 public function Output() { $data=array( 0=>array('id'=>1,'serial_number'=>'123','batch'=>'1'), 1=>array('id'=>2,'serial_number'=>'124','batch'=>'2'), 2=>array('id'=>3,'serial_number'=>'125','batch'=>'3'), ); $filename='序列号'; $field = array( 'A' => array('id', '序号'), 'B' => array('serial_number', '序列号'), 'C' => array('batch', '批次'), ); //$this->downloadExcel($data,$title,$filename); $this->phpExcelList($field,$data,$filename); }
If you want to continue an additional $ field then please write back C D excel so this is the inside of the listed $ data inside of data similar
Results in Figure 5