Equivalent ActiveX Code for xlsread

4 ビュー (過去 30 日間)
Me Y
Me Y 2015 年 5 月 22 日
回答済み: Image Analyst 2015 年 5 月 22 日
Hello everyone :) I have a program in which it reads some Excel files and use the data imported from them. I used the xlsread function to read from the files as in : [~,~,c]=xlsread(FileName,'','','basics'); and then worked on c to extract the data I need. But when I try to read multiple files or in a loop, it gets very slow, so I searched around and found out that using ActiveX would solve the problem. So I was wondering how I could do that. This is by far what I have found : exl = actxserver('excel.application'); exlWkbk = exl.Workbooks; exlFile = exlWkbk.Open(FileName); exlSheets = exlFile.Sheets; SheetCounts=exlSheets.Count;
Now how can I read all the data in Sheet 1 or 2, ...? And read the data into a cell array.

回答 (3 件)

Image Analyst
Image Analyst 2015 年 5 月 22 日
Here's a full example, attached.

Sebastian Castro
Sebastian Castro 2015 年 5 月 22 日
  2 件のコメント
Me Y
Me Y 2015 年 5 月 22 日
@Sebastian Thank you but it uses exlSheet1 = exlFile.Sheets.Item('Sheet1'); to point to the first sheet of the Excel file while I don't know the name of each sheets of the Excel file. Sometimes it's same as the filename, sometimes it's P1,P2,etc and sometimes it's Sheet1,Sheet2,etc so I can't use the Item property. Do you know another way to read an specific sheet?
Guillaume
Guillaume 2015 年 5 月 22 日
You can pass a sheet name or a sheet number to the item property of a Worksheets collection.
Both
exlsheet = exlFile.Sheets.Item('sheetname');
and
exlsheet = exlFile.Sheets.Item(sheetnumber);
work (assuming the name or number is valid obviously).
After that, you need to acquire a range object and extract its value or text property as per Sebastian's link.

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


Me Y
Me Y 2015 年 5 月 22 日
Looks like this worked to point to specific sheet number :)
SheetNo=2; ActiveSheet=get(exlSheets, 'Item', SheetNo);
But now How do I get the data?

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by