简体   繁体   中英

Interop.PowerPoint: How set slide background from another slide?

Sorry my English :)

I need to set the background color second slide from fifth 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();
    }                      
}

but code throw exception (second line):

Slide5.BackgroundStyle: msoBackgroundStyleNotAPreset

Slide (unknown member) : Integer out of range. 0 is not in the valid range of 1 to 12.

I solved problem

 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;                      
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM