在 Excel 中选择某些内容时,Excel::Application::Selection 属性包含所选对象。例如,如果我选择某个单元格,我可以使用以下命令轻松地将它们转换为 Excel::Range:
Excel.Range cells = Excel.Application.Selection as Excel.Range
其中 Excel = Microsoft.Office.Interop.Excel
Now when some picture is selected, I have to cast it to Excel::Picture, then Excel::Shape in case of some shapes but it seems there are different interfaces for each shape like Oval, Rectangle etc. I need to delete whatever thing在工作表上被选中。如果是单元格,则内容将被清除,图片、形状或 OLEObject 将被删除,但问题是我不想检查每个界面:
if (null != ThisApplication.Selection as Excel.Shape)
(ThisApplication.Selection as Excel.Shape).Delete();
else if (null != ThisApplication.Selection as Excel.Picture)
(ThisApplication.Selection as Excel.Picture).Delete();
else if (null != ThisApplication.Selection as Excel.OLEObject)
(ThisApplication.Selection as Excel.OLEObject).Delete();
我希望如果只有一个基本接口,我可以将所有形状/图片投射到其中并在它们上调用 delete。
是否可以获得:
- Application::Selection 中的真实类型 - 它显示 System::COMObject 但没有关于真实类型的信息
- 以某种方式识别选择包含图片/形状等并在基础类型上调用“删除”方法