我有一个c#应用程序,我已经转移到64位机器。此应用程序读入Excel文件以获取某些数据输入。我想将此项目构建为64位。有没有办法让我的程序在这个文件中读取?我发现很难相信没有办法使用和Excel文件作为64位应用程序的输入。我已经安装了Office 2010 64位以及2010 Office System Driver Beta:数据连接组件而没有运气。我确信我只是错过了一些非常简单的东西。我的应用程序与.xls和.xlsx文件的32位环境完美配合。对于64位,它只适用于.xls而不适用于.xlsx。以下代码抛出了异常,即不支持Specified方法(当我尝试在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;
}