Hi Friends,
I am using C# language,I am getting my data in Excel sheet for reporting purpose from database but i want to know how to put the company name or any other header into sheet.
Do you have any idea...Plz help.
thanks.
|
Headername |
Comapany name |
Headername |
|
Fieldname1 |
Fieldname2 |
Fieldname3 |
|
Value1 |
Value2 |
Value3 |
Fieldname and Value are coming from database.I want to put
|
Comapany name |
Headername |
public
static void ExportDataSetToExcel(DataTable ds, string filename){
string path = ConfigurationManager.AppSettings[0]; StringWriter Writer = new StringWriter();filename = path +
"\\" + filename +".xls"; StreamWriter streamWriter = new StreamWriter(filename); HttpResponse response = new HttpResponse(Writer);// first let's clean up the response.object
response.Clear();
response.Charset =
"";response.ContentType =
"application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()){
using (System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw)){
System.Web.UI.WebControls.
DataGrid dg = new System.Web.UI.WebControls.DataGrid();dg.DataSource = ds;
dg.DataBind();
dg.RenderControl(htw);
response.Write(sw.ToString());
streamWriter.Write(sw.ToString());
streamWriter.Close();
}
}
I am calling this code into my main function
Replies
Know the answer? Post it — somebody with the same question will find it here.