基本操作
use PHPExcel;
use PHPExcel_IOFactory;
use PHPExcel_Cell;
$excel = new PHPExcel();
$sheet = $excel->setActiveSheetIndex(0);
$sheet->setCellValue('A1', 'Hello');
$sheet->setCellValue('B1', 99);
$sheet->setCellValue('C1', '=SUM(A1:B1)');
$sheet->setCellValue('D1', true);
$current_sheet = $excel->getActiveSheet();
$current_sheet->setTitle('Test001');
$file_path = 'myexchel.xlsx';
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($file_path);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename=' . $file_paty . ')';
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007');
$objWriter->save( 'php://output');
$server = $this->request->server();
$fileurl = $server['REQUEST_SCHEME'] .'://'. $server['HTTP_HOST'] . '/export/' . $file_name;
return show(200, 'ok', $fileurl);
设置表格样式和数据格式
设置默认的字体和大小
$objPHPExcel = new PHPExcel();
$objPHPExcel->getDefaultStyle()->getFont()->setName( 'Arial');
$objPHPExcel->getDefaultStyle(