Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have an excel sheet which holds the test results in the form of XML. When I open the workbook in excel, asks to select Open as an xml table.

I have written the code for retrieving the records from the same excel sheet using OleDb provider of ADO.Net. Below is the Code.

C#
OleDbConnection objConnection = new OleDbConnection();

                    string con = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ strSourcePath + "\\" + row.Cells[2].Value.ToString() + ".xls" + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\"";
                    objConnection.ConnectionString = con;

 

                    OleDbCommand objCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", objConnection);
                    OleDbDataAdapter da = new OleDbDataAdapter(objCommand);

                    DataSet ds = new DataSet();

                    da.Fill(ds);

                    dataGridView2.DataSource = ds.Tables[0];


It is throwing an OleDbException, "External table is not in the expected format." when the Fill metod is called.

Please suggest a resolution for this.

Thanks & Regards,
Raghuveer
Posted
Comments
Richard MacCutchan 24-Mar-14 5:26am    
The message is quite clear, it is expecting the contents of Sheet1 to be in Excel table format. It is not clear from your question exactly what is contained in this worksheet.
W Balboos, GHB 24-Mar-14 8:34am    
It seems that you've an XML document which can be interpreted by Excel - but it is an XML document - so why not open it as XML instead of as an Excel object?
ZurdoDev 24-Mar-14 12:56pm    
As the others said, when you open in Excel it even asks you to open a different way. Why is Excel even involved if it is just an XML doc. Use the XDocument class or XmlDocument class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900