Run Actxsrver from the deployed DLL for Excel
2 views (last 30 days)
Show older comments
I created an excel based report template which will be used to allocate calculated data from MATLAB. In the code, I save the template as different names and allocate data on each sheet then save and do the same around 20 times. It works fine in MATLAB, and was working fine for a while and certainly stop working (no error but keep running and no response in Excel). Any suggestions for me to consider?
try
xlApp = actxGetRunningServer('Excel.Application');
xlApp.visible = 0;
xlApp.DisplayAlerts = false;
catch
xlApp = actxserver('Excel.Application');
xlApp.visible = 0;
xlApp.DisplayAlerts = false;
end
for j = 1:m
if ~exist(filenames(j), "file") % source file reference
eXL1 = xlApp.Workbooks.Open(sourceFile);
SaveAs(eXL1, filenames(j)); % create multiple files of the sourceFile and dump data
eXL1.Close;
end
eXL2 = xlApp.Workbooks.Open(filenames(j)); % target file reference
for k = 1:numel(tRpt) % each target workbook has several sheets in it
wSh1 = xlApp.ActiveWorkbook.Sheets;
tSh1 = wSh1.get('Item',tRpt(k));
tSh1.Activate;
tValue1 = IvOut.(IItems{k});
xlCol1 = convert2XLColumn([3; size(tValue1,2)+2]);
if tRpt_Rows(k) == 1
xlRng1 = [xlCol1(1), num2str(11), ':', xlCol1(2), num2str(11 + tMns(1,j))];
tRng1 = get(xlApp.ActiveSheet, 'Range', xlRng1);
tValue1 = squeezetValue1(:,:,j));
tValue1 = tValue1(1:(tMns(1,j) + 1),:);
tRng1.Value = tValue1;
else
xlRng1 = [xlCol1(1), num2str(11), ':', xlCol1(2), num2str(11 + tYrs(j))];
tRng1 = get(xlApp.ActiveSheet, 'Range', xlRng1);
tValue1 = squeeze(tValue1(:,:,j));
dumpValue1 = dumpValue1(1:(tYrs(j)+1),:);
tRng1.Value = tValue1;
end
% Report header information allocation
profileRange = get(xlApp.ActiveSheet, 'Range', 'A1');
profileRange.get('Offset', 2, 3).Value = calcData{j,1};
profileRange.get('Offset', 4, 3).Value = calcData{j,32};
profileRange.get('Offset', 5, 3).Value = calcData{j,66};
profileRange.get('Offset', 5, 4).Value = calcData{j,65};
...
end
eXL2.Save;
eXL2.Close;
end
clear eXL1;
clear eXL2;
0 Comments
Answers (0)
See Also
Categories
Find more on Use COM Objects in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!