文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > 用PHP生成WORD,EXCEL文件等(附格式数组)
侵权投诉

用PHP生成WORD,EXCEL文件等(附格式数组)

网站开发必备,用PHP生成WORD,EXCEL文件

用PHP生成WORD,EXCEL文件
<? //生成EXCEL文件
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");

echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
?>

//改动相应文件头就可以输出.doc .xls等文件格式了

在php环境运行上面的代码,大家就可以看到浏览器询问用户是否下载excel文档,点击保存,硬盘上就多了一个excel的文件,使用excel打开就会看到最终的结果,怎么样不错吧。

  其实在做真正的应用的时候,大家可以将数据从数据库中取出,然后按照每一列数据结束后加\t,每一行数据结束后加\n的方法echo出来,在php的开头用header("Content-type:application/vnd.ms-excel");表示输出的是excel文件,用header("Content-Disposition:filename=test.xls");表示输出的文件名为text.xls。这样就ok了。

  我们更可以修改header让他输出更多格式的文件,这样php在处理各种类型文件方面就更加方便了


哈哈,托你的福,我已经知道怎么解决了,你把下面着段代码存为.xls文件看看,知道该怎么做了吧?


<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="doc.guandang.net;
<head>
<meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name></x:Name>
<x:WorksheetOptions>
<x:DisplayGridlines/>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->

</head>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td align="center" class="big6" >Users (except the ones disabled)</td></tr>

<tr><td class="greyborder">
<table border="1" align="center" width="100%" cellpadding="1" cellspacing="1">
<tr align="center">
<td class="TableTopHeader" nowrap>
Login </td>
<td class="TableTopHeader" nowrap>
Name </td>
<td class="TableTopHeader" width="3%" nowrap>
EMail </td>
<td class="TableTopHeader" nowrap>
Department </td>
<td class="TableTopHeader" nowrap>
Position </td>
<td class="TableTopHeader" nowrap width="1%">
Level </td>
<td class="TableTopHeader">Address</td>
<td class="TableTopHeader">Phone</td>
</tr>
<tr class="even">


第1页

TOP相关主题

你可能喜欢

热门文档

相关文档

  • 导入导出工具

    导入导出工具 Oracle导入导出工具总览这些使用工具可以使你完成以下工作: 对历史数据进行归档(导出) 保存表(有数据或没数据)的定义,以防止用 户错误失效发生 在...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email