Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 此操作失败,因为在事件期间所做的一个或多个更改无效_C#_Xml_Vsto_Powerpoint - Fatal编程技术网

C# 此操作失败,因为在事件期间所做的一个或多个更改无效

C# 此操作失败,因为在事件期间所做的一个或多个更改无效,c#,xml,vsto,powerpoint,C#,Xml,Vsto,Powerpoint,我正在VS 2012中使用c#创建PowerPoint 2010加载项。 我在每个演示文稿中插入一个XML文件。此XML包含一些重要的幻灯片相关数据,在打开新演示文稿后必须读取这些数据。我以以下方式添加自定义XML Office.CustomXMLPart xmlPart; string xmlString = "<?xml version='1.0' ?>" + "<data xmlns:c='charts'>"

我正在VS 2012中使用c#创建PowerPoint 2010加载项。 我在每个演示文稿中插入一个XML文件。此XML包含一些重要的幻灯片相关数据,在打开新演示文稿后必须读取这些数据。我以以下方式添加自定义XML

Office.CustomXMLPart xmlPart;

string xmlString = "<?xml version='1.0' ?>" +
                            "<data xmlns:c='charts'>" +
                                "<c:Chart>" +
                                    "<c:ChartType>MyChartType</c:ChartType>" +
                                    "<c:ChartID>" + pShape.Id + "</c:ChartID>" +
                                "</c:Chart>" +
                            "</data>";

xmlPart = presentation.CustomXMLParts.Add(xmlString, missing);
从理论上讲,这应该行得通。但是当我运行代码时,编译器告诉我,此操作失败,因为在事件期间所做的一个或多个更改无效。在**行出现异常

更新:
使用
Pres.CustomXMLParts[1]
Pres.CustomXMLParts[2]
等运行代码时,不存在此类异常

这是一篇老帖子,但我是在谷歌搜索同一条错误消息时找到它的。 读了这篇文章后,我突然想到excel会使用1作为第一个索引,而不是我们都知道和喜欢的基于零的索引:)

因此,在您的更新中,您提到使用Pres.CustomXMLParts[1]和Pres.CustomXMLParts[2]运行代码是可行的,因为您使用的索引高于0


您的图表数据应该位于这些部分之一。

是的。我明白了。谢谢:)
void pptAPP_AfterPresentationOpen(PowerPoint.Presentation Pres)
{
    foreach (PowerPoint.Shape shapeItem in Pres.Windows[1].Selection.SlideRange.Shapes)
    {
        if (shapeItem.HasChart == Office.MsoTriState.msoTrue)
        {
            **customXMLPart = Pres.CustomXMLParts[0]**; //My XML is at this index
            customXMLNode = customXMLPart.SelectSingleNode("//Chart/ChartType");
        }
    }
}