0

I am very new to VSTO addon development and C# also. I'm having the below code.

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);
    }
 }
}

Once click the button_1 I want to add some custom xml into presentation. And I don't know how to run this code and how to get the Powerpoint and Office class parts.

I taken those code from ms-office docs. Can anyone help me with this? How can I insert the custom XML into the powerpoint file.

4

1 回答 1

1

Supposing you are able to click that button, your code won't work anyway, as it is with many MS examples. You have to pass the presentation into AddCustomXmlPartToPresentation.

This can be done, by obtaining the ActiveDocument / ActivePresentation from the application instance hosting your addin.

A nice tutorial on putting it together is this one: HowTo: Create a Powerpoint AddIn in C#

于 2021-02-11T07:00:44.773 回答