C# 使用Excel 2013打开.xls(97-2003)文件后,使用ACE读取这些文件

C# 使用Excel 2013打开.xls(97-2003)文件后,使用ACE读取这些文件,c#,excel,oledb,ms-jet-ace,C#,Excel,Oledb,Ms Jet Ace,很长一段时间以来,我们一直在使用Access Database Engine 2010 V.14.0.4763.1000从c.Net framework 4.0中读取Excel 97-2003.xls文件,并取得了成功的结果。但现在,在使用Excel 2013打开文件并以97-2003.xls格式再次保存后,我们无法再读取这些文件 它给出了以下错误: 外部表不是预期的格式 当我们使用Excel 2007或2010打开和保存文件时,不会发生这种情况,只有在使用2013时才会发生。我们使用以下连接字

很长一段时间以来,我们一直在使用Access Database Engine 2010 V.14.0.4763.1000从c.Net framework 4.0中读取Excel 97-2003.xls文件,并取得了成功的结果。但现在,在使用Excel 2013打开文件并以97-2003.xls格式再次保存后,我们无法再读取这些文件

它给出了以下错误:

外部表不是预期的格式

当我们使用Excel 2007或2010打开和保存文件时,不会发生这种情况,只有在使用2013时才会发生。我们使用以下连接字符串读取文件:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0;HDR=YES
其中{0}被文件名和路径替换。Excel 2013似乎以ACE不了解的方式破坏了97-2003文件结构。我们有办法解决这个问题吗

需要明确的是,我们需要读取的文件格式始终是.xls 97-2003,我们不想读取.xlsx文件。我们可以毫无问题地执行此操作,但为了与其他系统兼容,我们需要使用97-2003

编辑:

我做了一个非常简单的测试程序来说明,你可以在这里得到它:

.rar文件包含:

ExcelReadingTest.exe将启动该程序 Program.cs源代码 SavedFromExcel2007.xls以97-2003格式从Excel 2007保存的Excel文件示例 SavedFromExcel2013.xls以97-2003格式从Excel 2013保存的相同Excel文件 要运行示例,请在c:\temp中保存所有文件并在cmd控制台上键入:

C:\>cd c:\temp (Enter)
C:\temp>ExcelReadingTest SavedFromExcel2007.xls (Enter)
您将获得:

1       Hello
2       World
3       Reading
4       Excel
Press Enter...
如果您键入:

C:\temp>ExcelReadingTest SavedFromExcel2013.xls (Enter)
安装Access Database Engine 2007 12.0.6612.1000后,您将获得:

System.Data.OleDb.OleDbException (0x80040E37): The Microsoft Access database eng
ine could not find the object 'Sheet1$'. Make sure the object exists and that yo
u spell its name and the path name correctly. If 'Sheet1$' is not a local object
, check your network connection or contact the server administrator.
   en System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResul
t hr)
   en System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARA
MS dbParams, Object& executeResult)
   en System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   en System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Ob
ject& executeResult)
   en System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behav
ior, String method)
   en System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   en System.Data.OleDb.OleDbCommand.ExecuteReader()
   en ExcelReadingTest.Program.Main(String[] args)
Press Enter...
System.Data.OleDb.OleDbException (0x80004005): External table is not in the expe
cted format.
   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString cons
tr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOpti
ons options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection o
wningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbC
onnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection ow
ningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection ou
terConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()
   at ExcelReadingTest.Program.Main(String[] args) in c:\users\ivanm\documents\v
isual studio 2010\Projects\ExcelReadingTest\ExcelReadingTest\Program.cs:line 41
Press Enter...
或者,在安装Access数据库引擎2010 14.0.7015.1000后,您将获得此功能:

System.Data.OleDb.OleDbException (0x80040E37): The Microsoft Access database eng
ine could not find the object 'Sheet1$'. Make sure the object exists and that yo
u spell its name and the path name correctly. If 'Sheet1$' is not a local object
, check your network connection or contact the server administrator.
   en System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResul
t hr)
   en System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARA
MS dbParams, Object& executeResult)
   en System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   en System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Ob
ject& executeResult)
   en System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behav
ior, String method)
   en System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   en System.Data.OleDb.OleDbCommand.ExecuteReader()
   en ExcelReadingTest.Program.Main(String[] args)
Press Enter...
System.Data.OleDb.OleDbException (0x80004005): External table is not in the expe
cted format.
   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString cons
tr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOpti
ons options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection o
wningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbC
onnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection ow
ningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection ou
terConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()
   at ExcelReadingTest.Program.Main(String[] args) in c:\users\ivanm\documents\v
isual studio 2010\Projects\ExcelReadingTest\ExcelReadingTest\Program.cs:line 41
Press Enter...