creé una presentación de PowerPoint usando C#:¿Cómo puedo cambiar el color de fuente de un TextRange en PowerPoint desde C#?
PowerPoint.Application powerpointApplication;
PowerPoint.Presentation pptPresentation;
PowerPoint.Slide Slide;
// Create an instance of PowerPoint.
powerpointApplication = new PowerPoint.ApplicationClass();
// Create a PowerPoint presentation.
pptPresentation = powerpointApplication.Presentations.Add(
Microsoft.Office.Core.MsoTriState.msoTrue);
// Create empty slide
Slide = pptPresentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);
TextRange objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
objTextRng.Text = "Remote sensing calendar 1";
objTextRng.Font.Name = "Comic Sans MS";
objTextRng.Font.Size = 48;
// TODO: change color
// objTextRng.Font.Color
// Save presentation
pptPresentation.SaveAs(BasePath + "result\\2_example.ppt",
PowerPoint.PpSaveAsFileType.ppSaveAsDefault,
MsoTriState.msoTrue // TODO: что за параметр???
);
pptPresentation.Close();
Ahora, ¿cómo se puede cambiar el color de fuente para objTextRng
?
En realidad, eso lo configura en azul, a pesar del nombre * de esa propiedad. Los colores de PowerPoint interpretan en formato BGR. La manera más fácil (y menos elegante) de establecer el color de fuente en rojo es simplemente especificar el color en hexadecimal (invirtiendo los bytes R y B): 'range.Font.Color.RGB = 0x0000FF;' - del mismo modo, azul sería 'range.Font.Color.RGB = 0xFF0000;', etc. (*: en realidad es formato RGB, pero es big endian, lo que significa que los bytes se almacenan de derecha a izquierda en lugar de izquierda a derecha.) – BrainSlugs83