原本这一作用是一个朋友要做的,由于,以前从未有触碰过excel,这一作用都没有科学研究过,可是,这一作用较为好用的,由于,许多企业尽管有网站,可是,企业其他单位将会也要把企业数据信息导出来到紙上面,便于科学研究企业数据信息之用,因此,许多的企业对这一作用就需要求应用。
近几天科学研究了一下从织梦cms导出来数据信息作用,原本想自身去写一个这一php程序导出来到excel作用来,可是,自身从未有科学研究过excel,因此,就沒有往下去敲代码,因此检索了一放网上的有关这一实例教程,結果检索的实例教程到不是少,可是,沒有好多个是恰当的,包含百度搜索工作经验里边,检测了成千上万个都不行。
这一里边有许多的事例,包含excel,csv,word,pdf,htm等从数据信息库导出来来的文档文件格式,能够参照一下事例。
织梦cms产业基地先把从织梦cms系统软件导出来来的实际效果上一图给大伙儿看一下:
可是,我碰到了一个难题便是之前的時间,在excel是一切正常显示信息的,可是,如今再加的時间则显示信息:1970-01-01 ,我检索了一放网上实例教程,都没有寻找有关实例教程。见到在网上说excel也是有bug 并且excel测算的時间是以1900-1-1刚开始的,不知道道不是是也要计算一下?
時间难题总算寻找缘故了,原先字段名写不对。原本是pubdate,結果写出了sentdate
其他全是一切正常显示信息的,如今就详细介绍一下从织梦cms系统软件导出来数据信息的方式:
1.从海外网站免费下载上边的phpexcel类库,缓解压力后,放进网站根目录里边。
2.随后,写导出来程序,这一能够参照这儿面的事例写,一定要注意的是:若你的不好,程序将会会提醒404不正确,这一便是你的相对路径沒有设定好,一开始时,因为我是这一缘故一直弄错误,最终,才发觉原先是相对路径不对。
这一导出来程序关键做以下四步:
a. 从织梦cms中查寻出数据信息
b.设定报表
c.把数据信息放进报表
c.輸出数据信息到excel里边
里边的设定大多数数全是启用phpexcel类里边的涵数,这儿很少表述了,看着我在文档dedebase.php写的编码:
$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
//织梦cms产业基地
$objPHPExcel- setActiveSheetIndex(0)
- setCellValue( A1 , id )
- setCellValue( B1 , 题目 )
- setCellValue( C1 , 排列 )
- setCellValue( D1 , 出版发行時间 )
- setCellValue( E1 , 重要词 )
- setCellValue( F1 , 介绍 )
- setCellValue( G1 , 公布時间 )
- setCellValue( H1 , vip会员id )
- setCellValue( I1 , flag )
- setCellValue( J1 , 频道id
$query = Select * From `dede_archives`
$dsql- SetQuery($query);
$dsql- Execute();
$index = 1;
while ($row = $dsql- GetArray()) {
$index++;
$objPHPExcel- setActiveSheetIndex(0)
- setCellValue( A .
$index, $row[ id ])- setCellValue( B .
$index, iconv( gb2312 , utf-8 ,$row[ title ]))- setCellValue( C .
$index, $row[ sortrank ])- setCellValue( D .
$index, 2015-7-23 )- setCellValueExplicit( E .
$index, iconv( gb2312 , utf-8 ,$row[ keywords ]))- setCellValue( F .
$index, iconv( gb2312 , utf-8 ,$row[ description ]))- setCellValue( G .
$index, gmdate( Y-m-d ,$row[ pubdate ]))- setCellValue( H .
$index, $row[ mid ])- setCellValue( I .
$index, $row[ flag ])- setCellValue( J .
$index, $row[ typeid
}
// Rename
$objPHPExcel- getActiveSheet()- setTitle( Simple
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel- setActiveSheetIndex(0);
// Redirect output to a client s web browser (Excel5)
header( Content-Type: application/vnd.ms-excel
header( Content-Disposition: attachment;filename= list.xls
header( Cache-Control: max-age=0
$objWriter = PHPExcel_IOFactory :: createWriter($objPHPExcel, Excel5
$objWriter- save( php://output
exit;
非常非常留意:在这里个最上一行要写喜欢你的从网站在免费下载出来的phpexcel类的相对路径,也便是把这一类引进到这一文档里边,仅有引进到里边才可以启用。
最终,在你的模版里边把下边这二行中的随意一行写在模版里就可以: