May 19, 2006 at 2:32 pm
Hi,
In Test.xls, I’ve created a single sheet (Sheet1) that contains this data:
Chris | Bob | Andrew |
1 | 2 | 3 |
I run this query:
Select
*
From
OpenRowset (
'Microsoft.Jet.OLEDB.4.0'
, 'Excel 8.0;
Database=C:\Code\ToolsAndUtilities\Conversions\Test.xls;
HDR=YES;IMEX=1'
, Sheet1$
)
The result of the query is:
Andrew | Bob | Chris |
3.0 | 2.0 | 1.0 |
I have the following questions:
Thanks for any pointers,
Richard
May 22, 2006 at 12:34 am
To connect to Excel, one can use OleDb objects that will treat Excel as a database, and then the required information can be easily fetched by using SQL queries. The important steps that have to be considered while connecting to Excel are as follows:
The connection string should be set to the OleDbConnection
object. This is very critical as Jet Engine might not give a proper error message if the appropriate details are not given.
Syntax: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<Full Path of Excel File>; Extended Properties="Excel 8.0; HDR=No; IMEX=1"
.
Excel
= <No> One should specify the version of Excel Sheet here. For Excel 2000 and above, it is set it to Excel 8.0 and for all others, it is Excel 5.0.
HDR
= <Yes/No> This property will be used to specify the definition of header for each column. If the value is ‘Yes’, the first row will be treated as heading. Otherwise, the heading will be generated by the system like F1, F2 and so on.
IMEX
= <0/1/2> IMEX
refers to IMport EXport mode. This can take three possible values.
IMEX
=0 and IMEX
=2 will result in ImportMixedTypes
being ignored and the default value of ‘Majority Types’ is used. In this case, it will take the first 8 rows and then the data type for each column will be decided. IMEX
=1 is the only way to set the value of ImportMixedTypes
as Text
. Here, everything will be treated as text.
N 56°04'39.16"
E 12°55'05.25"
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply