Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 错误:外部表不是预期的格式_C#_Excel - Fatal编程技术网

C# 错误:外部表不是预期的格式

C# 错误:外部表不是预期的格式,c#,excel,C#,Excel,我使用下面的连接字符串读取excel文件 connectionString = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=D:\test2.xlsx;Extended Properties=\'Excel 12.0;HDR=No;\"; 打开时,会引发异常: "External table is not in the expected format" 我在几个站点进行了探索,并按照上面提到的方法更改了连接字符串,然后采用了其他解决方案。但

我使用下面的连接字符串读取excel文件

connectionString = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=D:\test2.xlsx;Extended Properties=\'Excel 12.0;HDR=No;\";
打开时,会引发异常:

 "External table is not in the expected format"
我在几个站点进行了探索,并按照上面提到的方法更改了连接字符串,然后采用了其他解决方案。但是没有一个不起作用。
请引导我解决这个问题。提前感谢。

您能在使用此连接字符串的地方发布代码吗?您尝试提取数据的实际代码可能会对您有所帮助。string connectionString=“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\test.xlsx;Extended Properties=\”Excel 12.0;HDR=否\“;使用(connection=new-OleDbConnection(connectionString)){connection.Open();--------------在这一行,我得到了错误dataTable=connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null);DataView-DataView=dataTable.DefaultView;DataView.Sort=“TABLE_NAME desc”;dataTable=DataView.ToTable();connection.Close();}这应该对您有所帮助