Is it possible to copy a figure into excel using a WebApp server?

1 回表示 (過去 30 日間)
Jens Peter Hansen
Jens Peter Hansen 2022 年 12 月 20 日
回答済み: Vijay 2022 年 12 月 28 日
I can successfully copy a figure into an exel sheet using below function:
function xlswritefig(hFig,filename,sheetname,range)
copygraphics(hFig)
% Connect to Ecel
Excel = actxserver('Excel.Application');
% Open file and active worksheet
op = invoke(Excel.Workbooks, 'open', filename);
Sheets = Excel.ActiveWorkBook.Sheets;
n_sheets = Sheets.Count;
Sheets.Add([], Sheets.Item(n_sheets));
Sheets.Item(n_sheets+1).Name = sheetname;
target_sheet = get(Sheets, 'Item', sheetname);
invoke(target_sheet, 'Activate');
Activesheet = Excel.Activesheet;
% Paste to specified cell
Paste(Activesheet,get(Activesheet,'Range',range))
% Save and quit
invoke(op, 'Save');
invoke(Excel, 'Quit');
delete(Excel)
close(filename)
However, is it also possible to run this function (or actxserver) from a Web App if I install Excel on my virtuel machine (MS Azure)?

回答 (1 件)

Vijay
Vijay 2022 年 12 月 28 日
Yes, you can create a create a COM server on your AZURE machine by supplying IP address of the remote machine from your MATLAB program.
Example
c = actxserver(progid,'machine',machineName)
%‘machinename' can be IP address of a remote computer or a name that can be resolved on your network.
For more information, please go through links below.
  1. Create COM server - MATLAB actxserver - MathWorks India
  2. How to run excel macro via MATLAB on another pc - MATLAB Answers - MATLAB Central (mathworks.com)
Hope that helps!

カテゴリ

Help Center および File ExchangeUse COM Objects in MATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by