仓酷云

标题: PHP网页编程之生成Excel文件典范(1):办事端 [打印本页]

作者: 小魔女    时间: 2015-2-4 00:09
标题: PHP网页编程之生成Excel文件典范(1):办事端
不过语法好学,但是怎么用语法来实现每个人都有每个人的方式,几乎是各有千秋。然而借鉴别人成功的代码,绝对是有益无害,因此,多看那些经过千锤百炼凝出来的经典代码,是进阶的最好方法。excel|生成excel   <?php
    ob_start();

?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 10">
<link rel=File-List href="Page.files/filelist.xml">
<style id="Book1_10519_Styles">
<!--table
    {mso-displayed-decimal-separator:"\.";
    mso-displayed-thousand-separator:"\,";}
.font510519
    {color:windowtext;
    font-size:9.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:宋体;
    mso-generic-font-family:auto;
    mso-font-charset:134;}
.xl1510519
    {padding-top:1px;
    padding-right:1px;
    padding-left:1px;
    mso-ignore:padding;
    color:windowtext;
    font-size:12.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:宋体;
    mso-generic-font-family:auto;
    mso-font-charset:134;
    mso-number-format:General;
    text-align:general;
    vertical-align:middle;
    mso-background-source:auto;
    mso-pattern:auto;
    white-space:nowrap;}
.xl2210519
    {padding-top:1px;
    padding-right:1px;
    padding-left:1px;
    mso-ignore:padding;
    color:windowtext;
    font-size:12.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:宋体;
    mso-generic-font-family:auto;
    mso-font-charset:134;
    mso-number-format:General;
    text-align:general;
    vertical-align:middle;
    border:.5pt solid windowtext;
    background:silver;
    mso-pattern:auto none;
    white-space:nowrap;}
.xl2310519
    {padding-top:1px;
    padding-right:1px;
    padding-left:1px;
    mso-ignore:padding;
    color:windowtext;
    font-size:12.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:宋体;
    mso-generic-font-family:auto;
    mso-font-charset:134;
    mso-number-format:General;
    text-align:general;
    vertical-align:middle;
    border:.5pt solid windowtext;
    mso-background-source:auto;
    mso-pattern:auto;
    white-space:nowrap;}
ruby
    {ruby-align:left;}
rt
    {color:windowtext;
    font-size:9.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:宋体;
    mso-generic-font-family:auto;
    mso-font-charset:134;
    mso-char-type:none;}
-->
</style>
</head>

<body>
<!--[if !excel]>  <![endif]-->
<!--以下信息由 Microsoft Excel 的“宣布为 Web 页”导游生成。-->
<!--假如统一条目从 Excel 中从头宣布,则一切位于 DIV 标志之间的信息均将被交换。-->
<!----------------------------->
<!--“从 EXCEL 宣布 Web 页”导游入手下手-->
<!----------------------------->

<div id="Book1_10519" align=center x:publishsource="Excel">
<?php
    if(false==isset($_POST["data"]))
    {
        echo    "没有要显示的数据"    ;
        exit;
    }
?>
<table x:str border=0 cellpadding=0 cellspacing=0 width=519 style='border-collapse:
collapse;table-layout:fixed;width:389pt'>
<col width=72 span=2 style='width:54pt'>
<col width=163 style='mso-width-source:userset;mso-width-alt:5216;width:122pt'>
<col width=87 style='mso-width-source:userset;mso-width-alt:2784;width:65pt'>
<col width=125 style='mso-width-source:userset;mso-width-alt:4000;width:94pt'>
<tr height=19 style='height:14.25pt'>
  <td height=19 class=xl1510519 width=72 style='height:14.25pt;width:54pt'></td>
  <td class=xl1510519 width=72 style='width:54pt'></td>
  <td class=xl1510519 width=163 style='width:122pt'></td>
  <td class=xl1510519 width=87 style='width:65pt'></td>
  <td class=xl1510519 width=125 style='width:94pt'></td>
</tr>
<tr height=19 style='height:14.25pt'>
  <td height=19 class=xl1510519 style='height:14.25pt'></td>
  <td class=xl2210519>称号</td>
  <td class=xl2210519 style='border-left:none'>地址</td>
  <td class=xl2210519 style='border-left:none'>QQ号</td>
  <td class=xl2210519 style='border-left:none'>电子邮件</td>
</tr>
<?php

    foreach($_POST["data"] as $val)
    {
        extract($val)    ;
?>

<tr height=19 style='height:14.25pt'>
  <td height=19 class=xl1510519 style='height:14.25pt'></td>
  <td class=xl2310519 style='border-top:none'><?php echo $username ; ?></td>
  <td class=xl2310519 style='border-top:none;border-left:none'><?php echo $add ; ?></td>
  <td class=xl2310519 style='border-top:none;border-left:none'><?php echo $qq ; ?> </td>
  <td class=xl2310519 style='border-top:none;border-left:none'><?php echo $email ; ?></td>
</tr>
<?php
    }
?>

<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=163 style='width:122pt'></td>
  <td width=87 style='width:65pt'></td>
  <td width=125 style='width:94pt'></td>
</tr>
<![endif]>
</table>

</div>


<!----------------------------->
<!--“从 EXCEL 宣布 Web 页”导游停止-->
<!----------------------------->
</body>

</html>
<?php
    $outStr=ob_get_contents();
    ob_end_clean();
     
        header("Content-type: application/octet-stream");
        Header("Accept-Ranges: bytes");
        Header("Accept-Length: ".strlen($outStr));
        Header("Content-Disposition: attachment; filename=test.Xls");
        // 输入文件内容         
        echo $outStr    ;
?>   现在,也有了从事软件工程的想法,在经过了一个月的PHP培训学习之后,发现其实软件工程并没有想像中的那么难。
作者: 若相依    时间: 2015-2-4 09:28
先学习php和mysql,还有css(html语言很简单)我认为现在的效果比以前的方法好。
作者: 透明    时间: 2015-2-5 17:36
对于懒惰的朋友,我推荐php的集成环境xampp或者是wamp。这两个软件安装方便,使用简单。但是我还是强烈建议自己动手搭建开发环境。
作者: 小女巫    时间: 2015-2-13 00:58
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。
作者: 分手快乐    时间: 2015-3-3 11:58
说点我烦的低级错误吧,曾经有次插入mysql的时间 弄了300年结果老报错,其实mysql的时间是有限制的,大概是到203X年  具体的记不清啦,囧。
作者: 第二个灵魂    时间: 2015-3-11 10:43
再就是混迹于论坛啦,咱们的phpchina的论坛就很强大,提出的问题一般都是有达人去解答的,以前的帖子也要多看看也能学到不少前辈们的经验。别的不错的论坛例如php100,javaeye也是很不错的。
作者: 简单生活    时间: 2015-3-15 21:37
首先声明:我是一个菜鸟,是一个初学者。学习了一段php后总是感觉自己没有提高,无奈。经过反思我认为我学习过程中存在很多问题,我改变了学习方法后自我感觉有了明显的进步。
作者: 飘灵儿    时间: 2015-3-19 23:46
基础有没有对学习php没有太大区别,关键是兴趣。
作者: 爱飞    时间: 2015-3-22 01:08
说php的话,首先得提一下数组,开始的时候我是最烦数组的,总是被弄的晕头转向,不过后来呢,我觉得数组里php里最强大的存储方法,所以建议新手们要学好数组。
作者: 爱飞    时间: 2015-4-3 13:54
曾经犯过一个很低级的错误,我在文件命名的时候用了一个横线\\\\\\\'-\\\\\\\' 号,结果找了好几个小时的错误,事实是命名的时候 是不能用横线 \\\\\\\'-\\\\\\\' 的,应该用的是下划线  \\\\\\\'_\\\\\\\' ;
作者: 乐观    时间: 2015-4-4 16:59
最后祝愿,php会给你带来快乐的同时 你也会给他带来快乐。
作者: 若天明    时间: 2015-4-6 11:57
首推的搜索引擎当然是Google大神,其次我比较喜欢 百度知道。不过搜出来的结果往往都是 大家copy来copy去的,运气的的概率很大。
作者: 海妖    时间: 2015-4-7 10:53
有位前辈曾经跟我说过,phper 至少要掌握200个函数 编起程序来才能顺畅点,那些不熟悉的函数记不住也要一拿手册就能找到。所以建议新手们没事就看看php的手册(至少array函数和string函数是要记牢的)。
作者: 山那边是海    时间: 2015-4-16 18:11
这些中手常用的知识,当你把我说的这些关键字都可以熟练运用的时候,你可以选择自己
作者: 因胸联盟    时间: 2015-4-24 03:56
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
作者: 蒙在股里    时间: 2015-4-30 21:58
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,
作者: 金色的骷髅    时间: 2015-5-4 16:28
我要在声明一下:我是个菜鸟!!我对php这门优秀的语言也是知之甚少。但是我要在这里说一下php在网站开发中最常用的几个功能:
作者: 深爱那片海    时间: 2015-6-6 02:07
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
作者: 只想知道    时间: 2015-6-12 08:42
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
作者: 莫相离    时间: 2015-6-29 23:25
建议加几个专业的phper的群,当然啦需要说话的人多,一处一点问题能有人回答你的,当然啦要让人回答你的问题,平时就得躲在里面聊天,大家混熟啦,愿意回答你问题的人自然就多啦。
作者: 不帅    时间: 2015-7-4 01:37
爱上php,他也会爱上你。




欢迎光临 仓酷云 (http://www.ckuyun.com/) Powered by Discuz! X3.2