Can anyone give me a simple explanation of how to use actxserver to import data from matlab. I have a working code by using loops and xlsread but the running time is way too long. All I understand about actxserver is that it will save time as it doesn't open and close excel every time it goes through the loop.
I've got this far:
hExcel = actxserver('Excel.Application');
hExcel.visible = 1; % If you want Excel visible.
hExcel.DisplayAlerts = false; % Avoid excel warning popups
Which basically just opens excel. I now need to get some data...

 採用された回答

Jan
Jan 2011 年 12 月 2 日

1 投票

4 件のコメント

Richard
Richard 2011 年 12 月 2 日
from one of the topics on the forum I cam across
http://www.orient-lodge.com/node/3430
Where in this link it shows how to use ActiveX. I have 2 questions which don't seem to be covered:
1) in the command
sheet1=excel.Worksheets.get(‘Item’, ‘Sheet1’);
is it possible to obtain everything from 'Sheet1' without having to specify the range with:
range1=get(sheet1,’Range’, ‘A1’);
a1=range1.Value;
instead can you do something like
a1=sheet1.Value;
Because your not going to know the range without looking at each .xls file first, where if you have 100 .xls files it would take some time.
2) if I have several .xls files in different directories is it a simple case of making a loop and having the path name of each file and then placing it in the line below?
file = excel.Workbooks.Open(xlsfile);
Richard
Richard 2011 年 12 月 2 日
編集済み: Walter Roberson 2022 年 5 月 23 日
ok I've covered this much so far:
excel = actxserver('Excel.Application');
excel.Visible=1
file = excel.Workbooks.Open(Filename');
sheet1=excel.Worksheets.get('Item', 'data');
rowEnd = sheet1.Range('A1').End('xlDown').Row
colEnd = sheet1.Range('A1').End('xlToRight').Column
So now I have the number of rows and the number of columns for the spreadsheet. I just need to know how to define the range of values from these numbers instead of using cell name i.e. 'A1'.
Any advice?
Fangjun Jiang
Fangjun Jiang 2011 年 12 月 2 日
Yes, to loop through different files, it's better to provide the full path of the files.
To read all the data in the sheet without specifying the range, use
MyRange=Sheet.UsedRange;
MyData=MyRange.Value;
Richard
Richard 2011 年 12 月 2 日
great.

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2011 年 12 月 2 日

編集済み:

2022 年 5 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by