PHP操作excel类 PHPExcel
http://www.cr173.com/soft/40741.html 我的微云:http://share.weiyun.com/2db79f1438f87999cfb09ca05890d764
下载后:
Tests/01simple.php 看代码就可以了 很简单
--------------------
我的案例(打包):
将dede站内文章导出到excel中 http://share.weiyun.com/76eac46f5f5897bf70518c9043366681
我的案例分析
article_add.php
require_once 'phpexcel/Classes/PHPExcel.php';//fff 注意一定要第一个引入这个文件 PHPExcel.php 否则会出现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');//取消内存使用消耗限制 这里很重要 否则只能导出部分数据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注意这里限定一下文章数量 否则内存消耗完毕
$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);//根据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', 'éàèùâêîôûëïüÿäöüç');
*/// 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导入excel数据到MYSQL数据库 http://blog.163.com/ylx282006@126/blog/static/59772717201201143512283/