c# - how to cast COM object type to Excel.Checkbox type -
c# - how to cast COM object type to Excel.Checkbox type -
i adding checkbox excel , have issue casting com object of type 'system.__comobject' interface type 'microsoft.office.interop.excel.checkbox', help appreciated! working on web app using visual studio 2008 , office 2007. error happens @ line :- chkbx = (microsoft.office.interop.excel.checkbox)obj;
microsoft.office.interop.excel.oleobjects objs = (microsoft.office.interop.excel.oleobjects)mwsheet1.oleobjects(system.reflection.missing.value); microsoft.office.interop.excel.oleobject obj = objs.add("forms.checkbox.1", system.reflection.missing.value, system.reflection.missing.value, false, false, system.reflection.missing.value, system.reflection.missing.value, 234, 234, 108, 21); microsoft.office.interop.excel.checkbox chkbx; chkbx = (microsoft.office.interop.excel.checkbox)obj; chkbx.value = true; chkbx.caption = "xyz";
it looks me can't cast because doesn't implement interface. can check if system.__comobject
supports interface without casting, , consequently throwing exception, using as
operator described here: how to: check type of com object (system.__comobject) visual c# .net.
i wonder if using wrong method add together checkbox worksheet. isn't more mutual method go through microsoft.office.tools.excel.controlcollection
described here: adding controls office documents @ run time.
if used controlcollection
, think code end looking this:
private void addcheckbox() { worksheet vstoworksheet = globals.factory.getvstoobject( this.application.activeworkbook.worksheets[1]); system.windows.forms.checkbox checkbox = new system.windows.forms.checkbox(); checkbox.checked = true; checkbox.text = "xyz" vstoworksheet.controls.addcontrol(234, 234, 108, 21, "checkbox1"); }
c# office-interop excel-interop comobject
Comments
Post a Comment