微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我使用C#创建了一个PowerPoint演示文稿:
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的字体颜色?

解决方法

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

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

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

原文地址:https://www.jb51.cc/csharp/244431.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐