【发布时间】:2010-03-02 20:34:40
【问题描述】:
有谁知道如何使用 C# 更改 powerpoint 加载项中选定文本范围的颜色?
【问题讨论】:
标签: c# text add-in selection powerpoint
有谁知道如何使用 C# 更改 powerpoint 加载项中选定文本范围的颜色?
【问题讨论】:
标签: c# text add-in selection powerpoint
或者只是:
Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange.Font.Color.RGB = c.ToArgb();
'c' 是你的颜色元素。
【讨论】:
好吧,如果您使用互操作...
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>)
【讨论】:
如果有人还在寻找解决方案:
我遇到了同样的问题。花了一些时间想通了这个办法,
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;
}
我希望这会有所帮助!
【讨论】: