我正在創建一個PowerPoint AddIn,它應該從外部文件讀取信息並將該信息集成到包含形狀的當前幻燈片中,大多數爲文本框形狀和連接文本框的連接器形狀。每個連接器位於一個組中,包含連接器形狀和文本框,用作連接器的標籤。下圖描述了這種情況。當訪問嵌套連接器形狀的BeginConnectedShape和EndConnectedShape時發生COMException(災難性故障)
我的手頭任務涉及如上所描述的,即BeginConnectedShape和EndConnectedShape訪問含有組內連接器的形狀的性質。下面是一些代碼這是爲了做到這一點:
Shape groupShape = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange[1];
//check if groupshape actually is a group
if (groupShape.Type == Microsoft.Office.Core.MsoShapeType.msoGroup) {
//iterate over all elements within groupShape
foreach (Shape childShape in groupShape.GroupItems)
{
if (childShape.Connector == Microsoft.Office.Core.MsoTriState.msoTrue)
{
//if the shape is a connector, retrieve source and target of the connector
Shape source = childShape.ConnectorFormat.BeginConnectedShape;
Shape target = childShape.ConnectorFormat.EndConnectedShape;
//Do something with source and target.
}
}
}
同時具有含正確連接的連接器的形狀的一組運行這個代碼(即,兩端連接到錨的其他形狀的點)中選擇產生以下例外。
System.Runtime.InteropServices.COMException wurde nicht von Benutzercode behandelt.
HResult=-2147418113
Message=Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
Source=HandoverAddin
ErrorCode=-2147418113
StackTrace:
at Microsoft.Office.Interop.PowerPoint.ConnectorFormat.get_BeginConnectedShape()
at MyAddin.Ribbon.button1_Click(Object sender, RibbonControlEventArgs e) in Ribbon.cs:line 56
at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ControlActionRaise(IRibbonControl control)
at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ButtonClickCallback(RibbonComponentImpl component, Object[] args)
at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.Invoke(RibbonComponentCallback callback, Object[] args)
at Microsoft.Office.Tools.Ribbon.RibbonMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.System.Reflection.IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
InnerException:
執行childShape.ConnectorFormat.BeginConnectedShape
時會引發此異常。 childShape.ConnectorFormat.EndConnectedShape
也引發了這個例外。 ConnectorFormat
內的其他操作正常工作(即BeginDisconnect
成功斷開連接器的啓動)。
shape.ConnectorFormat.BeginConnectedShape
工作正常,如果連接器不包含在一個組中。在我的情況下,連接器和相關標籤必須組合在一起。
我還觀察到,在連接器上訪問BeginConnectedShape
時,如果連接器啓動斷開,將引發UnauthorizedAccessException
,而不管該連接器是否包含在組中。這似乎是預期的行爲。
上面列出的異常似乎是某種內部異常,在正常情況下不應該引起異常。因此,我檢查了任何可用的更新,但沒有發現Office 2010和Visual Studio 2010 Professional。
有關此問題的任何幫助,可能的解決方法或解決方法都非常感謝。
編輯:使用VBA實現相同的功能也會導致代碼爲8000FFFF(與上面相同)的錯誤。
該錯誤消息僅評估錯誤報告的質量。您應該檢查BeginConnected和EndConnected屬性以確保它們實際連接。 – 2014-09-29 15:11:33
BeginConnected和EndConnected在本例中均返回true。 – 2014-09-29 15:33:34
我的測試顯示這是PowerPoint中的一個真正的錯誤。 – dotNET 2017-06-29 13:30:43