社区
基础编程
帖子详情
如何用php生成excel ?在线等!
sdlool
2003-11-29 09:43:02
如何用php生成excel ?在线等!
...全文
163
8
打赏
收藏
如何用php生成excel ?在线等!
如何用php生成excel ?在线等!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
8 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
linxzm
2003-12-01
打赏
举报
回复
用PHP将mysql数据表转换为excel文件格式
作者:mydowns 出处:把握时间网站:http://www.85time.com, http://www.mydowns.com
原贴地址如下:
http://www.mydowns.com/article_show.php?id=32
详细内容如下:
<?php
$DB_Server = "localhost";
$DB_Username = "mydowns";
$DB_Password = "";
$DB_DBName = "mydowns";
$DB_TBLName = "user";
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect.");
$Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database.");
$file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=mydowns.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
$now_date = date('Y-m-d H:i');
$title = "数据库名:$DB_DBName,数据表:$DB_TBLName,备份日期:$now_date";
$sql = "Select * from $DB_TBLName";
$ALT_Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database");
$result = @mysql_query($sql,$Connect)
or die(mysql_error());
echo("$title\n");
$sep = "\t";
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . "\t";
}
print("\n");
$i = 0;
while($row = mysql_fetch_row($result))
{
$schema_insert = "";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
$i++;
}
return (true);
?>
「已注销」
2003-12-01
打赏
举报
回复
回复人: soniclee(疯宝宝)
excel支持打开一种csv格式的文件,其实源文件是一个很规则的文本
打开excel,做一个规则表格,然后另存为csv格式,用文本编辑器打开这个文件看一下就成了
-----------------------------------------------------------------------------
然后用PHP去生成这样一个规则的文本文件就可以被excel识别了。。。
这么简单的问题明白了么???
方法给了你两个,自己试一下吧,就差帮你写程序啦~!
「已注销」
2003-12-01
打赏
举报
回复
这是以前PHP版老斑竹Yorgo的一篇文章:
大家来看代码:
<?
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
?>
在php环境运行上面的代码,大家就可以看到浏览器询问用户是否下载excel
文档,点击保存,硬盘上就多了一个excel的文件,使用excel打开就会看到
最终的结果,怎么样不错吧。
其实在做真正的应用的时候,大家可以将数据从数据库中取出,然后按照每
一列数据结束后加\t,每一行数据结束后加\n的方法echo出来,在php的开头
用header("Content-type:application/vnd.ms-excel");表示输出的是
excel文件,用header("Content-Disposition:filename=test.xls");表
示输出的文件名为text.xls。这样就ok了。
我们更可以修改header让他输出更多格式的文件,这样php在处理各种类型
文件方面就更加方便了。
Yorgo Sun
2000/11/14
shuzai
2003-11-30
打赏
举报
回复
兄弟,哪个不叫例子啊?
sdlool
2003-11-30
打赏
举报
回复
test1,test2,是什么意思?
兄弟,我搞上去了怎么什么也不可以用呀!
能不能说的详细些呀!
或者给个例子看一下的呀!
小第感谢不已呀!
HighRugal
2003-11-30
打赏
举报
回复
re,更多东西
http://home.jlu.edu.cn/~rugal/docs/showdoc.php?doc_id=0005
shuzai
2003-11-30
打赏
举报
回复
<?
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
?>
//改动相应文件头就可以输出.doc .xls等文件格式了
「已注销」
2003-11-29
打赏
举报
回复
excel支持打开一种csv格式的文件,其实源文件是一个很规则的文本
打开excel,做一个规则表格,然后另存为csv格式,用文本编辑器打开这个文件看一下就成了
生成
excel
文件到指定目录的函数
php
类库
生成
excel
函数
php
类库
生成
excel
文件到指定目录的函数
php
类库
php
生成
excel
类
简单的
php
生成
excel
的类。操作很简单,直接传入相应的抬头和数据就行了。
PHP
生成
excel
PHP
生成
excel
直接参考demo.
php
文件即可
一个可以
生成
excel
文件的
php
类库.zip
php
生成
excel
文件类库,需要的朋友可以参考下,方便大家学习
php
PHP
生成
、下载
excel
、zip压缩文件_
excel
php
图片_
excel
_zip_
php
_
PHP
导出包含图片的
excel
文件;
PHP
生成
压缩文件
基础编程
21,886
社区成员
140,364
社区内容
发帖
与我相关
我的任务
基础编程
从PHP安装配置,PHP入门,PHP基础到PHP应用
复制链接
扫一扫
分享
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章