Unable to Read Exported excel file

Mar 21, 2012 at 11:23 AM

I have used this tool for reading Excel and Validate data.

The problem is unable to read excel file which are exported from another page.

There is a functionality to export excel from c# .net and I have written follwoing code.

 

 string fileName = "Test.xls";
        
 #region Clean up Response Object
 Response.Clear();
 Response.Buffer = true;
 Response.ClearHeaders();
 Response.ClearContent();
 Response.Charset = "";
 Response.ContentEncoding = System.Text.Encoding.Default;
 #endregion

 #region Set the response mime type for excel
   Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.xls", fileName));
   Response.ContentType = "application/vnd.xls;charset=utf-8";//"application/ms-excel";
 #endregion

  #region Create a string writer
    using (StringWriter sw = new StringWriter())
    {
       using (HtmlTextWriter htw = new HtmlTextWriter(sw))
       {
          // instantiate a datagrid  
         GridView gvTreatmentResults = new GridView();
         gvTreatmentResults.DataSource = this.resultsDS.Tables[0];
         gvTreatmentResults.DataBind();
         gvTreatmentResults.RenderControl(htw);
         Response.Write(sw.ToString());
         Response.End();
        }
     }
 #endregion

 After then , I tried to upload expored file, but was not able to read. ExcelDatareader object is not null, but all properties are null. IsValid and Read() and ASDataSet().

Can you please do the needful. As I have to complete it on trgent basis.

 

Thanks in Advance.