Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem opening Excel 2007 file from OleDbConnection

I am attempting to open an Excel 2007 file (test1.xlsx) from my Word 2007
addin using OleDb. The code runs fine as long as I have the Excel 2007
application running with "test1.xlsx" open. But if Excel 2007 is not
running, I get an exception "External table is not in the expected format" on
the myConn.Open() statement. If I replace the Excel 2007 file with the
equivalent Excel 2003 binary file it always works.

Do I need a new JET engine to open Excel 2007 files? Why does the code work
when Excel 2007 has the file open? Does the old JET engine notice that Excel
2007 has the file open and use its code? Thanks for any help.

Here is the code:

string filename = @"c:\test1.xlsx";
if (!File.Exists(filename))
throw new Exception("File not found");

string myConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" + filename + ";" + "Extended Properties=\"Excel 8.0;HDR=YES\"";
OleDbConnection myConn = new OleDbConnection(myConnStr);
myConn.Open(); // HERE IS WHERE IT FAILS
myConn.Close();

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem opening Excel 2007 file from OleDbConnection

I think I found the solution. It works if you replace the connection string
with "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + ";" +
"Extended Properties=\"Excel 12.0;HDR=YES\"". Evidently, there's an ACE
engine that's replacing the JET engine. I found this on
http://msdn2.microsoft.com/en-us/library/aa395290.aspx.

"Dave Jenkins" wrote:

I am attempting to open an Excel 2007 file (test1.xlsx) from my Word 2007
addin using OleDb. The code runs fine as long as I have the Excel 2007
application running with "test1.xlsx" open. But if Excel 2007 is not
running, I get an exception "External table is not in the expected format" on
the myConn.Open() statement. If I replace the Excel 2007 file with the
equivalent Excel 2003 binary file it always works.

Do I need a new JET engine to open Excel 2007 files? Why does the code work
when Excel 2007 has the file open? Does the old JET engine notice that Excel
2007 has the file open and use its code? Thanks for any help.

Here is the code:

string filename = @"c:\test1.xlsx";
if (!File.Exists(filename))
throw new Exception("File not found");

string myConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" + filename + ";" + "Extended Properties=\"Excel 8.0;HDR=YES\"";
OleDbConnection myConn = new OleDbConnection(myConnStr);
myConn.Open(); // HERE IS WHERE IT FAILS
myConn.Close();

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening Excel 2007 Book1 problem DanieB Excel Discussion (Misc queries) 3 November 4th 09 07:53 PM
Opening a spreadsheet problem Excel 2007 RainyDay Setting up and Configuration of Excel 1 April 21st 09 05:25 PM
date format problem from opening dbf file in excel 2007 pol Excel Discussion (Misc queries) 5 December 1st 08 11:42 AM
Problem opening Excel 2007 files Michael Julson Excel Discussion (Misc queries) 18 December 2nd 07 05:21 PM


All times are GMT +1. The time now is 02:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"