PHP操作excel类 PHPExcel
生活随笔
收集整理的這篇文章主要介紹了
PHP操作excel类 PHPExcel
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
PHP操作excel類 PHPExcel
http://www.cr173.com/soft/40741.html ? 我的微云:http://share.weiyun.com/2db79f1438f87999cfb09ca05890d764
下載后:
Tests/01simple.php ?看代碼就可以了 ?很簡單
?--------------------
我的案例(打包):
將dede站內(nèi)文章導(dǎo)出到excel中 ? http://share.weiyun.com/76eac46f5f5897bf70518c9043366681
?
我的案例分析
article_add.phprequire_once 'phpexcel/Classes/PHPExcel.php';//fff 注意一定要第一個引入這個文件 PHPExcel.php 否則會出現(xiàn)404錯誤 require_once(dirname(__FILE__).'/config.php'); CheckPurview('a_New,a_AccNew'); require_once(DEDEINC.'/customfields.func.php'); require_once(DEDEADMIN.'/inc/inc_archives_functions.php'); ini_set('memory_limit', '-1');//取消內(nèi)存使用消耗限制 ? 這里很重要 ?否則只能導(dǎo)出部分數(shù)據(jù)if(file_exists(DEDEDATA.'/template.rand.php')) {require_once(DEDEDATA.'/template.rand.php'); } if(empty($dopost)) $dopost = '';if($dopost!='save') {//PHPexcel開始 //fffmysql_query("set names utf8");//這里一定要注意寫上utf8$sql="select aid,title from dede_archives arc left join dede_addonarticle as onarc on arc.id=onarc.aid limit 0,100;";//fff注意這里限定一下文章數(shù)量 否則內(nèi)存消耗完畢 $result=mysql_query($sql); while($row=mysql_fetch_assoc($result)){$rows[]=$row; } //PHP EXCEL 開始 error_reporting(E_ALL);date_default_timezone_set('Europe/London');// Create new PHPExcel object echo date('H:i:s') , " Create new PHPExcel object" , PHP_EOL; $objPHPExcel = new PHPExcel();// Set document properties echo date('H:i:s') , " Set document properties" , PHP_EOL; $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")->setLastModifiedBy("Maarten Balliauw")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("Test result file");// Add some data echo date('H:i:s') , " Add some data" , PHP_EOL;foreach($rows as $k=>$v){$kk=$k+1;$v['aid'] = MakeArt($v['aid'],true,true,0);//根據(jù)aid得到 文章url$objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$kk}", "{$v['title']}") //給表格賦值->setCellValue("B{$kk}", "{$v['aid']}"); //給表格賦值 }/* // Miscellaneous glyphs, UTF-8 $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A4', 'Miscellaneous glyphs')->setCellValue('A5', 'éàèùaê?????ü???ü?'); */// Rename worksheet echo date('H:i:s') , " Rename worksheet" , PHP_EOL; $objPHPExcel->getActiveSheet()->setTitle('Simple');// Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0);// Save Excel 2007 file echo date('H:i:s') , " Write to Excel2007 format" , PHP_EOL; $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', __FILE__) , PHP_EOL;// Echo memory peak usage echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , PHP_EOL;// Echo done echo date('H:i:s') , " Done writing file" , PHP_EOL;
?-------------------------------------
?
phpexcel導(dǎo)入excel數(shù)據(jù)到MYSQL數(shù)據(jù)庫 ?http://blog.163.com/ylx282006@126/blog/static/59772717201201143512283/
?
轉(zhuǎn)載于:https://www.cnblogs.com/zff193/p/4269248.html
總結(jié)
以上是生活随笔為你收集整理的PHP操作excel类 PHPExcel的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android tcp 工具,TcpIp
- 下一篇: tomcat GET 编码疑惑