Excel com server with simulink

I have written some excel COM server code that runs successfully on MATLAB. I am now implementing it in Simulink, virtually trying to use simulink matlab function blocks to write/read data from specific spreadsheets. But when I run the same code on Simulink, I get a
Undefined function or variable 'exl'.
exl is of course the handle for the COM server. The exact same code works fine running from matlab. Just in case, I initially create the com server outside simulink, so the handle and the server are open once the simulink matlab function block runs.
The entire code is the following:
%% Activate specific sheet (Runs on MATLAB first)
exlSheets = exl.ActiveWorkbook.Sheets;
exlBiotreater = exlSheets.get('Item','Biotreater');
exlBiotreater.Activate
%% Create influent from signal (Rest of code in Simulink MATLAB function block)
bio1feed = influent
%% Write to specified range, calculate and read back.
exlActivesheetRange = get(exl.Activesheet,'Range','C5:C26');
exlActivesheetRange.Value = bio1feed;
if ~isempty(recycle)
exlActivesheetRange = get(exl.Activesheet,'Range','D5:D26');
exlActivesheetRange.Value = recycle;
end
exlBiotreater.Calculate
exlBiotreaterEFfluent = get(exl.Activesheet,'Range','J5:J26');
effluent = exlBiotreaterEFfluent.Value;
effluent = reshape([effluent{:}],size(effluent));
exlBiotreaterSludge = get(exl.Activesheet,'Range','K5:K26');
sludge = exlBiotreaterSludge.Value;
sludge = reshape([sludge{:}],size(sludge));

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息

产品

版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by