Import Excel worksheet data into SQL 2000 with DTS

Import Excel worksheet data into SQL 2000 with DTS

Post by Andrew C » Wed, 27 Mar 2002 03:08:53



Hi all,
I'm looking for any directions on how to pull data from
specific cells in an Excel 2000 worksheet into SQL 2000
with DTS or DTS object in VB6. So far I was able to
determine that DTS package can import data from Excel if
the worksheet is formatted in a certain way (spreadsheet
columns have to correspond to the fields in SQL table, no
blank rows, etc.). My spreadsheets are not formatted that
way, so I have to go after specific cells/blocks of cells
and pull this data into SQL.
Does anybody have any idea how to do it or of it is at all
possible? I'd appreciate any help.

Thank you!

Andrew

 
 
 

Import Excel worksheet data into SQL 2000 with DTS

Post by Douglas Laudenschlager [M » Wed, 27 Mar 2002 05:37:40


Andrew,

If your Excel data was indeed in "blocks", you could still use DTS to
import those blocks if you made them "Named Ranges" in Excel. (Where you
see a list of the "tables" available from an Excel file in DTS, those with
the $ like Sheet$ are worksheets, those without are named ranges.)

I have never tried using a single-cell named range with ADO/OLE DB (which
is what DTS is using underneath), so I'm not sure what results you'd see if
you tried to retrieve individual cell values this way.

If you do need to pick up individual worksheet cells from various
locations, you might need to automate Excel in an ActiveX Script Task and
use the Excel object model to retrieve those values. However you normally
don't want to automate Office applications in an unattended server
environment.

Let us know what additional information we can offer.

-Doug

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

 
 
 

Import Excel worksheet data into SQL 2000 with DTS

Post by Andrew C » Wed, 27 Mar 2002 06:26:25


Doug,
Thank you for reply. For my Excel import package, in DTS,
under a list of tables, all I see is the listing of
worksheets (for example:'January 02$'). The problem with
these worksheets is that they are created, formatted and
maintained by users who use them for all kinds of
reporting. I 'm looking for a way to pull some data from
those worksheets into SQL server with DTS package. I was
hoping that either the DTS designer or a package created
in VB6 would be able to access specific cells or groups of
cells (I would liek to leave the spreadsheets the way they
are) and pull the data from those cells. However, I don't
see such functionality built into neither the DTS designer
(SQL Enterprise Manager) nor the DTS object model (VB6).

Thanks,
Andrew

Quote:>-----Original Message-----

>Andrew,

>If your Excel data was indeed in "blocks", you could
still use DTS to
>import those blocks if you made them "Named Ranges" in
Excel. (Where you
>see a list of the "tables" available from an Excel file
in DTS, those with
>the $ like Sheet$ are worksheets, those without are named
ranges.)

>I have never tried using a single-cell named range with
ADO/OLE DB (which
>is what DTS is using underneath), so I'm not sure what

results you'd see if
Quote:>you tried to retrieve individual cell values this way.

>If you do need to pick up individual worksheet cells from
various
>locations, you might need to automate Excel in an ActiveX
Script Task and
>use the Excel object model to retrieve those values.

However you normally
Quote:>don't want to automate Office applications in an
unattended server
>environment.

>Let us know what additional information we can offer.

>-Doug

>This posting is provided "AS IS" with no warranties, and
confers no rights.

>Are you secure? For information about the Microsoft

Strategic Technology

- Show quoted text -

Quote:>Protection Program and to order your FREE Security Tool
Kit, please visit
>http://www.microsoft.com/security.

>.

 
 
 

Import Excel worksheet data into SQL 2000 with DTS

Post by Allan Mitchel » Wed, 27 Mar 2002 05:56:32


I think to tell you the truth your easiest way is to use the Excel Object
library and ADO in VB6

Here is a quick example of retrieving cell in formation in VB

Dim Excel_app As Excel.Application
Dim Excel_Worksheet As Excel.Worksheet
Dim Excel_WorkBook As Excel.Workbook

Set Excel_app = New Excel.Application

Set Excel_WorkBook =
Excel_app.Workbooks.Open("f:\xl\testfiles\cellfinder.xls")

Set Excel_Worksheet = Excel_WorkBook.Worksheets(1)

For Each c In Excel_Worksheet.Range("D6:G6").Cells
    MsgBox c.Value
Next

'Clean Up

Excel_WorkBook.Close
Set Excel_Worksheet = Nothing
Set Excel_WorkBook = Nothing
Set Excel_app = Nothing

--

Allan Mitchell
www.allisonmitchell.com


Quote:> Hi all,
> I'm looking for any directions on how to pull data from
> specific cells in an Excel 2000 worksheet into SQL 2000
> with DTS or DTS object in VB6. So far I was able to
> determine that DTS package can import data from Excel if
> the worksheet is formatted in a certain way (spreadsheet
> columns have to correspond to the fields in SQL table, no
> blank rows, etc.). My spreadsheets are not formatted that
> way, so I have to go after specific cells/blocks of cells
> and pull this data into SQL.
> Does anybody have any idea how to do it or of it is at all
> possible? I'd appreciate any help.

> Thank you!

> Andrew

 
 
 

Import Excel worksheet data into SQL 2000 with DTS

Post by Douglas Laudenschlager [M » Thu, 28 Mar 2002 05:25:21


Andrew,

I agree with Allan that your best bet is probably Excel Automation if you
need to access cells that are all over the place in the source worksheets.

Although you can place this code in an ActiveX Script Task in DTS, that's
not really taking advantage of DTS other than as a convenient context to
run VB code in SQL Server. If your source cells are designated as Named
Ranges, as I mentioned, then you could use some DTS capabilities a little
more (since those ranges can be datasources).

By the way, I would add the line "Excel_app.Quit" to Allan's cleanup code
in the VB sample, to explicitly close Excel.

Best wishes,

-Doug

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

 
 
 

Import Excel worksheet data into SQL 2000 with DTS

Post by Allan Mitchel » Thu, 28 Mar 2002 05:42:20


I have asked Darren if he would mind hosting some examples of using things
like Excel and Word Automation that I have written.

I hopefully should get something to press in the next day or so and then it
should go up when Darren has the time.

One of them will use named ranges in Excel and creating them in an ActiveX
script at the start of a package.  We then change the source query to
reference this data

This would be useful if you have a group of salesmen using the same XL
template but it starts in the middle of the page and you have to go and get
the data from there.

--

Allan Mitchell
www.allisonmitchell.com



Quote:> Andrew,

> I agree with Allan that your best bet is probably Excel Automation if you
> need to access cells that are all over the place in the source worksheets.

> Although you can place this code in an ActiveX Script Task in DTS, that's
> not really taking advantage of DTS other than as a convenient context to
> run VB code in SQL Server. If your source cells are designated as Named
> Ranges, as I mentioned, then you could use some DTS capabilities a little
> more (since those ranges can be datasources).

> By the way, I would add the line "Excel_app.Quit" to Allan's cleanup code
> in the VB sample, to explicitly close Excel.

> Best wishes,

> -Doug

> This posting is provided "AS IS" with no warranties, and confers no
rights.

> Are you secure? For information about the Microsoft Strategic Technology
> Protection Program and to order your FREE Security Tool Kit, please visit
> http://www.microsoft.com/security.

 
 
 

Import Excel worksheet data into SQL 2000 with DTS

Post by itrain.d » Fri, 29 Mar 2002 07:26:28


Hi there,
I think there is no need to use the Excel-Object library to pull out certain
cells from an Excel-Sheet - all this can easily be
done with standard DTS and Jet-Driver technology.

If you can identify the ranges and these ranges do have a header row  you
can use an Excel connection.
Instead of selecting just the worksheet from the drop down in the source
page write a SELECT statement:
For example:
Let's say you have an excel sheet with the following data in Sheet ASheet

B3 Name C3 Number
B4 ABC  C4 1
B5 XYZ  C5  23

You can select the data from the sheet using the following SELECT statement:
SELECT * FROM [ASheet$B3:C5]

If you do not have a Header row you are better of using a standard data link
connection to the Excel Sheet.
Select the Microsoft.Jet.OLEDB.4.0 provider
Specify the name of the Excel-workbook as the data source.
Specify under "Extended Properties": Excel 8.0;HDR=NO;

Now use this connection as the source for your data.
Now lets take the same sample data, but this time without the header row
B4 ABC  C4 1
B5 XYZ  C5  23

Just use the SELECT-statement
SELECT * FROM [Asheet$B4:C5]

You can than map the columns to the appropriate columns in your target
table...

I hope this helps - and by the way - not everyone has Excel installed on the
server...

sven




> I think to tell you the truth your easiest way is to use the Excel Object
> library and ADO in VB6

> Here is a quick example of retrieving cell in formation in VB

> Dim Excel_app As Excel.Application
> Dim Excel_Worksheet As Excel.Worksheet
> Dim Excel_WorkBook As Excel.Workbook

> Set Excel_app = New Excel.Application

> Set Excel_WorkBook =
> Excel_app.Workbooks.Open("f:\xl\testfiles\cellfinder.xls")

> Set Excel_Worksheet = Excel_WorkBook.Worksheets(1)

> For Each c In Excel_Worksheet.Range("D6:G6").Cells
>     MsgBox c.Value
> Next

> 'Clean Up

> Excel_WorkBook.Close
> Set Excel_Worksheet = Nothing
> Set Excel_WorkBook = Nothing
> Set Excel_app = Nothing

> --

> Allan Mitchell
> www.allisonmitchell.com



> > Hi all,
> > I'm looking for any directions on how to pull data from
> > specific cells in an Excel 2000 worksheet into SQL 2000
> > with DTS or DTS object in VB6. So far I was able to
> > determine that DTS package can import data from Excel if
> > the worksheet is formatted in a certain way (spreadsheet
> > columns have to correspond to the fields in SQL table, no
> > blank rows, etc.). My spreadsheets are not formatted that
> > way, so I have to go after specific cells/blocks of cells
> > and pull this data into SQL.
> > Does anybody have any idea how to do it or of it is at all
> > possible? I'd appreciate any help.

> > Thank you!

> > Andrew

 
 
 

1. using DTS to import Excel data into SQL Server 2000

Hi
I wonder if anyone can help. I'm currently trying to import a large
quantity of data, stored in Excel files, into SQL Server 2000 using
the DTS Metadata Services Package. I'm hitting a recurrent problem
which, it seems to me, is a variant on a general problem associated
with Excel files.

Problem variant a) I have columns of data which I wish to store as
varchar(2), and these are typically of the form: aa, a1, 1b, bb etc.
When I import them, a minority are transformed into nulls. I can
resolve this by saving the .xls file as a .csv file and importing them
as text.

Problem variant b) For various reasons, I wish to import all data in
the same format (primarily to avoid confusion with my colleagues). So
when I then try to import a table, duly saved as a .csv file, where I
have a column of data I wish to convert to either smallint or int
format, the datapump in SQL server returns an error message to the
effect that it cannot convert a string to an int. Am I right in
thinking that any column of text in a .csv file which I wish to
convert to a number cannot be converted ? I am not an expert in these
matters, and I could well be making a basic error, but it seems
peculiar to me that I cannot convert a string to an int.

Is there a workaround in SQL Server equivalent to changing the IMEX
value in VB 6.0 OpenDatabase method ? Anyone have any suggestions at
all ?

2. object permission

3. Import Data from Excel Worksheet

4. Distinct aggregation problem

5. Problem in Importing Data From Excel To Sql Server 2000

6. Java Runtime Environment under OS/2 Warp 4

7. Query Excel Worksheet via SQL Task in DTS

8. Certification MCDBA

9. How to save a Excel worksheet interactively to SQL from VBA/DTS

10. How do I make use of DTS to import excel data into SQL relational database

11. How to import data from Excel to SQl Server7, by VS or DTS

12. DTS or Import Data into SQL Server 7/2000 from Oracle Stored Proc returning resultset