我同事写了一个生成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;
  ?>

解决方案 »

  1.   

    //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 "保存失败!";
      

  2.   


    <?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 "保存失败!";
      ?>
      

  3.   

    参数顺序写错了if(file_put_contents('./orders.xls',$output))
      

  4.   


    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));