Excel 2003 读取时出错
1. 代码
A. 连接字符串
private const string connectionStringFormatForRead2003 =
"Provider=Microsoft.Ace.OleDb.12.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\"";
private const string connectionStringFormatForRead2007 =
"Provider=Microsoft.Ace.OleDb.12.0;Data Source={0};Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1;\"";
B. OleDbConnection 代码
public static OleDbConnection CreateConnection(string filePath)
{
Log.Logger.LogOperationStart("OleDbConnection CreateConnection(string filePath). Start....");
ValidateExcelFile(filePath);
try
{
connectionString = string.Format(connectionStringFormatForRead2003, filePath);
Log.Logger.LogInformation(string.Format("Excel2003 Read OleDbConnection ConnectionString={0}",connectionString));
conn = new OleDbConnection(connectionString);
conn.Open();
return conn;
}
catch (Exception ex)
{
Log.Logger.LogException(ex);
try
{
connectionString = string.Format(connectionStringFormatForRead2007, filePath);
Log.Logger.LogInformation(string.Format("Excel2007 Read OleDbConnection ConnectionString={0}", connectionString));
conn = new OleDbConnection(connectionString);
conn.Open();
return conn;
}
catch (Exception exp)