<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[阿Tim日志]]></title> 
<link>https://atim.cn/index.php</link> 
<description><![CDATA[专业的php开发者.开发团队的带队人]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[阿Tim日志]]></copyright>
<item>
<link>https://atim.cn/post//</link>
<title><![CDATA[PHP 建立 Excel 檔案 ]]></title> 
<author>bkkkd &lt;partybase@gmail.com&gt;</author>
<category><![CDATA[开发应用]]></category>
<pubDate>Sun, 05 Feb 2006 01:19:50 +0000</pubDate> 
<guid>https://atim.cn/post//</guid> 
<description>
<![CDATA[ 
	有時需要將資料庫內的資料或 PHP 的動態內容儲存成 excel 檔，本文會介紹一個概簡單又實用的方法。<br /><br /><h3>建立 Excel 檔案</h3>如果需要用 PHP 建立 Excel 檔案，只需用一般的檔案處理函式，而檔案名稱儲存成 .xls 副檔名即可，例如：<br /><table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0"><tbody><tr><td style="WORD-WRAP: break-word" bgcolor="#f3f3f3"><font style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</font><br /><div class="output"><code><span style="COLOR: #808080"><font face="新宋体"> </font></span><font color="#000000"><font face="新宋体"><font color="#0000bb">&lt;?php<br /><span style="COLOR: #808080"> </span>$fp </font><font color="#007700">= </font><font color="#0000bb">fopen</font><font color="#007700">(</font><font color="#dd0000">&quot;excel/filename.xls&quot;</font><font color="#007700">, </font><font color="#dd0000">&quot;w&quot;</font></font><font face="新宋体"><font color="#007700">);<br /><span style="COLOR: #808080"> </span></font><font color="#0000bb">fputs</font><font color="#007700">(</font><font color="#0000bb">$fp</font><font color="#007700">, </font><font color="#dd0000">&quot;MontTuetWedtThutFritSattSun&quot;</font></font><font face="新宋体"><font color="#007700">);<br /><span style="COLOR: #808080"> </span></font><font color="#0000bb">fclose</font><font color="#007700">(</font><font color="#0000bb">$fp</font></font><font face="新宋体"><font color="#007700">);<br /><span style="COLOR: #808080"> </span></font><font color="#0000bb">?&gt;</font></font></font></code></div></td></tr></tbody></table><br />以上程式碼會在 excel 目錄建立一個名為 filename.xls 的檔案，內容是在第一行寫入一星期七天的英文簡寫，每一欄一天。<br /><br />實際上與建立一般文字檔的方法一樣，只是如果要跳到下一個欄位，就用 t 字元，而要跳到下一行，則用 n 字元。<br /><br /><h3>顯示下載窗口</h3>如果電腦內有安裝 Excel 的話，在預設情況下當在 IE 按了 .xls 副檔名的文件時，IE 不會彈出下載窗口，而是直接顯示內容，以下兩個例子可避免這情況：<br /><br />直接將內容輸出給瀏覽器下載<br /><div class="output"><table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0"><tbody><tr><td style="WORD-WRAP: break-word" bgcolor="#f3f3f3"><font style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</font><br /><span style="COLOR: #808080"><font face="新宋体"> </font></span><font color="#000000"><font face="新宋体"><font color="#0000bb">&lt;?php<br /><span style="COLOR: #808080"> </span>header</font><font color="#007700">(</font><font color="#dd0000">&quot;Content-type:application/vnd.ms-excel&quot;</font></font><font face="新宋体"><font color="#007700">);<br /><span style="COLOR: #808080"> </span></font><font color="#0000bb">header</font><font color="#007700">(</font><font color="#dd0000">&quot;Content-Disposition:filename=php_excel.xls&quot;</font></font><font face="新宋体" color="#007700">);<br /><span style="COLOR: #808080"> </span><br /><span style="COLOR: #808080"></span>echo </font><font face="新宋体"><font color="#dd0000">&quot;MontTuetWedtThutFritSattSun&quot;<br /><span style="COLOR: #808080"> </span></font><font color="#0000bb">?&gt;</font></font></font></td></tr></tbody></table></div><div class="output">讀取已存在的檔案給瀏覽器下載<br /><table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0"><tbody><tr><td style="WORD-WRAP: break-word" bgcolor="#f3f3f3"><font style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</font><br /><div class="output"><code><font color="#000000"><font face="新宋体"><font color="#0000bb">&lt;?php<br />header</font><font color="#007700">(</font><font color="#dd0000">&quot;Content-type:application/vnd.ms-excel&quot;</font></font><font face="新宋体"><font color="#007700">);<br /></font><font color="#0000bb">header</font><font color="#007700">(</font><font color="#dd0000">&quot;Content-Disposition:filename=php_excel.xls&quot;</font></font><font face="新宋体"><font color="#007700">);<br /></font><font color="#0000bb">readfile</font><font color="#007700">(</font><font color="#dd0000">&quot;excel/filename.xls&quot;</font></font><font face="新宋体"><font color="#007700">);<br /></font><font color="#0000bb">?&gt;</font></font></font></code></div></td></tr></tbody></table><br />上面使用了 header() 傳送檔頭資訊給瀏覽器，可使瀏覽器出現下載窗口，而預設儲存的檔案名稱是 php_excel.xls。</div>
]]>
</description>
</item><item>
<link>https://atim.cn/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>https://atim.cn/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>