phpexcel使用实例
Posted 半醉半醒的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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使用实例的主要内容,如果未能解决你的问题,请参考以下文章