我创建使用C#PowerPoint演示文稿:如何更改C#中PowerPoint中TextRange的字体颜色?
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();
现在,我怎么能更改objTextRng
字体颜色?
实际上,尽管该属性的PowerPoint名称*为BGR格式的解释颜色,但它将其设置为蓝色。 将字体颜色设置为红色的最简单(也是最不优雅的)方法是指定十六进制颜色(反转R和B字节):'range.Font.Color.RGB = 0x0000FF; - 同样,蓝色将是'range.Font.Color.RGB = 0xFF0000;'等 (*:它实际上是RGB格式,但它是大端,意味着这些字节从右到左存储,而不是从左到右)。 – BrainSlugs83