Juan Juan - 2 months ago 6
C# Question

Reading an Excel File From C#

I have a connection string to read an excel file from my C# project that looks like this..

String ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + VariableFile + ";" +
"Extended Properties=Excel 8.0;";


and I also have objConn.Open(); to open the file..

The problem is the only time my program will open the file is if I open the Excel file manually and run my program. Can anyone help me to open the file from my C# code instead of having to open it first manually. I get the error message: Could not find installable ISAM when I try to run it without opening the Excel file first.

Thank you

Answer

I think your connection string is formatted wrong and the "Could not find installable ISAM" is usually an indication of this.

Try this, it's from a piece of operational code I have:

Excel 2007

string connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=No;IMEX=1\";", fullPath);

Excel 2003

string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\";", fullPath);
Comments