简体   繁体   English

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

[英]Add custom XML using C# VSTO addon

I am very new to VSTO addon development and C# also.我对 VSTO 插件开发和 C# 也很陌生。 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.单击 button_1 后,我想将一些自定义 xml 添加到演示文稿中。 And I don't know how to run this code and how to get the Powerpoint and Office class parts.而且我不知道如何运行此代码以及如何获取 Powerpoint 和 Office class 部件。

I taken those code from ms-office docs.我从ms-office文档中获取了这些代码。 Can anyone help me with this?谁能帮我这个? How can I insert the custom XML into the powerpoint file.如何将自定义 XML 插入到 powerpoint 文件中。

Supposing you are able to click that button, your code won't work anyway, as it is with many MS examples.假设您能够单击该按钮,那么您的代码将无法正常工作,就像许多 MS 示例一样。 You have to pass the presentation into AddCustomXmlPartToPresentation .您必须将演示文稿传递给AddCustomXmlPartToPresentation

This can be done, by obtaining the ActiveDocument / ActivePresentation from the application instance hosting your addin.这可以通过从托管您的插件的应用程序实例中获取 ActiveDocument / ActivePresentation 来完成。

A nice tutorial on putting it together is this one: HowTo: Create a Powerpoint AddIn in C#将它放在一起的一个很好的教程是: HowTo: Create a Powerpoint AddIn in C#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在C#中使用VSTO将XML转换为EXCEL - Convert XML to EXCEL using VSTO in C# 如何使用C#VSTO自动加载Microsoft Word中的自定义加载项? - how to auto load unload a custom add-in in Microsoft word using C# VSTO? 如何使用C#VSTO在PowerPoint中自动卸载自定义加载项? - how to auto-unload a custom add-in in PowerPoint using C# VSTO? 使用 C# VSTO 插件获取选定的图表 object 或文本框架或表格? - Get selected chart object or text frame or table using C# VSTO addon? 如果我忘记向电子邮件添加附件,则 VSTO C# 自定义表单 - VSTO C# custom form if i forget add attachment to email C#vsto添加工作表 - C# vsto add worksheet C# VSTO - 缓慢加载 Outlook 加载项(由 Ribbon.xml 引起?) - C# VSTO - Slowly loading Outlook Add-in (caused by Ribbon.xml?) C#VSTO附加任务序列 - C# VSTO add-in task sequence 如何在C#Word VSTO加载项中使用功能区XML自定义快速访问工具栏(QAT),同时仍允许用户随后修改QAT? - How to Customize Quick Access Toolbar (QAT) Using Ribbon XML in C# Word VSTO Add-In WHILE STILL Allowing User to Subsequently Modify the QAT? 如果使用C#和XML选择了下拉菜单VSTO Outlook,则执行操作 - Perform action if drop down item is selected VSTO Outlook using C# and XML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM