PHP轻量级实现导出数据到cvs文件(原创)

#1 mulanhua

最近接到一个朋友的电话,需要将asp程序放到linux下,想到了移植到php,于是谷歌到了SpeedPHP。
由于哥自己是做Java开发的,所以项目是基于Netbeans7.0 + Glassfish3 + quercus-4.0.18 开发的。
原asp程序有个功能是导出报名数据到excel,移植到php的话,程序得重写。经过小半天的学习SpeedPHP手册,和谷歌大婶的讨论,还有自己的尝试。总算搞了出来。
之前也到论坛看过,没有类似的代码,提取出来和大家分享。
俺之前几乎没写过php,高手就不要笑话了。
项目工程截图:

main.php
......   

function e2e() { // 导出报名列表到csv文件
        header("Content-Type: text/csv");
        header("Content-Disposition: attachment; filename=中日招生报名表.csv");
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0');
        header('Pragma:public');
        $tpl = $this->spArgs("tpl", "skyblue"); // 这里接收tpl参数,使得模板变化
        $baoming = spClass("baoming");
        $this->results = $baoming->findAll();
        $this->display("{$tpl}/e2e.html");      
    }

......
e2e.html
"中日经济技术学院报名表","","","","","","","","","","","","","","","","","","","","","","","","","" "姓名","性别","年龄","毕业中学","毕业时间","文理科","准考证号","高考时间","高考地点","外语","语文","数学","总分","联系电话","通讯地址","报名时间","身份证","兴趣爱好","父亲姓名","父亲工作单位","母亲姓名","母亲工作单位","报名项目","备注" <{foreach from=$results item=one}> "<{$one.xingming}>","<{$one.xingbie}>","<{$one.nianling}>","<{$one.biyezhongxue}>","<{$one.biyeshijian}>","<{$one.wenlike}>","'<{$one.zhunkaozhenghao}>","<{$one.gaokaoshijian}>","<{$one.gaokaodidian}>","<{$one.waiyu}>","<{$one.yuwen}>","<{$one.shuxue}>","<{$one.zongfen}>","<{$one.lianxidianhua}>","<{$one.tongxundizhi}>","<{$one.baomingshijian}>","'<{$one.shenfenzheng}>","<{$one.xingquaihao}>","<{$one.fuqinxingming}>","<{$one.fuqingongzuodanwei}>","<{$one.muqinxingming}>","<{$one.muqingongzuodanwei}>","<{$one.baomingxiangmu}>","<{$one.beizhu}>" <{/foreach}>

2011-05-31 18:23:56

#2 mulanhua

没找到编辑自己的主题的链接。
难道是论坛限制?

2011-05-31 18:27:43

#3 mulanhua

没找到编辑自己的主题的链接。
难道是论坛限制?

2011-05-31 18:28:18

#4 mulanhua

第二段代码重发一下:
"中日经济技术学院报名表","","","","","","","","","","","","","","","","","","","","","","","","","" "姓名","性别","年龄","毕业中学","毕业时间","文理科","准考证号","高考时间","高考地点","外语","语文","数学","总分","联系电话","通讯地址","报名时间","身份证","兴趣爱好","父亲姓名","父亲工作单位","母亲姓名","母亲工作单位","报名项目","备注" 
<{foreach from=$results item=one}>
"<{$one.xingming}>","<{$one.xingbie}>","<{$one.nianling}>","<{$one.biyezhongxue}>","<{$one.biyeshijian}>","<{$one.wenlike}>","'<{$one.zhunkaozhenghao}>","<{$one.gaokaoshijian}>","<{$one.gaokaodidian}>","<{$one.waiyu}>","<{$one.yuwen}>","<{$one.shuxue}>","<{$one.zongfen}>","<{$one.lianxidianhua}>","<{$one.tongxundizhi}>","<{$one.baomingshijian}>","'<{$one.shenfenzheng}>","<{$one.xingquaihao}>","<{$one.fuqinxingming}>","<{$one.fuqingongzuodanwei}>","<{$one.muqinxingming}>","<{$one.muqingongzuodanwei}>","<{$one.baomingxiangmu}>","<{$one.beizhu}>"
<{/foreach}>

2011-05-31 18:30:23

#5 jake

不错!:handshake

2011-05-31 21:09:41

#6 mulanhua

多谢版主的称赞!
最近在oschina看到有新手咨询哪个框架适合新手用。俺当仁不让的推荐了speedphp;
http://www.oschina.net/question/190980_29377
并且给出了自己的评价:
使用之前,请忘记她是国产PHP框架;
使用之后,请记住她是国产PHP框架;
哇咔咔!

2011-10-14 10:18:43

#7 jake

多谢版主的称赞!
最近在oschina看到有新手咨询哪个框架适合新手用。俺当仁不让的推荐了speedphp;
http:// ...
mulanhua 发表于 2011-10-14 10:18
:handshake,谁用谁知道,呵呵

2011-10-14 11:30:00

#8 lkmtdgt

推荐此贴

2011-10-14 19:53:04

#9 lkmtdgt

推荐此贴

2011-10-14 19:53:05

#10 lkmtdgt

推荐此贴

2011-10-14 19:53:07

#11 mulanhua

因个人博客域名过期,旧有的工程目录图片已经挂了,放了新的链接。
[img=309,661]http://m3.img.srcdd.com/farm5/d/2012/1230/12/B2C76B4252A06AF234961ECF06528496_B500_900_309_661.PNG[/img]

2014-07-11 15:29:02