I have Exported some data in a Excel file using this code-
Expand|Select|Wrap|Line Numbers
- Response.Clear();
- Response.AddHeader("content-disposition", "attachment;filename=dependencymatrix.xls");
- Response.Charset = "";
- Response.ContentType = "application/vnd.xls";
- System.IO.StringWriter stringWrite = new System.IO.StringWriter();
- System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
- resultGrid.AllowPaging = false;
- resultGrid.DataSource = dtResult;
- resultGrid.DataBind();
- resultGrid.RenderControl(htmlWrite);
- Response.Write(stringWrite.ToString());
- stringWrite.Dispose();
- htmlWrite.Dispose();
- Response.End();
Now I have to import this excel file.For this I have written the below code-
Expand|Select|Wrap|Line Numbers
- String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath.ToString() + ";Extended Properties=Excel 8.0;";
- OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT * FROM [dependencymatrix$]", strConn);
- da1.Fill(ds1);
If I open the excel file and save as it as "Microsoft Excel workbook",then its working perfect.
Could any body help me to solve this problem?
My client dont want to do "save as" to the exported excel file.
Thanks in advance