文件名称:PHPExecl.tar.gz
文件大小:3.92MB
文件格式:GZ
更新时间:2021-01-11 08:17:13
PHPExcel
亲测没有问题,使用方法(*输出Excel之前,不可以有echo,var_dump()等,否则报错*) 1,首先引入 2,$objPHPExcel = new PHPExcel();$objPHPExcelWrite = new PHPExcel(); 3,读: $filename = "/www/htdocs/invlist.xlsx"; $objReader = PHPExcel_IOFactory::createReaderForFile($filename); $objPHPExcel = $objReader->load($filename); $objPHPExcel->setActiveSheetIndex(0); 4,写 header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="resinvlist.xls"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed 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 $objWriter = new PHPExcel_Writer_Excel5($objPHPExcelWrite); $objPHPExcelWrite->getActiveSheet()->getStyle('C')->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT); $objPHPExcelWrite->setActiveSheetIndex(0) ->setCellValue( "A1", 'ID' ) ->setCellValue( "B1", 'CustomerExID' ) ->setCellValue( "C1",'InvNo'); Last: $objWriter->save('php://output');