cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Translate the entire conversation x

Is it possible to read data from several tabs in Mathcad 15 from an excel file?

DD_13910355
10-Marble

Is it possible to read data from several tabs in Mathcad 15 from an excel file?

Is it possible to read data from several tabs in Mathcad 15 from an excel file?

Snag_1519f88f.png

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:DD_13910355)

I don't know of any built-in way to get the number of sheets in an Excel file or (equally important) the names of the sheets.

As long as the names of all sheets are left at their default value (which is "Sheet" in English versions followed by a number starting by "1")  you can let Mathcad read in the sheets until it fails. Failing could mean that no further sheet is found but it could also mean that the next sheet has a different name.

The attached demo Excel file consists of four sheets. The first three have the names "Sheet1", "Sheet2" and "Sheet3", but the fourth is names "Tabelle4" (which is the default name in the German Excel version).

The aforementioned approach will only read in the data from the first three sheets and stop.

The "range" parameter provided in the READEXCEL function is just "Sheet1!" without providing a cell address and so the data from the whole sheet is read in.

Werner_E_0-1754923803400.png

 

BTW, Prime still lags behind the ancient Mathcad15 in many respects, but one of the improvements in Prime is that READEXCEL allows you to address the individual sheets of an Excel file by their number (regardless of their name). So in Prime with the approach presented here, you could really read in all the sheets of the file.

 

View solution in original post

7 REPLIES 7

There is no ban and nothing interferes.

How to do this? If I do this via "Insert - Data - Input from file...", then reading occurs only from the first tab. How to make reading from all tabs?

Werner_E
25-Diamond I
(To:DD_13910355)

You may use the READEXCEL function multiple times to do the job.

Werner_E_0-1754911377620.png

 

If you don't know in advance how many tabs an excel file contains, is there a way to read the data?

Werner_E
25-Diamond I
(To:DD_13910355)

I don't know of any built-in way to get the number of sheets in an Excel file or (equally important) the names of the sheets.

As long as the names of all sheets are left at their default value (which is "Sheet" in English versions followed by a number starting by "1")  you can let Mathcad read in the sheets until it fails. Failing could mean that no further sheet is found but it could also mean that the next sheet has a different name.

The attached demo Excel file consists of four sheets. The first three have the names "Sheet1", "Sheet2" and "Sheet3", but the fourth is names "Tabelle4" (which is the default name in the German Excel version).

The aforementioned approach will only read in the data from the first three sheets and stop.

The "range" parameter provided in the READEXCEL function is just "Sheet1!" without providing a cell address and so the data from the whole sheet is read in.

Werner_E_0-1754923803400.png

 

BTW, Prime still lags behind the ancient Mathcad15 in many respects, but one of the improvements in Prime is that READEXCEL allows you to address the individual sheets of an Excel file by their number (regardless of their name). So in Prime with the approach presented here, you could really read in all the sheets of the file.

 

Thank you!
Did I understand correctly: if you don't know exactly how many sheets there are, but know their names for any given number, then the problem is solved completely by finding out the moment when the error occurs when trying to read?

Werner_E
25-Diamond I
(To:DD_13910355)


@DD_13910355 wrote:

Thank you!
Did I understand correctly: if you don't know exactly how many sheets there are, but know their names for any given number, then the problem is solved completely by finding out the moment when the error occurs when trying to read?


As long as all sheets are named the same ("Sheet" in my example) followed by consecutive numbers starting by 1, my approach should work and return a nested matrix with all sheets.

If the sheets are named "Sheet1", "Sheet2" and "Sheet4", my approach would only read in the first two sheets because when trying to access the non-existing "Sheet3" an error would occur.

Announcements

Top Tags