1个回答
展开全部
页面上放一个linkbutton
在他的单击事件里添加如下,,代码
Protected void lnkbtnExport_Click(Object sender, System.EventArgs e){
String strname = "Voucher" + Now.Date + ".xls";
ExportToExcel(gvExcel, strname);
}
void ExportToExcel(System.Web.UI.WebControls.GridView gv, String fileName){
Response.Clear();
Response.Buffer = True;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=" & fileName);
Response.Charset = "GB2312";
EnableViewState = False;
Dim sw As System.IO.StringWriter = New System.IO.StringWriter();
Dim htw As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
在他的单击事件里添加如下,,代码
Protected void lnkbtnExport_Click(Object sender, System.EventArgs e){
String strname = "Voucher" + Now.Date + ".xls";
ExportToExcel(gvExcel, strname);
}
void ExportToExcel(System.Web.UI.WebControls.GridView gv, String fileName){
Response.Clear();
Response.Buffer = True;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=" & fileName);
Response.Charset = "GB2312";
EnableViewState = False;
Dim sw As System.IO.StringWriter = New System.IO.StringWriter();
Dim htw As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询