MATLAB Answers

enumeration Fails with get(), set() arguments

13 views (last 30 days)
dpb on 31 May 2021
Edited: dpb on 31 May 2021
classdef XlBordersIndex < int32
xlDiagonalDown (5)
xlDiagonalUp (6)
xlEdgeLeft (7)
xlEdgeTop (8)
xlEdgeBottom (9)
xlEdgeRight (10)
xlInsideVertical (11)
xlInsideHorizontal (12)
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)
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)
called as
% draw border above totals row to show summations, payouts
ixTotal=find(matches(cBill(:,matches(cBill(1,:),'Scholarship')),'Billing Total'));
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, ...
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 Comment
dpb on 31 May 2021
Oh. There's a secondary Q? here as well -- one will note the peculiar code in the catch clause of
catch ME
fprintf('Error in function SetBorder.\nError Message:\n%s\n', ME.message)
%warning('Error in function SetBorder.\n%s\n', ME.message)
The initial use of the warning() statement on its own caused me to not discover the above error for some time when looking at the resulting spreadsheet instead of letting me know when was created -- why is no warning message shown if write
catch ME
msg=sprintf('Error in function SetBorder.\nError Message:\n%s\n', ME.message);
or the version with the formatting string inside warning() as the nag screen would have you?
Hence, just the expedient of fprintf w/o the trailing semicolon so see the message.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!