码迷,mamicode.com
首页 > Web开发 > 详细

phpexcel使用实例

时间:2017-02-12 13:33:50      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:dir   val   cat   port   get   ica   app   return   for   

if($_GPC[‘export‘] != ‘‘){
                include(dirname(__FILE__).‘/./PHPExcel-1.8/Classes/PHPExcel.php‘);
                $template = ‘./sdpost2.xlsx‘;
    			//var_dump($_GPC);
    			$objReader = PHPExcel_IOFactory::createReaderForFile($template);
    			$objPHPExcel = $objReader->load($template);
    			//$objPHPExcel->setActiveSheetIndex(1);
    			$title = $objPHPExcel->getActiveSheet()->getCell(‘A2‘)->getValue();
    			
    			$title = eval(‘return "‘ . $title . ‘";‘);
    			$objPHPExcel->getActiveSheet()->setCellValue(‘A2‘, $title);
    			$objPHPExcel->getActiveSheet()->setCellValue(‘B5‘, $_GPC[‘time‘][‘start‘]);
    			$objPHPExcel->getActiveSheet()->setCellValue(‘C5‘, $_GPC[‘time‘][‘end‘]);
    		
    
    			$line_no = 8;
    			foreach($branches as $branch){
    				$objPHPExcel->getActiveSheet()->setCellValue("A{$line_no}", $branch[‘dist2‘]);
    				$objPHPExcel->getActiveSheet()->setCellValue("B{$line_no}", $branch[‘num‘]+0);
    				$objPHPExcel->getActiveSheet()->setCellValue("C{$line_no}", $branch[‘money‘]+0);
    
    				$line_no++;
    			}
    
    			//$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel2007‘);
    			//$objWriter->save(‘myexchel.xlsx‘);
    
    			// 输出 97-2003 版本的
    			header(‘Content-Type: application/vnd.ms-excel‘);
    			header(‘Content-Disposition: attachment;filename="‘ . $title . ‘.xls"‘);
    			header(‘Cache-Control: max-age=0‘);
                
    			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel5‘);
    			$objWriter->save(‘php://output‘);
    			return;
    			exit;
    		}

  

phpexcel使用实例

标签:dir   val   cat   port   get   ica   app   return   for   

原文地址:http://www.cnblogs.com/sbfnxk201/p/6390741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!