cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
tsl
tsl
Level III

How Can I get a list of sheets in an Excel workbook ?

I have a situation where I am opening Excel sheets using Open Database().

This has been a good way to do it since I want specific columns from specific sheets, so using an SQL SELECT statement is ideal.

I am now discovering there is no standardization on the sheet names. So what I want to do is query the Excel workbook and get a list of sheets in it. I can then use some logic in my code to decide which ones I actually want ( because while there is no standardization, there are enough "similarities" that I could figure out what I want, by checking does the sheet name contain StringA or StringB or StringC for example )

I have no idea how this can be done in JSL. Searching onling, there are plenty of code examples using VBScripting etc which will return the sheets in an Excel workbook, but that is not much help.

I tried also to find some SQL statement that would do it, but I don't know of a table name that would list the "tables"  / sheets in the workbook.

I know JMP can do it because if I use File -> DataBase -> Open Table and connect to an Excel data source it will list all the sheets available in the Schemas - Tables column. Likewise if I set a user preference to select individual Excel Worksheets and use the Open() command it will ask me to select which sheets I want to open.

So my question is does anybody know if JMP exposes that capability to figure out the Excel sheet names to the scripting language ?

many thanks

Thomas

3 REPLIES 3
mpb
mpb
Level VII

Re: How Can I get a list of sheets in an Excel workbook ?

Here's a very clunky way which may not even be feasible if the tables are very large. Just a fragment ...

1. Set preferences to open all Excel sheets on file>open.

2. countBefore = N Table();

3. Open the Excel file using open()

4. countAfter = N Table();

5. nSheets = countAfter - countBefore

5. dtname = {};

5. for(i=1, i <= nSheets, i++, dtname = Data Table(i) << get name);

Then dtname is a list of Sheet names you can play with and you can close the tables you don't want.

Message was edited by: mpb
Corrected indexing in the code fragment.

mpb
mpb
Level VII

How Can I get a list of sheets in an Excel workbook ?

Note that the code fragment above was corrected.

Re: How Can I get a list of sheets in an Excel workbook ?

The last step may get you messed up if you have data tables open before you open the excel worksheets.  Quick correction is

for(i=1, i <= nSheets, i++, dtname = Data Table(i+countBefore) << get name);