gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:10:47 25 4
gpt4 key购买 nike

我使用 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 值.

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

关于c# - 如何从 C# 更改 PowerPoint 中 TextRange 的字体颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5247135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com