如何从C#更改PowerPoint中TextRange的字体颜色?

前端之家收集整理的这篇文章主要介绍了如何从C#更改PowerPoint中TextRange的字体颜色?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用C#创建了一个PowerPoint演示文稿:
  1. PowerPoint.Application powerpointApplication;
  2. PowerPoint.Presentation pptPresentation;
  3. PowerPoint.Slide Slide;
  4.  
  5. // Create an instance of PowerPoint.
  6. powerpointApplication = new PowerPoint.ApplicationClass();
  7.  
  8. // Create a PowerPoint presentation.
  9. pptPresentation = powerpointApplication.Presentations.Add(
  10. Microsoft.Office.Core.MsoTriState.msoTrue);
  11.  
  12.  
  13. // Create empty slide
  14. Slide = pptPresentation.Slides.Add(1,PowerPoint.PpSlideLayout.ppLayoutBlank);
  15.  
  16. TextRange objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
  17. objTextRng.Text = "Remote sensing calendar 1";
  18. objTextRng.Font.Name = "Comic Sans MS";
  19. objTextRng.Font.Size = 48;
  20. // TODO: change color
  21. // objTextRng.Font.Color
  22.  
  23.  
  24.  
  25. // Save presentation
  26. pptPresentation.SaveAs( BasePath + "result\\2_example.ppt",PowerPoint.PpSaveAsFileType.ppSaveAsDefault,MsoTriState.msoTrue // TODO: что за параметр???
  27. );
  28. pptPresentation.Close();

现在,我该如何更改objTextRng的字体颜色?

解决方法

以下代码将字体颜色设置为红色:
  1. objTextRng.Font.Color.RGB = Color.Red.ToArgb();

如果要指定其他颜色,可以使用其他pre-defined colors之一,或使用Color.FromArgb method指定自己的RGB值.

无论哪种方式,请确保在您使用的Color对象上调用ToArgb method. RGB属性要求指定RGB颜色值.

猜你在找的C#相关文章