G
Guest
Hi,
I use the following code to export and import a file Excel from resp. into a
Web page with the following code:
//EXPORT
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
HtmlTextWriter(oStringWriter);
DataGrid1.AllowPaging = false;
DataGrid1.DataBind();
this.ClearControls(DataGrid1);
DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
DataGrid1.AllowPaging = true;
DataGrid1.DataBind();
//IMPORT
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
strFileNamePath + ";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
string sql = "SELECT * FROM [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataGrid1.DataSource = rd;
DataGrid1.DataBind();
rd.Close();
The export code works fine, whether the import code has a problem,namely:
when I import a Excel file which I have created from scratch with two simple
column, the Import code works.... When I import an Excel file which I've
exported with my Export code, I obtain the following error at the line
conn.Open():
External table is not in the expected format.
I've already check in the exported Excel file,
the name of the sheet which is "Sheet1" and I've also deleted the formatting
namely rows and columns colors... but it doesn't work!!
How can I solve the problem?
Thanks
I use the following code to export and import a file Excel from resp. into a
Web page with the following code:
//EXPORT
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
HtmlTextWriter(oStringWriter);
DataGrid1.AllowPaging = false;
DataGrid1.DataBind();
this.ClearControls(DataGrid1);
DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
DataGrid1.AllowPaging = true;
DataGrid1.DataBind();
//IMPORT
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
strFileNamePath + ";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
string sql = "SELECT * FROM [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataGrid1.DataSource = rd;
DataGrid1.DataBind();
rd.Close();
The export code works fine, whether the import code has a problem,namely:
when I import a Excel file which I have created from scratch with two simple
column, the Import code works.... When I import an Excel file which I've
exported with my Export code, I obtain the following error at the line
conn.Open():
External table is not in the expected format.
I've already check in the exported Excel file,
the name of the sheet which is "Sheet1" and I've also deleted the formatting
namely rows and columns colors... but it doesn't work!!
How can I solve the problem?
Thanks