asp.net 表导出excel 报错
“/WebSite”应用程序中的服务器错误。---------------------------------------------------------------...
“/WebSite”应用程序中的服务器错误。--------------------------------------------------------------------------------长度不能小于 0。参数名: length 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 长度不能小于 0。参数名: length
展开
展开全部
用这试试
public void ExportExcelFile()
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ExcelFile.xls");
Response.Charset = "gb2312";
Response.ContentType = "application/ms.xls";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
System.IO.StringWriter stringw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlT = new HtmlTextWriter(stringw);
GridView1.AllowPaging = false;
GridView1.AllowSorting = false;
bind();
GridView1.RenderControl(htmlT);
Response.Write(stringw.ToString());
Response.End();
GridView1.AllowPaging = true;
GridView1.AllowSorting = true;
bind();
}
protected void btnDCExcel_Click(object sender, EventArgs e) //gridView导出到Excel
{
ExportExcelFile();
Lab_Visible();
}
public void ExportExcelFile()
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ExcelFile.xls");
Response.Charset = "gb2312";
Response.ContentType = "application/ms.xls";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
System.IO.StringWriter stringw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlT = new HtmlTextWriter(stringw);
GridView1.AllowPaging = false;
GridView1.AllowSorting = false;
bind();
GridView1.RenderControl(htmlT);
Response.Write(stringw.ToString());
Response.End();
GridView1.AllowPaging = true;
GridView1.AllowSorting = true;
bind();
}
protected void btnDCExcel_Click(object sender, EventArgs e) //gridView导出到Excel
{
ExportExcelFile();
Lab_Visible();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询