首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从C#更改PowerPoint中TextRange的字体颜色?

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

Stack Overflow用户
提问于 2011-03-09 22:23:32
回答 4查看 12.3K关注 0票数 7

我使用C#创建了一个PowerPoint演示文稿:

代码语言:javascript
复制
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的字体颜色

EN

回答 4

Stack Overflow用户

发布于 2011-03-09 22:27:41

下面的代码将字体颜色设置为红色:

代码语言:javascript
复制
objTextRng.Font.Color.RGB = Color.Red.ToArgb();

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

无论采用哪种方法,都要确保在所使用的Color对象上调用ToArgb methodRGB属性要求指定RGB颜色值。

票数 7
EN

Stack Overflow用户

发布于 2012-01-04 06:54:29

将此用于PPTX 2007

代码语言:javascript
复制
    private int BGR(Color color)
    {
        // PowerPoint's color codes seem to be reversed (i.e., BGR) not RGB
        //      0x0000FF    produces RED not BLUE
        //      0xFF0000    produces BLUE not RED
        // so we have to produce the color "in reverse"

        int iColor = color.R + 0xFF * color.G + 0xFFFF * color.B;

        return iColor;
    }

例如

代码语言:javascript
复制
    shape.TextFrame.TextRange.Font.Color.RGB = BGR(Color.Red);  
票数 5
EN

Stack Overflow用户

发布于 2011-03-09 22:33:50

我想this MSDN page会解释的。

EDIT:,但这只解释了如何在VBScript中进行编辑。您可以看到TextRange对象有一个属性Font。这将返回Font对象describe here这些资源显示您有权访问RGB属性。你可以按照科迪告诉你的那样设置。如果您需要更多信息,请参阅MSDN部分,我只是给您指出。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5247135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档