将网格导出到Excel时,我不想显示复选框。我的标题checbox没有显示,而所有的孩子chechboxes总是在那里.. :(我调试,并找出了gridview连接自己的名称到每行的原因,以便我的代码无法检测复选框。这里是我的代码
protected void Export_to_Excel(object sender, EventArgs e)
{
GridView1.AllowPaging = false;
GridView1.DataSource = dtPatientList;
GridView1.DataBind();
System.Diagnostics.Debugger.Break();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=PatientSearchReport.xls");
Response.ContentType = "application/vnd.xlsx";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
string html2 = Regex.Replace(stringWrite.ToString(), @"(<input type=""image""\/?[^>]+>)", @"", RegexOptions.IgnoreCase);
html2 = Regex.Replace(html2, @"(<input type=""checkbox""\/?[^>]+>)", @"", RegexOptions.IgnoreCase);
html2 = Regex.Replace(html2, @"(<a \/?[^>]+>)", @"", RegexOptions.IgnoreCase);
Response.Write(html2.ToString());
Response.End();
GridView1.AllowPaging = true;
GridView1.DataSource = dtPatientList;
GridView1.DataBind();
}
答案 0 :(得分:1)
尝试
protected void Export_to_Excel(object sender, EventArgs e)
{
//System.Diagnostics.Debugger.Break();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=PatientSearchReport.xls");
Response.ContentType = "application/vnd.xlsx";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
string html2 = Regex.Replace(stringWrite.ToString(), @"(<input type=""image""\/?[^>]+>)", @"", RegexOptions.IgnoreCase);
html2 = Regex.Replace(html2, @"(<input class=""checkbox""\/?[^>]+>)", @"", RegexOptions.IgnoreCase);
html2 = Regex.Replace(html2, @"(<a \/?[^>]+>)", @"", RegexOptions.IgnoreCase);
Response.Write(html2.ToString());
Response.End();
}