I am pulling data from a SQL Server Database into a C# datagrid. I then want to take C# to write into column A1 - R1 information about what is being pulled into the Excel, for example the data would be like this (A1) ID, (B1) Phone Number, (C1) Email etc etc
The only examples I have been able to find thus far show how to write cell by cell, but there has to be a way to just assign a value like you would do in Excel VBA:
FormulaR1C1 = "ID"
Can someone please provide me with a way to perform this daunting task?
VulpesPosted Mar 13, 2013, 9:19 AM
richard smithPosted Mar 13, 2013, 7:55 AM
darma tejaPosted Mar 13, 2013, 6:06 AM
try like this:
Mahesh MohanPosted Mar 13, 2013, 5:58 AM
protected void lnkBtnExcel_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition",
string.Format("attachment; filename={0}", "Customers.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvCompetitor.AllowPaging = false; gvCompetitor.DataBind();
gvCompetitor.HeaderRow.Style.Add("background-color", "#FFFFFF");
gvCompetitor.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
Satyapriya NayakPosted Mar 12, 2013, 10:42 PM