<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[用PHP把数据库导出为excel文件，并且能导出格式及背景、线条等！]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Fri, 14 Mar 2008 07:40:52 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	问：<br/>用PHP把数据库导出为excel文件，并且能导出格式及背景、线条等！<br/>______________________________________________________________________________________________<br/>答1：<br/>gz<br/>______________________________________________________________________________________________<br/>答2：<br/>gz<br/>______________________________________________________________________________________________<br/>答3：<br/>如果是直接导出到EXCEL的话，依目前的技术能力似乎还不能做到。连大名鼎鼎的OpenOffice对EXCEL的支持也不是很好。<br/>不过有种投机取巧的方法可以实现，就是从数据库中取出数据后，生成一个表格，样式自己定义好，然后让浏览器识别为下载excel。以下只是一个示例：<br/><br/>&lt;?php<br/>// 转载请注明phpteam<br/>$title = &quot;数据库名:test, 数据表:test, 备份日期:&quot; . date(&quot;Y-m-d H:i:s&quot;);<br/><br/>$conn = @mysql_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;) or die(&quot;不能连接数据库&quot;);<br/>@mysql_select_db(&quot;test&quot;, $conn);<br/>header(&quot;Content-Type: application/vnd.ms-excel&quot;);<br/>header(&quot;Content-Disposition: attachment; filename=test.xls&quot;);<br/>header(&quot;Pragma: no-cache&quot;);<br/>header(&quot;Expires: 0&quot;);<br/>echo &#039;&lt;table border=&quot;1&quot; cellspacing=&quot;2&quot; cellpadding=&quot;2&quot; width=&quot;50%&quot; align=&quot;center&quot;&gt;&#039;;<br/>// 输出标题<br/>echo &#039;&lt;tr bgcolor=&quot;#cccccc&quot;&gt;&lt;td colspan=&quot;3&quot; align=&quot;center&quot;&gt;&#039; . $title . &#039;&lt;/td&gt;&lt;/tr&gt;&#039;;<br/><br/>$query = &quot;select * from test&quot;;<br/>$result = mysql_query($query) or die(mysql_error());<br/>$fields = mysql_num_fields($result);<br/>// 输出字段名<br/>echo &#039;&lt;tr bgcolor=&quot;blue&quot;&gt;&#039;;<br/>for($i = 0; $i &lt; $fields; $i++) {<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;&lt;td&gt;&#039; . mysql_field_name($result, $i) . &#039;&lt;/td&gt;&#039;;<br/>}<br/>echo &#039;&lt;/tr&gt;&#039;;<br/>// 输出内容<br/>while($row = mysql_fetch_row($result)) {<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;&lt;tr&gt;&#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;for($i = 0; $i&lt;$fields; $i++) {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;&lt;td&gt;&#039; . $row[$i] . &#039;&lt;/td&gt;&#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;&lt;/tr&gt;&#039;;<br/>}<br/>echo &#039;&lt;/table&gt;&#039;;<br/>?&gt;<br/>______________________________________________________________________________________________<br/>答4：<br/>其实这个问题应该这样问：用ASP把数据库导出为excel文件，并且能导出格式及背景、线条等<br/>如果行，则用php就行<br/><br/>______________________________________________________________________________________________<br/>答5：<br/>我今天找到一个网上，可以这样做的，但不知道怎么做的。<br/><br/>http://www.time-assistant.com/tastandard/hlogin.php<br/><br/>username:joesen<br/><br/>password:joesen<br/><br/>进入admin菜单下，有一个XLS按钮，导出为excel，导到本地，你看一下就知道了。<br/>______________________________________________________________________________________________<br/>答6：<br/>哈哈，托你的福，我已经知道怎么解决了，你把下面着段代码存为.xls文件看看，知道该怎么做了吧？<br/><br/><br/>&nbsp;&nbsp;&lt;html xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns=&quot;http://www.w3.org/TR/REC-html40&quot;&gt;<br/>&nbsp;&nbsp;&lt;head&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv=&quot;expires&quot; content=&quot;Mon, 06 Jan 1999 00:00:01 GMT&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv=Content-Type content=&quot;text/html; charset=iso-8859-1&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;x:ExcelWorkbook&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;x:ExcelWorksheets&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;x:ExcelWorksheet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;x:Name&gt;&lt;/x:Name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;x:WorksheetOptions&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;x:DisplayGridlines/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/x:WorksheetOptions&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/x:ExcelWorksheet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/x:ExcelWorksheets&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/x:ExcelWorkbook&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xml&gt;&lt;![endif]--&gt;<br/><br/>&nbsp;&nbsp;&lt;/head&gt;<br/><br/>&lt;table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;<br/>&lt;tr&gt;&lt;td align=&quot;center&quot; class=&quot;big6&quot; &gt;Users (except the ones disabled)&lt;/td&gt;&lt;/tr&gt;<br/> <br/>&lt;tr&gt;&lt;td class=&quot;greyborder&quot;&gt;<br/>&nbsp;&nbsp;&lt;table border=&quot;1&quot; align=&quot;center&quot; width=&quot;100%&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot;&gt;<br/>&nbsp;&nbsp;&lt;tr align=&quot;center&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;TableTopHeader&quot; nowrap&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Login&nbsp;&nbsp; &lt;/td&gt;<br/>&nbsp;&nbsp; &lt;td class=&quot;TableTopHeader&quot; nowrap&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name&nbsp;&nbsp; &lt;/td&gt;<br/>&nbsp;&nbsp; &lt;td class=&quot;TableTopHeader&quot; width=&quot;3%&quot; nowrap&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EMail&nbsp;&nbsp; &lt;/td&gt;<br/>&nbsp;&nbsp; &lt;td class=&quot;TableTopHeader&quot; nowrap&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;Department&nbsp;&nbsp; &lt;/td&gt;<br/>&nbsp;&nbsp; &lt;td class=&quot;TableTopHeader&quot; nowrap&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;Position&nbsp;&nbsp; &lt;/td&gt;<br/>&nbsp;&nbsp; &lt;td class=&quot;TableTopHeader&quot; nowrap width=&quot;1%&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; Level&nbsp;&nbsp; &lt;/td&gt;<br/>&nbsp;&nbsp; &lt;td class=&quot;TableTopHeader&quot;&gt;Address&lt;/td&gt;<br/>&nbsp;&nbsp; &lt;td class=&quot;TableTopHeader&quot;&gt;Phone&lt;/td&gt;<br/>&lt;/tr&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&nbsp;&nbsp;class=&quot;even&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;mtlist&quot;&gt; joesen&lt;/td&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;mtlist&quot;&gt; hong joesen&lt;/td&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;mtlist&quot; &gt;allfu@163.net&lt;/td&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;mtlist&quot;&gt; Software developments&lt;/td&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;mtlist&quot;&gt; System Administrator&lt;/td&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;mtlist&quot;&gt; Admin&lt;/td&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;mtlist&quot;&gt; &lt;/td&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;mtlist&quot;&gt; &lt;/td&gt;<br/>&nbsp;&nbsp;&lt;/tr&gt;<br/>&nbsp;&nbsp;&lt;/table&gt;<br/>&lt;/td&gt;&lt;/tr&gt;&nbsp;&nbsp;<br/>&lt;/table&gt;<br/>______________________________________________________________________________________________<br/>答7：<br/>结贴吧！<br/>这就是 phpteam(我忍住不哭) 提供的方法<br/><br/>不错，不错。有长见识了！<br/><br/>______________________________________________________________________________________________<br/>答8：<br/>能说清楚点吗？我还是不明白。<br/>______________________________________________________________________________________________<br/>答9：<br/>up<br/>______________________________________________________________________________________________<br/>答10：<br/>zh_yuandc(中原大帝)贴出的就是从http://www.time-assistant.com/tastandard/hlogin.php<br/>下载下来的.xls文件，你用文本编辑器打开就是那个样子。你用Excel打开就可以进行编辑。<br/><br/>我理解他是一个Excel可识别处理的xml文档，不是真正的Excel文档。但这已经很好了。<br/>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 用PHP把数据库导出为excel文件，并且能导出格式及背景、线条等！]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>