Click here to Skip to main content
15,885,366 members

C# Powerpoint - Insert slides from another file, background lost

Vikas K Solegaonkar asked:

Open original thread
Hi
For an application that I am working, I need to insert slides from one pptx into another.

I tried doing this using the following code

C#
mi_App = new Microsoft.Office.Interop.PowerPoint.Application();
mi_Pres = mi_App.Presentations.Open2007("File1.pptx", MsoTriState.msoTrue,MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);

mi_Pres.Slides.InsertFromFile("File2.pptx", 2, 1, 2);

mi_Pres.SaveAs("File3.pptx", PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoFalse);
mi_Pres.Close();


This does insert the corresponding slides from File2.pptx. But the problem is that their background is lost. The slides take up the default background of File1.pptx.
The slides in File2.pptx have the backgrounds defined for each slide. But the ones inserted into the new pptx have a uniform background that is same as the default background of File1.pptx.

I tried copying background by assigning to mi_Pres.Slides[3].Background

But that did not work, because Background is a readonly!

Can you please tell me what is the correct way of doing this? How do I insert slides from another file, along with the corresponding background?
Tags: C#

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900