在演示文稿幻灯片中应用配色方案不会使用正确的文本重新呈现所有幻灯片

问题描述 投票:0回答:0

我想使用

ThemeColorScheme.Load(colorSchemeFile)
在 Office VSTO 加载项中应用配色方案,但并非所有幻灯片都显示应用的配色方案。在幻灯片缩略图窗格中,所有幻灯片都显示为应用了正确的配色方案,并且所选幻灯片(执行
ThemeColorScheme.Load
操作时)也将应用正确的配色方案,但如果经过多次测试,其余幻灯片的行为会不一致演示文稿中有不同的幻灯片,但即使有两张幻灯片,也总是无法正确呈现未选择的幻灯片。

我已经创建了一个 repo 可以被克隆来重现这个问题,但主要的事情是:

  1. 在 Visual Studio 中创建一个 power point VSTO 插件项目
  2. 创建一个带有按钮的用户控件,单击该按钮将更改活动演示幻灯片的配色方案(也尝试使用
    presentation.Designs[i].SlideMaster.Theme.ThemeColorScheme.Load
    应用颜色主题,但产生了相同的结果
    using System;
    using System.IO;
    using System.Linq;
    using System.Windows.Forms;
    
    namespace UserControls
    {
        public partial class UserControl1 : UserControl
        {
            private readonly string[] availableColorThemes = { "Test Dark", "Test Light" };
            
            private string currentTheme;
            private Microsoft.Office.Interop.PowerPoint.Application application;
    
            public UserControl1(Microsoft.Office.Interop.PowerPoint.Application application)
            {
                InitializeComponent();
                this.application = application;
                currentTheme = "Test Light";
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                var presentation = application.ActivePresentation;
                currentTheme = availableColorThemes.Where(c => c != currentTheme).First();
                string fileName = Path.Combine(Path.GetTempPath(), "PowerPointAddIn", $"{currentTheme}.xml");
    
                for (var i = 1; i <= presentation.Slides.Count; i++)
                {
                    presentation.Slides[i].ThemeColorScheme.Load(fileName);
                    presentation.Designs[i].SlideMaster.Theme.ThemeColorScheme.Load(fileName);
                }
            }
        }
    }

在我链接的复制存储库中,代码正在从

%localappdata%\Temp\PowerPointAddIn
读取配色方案文件,我使用的两种配色方案(Test Dark,Test Light)位于存储库根目录以及测试演示(Test Presentation)中。

  1. 将之前创建的用户控件类型添加到任务窗格
using UserControls;

namespace PowerPointAddIn2
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            UserControl1 userControl1 = new UserControl1(Application);
            Microsoft.Office.Tools.CustomTaskPane myCustomTaskPaneContainer =
                CustomTaskPanes.Add(userControl1, "My Custom Task Pane");
            myCustomTaskPaneContainer.Visible = true;
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}

  1. 使用至少包含两张幻灯片的演示文稿调试加载项

这是一个已知问题吗?如果是这样,是否有另一种正确应用配色方案文件的方法?

感谢任何帮助

c# powerpoint ms-office office-interop office-addins
© www.soinside.com 2019 - 2024. All rights reserved.