首页 > 代码库 > phpexcel使用实例

phpexcel使用实例

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使用实例