簡體   English   中英

Interop.PowerPoint:如何設置另一張幻燈片的幻燈片背景?

[英]Interop.PowerPoint: How set slide background from another slide?

對不起,我的英語:)

我需要從第五張幻燈片中設置第二張幻燈片的背景色

static void Main(string[] args)
{
    var presentationPath = @"d:\myPresentation.pptx";
    var app = new PowerPoint.Application();
    var presentation = app.Presentations.Open(presentationPath, WithWindow: MsoTriState.msoFalse);
    var slide2 = presentation.Slides[2];
    var slide5 = presentation.Slides[5];

    slide2.FollowMasterBackground = MsoTriState.msoFalse;
    var backgroundStyle = slide5.BackgroundStyle;
    try
    {
        slide2.BackgroundStyle = backgroundStyle;
    }
    catch (Exception exception)
    {
        Console.WriteLine($@"Slide5.BackgroundStyle: {backgroundStyle.ToString()}");
        Console.WriteLine(exception.Message);
        Console.ReadKey();
    }
    finally
    {
        presentation.Close();
    }                      
}

但是代碼拋出異常(第二行):

Slide5.BackgroundStyle:msoBackgroundStyleNotAPreset

幻燈片(未知成員):整數超出范圍。 0不在1到12的有效范圍內。

我解決了問題

 static void Main(string[] args)
    {
        var presentationPath = @"d:\myPresentation.pptx";
        var app = new PowerPoint.Application();
        var presentation = app.Presentations.Open(presentationPath, WithWindow: MsoTriState.msoFalse);
        var slide2 = presentation.Slides[2];
        var slide5 = presentation.Slides[5];

        slide2.FollowMasterBackground = MsoTriState.msoFalse;
        slide2.Background.Fill.ForeColor.RGB = slide5.Background.Fill.ForeColor.RGB;                      
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM