導出步驟
1.新建一個excel表格
實例化PHPExcel類
2.創建sheet(內置表)
createSheet()
setActiveSheetIndex()
getActiveSheet()
3.填充數據
setCellValue()
4.保存文件
PHPExcel_IOFactory::createWriter()
save()
setActiveSheetIndex(0); $objSheet = $objPHPExcel->getActiveSheet(); //獲得當前sheet $objSheet->setTitle(demo); //給當前sheet設置名稱 $array = array( array(姓名,分數), array(李四,60), array(王五,70) ); $objSheet->setCellValue(A5,姓名); $objSheet->setCellValue(B5,分數); //給當前sheet填充數據 $objSheet->setCellValue(A6,張三); $objSheet->setCellValue(B6,70); $objSheet->fromArray($array); //直接加載數據塊填充數據 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); //按照指定格式生成excel文件 $objWriter->save(str_replace('.php', '.xls', __FILE__));