Asp.Net Grid To Excel [英] Asp.Net Grid To Excel
本文介绍了Asp.Net Grid To Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些带有一些记录的gridview,我想将数据从Gridview导出到
Excel,我想在客户端机器上保存excel(Excel 2007,即.xlsb,.xlsx)
请帮我这样做......
I have a gridview with some records and i want to Export data from Gridview to
Excel and i want to save that excel(Excel 2007 ie. .xlsb, .xlsx )on client machine
please help me to do this ......
推荐答案
检查这个 [ ^ ] out。
希望它有所帮助: )
check this [^]out.
hope it helps :)
protected void btnExpExcel_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Report.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataTable dt = new DataTable();
dt = (DataTable)Session["dtReport"];
gvMISReport.AllowPaging = false;
gvMISReport.DataSource = dt;
gvMISReport.DataBind();
//Change the Header Row back to white color
gvMISReport.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < gvMISReport.HeaderRow.Cells.Count; i++)
{
gvMISReport.HeaderRow.Cells[i].Style.Add("background-color", "#157CB0");
}
int j = 1;
//This loop is used to apply stlye to cells based on particular row
foreach (GridViewRow gvrow in gvMISReport.Rows)
{
gvrow.BackColor = Color.White;
if (j <= gvMISReport.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
gvMISReport.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
这 [ ^ ]可能对你有帮助。
Hi,
This[^] might help you.
这篇关于Asp.Net Grid To Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文