enumeration Fails with get(), set() arguments
Mostrar comentarios más antiguos
classdef XlBordersIndex < int32
enumeration
xlDiagonalDown (5)
xlDiagonalUp (6)
xlEdgeLeft (7)
xlEdgeTop (8)
xlEdgeBottom (9)
xlEdgeRight (10)
xlInsideVertical (11)
xlInsideHorizontal (12)
end
end
Sample consumer routine
function SetBorder(sheetReference, ranges, border, weight, style)
% Usage
% SetBorder(WorksheetObject, ranges, borderIndex, borderWeight, lineStyle)
%
% sets the worksheet cell ranges specific border to the weight and style specified
% ranges is a char string, cellstr, or array of cellstr or string ranges
% borderIndex, borderWeight and lineStyle are scalar values
if ischar(ranges), ranges=cellstr(ranges); end
for i=1:numel(ranges)
try
theCell=sheetReference.Range(ranges{i});
borders=get(theCell, 'Borders');
thisBorder=get(borders, 'Item', border);
set(thisBorder,'LineStyle', style,'Weight',weight);
catch ME
fprintf('Error in function SetBorder.\nError Message:\n%s\n', ME.message)
%warning('Error in function SetBorder.\n%s\n', ME.message)
end
end
end
called as
excel=actxserver('Excel.Application');
wbk=excel.Workbooks.Open(outputFile);
wksht=Excel_utils.sheetReference(excel,outputSheet);
% draw border above totals row to show summations, payouts
ixTotal=find(matches(cBill(:,matches(cBill(1,:),'Scholarship')),'Billing Total'));
ixCols=find(matches(cBill(1,:),{'Student','Scholarship','Paid'}));
addr=[cellstr(join(string([arrayfun(@(r) xlsAddr(r,ixCols(1)),ixTotal,'UniformOutput',false), ...
arrayfun(@(r) xlsAddr(r,ixCols(2)),ixTotal,'UniformOutput',false)]),':')); ...
arrayfun(@(r) xlsAddr(r,ixCols(3)),ixTotal,'UniformOutput',false)];
Excel_utils.SetBorder(wksht,addr,XlBordersIndex.xlEdgeTop,XlBorderWeight.xlMedium, ...
XlLineStyle.xlContinuous);
results in
errorMessage =
'Error in function SetBorder.
Error Message:
Error: Object returned error code: 0x800A03EC'
If one inserts
if isenum(border), border=int32(border); end
if isenum(weight), weight=int32(weight); end
before the loop, the function runs without error and successfully changes the desired cell range borders to style and type requested.
This seems to pretty-much negate the whole point of an enumeration -- is there any cleaner workaround?
Looks to me like a bug although I suppose since is external interface they can claim "unsupported" usage.
1 comentario
Respuestas (1)
dpb
el 31 de Dic. de 2021
Categorías
Más información sobre Use COM Objects in MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!