PHP头条
热点:

php生成Excel文件 实现代码


 <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 "Title\t";
echo "Keywords\t";
echo "Description\t";
echo "URL\t\n";
/* 格式: 换行:"\t\n": 单元格之间: "\t" */

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

}


// 释放结果集
mysql_free_result($result);
// 关闭连接
mysql_close($link);
-->
</pre>
<div>&nbsp;</div>

www.phpzy.comtrue/php/19133.htmlTechArticlephp生成Excel文件 实现代码 p有段日子没有更新博客了,生怕被百度遗忘啊,biu~biu~.最近有个项目需要统计网站的url和title,保存在excel里面,下面是具体的代码/p pre class=php name=code!--p //php生成...

相关文章

    暂无相关文章

PHP之友评论

今天推荐