2010-03-02 52 views

回答

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>) 
1

或者只是:

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

,其中 'C' 是你的顏色元素。

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; 
} 

我希望這可以幫助!