I nead help, xlsread(file,-1).

14 views (last 30 days)
Jola P
Jola P on 30 Jul 2012
from doc:
[num,txt,raw] = xlsread(filename,-1) opens an Excel window to interactively select data. Select the worksheet, drag and drop the mouse over the desired range, and click OK.
How can I save this selected area (ex ‘A3:AB187’ or other) to use as a variable.I wont read in the same area (ex ‘A3:AB187’ or other) with multiple files.
Thanks,
Jola
  3 Comments
nanren888
nanren888 on 1 Aug 2012
Edited: nanren888 on 1 Aug 2012
Maybe he means, can he find out the range that was selected as well as the contents.
Jola P
Jola P on 1 Aug 2012
You're right nanren888. How can I save range that was selected, for example ‘A3:AB187’ or 'B17: D38' or other, from xlsread(FileName1,-1) to use as a variable. I wont read Data from this range (ex. ‘A3:AB187’ or other) with multiple files (FileName2, FileName3, ....FileName100).
Thanks.

Sign in to comment.

Accepted Answer

Oleg Komarov
Oleg Komarov on 1 Aug 2012
I'll rephrase the question to make it clear.
How can I return the address of the data which I selected interactively with:
xlsread(filename,-1)
After a bit of reverse engineering I found a semi-undocumented feature. It is possible to play with the COM object through the 5th input. The syntax I am gonna use is:
[num,txt,raw,custom] = xlsread(filename,sheet,range,'',functionHandle)
Step 1 Create the following function which will query the Address property
function [DataRange, range] = customOut(DataRange)
range = DataRange.Address;
end
Step 2 Now simply import the data with:
[num,txt,raw,address] = xlsread('test.xlsx',-1,[],[],@customOut)
address =
$B$7:$D$12

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!