小妹请教生成Excel文件的问题!

wangtiantian23 2010-06-28 03:01:51
我同事写了一个生成Excel的代码!

是需要每次都得点保存才能够生成Excel文件!!

有没有什么办法!直接生成到我一个指定目录下那!

下面是生成Excel的代码!

<?php
header("Content-Type: application/msword");
header('Content-Disposition: attachment; filename="orders.xls"');
header("Pragma:no-cache");
header("Expires:0");
$output="";
$output.= "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">\r\n";
$output.= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n";
$output.= "<html>\r\n";
$output.= "<head>\r\n";
$output.= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
$output.= "</head>\r\n";
$output.= "<body>\r\n";
$output.= "<div id=\"Classeur1_16681\" align=center x:publishsource=\"Excel\">\r\n";
$output.='<table border="1" cellspacing="2" cellpadding="2" width="90%" align="center">';
$output.='<tr bgcolor="#cccccc"><td align="center">图片</td></tr>';
$output.='<tr bgcolor="#f6f7fa"><td><span style="color:#FF0000;"><strong>下面是一张图片</strong></span></td></tr>';
$output.='<tr><td align="center"><img src="http://zi.csdn.net/48260_2.gif"></td></tr>';
$output.= "</table></div>";
$output.= "</body>\r\n";
$output.= "</html>";

echo $output;
?>
...全文
61 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kyzy_yy_pm 2010-06-28
  • 打赏
  • 举报
回复



header("Content-Type: application/msword");
header('Content-Disposition: attachment; filename="orders.xls"');
header("Pragma:no-cache");
header("Expires:0");
$output='';
$output.= '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">';
$output.= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
$output.= '<html>';
$output.= '<head>';
$output.= '<meta http-equiv="Content-Type" content="text/html; charset=gbk" />';
$output.= '</head>';
$output.= '<body>';
$output.= '<div id="Classeur1_16681" align=center x:publishsource="Excel">';
$output.= '<table border="1" cellspacing="2" cellpadding="2" width="90%" align="center">';
$output.= '<tr bgcolor="#cccccc"><td align="center">图片</td></tr>';
$output.= '<tr bgcolor="#f6f7fa"><td><span style="color:#FF0000;"><strong>下面是一张图片</strong></span></td></tr>';
$output.= '<tr><td align="center"><img src="http://zi.csdn.net/48260_2.gif"></td></tr>';
$output.= '</table></div>';
$output.= '</body>';
$output.= '</html>';

echo $output;

file_put_contents('orders.xls', $output, strlen($output));
wangtiantian23 2010-06-28
  • 打赏
  • 举报
回复
非常感谢!
BooJS 2010-06-28
  • 打赏
  • 举报
回复
参数顺序写错了

if(file_put_contents('./orders.xls',$output))
wangtiantian23 2010-06-28
  • 打赏
  • 举报
回复

<?php
/*header("Content-Type: application/msword");
header('Content-Disposition: attachment; filename="orders.xls"');
header("Pragma:no-cache");
header("Expires:0");*/
$output="";
$output.= "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">\r\n";
$output.= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n";
$output.= "<html>\r\n";
$output.= "<head>\r\n";
$output.= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
$output.= "</head>\r\n";
$output.= "<body>\r\n";
$output.= "<div id=\"Classeur1_16681\" align=center x:publishsource=\"Excel\">\r\n";
$output.='<table border="1" cellspacing="2" cellpadding="2" width="90%" align="center">';
$output.='<tr bgcolor="#cccccc"><td align="center">图片</td></tr>';
$output.='<tr bgcolor="#f6f7fa"><td><span style="color:#FF0000;"><strong>下面是一张图片</strong></span></td></tr>';
$output.='<tr><td align="center"><img src="http://zi.csdn.net/48260_2.gif"></td></tr>';
$output.= "</table></div>";
$output.= "</body>\r\n";
$output.= "</html>";

echo $output;
//if(file_put_contents($ouput,'../orders.xls'))这两种方式都不对,我想自动生成文件。
if(file_put_contents($ouput,'D:\\wamp\\www\\hit\\orders.xls'))
{
echo "保存成功!";
}
else echo "保存失败!";
?>
wangtiantian23 2010-06-28
  • 打赏
  • 举报
回复
不对啊!总提示我保存失败!
BooJS 2010-06-28
  • 打赏
  • 举报
回复
//header("Content-Type:   application/msword");
//header('Content-Disposition: attachment; filename="orders.xls"');
//header("Pragma:no-cache");
//header("Expires:0");
$output="";
$output.= "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">\r\n";
$output.= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n";
$output.= "<html>\r\n";
$output.= "<head>\r\n";
$output.= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
$output.= "</head>\r\n";
$output.= "<body>\r\n";
$output.= "<div id=\"Classeur1_16681\" align=center x:publishsource=\"Excel\">\r\n";
$output.='<table border="1" cellspacing="2" cellpadding="2" width="90%" align="center">';
$output.='<tr bgcolor="#cccccc"><td align="center">图片</td></tr>';
$output.='<tr bgcolor="#f6f7fa"><td><span style="color:#FF0000;"><strong>下面是一张图片</strong></span></td></tr>';
$output.='<tr><td align="center"><img src="http://zi.csdn.net/48260_2.gif"></td></tr>';
$output.= "</table></div>";
$output.= "</body>\r\n";
$output.= "</html>";

if(file_put_contents($ouput,'./orders.xls'))
{
echo "保存成功!";
}
else echo "保存失败!";

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧