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

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历