感受技術掌握的有些太雜了,一下子鼓搗java,一下子鼓搗php,一邊還搞着.net, maybe this just is life.php
此前同事給某縣政法委作的一套維穩信息平臺,數據庫是封裝了mysql,如今客戶想把裏面的數據導出遷移到省裏的某套平臺中,最好是導出到excel中,網上搜索資料後算是簡單實現了。java
1.下載PHPExcel類庫,http://phpexcel.codeplex.com/,放入本地Lib/phpexcel中mysql
2.參照示例實現導出excel代碼以下:sql
include_once './lib/phpexcel/PHPExcel.class.php'; include_once './lib/phpexcel/phpexcel/IOFactory.php'; $inputFileName='./dispute.xls'; $excel = PHPExcel_IOFactory::load($inputFileName); $excel->getProperties()->setCreator("sxg") ->setLastModifiedBy("sxg") ->setTitle("矛盾糾紛導出數據") ->setSubject("矛盾糾紛導出數據") ->setDescription("dispute矛盾糾紛導出數據"); $excel->setActiveSheetIndex(0); $objActSheet = $excel->getActiveSheet(); $SQL = "SELECT * FROM dispute order by dispId limit 0,2"; $rst = DB::Execute($SQL, 20011, 'dispute', 'admin', '', '',"query"); $arr = split("\1",$rst); $row=2; foreach($arr as $rs){ $col=0; $valArr = split("\2",$rs); foreach($valArr as $val) { $objActSheet->setCellValueByColumnAndRow($col,$row,$val); $col++; } $row++; } $objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5'); $objWriter->save(str_replace('.php', '.xls', __FILE__));