当前位置: 代码迷 >> ASP.NET >> 求EXCEL导出,该如何解决
  详细解决方案

求EXCEL导出,该如何解决

热度:8493   发布时间:2013-02-25 00:00:00.0
求EXCEL导出
Excel导出,如何让导出的文件自动压缩? 我是用的gridview导出,不存服务器端。

------解决方案--------------------------------------------------------
以Gridview为例,其他类似
C# code
        Response.Clear();        Response.Buffer = true;        Response.Charset = "GB2312";        Response.AppendHeader("Content-Disposition", "attachment;filename=out.xls");        Response.ContentType = "application/ms-excel";        this.EnableViewState = false;        System.IO.StringWriter swOut = new System.IO.StringWriter();        HtmlTextWriter hTw = new HtmlTextWriter(swOut);        GridView1.RenderControl(hTw);        Response.Write(swOut.ToString());        Response.End();
------解决方案--------------------------------------------------------
打开excel赋值给单元格,再使用winrar等压缩输出
string style = @"<style> .text { mso-number-format:\@; } </script> "; 
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(style); 
Response.Write(sw.ToString());
Response.End();
public override void VerifyRenderingInServerForm(Control control)
{
}

------解决方案--------------------------------------------------------
http://www.csharp360.com/bbs/viewthread.php?tid=142&extra=page%3D1
上面有
  相关解决方案