笨笨的菜鸟张 2019-11-25 13:15 采纳率: 0%
浏览 362

用一般处理程序写了个导出excel,结果导不出来,请问是什么问题?

public void DownloadExcel(HttpContext context )
    {
        string fileName = "值班人员信息表模板.xlsx";//客户端保存的文件名 
        System.Web.HttpServerUtility server = System.Web.HttpContext.Current.Server;
        string filePath = server.MapPath(@"~/template/muban.xlsx");//路径

        System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
        context.Response.Clear();
        context.Response.ClearContent();
        context.Response.ClearHeaders();
        context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
        context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        context.Response.AddHeader("Content-Transfer-Encoding", "binary");
        context.Response.ContentType = "application/ms-excel";
        context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        context.Response.WriteFile(fileInfo.FullName);
        context.Response.Flush();
        context.Response.End();

    }

图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-11-25 13:23
    关注

    导出的流就是excel文件。你另存为,后缀名修改为 xlsx 看一下

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器