使用 C# VSTO 插件添加自定义 XML

Add custom XML using C# VSTO addon

我对 VSTO 插件开发和 C# 都很陌生。我有以下代码。

using Microsoft.Office.Tools.Ribbon;
using System;
using System.Diagnostics;

namespace POC_Powerpoint
{
  public partial class Ribbon1
  {
    private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
    {

    }

    private void button1_Click(object sender, RibbonControlEventArgs e)
    {
        Debug.WriteLine("POC Running");
        AddCustomXmlPartToPresentation()
    }

    private void AddCustomXmlPartToPresentation(PowerPoint.Presentation presentation)
    {
        string xmlString =
            "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
            "<employees xmlns=\"http://schemas.microsoft.com/vsto/samples\">" +
                "<employee>" +
                    "<name>Karina Leal</name>" +
                    "<hireDate>1999-04-01</hireDate>" +
                    "<title>Manager</title>" +
                "</employee>" +
            "</employees>";

        Office.CustomXMLPart employeeXMLPart =
            presentation.CustomXMLParts.Add(xmlString, missing);
    }
 }
}

单击 button_1 后,我想在演示文稿中添加一些自定义 xml。而且我不知道如何 运行 此代码以及如何获取 Powerpoint 和 Office class 部分。

我从 ms-office 文档中获取了这些代码。谁能帮我这个?如何将自定义 XML 插入到 powerpoint 文件中。

假设您能够单击该按钮,您的代码将无法正常工作,就像许多 MS 示例一样。您必须将演示文稿传递到 AddCustomXmlPartToPresentation.

这可以通过从托管插件的应用程序实例中获取 ActiveDocument / ActivePresentation 来完成。

关于将它组合在一起的一个很好的教程是: HowTo: Create a Powerpoint AddIn in C#