PHP导出MySQL数据库为EXCEL文件格式(.xls)的方法 http://www.kankanblog.com/read.php/144.htm
2007-06-29 13:30
931 查看
使用PHP导出MySQL数据库中的数据,文本格式为下面的格式,但导出的文件后缀名保存为EXCEL表格的后缀名:xls,导出的数据就是Excel文件了。
Table标签中的数据可以循环输出,就是你要导出到Excel表格文件中的数据。
相反的方法,可以把已经导出的数据导入MySQL数据库。
(可以把下面信息保存为Xls文件看看效果)
HTML标签的属性如:颜色color,bgcolor,font size等可以使用。
具体的实现代码可以参考这里。
<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="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>
<body link=blue vlink=purple leftmargin=0 topmargin=0>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td align="center" class="big6" >Users</td></tr>
<tr><td bgcolor=red>
<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">
<td class="mtlist">King</td>
<td class="mtlist"><b>Sangern</b></td>
<td class="mtlist" >XX@Gmail.com</td>
<td class="mtlist">Interneter</td>
<td class="mtlist">SEO</td>
<td class="mtlist">Admin</td>
<td class="mtlist">SH</td>
<td class="mtlist">110</td>
</tr>
</table>
</td></tr>
</table>
</body>
</html>
Table标签中的数据可以循环输出,就是你要导出到Excel表格文件中的数据。
相反的方法,可以把已经导出的数据导入MySQL数据库。
(可以把下面信息保存为Xls文件看看效果)
HTML标签的属性如:颜色color,bgcolor,font size等可以使用。
具体的实现代码可以参考这里。
<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="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>
<body link=blue vlink=purple leftmargin=0 topmargin=0>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td align="center" class="big6" >Users</td></tr>
<tr><td bgcolor=red>
<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">
<td class="mtlist">King</td>
<td class="mtlist"><b>Sangern</b></td>
<td class="mtlist" >XX@Gmail.com</td>
<td class="mtlist">Interneter</td>
<td class="mtlist">SEO</td>
<td class="mtlist">Admin</td>
<td class="mtlist">SH</td>
<td class="mtlist">110</td>
</tr>
</table>
</td></tr>
</table>
</body>
</html>
相关文章推荐
- PHP导出excel(*.xls)文件的简单方法
- datagrid数据导出到excel文件给客户端下载的几种方法 (xls,csv,html)
- php excel 读取日期问题 在 php excel 读取 xls 格式的文件时,xls 上面显示的是正常的日期格式 但是读取出来的话,就会是一个万位整形数据,这显然不是我们想要的日
- http://www.blogshares.com/blogs.php?blog=http://yourlink/
- 寻找最快的大文件拷贝方法(转自:http://www.cnblogs.com/hesicong/archive/2007/08/18/860763.html)
- mysql命令行下将数据导出成excel文件(.xls格式) (转)
- 在asp.net中读取XML文件信息的4种方法 (http://www.cnblogs.com/liping19851014/archive/2007/10/16/926137.html)
- asp.net 导出excel(xls)文件 资料 --- 之一: xml文件格式导出
- php导出数据到excel,防止身份证等数字字符格式变成科学计数的方法
- poi导入导出excel文件,兼容.xls和.xlsx两种格式
- 让IIS6.0全面支持asp+php+jsp最新完整版 http://www.marktip.com/blog/article.asp?id=151
- ubuntu 自添加开机启动程序(一种使ethtool设置永久保存在网络设备中的曲线救国方法) 转自:http://www.groad.net/bbs/read.php?tid-1393.html
- ORCAD原理图更新到PADS的方法(转帖)(http://www.asmyword.com/forum.php)
- linux找不到动态链接库 .so文件的解决方法(转自:http://www.cnblogs.com/xudong-bupt/p/3698294.html)
- datagrid数据导出到excel文件给客户端下载的几种方法 (xls,csv,html)
- (转载),方便使用http://www.cocoachina.com/bbs/read.php?tid=128244
- datagrid数据导出到excel文件给客户端下载的几种方法 选择自 yangyifan0 的 Blog
- 使用SQL*PLUS,构建完美excel或html输出(http://www.eygle.com/blog)
- php导出数据到excel,防止身份证等数字字符格式变成科学计数的方法
- 使用owc的spreadsheet导出Excel文件时,格式丢失的解决方法