php制作Excel表格,并导出文件的例子! include文件在我的资源里! require_once 'PHPExcel/Writer/Excel5.php'; require_once 'PHPExcel.php'; $objExcel = new PHPExcel(); //默认编码 $objExcel->getDefaultStyle()->getFont()->setName(iconv('gbk', 'utf-8', '宋体')); //默认字体大小 $objExcel->getDefaultStyle()->getFont()->setSize(12); //默认显示位置为局中 *号所有单元格 $objExcel->getDefaultStyle()->getAlignment('*')->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objExcel->getDefaultStyle()->getAlignment('*')->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); $objProps = $objExcel->getProperties(); //创建excel属性 $objProps->setCreator("GCG-GRIRMS"); $objProps->setLastModifiedBy("GCG-GRIRMS"); $objProps->setTitle("Inspect Report"); $objProps->setSubject("Inspect Report Document"); $objProps->setDescription("Document,generated by PHPExcel."); $objProps->setKeywords("office excel PHPExcel"); $objProps->setCategory("Test"); //缺省情况下,PHPExcel会自动创建第一个sheet被设置SheetIndex=0 $objExcel->setActiveSheetIndex(0); $objActSheet = $objExcel->getActiveSheet(); //合并单元格 $objActSheet = $objExcel->getActiveSheet()->mergeCells('A1:d1'); //设置A单元格字体大小及样式 $objActSheet->getStyle('A1')->getFont()->setSize(25); $objActSheet->getStyle('A1')->getFont()->setBold(true); //A2单元格内容 $objActSheet->setCellValue('A2',"A2"); $objWriter = new PHPExcel_Writer_Excel5($objExcel); 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=" . strtotime("now") . ".xls"); header("Content-Transfer-Encoding:binary"); $objWriter->save("php://output");