阅读Excel Sheet使用OleDb
我有一张excel表格,它以XML的形式保存测试结果。当我在excel中打开工作簿时,要求选择Open作为xml表。
我编写了使用OleDb提供程序从同一个excel表中检索记录的代码ADO.Net。下面是代码。
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.
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];
抛出OleDbException,外部表不是预期的格式。当Fill metod被调用时。
请为此建议解决方案。
谢谢&此致,
Raghuveer
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
,objConnection);
OleDbDataAdapter da = new OleDbDataAdapter(objCommand);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView2.DataSource = ds.Tables [ 0 ];
", objConnection); OleDbDataAdapter da = new OleDbDataAdapter(objCommand); DataSet ds = new DataSet(); da.Fill(ds); dataGridView2.DataSource = ds.Tables[0];
当调用Fill metod时,抛出OleDbException,外部表格不是预期的格式。
请为此建议解决方案。
谢谢和问候,
Raghuveer
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