2010-03-02 9 views

Répondre

1

Eh bien, si vous utilisez Interop ...

 

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; 
 

Et ne pas oublier de

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

ou tout simplement:

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

où 'c' est votre élément de couleur.

1

Si quelqu'un cherche encore une solution:

J'ai eu le même problème. Après avoir passé du temps à comprendre de cette façon,

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

J'espère que cela aide!