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

12 views (last 30 days)
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');

Accepted Answer

ES
ES on 20 Sep 2013
use ActiveX to write and read instead of xlswrite and xlsread respectively.

More Answers (1)

Image Analyst
Image Analyst on 20 Sep 2013
Edited: Image Analyst on 23 Sep 2013
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 Comment
ES
ES on 23 Sep 2013
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!