写入资料到EXCEL中

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

<?php

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

header("Content-type:application/vnd.ms-excel");

header("Content-Disposition:filename=order.xls");

//下面就可以处理一般的PHP文件一样处理,可以连接数据库,显示图象等操作,最后会显示在EXCEL文件中

?>

在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了。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航