dongyiluan1718 2011-04-01 08:56
浏览 47
已采纳

使用php 4.3.9将数据从数据库转储到excel文件

I am recently using the following code to export my data in database as an excel file. But the output is showing as html page with correct data from database.

<?php
/* database connection here */

$file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=$table.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");

/* extract from database */

It pulls out the all data from database so I assume database function are correct but its just not saving as excel file. This code I used exactly the same in my previous project and working fine. Any idea how to solve this? plz help.

  • 写回答

4条回答 默认 最新

  • dtu72460 2011-04-04 05:42
    关注

    Finally just found out this is the same problem I had. Just solved it by just setting UTF-8 to UTF-8 without BOM in my editor.... code was seems correct but here is better header content I am using now. Thank you guys for help. ;)

            header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Disposition: attachment;filename=".$filename.".xls");
        header("Content-Transfer-Encoding: binary ");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?