是否有人知道如何使用C#更改powerpoint加载项中所选文本范围的颜色?
答案 0 :(得分:2)
或只是:
Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange.Font.Color.RGB = c.ToArgb();
其中'c'是你的颜色元素。
答案 1 :(得分:1)
好吧,如果你正在使用互操作......
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>)
答案 2 :(得分:1)
如果有人还在寻找解决方案:
我遇到了同样的问题。花了一些时间想出这个方法,
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;
}
我希望这有帮助!