簡體   English   中英

使用 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#

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM