继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

php导出excel

Qyouu
关注TA
已关注
手记 311
粉丝 87
获赞 413

php导出excel(转)

在index.php文件中,添加一个连接,<a href="test1.php">导出excel</a>。
test1.php文件如下:
<?
 Header("Content-type:    application/octet-stream");  
 Header("Accept-Ranges:    bytes");  
 Header("Content-type:application/vnd.ms-excel");    
 Header("Content-Disposition:attachment;filename=export_excel_gshjsl.xls");    

 $tx='表头';  
 echo    $tx."\n\n";
 echo    "编号"."\t";  
 echo    "姓名"."\t";  
 echo    "\n";

echo "=\"411481198507150666\""."\t";
echo "=\"0123456\""."\t";            //带上引号方便字符串输出。相当如设置单元格格式为文本。
echo "\n";
?>



顺便把简单导出word文档的代码贴到这里:

<?php        
 header("Content-Type:    application/msword");        
 header("Content-Disposition:    attachment;    filename=doc.doc");        
 header("Pragma:    no-cache");        
 header("Expires:    0");        

 $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 ><strong>下面是一张图片</strong></span&gt;</td></tr>';        
 $output    .=    '<tr><td align="center"><img src=";        
 $output    .=    '</table>';  


 echo    $output;        
 ?>


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP