How can I speed-up the ''write, read and save'' of an excel file from matlab?

I want to write on an excel file, run a VBA macro, save the excel file and finally read from the file, several times. I used below code, but it is very time-consuming. The question is how can I speed up the above commands? xlswrite usually takes: 11 sec., open: 1 sec., Run: 10 sec., save: 20 sec. and xlsread: 2 sec. It should be mentioned that I don't need to save the file but if I don't save, the command xlsread doesn't read the newly-changed cells values!
xlswrite ('C:\test.xls',M ,'sheet_name_1','T10:T16');
excelObject = actxserver('Excel.Application');
excelObject.Workbooks.Open('C:\test.xls');
excelObject.Run('VBAMacro');
excelObject.WorkBooks.Item('test.xls').Save;
excelObject.WorkBooks.Item('test.xls').Close;
CC = xlsread ('C:\test.xls','sheet_name_2','E:E');

 채택된 답변

ES
ES 2013년 9월 20일

0 개 추천

use ActiveX to write and read instead of xlswrite and xlsread respectively.

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 9월 20일
편집: Image Analyst 2013년 9월 23일

1 개 추천

I don't understand what you're doing. You either use xlsread() and xlswrite(), OR use ActiveX, not both. After you did the xlswrite there was no need to write it again using ActiveX. For speed when you need to open, transfer data, and save multiple times you should be using ActiveX, not xlsread() and xlswrite(). See attached demo.

댓글 수: 1

Cant Agree more. Use of (xlsread, xlswrite) and (ActiveX) methods should be exclusive of each other. I would recommend use of (xlsread, xlswrite) in cases were there is little data to read and write. For large data, formatting and so on, ActiveX is ideal. Using both approaches together is not recommended.

댓글을 달려면 로그인하십시오.

카테고리

질문:

2013년 9월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by