1.下面的代码实现了单页导出Excel,我想实现当checkbox选中多少个就导出多少.
2.下面的RepExcelBind()方法里,导出前先让GridView1.AllowPaging = false;,但是导不出来数据,只有一对<div></div>在Excel里,这是什么原因?
protected void btnExcel_Click(object sender, EventArgs e)
{
int intCount = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (chk.Checked)
{
intCount++;
}
}
if (intCount == 0)
{
RepExcelBind();
}
else
{
Response.Write("<script>alert('这里根据勾选的行数导出..');</script>");
}
} private void RepExcelBind()
{
//GridView1.AllowPaging = false;
//GridView1.AllowSorting = false;
//GridView1.DataBind();
RepExcel();
//GridView1.AllowPaging = true;
//GridView1.AllowSorting = true;
//GridView1.DataBind();
} private void RepExcel()
{
//string style = @"<style> .text { mso-number-format:yyyy/mm/dd; } </style>";
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=MyExcelFile.xls");
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
//Response.Write(style);
Response.Write(sw.ToString());
Response.End();
}
2.下面的RepExcelBind()方法里,导出前先让GridView1.AllowPaging = false;,但是导不出来数据,只有一对<div></div>在Excel里,这是什么原因?
protected void btnExcel_Click(object sender, EventArgs e)
{
int intCount = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (chk.Checked)
{
intCount++;
}
}
if (intCount == 0)
{
RepExcelBind();
}
else
{
Response.Write("<script>alert('这里根据勾选的行数导出..');</script>");
}
} private void RepExcelBind()
{
//GridView1.AllowPaging = false;
//GridView1.AllowSorting = false;
//GridView1.DataBind();
RepExcel();
//GridView1.AllowPaging = true;
//GridView1.AllowSorting = true;
//GridView1.DataBind();
} private void RepExcel()
{
//string style = @"<style> .text { mso-number-format:yyyy/mm/dd; } </style>";
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=MyExcelFile.xls");
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
//Response.Write(style);
Response.Write(sw.ToString());
Response.End();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货