Hi,
I am using Microsoft.Interop dll Version 14.
OLEDB Connection string 12.0
My code,
try
{
string connStr = CommonConstants.ExcelConnectionString.Replace("FILENAME", InputFileWithPath);
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wb = null;
excel.Visible = false;
string SheetName = string.Empty;
try
{
object missing = System.Reflection.Missing.Value;
wb = excel.Workbooks.Open(InputFileWithPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
foreach (Microsoft.Office.Interop.Excel.Worksheet sheet in wb.Sheets)
{
SheetName = sheet.Name + "$";
break;
}
excel.Quit();
}
finally
{
if (excel != null)
{
excel.Quit();
ClsCommon.ExcelClose(excel);
}
}
using (conn = new OleDbConnection(connStr))
{
conn.Open();
System.Data.DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
String[] excelSheets = new String[dt.Rows.Count];
adapter = new OleDbDataAdapter("SELECT F1,F3,F5,F7,F8,F9,F10,F14,F16,F17,F18 FROM [" + SheetName + "]", conn);
adapter.Fill(ClsParameter.dtInputFile);
conn.Close();
for (int j = 0; j < 10; j++)
{
ClsParameter.dtInputFile.Rows.RemoveAt(0);
}
ClsParameter.dtInputFile.AcceptChanges();
}
}
catch (Exception ex)
{
ClsParameter.TotalErrorCount++;
ClsLog.WriteLogFile("Error while Reading Input File. Error : " + ex.Message.ToString(), CommonConstants.LogType_Error);
return false;
}
finally
{
if (conn != null && conn.State == ConnectionState.Open)
{
conn.Close();
conn.Dispose();
conn = null;
System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("Excel");
foreach (System.Diagnostics.Process p in process)
{
if (!string.IsNullOrEmpty(p.ProcessName))
{
try
{
p.Kill();
}
catch { }
}
}
}
}
When i am trying to run the same on system having Microsoft Office 2013 i am getting error as described below :
Exception from HRESULT: 0x800AC472.
I have installed 2007 office System Data Drivers but it dint work.
Kindly help.