【问题标题】:Text Color in PowerPoint Add-inPowerPoint 加载项中的文本颜色
【发布时间】:2010-03-02 20:34:40
【问题描述】:

有谁知道如何使用 C# 更改 powerpoint 加载项中选定文本范围的颜色?

【问题讨论】:

    标签: c# text add-in selection powerpoint


    【解决方案1】:

    或者只是:

    Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange.Font.Color.RGB = c.ToArgb();
    

    'c' 是你的颜色元素。

    【讨论】:

      【解决方案2】:

      好吧,如果您使用互操作...

      var app = new ApplicationClass(); app.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; var myPresentation = app.Presentations.Open("c:\\test.pptx", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue); var slide1 = myPresentation.Slides[1]; var range = slide1.Shapes[1].TextFrame.TextRange; range.Font.Color.RGB = -654262273;

      别忘了

      System.Runtime.InteropServices.Marshal.ReleaseComObject(<your com objects here>)
      

      【讨论】:

        【解决方案3】:

        如果有人还在寻找解决方案:

        我遇到了同样的问题。花了一些时间想通了这个办法,

        var paragraph1 = oTxtRange.Paragraphs(1);
        paragraph1.Text = "Test ";
        paragraph1.Font.Color.RGB = BGR(Color.Black);
        
        var paragraph2 = oTxtRange.Paragraphs(2);
        paragraph2.Text = "Application ";
        paragraph2.Font.Color.RGB = BGR(Color.Green);
        
        private int BGR(Color color)
        {
        
         // PowerPoint's color codes seem to be reversed (i.e., BGR) not RGB, so we have  to  produce the color in reverse
        
         int iColor = (color.A << 24) | (color.B << 16) | (color.G << 8) | color.R;
         return iColor;
        }
        

        我希望这会有所帮助!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-07-31
          • 2021-01-21
          • 2014-11-30
          • 1970-01-01
          相关资源
          最近更新 更多