Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

import from multiple worksheets

Status
Not open for further replies.

i12hvfun

Programmer
Jul 26, 2002
20
SG
HI,
the search is under maintenance and hence I have to start a new thread, which most probably someone would have started it before.

I am looking for ways of importing multiple worksheets with a EXCEL file.

Please advise.
 
Quick and dirty:
Code:
IMPORT FROM MyFIle.xls TYPE XL8 SHEET "SheetName"
Brian
 
Thanks Brian,
the problem is that the worksheet name will vary according to user's liking.
I will need to know how many worksheet is in there and the name for these worksheets.
The number of column in each worksheet will varies and I will need to capture all these columns.

 
First, the fact that you importing a different number of columns is not a problem. The IMPORT command will pick up all the columns in the sheet.

To find the name of the sheets in the workbook, you have two options:

- Ask the user. Not a very good idea, as you will rely on them giving you exactly the right name.

- Use COM Automation to interrogate the workbook. Here is some code to do that (this is not tested; it is only meant to illustrate the general idea):

Code:
loExcel = CREATEOBJECT("excel.application")
loWorkbook = loExcel.Workbooks.Open("MyWorkbook")
FOR EACH loSheet IN loWorkbook.Sheets
  ? loSheet.name
ENDFOR 
loWorkbook.Close
loExcel.Quit

As you can see, this simply displays the names of the sheets on the screen. Obviously, you will need to capture them somehow, for example in an array or cursor.

Mike



Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Thanks Mike. The code is really a great help.
 
IMPORT does not pick up on all colums and rows. If there's a break in headers it'll miss subsequent columns, and if there's no data for the 1st several rows, it won't import rows either.

Just something to be aware of. If you need to overcome it you'd need to test individual cells and move data around prior to IMPORT.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top