Reputation: 1
Hello all I'm trying to pull from an Excel xlsx document but I keep getting an error "External table not in the expected format." Heres what I'm using as my connection string:
String excelConnString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties='Excel 12.0;'", filePath);
using (OleDbConnection excelConnection = new OleDbConnection(excelConnString))
{
excelConnection.Open();
filepath- Is simply a string with the file path of my Excel Spreadsheet, which is pulled from a form upload control.
I get to the point of my code where I want to open the connection and it just errors out. But here's the kicker....I tried the same connection string on a .XLS file and it connected fine, even ran a query as expected. When I google the connection string I find that I'm using the same connection as everyone else just mine wont work. Any help is appreciated.
Upvotes: 0
Views: 6798
Reputation: 2017
Try with this macro enabled connection string:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsm;
Extended Properties="Excel 12.0 Macro;HDR=YES";
Upvotes: 0
Reputation: 1013
Try this
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties='Excel 12.0 Xml; HDR=YES'"
or this
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties='Excel 12.0; HDR=YES'"
Upvotes: 2