none
Exporting Dataview to Excel 2007 RRS feed

  • Question

  • hi

     

      i am using the following code to export Dataview to Excel 2007.

     

    Response.ClearContent();

    Response.ClearHeaders();

    Response.Buffer = true;

    //Response.Write("<br><b>" + lblheader.Text + "</b><br>");

    Response.ContentType = @"application/vnd.-excel.document.12";

    Response.ContentEncoding = System.Text.Encoding.UTF8;

    this.EnableViewState = false;

    Response.AddHeader("Content-Disposition", "attachment; filename=AuditHistory.xlsx;");

    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

    BindAuditHistory();

    HtmlForm myForm = new HtmlForm();

    myForm.Controls.Clear();

    Page.Controls.Add(myForm);

    myForm.Controls.Add(gvAuditHistory);

    myForm.RenderControl(oHtmlTextWriter);

    Response.Write(oStringWriter.ToString());

    Response.End();

     

    but when i open the excel it says the 'File is corrupted or file fomat is not correct'.

     

    please help me .

     

    regards

    muthu

     

    Wednesday, April 2, 2008 12:24 PM

Answers