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 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求