php產生Excel檔案 實現代碼

來源:互聯網
上載者:User

 <p>有段日子沒有更新部落格了,生怕被百度遺忘啊,biu~biu~.最近有個項目需要統計網站的url和title,儲存在excel裡面,下面是具體的代碼</p>

<pre class="php" name="code"><!--p

//php產生excel報表,是通過發送header()頭資訊完成的
header("Content-Type: application/vnd.ms-execl");
header("Content-Type: application/vnd.ms-excel; charset=gb2312");
//告知瀏覽器檔案名稱,並要求用戶端下載
header("Content-Disposition:filename=test.xls");
header("Pragma: no-cache");
header("Expires: 0");

$link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());
mysql_select_db('novartis') or die('Could not select database');

mysql_query("SET NAMES gb2312");
$query = 'SELECT title,keywords,url,description FROM cms_content';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// 用 HTML 顯示結果
//$str =mb_convert_encoding ("測試1","gb2312","utf-8");
echo "Titlet";
echo "Keywordst";
echo "Descriptiont";
echo "URLtn";
/* 格式: 換行:"tn": 儲存格之間: "t" */

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo $line['title']."t";
echo $line['keywords']."t";
echo $line['description']."t";
echo $line['url']."tn";

}


// 釋放結果集
mysql_free_result($result);
// 關閉串連
mysql_close($link);
-->
</pre>
<div>&nbsp;</div>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.