我有 ac# 应用程序已移至 64 位机器。此应用程序读入 Excel 文件以获取一些数据输入。我想将此项目构建为 64 位。有什么办法可以让我的程序读入这个文件?我很难相信没有办法使用 Excel 文件作为 64 位应用程序的输入。我已经安装了 Office 2010 64 位以及 2010 Office System Driver Beta:数据连接组件,但没有成功。我确定我只是错过了一些非常简单的东西。我的应用程序与 .xls 和 .xlsx 文件的 32 位环境完美配合。对于 64 位,它仅适用于 .xls 而不适用于 .xlsx。以下代码抛出不支持指定方法的异常(当我尝试在 64 位环境中打开与 xlsx 的连接时。)。
例外:
<Exception>
<Description>An exception of type 'System.NotSupportedException' occurred and was caught.</Description>
<DateTime>2012-10-12 17:53:53Z</DateTime>
<ExceptionType>System.NotSupportedException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Specified method is not supported.</Message>
<Source>ExcelHelper</Source>
<HelpLink />
<Property name="Data">System.Collections.ListDictionaryInternal</Property>
<Property name="TargetSite">System.Data.OleDb.OleDbConnection GetConnection(System.String)</Property>
<StackTrace> at ExcelOperations.ExcelHelper.GetConnection(String excelFile)
at ExcelOperations.ExcelHelper.GetExcelSheetDataSet(String excelFile, String sheetName)
at ExcelOperations.ExcelHelper.GetXLSXDataSet(String dataFilePath, String sheetName, Int64 rowNo)
at Intralinks.Platform.ObjectImpl.DataSource.ExcelFileSource.UpdateDataFilePath(String dataFilePath)</StackTrace>
<additionalInfo>
<info name="MachineName" value="NYCVMQCA007" />
<info name="TimeStamp" value="10/12/2012 9:53:53 PM" />
<info name="FullName" value="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
<info name="AppDomainName" value="ILPlatform.exe" />
<info name="ThreadIdentity" value="" />
<info name="WindowsIdentity" value="INTRALINKS\VPatel" />
</additionalInfo>
</Exception>
Category: Logging Exception
Priority: 1
EventId: 100
Severity: Error
Title:Enterprise Library Exception Handling
Machine: NYCVMQCA007
Application Domain: ILPlatform.exe
Process Id: 3548
Process Name: C:\IntraLinks\IntraLinks Designer\ILPlatform.exe
Win32 Thread Id: 5360
Thread Name:
代码片段:
public static OleDbConnection GetConnection(string excelFile)
{
OleDbConnection objConn = null;
try
{
// Connection String. Change the excel file to the file you
// will search.
String connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFile + ";Extended Properties=\"Excel 12.0 xml;IMEX=1\"";
// Create connection object by using the preceding connection string.
objConn = new OleDbConnection(connString);
// Open connection with the database.
objConn.Open();
}
catch (Exception)
{
try
{
// Connection String. Change the excel file to the file you
// will search.
String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
// Create connection object by using the preceding connection string.
objConn = new OleDbConnection(connString);
// Open connection with the database.
objConn.Open();
}
catch (Exception)
{
throw new NotSupportedException();
}
}
return objConn;
}