如何从 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
的字体颜色?
I created a PowerPoint presentation using 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();
Now, how can I change the font color for objTextRng
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下代码将字体颜色设置为红色:
如果要指定不同的颜色,可以使用其他颜色之一 预定义颜色,或使用指定您自己的 RGB 值
Color.FromArgb
方法。无论哪种方式,请确保调用
ToArgb
方法 您使用的Color
对象上。RGB
属性要求指定 RGB 颜色值。The following code will set the font color to red:
If you want to specify a different color, you can use one of the other pre-defined colors, or specify your own RGB values using the
Color.FromArgb
method.Either way, make sure that you call the
ToArgb
method on theColor
object that you use. TheRGB
property requires that an RGB color value be specified.将此用于 PPTX 2007
例如,
Use this for PPTX 2007
for example
我认为此 MSDN 页面对此进行了解释。
编辑:
但这仅解释了如何在 VBScript 中执行此操作。您可以看到
TextRange
对象有一个属性Font
。这将返回 此处描述的Font
对象资源显示您可以访问 RGB 属性。你可以像科迪告诉你的那样设置它。如果您需要更多信息,请参阅我刚刚指出的 MSDN 部分。I think this MSDN page explain it.
EDIT:
But this only explain how to do it in VBScript. You can see that the
TextRange
object have a propertyFont
. This returns theFont
object describe here These resources show you that you have access to a RGB property. You can set it like Cody told you. If you need further info, refer to the MSDN section I just point you.objTextRng.Font.Color.RGB = System.Drawing.ColorTranslator.ToOl(System.Drawing.Color.Blue);
objTextRng.Font.Color.RGB = System.Drawing.ColorTranslator.ToOl(System.Drawing.Color.Blue);