从gridview数据导出到excel? [英] export to excel from gridview data ?
问题描述
如何从gridview数据导出到excel ...请任何人帮助我?
how to export to excel from gridview data...please any one help me?
推荐答案
在提问之前,尝试 google [ ^ ]一次。
查看以下链接..
Export-GridView-to-Excel-in-ASPNet-with-Formatting-using-C-and-VBNet.aspx [ ^ ]
如何出口 - gridview-data-to-excel-or.html [ ^ ]
Before asking question, try to google [^]once.
check the below links..
Export-GridView-to-Excel-in-ASPNet-with-Formatting-using-C-and-VBNet.aspx[^]
how-to-export-gridview-data-to-excel-or.html[^]
put dll itextsharp.dll
put dll itextsharp.dll
using iTextSharp.text.html;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
protected void btnExportToExcel_Click(object sender, ImageClickEventArgs e)
{
Response.Clear( );
Response.Buffer = true;
Response.AddHeader(content-disposition,attachment; filename = ExamReport.xls);
Response.Charset =;
Response.ContentType =application / vnd.xls;
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView grd = new GridView();
grd.AllowPaging = false ;
grd.AllowSorting = false;
grd.AutoGenerateEditButton = false;
grd.AutoGenerateDeleteButton = false;
// // // //下面的网格视图mathod ...哪个ru绑定..... // // // //
grd.DataSource = objReport.GetAllExamOfInstitute();
grd.DataBind();
grd.HeaderRow.Style.Add( width,10%);
grd.HeaderRow.Style.Add(font-size,16px);
grd.HeaderRow.Style.Add(color,#990000);
grd.Style.Add(text-decoration,none);
grd.Style.Add(font-family,Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif;);
grd.Style.Add( font-size,14px);
grd.RenderControl(hw);
回复.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=ExamReport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls ";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView grd = new GridView();
grd.AllowPaging = false;
grd.AllowSorting = false;
grd.AutoGenerateEditButton = false;
grd.AutoGenerateDeleteButton = false;
// // // //grid view mathod in below... which r u bind.....// // // //
grd.DataSource = objReport.GetAllExamOfInstitute();
grd.DataBind();
grd.HeaderRow.Style.Add("width", "10%");
grd.HeaderRow.Style.Add("font-size", "16px");
grd.HeaderRow.Style.Add("color", "#990000");
grd.Style.Add("text-decoration", "none");
grd.Style.Add("font-family", " Segoe UI , Lucida Grande ,Verdana , Arial , Helvetica , sans-serif;");
grd.Style.Add("font-size", "14px");
grd.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
从EXCEL导出到EXCEL d在C#.Net [ ^ ]
Export to EXCEL from Datatable in C#.Net[^]
protected void lnkExport_Click(object sender, EventArgs e)
{
try
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attament;filename=Tally.xls");
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
divbirdtal.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
catch (Exception ex)
{
Log(ex.Message, ex.StackTrace);
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "Exception Message", "alert('You have an exception')", true);
}
}
public override void VerifyRenderingInServerForm(Control control)
{
}
这篇关于从gridview数据导出到excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!