[英]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
Slide5.BackgroundStyle:msoBackgroundStyleNotAPreset
Slide (unknown member) : Integer out of range.
幻灯片(未知成员):整数超出范围。 0 is not in the valid range of 1 to 12.
0不在1到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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.