日期:2014-05-17  浏览次数:20473 次

NPOI2.0在网页中输出时为什么会打不开?
        string filename = string.Format("{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss"));
        Response.ContentType = "application/vnd.ms-excel";
        Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename));
        Response.Clear();

        MemoryStream file = new MemoryStream();
        hssfworkbook.Write(file);
        Response.BinaryWrite(file.GetBuffer());
        Response.End();

换成winform这种格式就可以的

            FileStream sw = File.Create("test.xlsx");
            workbook.Write(sw);
            sw.Close();
实在是没有发现有什么不同,请各位大虾指正一下,谢谢。

------解决方案--------------------
我一般是先在服务器上生成文件并打包成zip再输出给用户,也方便追踪用户下载的数据到底对不对
直接输出的方式没玩过
------解决方案--------------------
FileStream sw = File.Create("test.xlsx");

文件路径不对吧,要先创建文件?