C# Read a excel and that excel is created by Grid.RenderControl function

poliuyn

New Member
\[code\] protected void ExportExcel() { GridView gvDownload = new GridView(); DataSet dsDownload = new DataSet(); StringWriter strWriter = new StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("content-disposition", "attachement;filename=Just.xls"); Response.Charset = string.Empty; Response.Cache.SetCacheability(HttpCacheability.Public); Response.ContentType = "application/excel"; dsDownload = GetDataTableForTest(); gvDownload.DataSource = dsDownload.Tables[0]; gvDownload.DataBind(); gvDownload.RenderControl(htmlWriter); Response.Write(strWriter.ToString()); Response.End(); }\[/code\]1)When reading this excel .I am getting error like "external table is not in the expected format."2) When try to open a excel file through double click am getting like this" The file you are tying to open ,"just.xls' ,is in a different format than specified by the file extension.Verify that the file is not corrupted and is from a trusted source before opening the file .Do you want to open the file now? "Please give any solution. What wrong happened in this? Please help..!
 
Back
Top