PowerPoint Interop 添加图片的顺序很重要吗?

PowerPoint Interop order of add picture matters?

我必须自动创建 powerpoint 演示文稿。

导致问题的母版幻灯片有 2 个图片框和一些文本字段。

我通过获取带有 id 的 shape(准备好的图片框)并在位置 shape.Leftshape.Right.

添加图片来添加图片

现在变得奇怪了... 当我这样做时,图片位置正确。

var shape = slide.Shapes[ContentFields.Print.WithImage.Bild];
slide.Shapes.AddPicture(artikel.BildPath, MsoTriState.msoFalse, MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height);

shape = slide.Shapes[ContentFields.Print.WithImage.Kanal];
slide.Shapes.AddPicture(artikel.KanalIconPath, MsoTriState.msoFalse, MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height);

但是我先加上Kanal的时候,图片搞错了(Kanal在Bild的位置,Bild在Kanal的位置)

var shape = slide.Shapes[ContentFields.Print.WithImage.Kanal];
slide.Shapes.AddPicture(artikel.KanalIconPath, MsoTriState.msoFalse, MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height);

shape = slide.Shapes[ContentFields.Print.WithImage.Bild];
slide.Shapes.AddPicture(artikel.BildPath, MsoTriState.msoFalse, MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height);

这是为什么?
我用 Id 得到了正确的形状,为什么它们会混淆? :-S

提前致谢

至少在某些版本的 PPT 中,如果您将图片添加到包含空图片或内容占位符的幻灯片,图片将添加到占位符,而不是作为新形状放置。

如果幻灯片上有两个占位符,添加的第一张图片将位于第一个占位符中,第二张将位于第二个占位符中,因此添加图片的顺序很重要。

在没有占位符的幻灯片上尝试相同的代码;如果您需要形状来确定图片位置,请替换为矩形。

或者如果您需要保留占位符,请在添加图片之前临时将 "dummy" 文本添加到任何空的内容占位符,然后再删除虚拟文本。