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