Hi There,

I had this post before,but I have some problems when I add a header for specific charcter set,and also add some additional data,

here is my code;


    Response.Buffer = true;
    Response.AddHeader("content-disposition", "attachment;filename=aname.xls");

    string header = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<title></title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1254\" />\n<style>\n</style>\n</head>\n<body>\n";
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1254");
    Response.Charset = "windows-1254"; //ISO-8859-9  windows-1254

    Response.ContentType = "application/vnd.ms-excel";
    System.IO.StringWriter sw = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);

    gvMaster.AllowPaging = false;


    //write the output
    Response.Output.Write("Some title\n");
    //to write current date and time
    System.DateTime tDate1 = System.DateTime.Now;



The problem is when I add header next Line is not working and the Title and system time are all in one row,

My question is how can I write the gridview to specific row in output excel or how can I add some line on top of gridview and also how can I add some style to title?

Thanks in advance

If you want I can provide you the code.

Export To Excel from asp.Net Datagrid & Gridview

I Appreciate,If you can provide the code

I think Steve11 Solve your problem. If you still searching for code. Please tell me.

Sorry for the late reply.

The generic approach for style is create an excel file -- format the cell that you want. Then from file menu select the 'Save as Web Page' option to create a html file. Read & examine the code for this and findout the mso-number-format from the style declarations. Hope now you can integrate any styles from excel in asp.net application.

This article has been dead for over six months. Start a new discussion instead.