Mike Lewis
Programmer
I am trying to retrieve data form an Excel 2007 workbook.
I downloaded AccessDatabaseEngine.EXE from Microsoft and installed it. I understand this installs the drivers for the new Office 2007 data format, including Excel's XLSX format.
I then tried this connection string:
On trying to connect, the ODBC Select Data Source window appeared. This is the window which prompts you to choose a DSN. I clicked Cancel, and the window went away. The connection was then successful.
However, I don't want the end-user to see this window. So I tried a different connection string:
In this case, the connection went smoothly, without anything popping up. But this isn't ideal, because it requires a DSN to be present, which is an extra dependency.
In both cases, when I did a SELECT on the workbook, all the data was correctly returned except the first row. In fact, first row of data appeared as the column headings in the result set, which is not what I want.
I know that the parameter HDR=NO is supposed to treat the first row of the sheet as data, not as a header, but this seems to have no effect. I tried setting it to NO, YES and leaving it out completely. I did this with both the above connection strings. In all cases, the result was the same: the result set was always missing the first row.
So, I've got two questions:
1. If I use the first of the above connection strings, how can I avoid the Select Data Source window from appearing?
2. How can I tell the system to return the first row of the worksheet?
I hope I have posted this in the right forum. I wondered about posting in the VBA forum, but this isn't really a VB issue. I'm doing all this from a different development platform (Visual FoxPro).
Thanks in advance.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro tips, advice, training, consultancy
Custom software for your business
I downloaded AccessDatabaseEngine.EXE from Microsoft and installed it. I understand this installs the drivers for the new Office 2007 data format, including Excel's XLSX format.
I then tried this connection string:
Code:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=MyFile.XLSX;
Extended Properties="Excel 12.0 Xml;HDR=NO"
On trying to connect, the ODBC Select Data Source window appeared. This is the window which prompts you to choose a DSN. I clicked Cancel, and the window went away. The connection was then successful.
However, I don't want the end-user to see this window. So I tried a different connection string:
Code:
Provider=MSDASQL.1;Persist Security Info=False;DSN=Excel Files;
DBQ=MyFile.xls;DriverId=790;MaxBufferSize=2048;PageTimeout=5
In this case, the connection went smoothly, without anything popping up. But this isn't ideal, because it requires a DSN to be present, which is an extra dependency.
In both cases, when I did a SELECT on the workbook, all the data was correctly returned except the first row. In fact, first row of data appeared as the column headings in the result set, which is not what I want.
I know that the parameter HDR=NO is supposed to treat the first row of the sheet as data, not as a header, but this seems to have no effect. I tried setting it to NO, YES and leaving it out completely. I did this with both the above connection strings. In all cases, the result was the same: the result set was always missing the first row.
So, I've got two questions:
1. If I use the first of the above connection strings, how can I avoid the Select Data Source window from appearing?
2. How can I tell the system to return the first row of the worksheet?
I hope I have posted this in the right forum. I wondered about posting in the VBA forum, but this isn't really a VB issue. I'm doing all this from a different development platform (Visual FoxPro).
Thanks in advance.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro tips, advice, training, consultancy
Custom software for your business