日期:2014-05-18 浏览次数:20451 次
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
上面有