Reputation: 333
I just need to create a .pptx
file with 1 dummy slide using C# and save it to the current directory. Can anyone tell me how to do this?
So far, I have this code to create a Powerpoint presentation:
Microsoft.Office.Interop.PowerPoint.Application obj = new Application();
obj.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
Upvotes: 6
Views: 9502
Reputation: 41
This code snippet creates a new presentation:
private void DpStartPowerPoint()
{
// Create the reference variables
PowerPoint.Application ppApplication = null;
PowerPoint.Presentations ppPresentations = null;
PowerPoint.Presentation ppPresentation = null;
// Instantiate the PowerPoint application
ppApplication = new PowerPoint.Application();
// Create a presentation collection holder
ppPresentations = ppApplication.Presentations;
// Create an actual (blank) presentation
ppPresentation = ppPresentations.Add(Office.MsoTriState.msoTrue);
// Activate the PowerPoint application
ppApplication.Activate();
}
And this code snippet saves it:
// Assign a filename under which to save the presentation
string myFileName = "myPresentation";
// Save the presentation unconditionally
ppPresentation.Save();
// Save the presentation as a PPTX
ppPresentation.SaveAs(myFileName,
PowerPoint.PpSaveAsFileType.ppSaveAsDefault,
Office.MsoTriState.msoTrue);
// Save the presentation as a PDF
ppPresentation.SaveAs(myFileName,
PowerPoint.PpSaveAsFileType.ppSaveAsPDF,
Office.MsoTriState.msoTrue);
// Save a copy of the presentation
ppPresentation.SaveCopyAs(“Copy of “ + myFileName,
PowerPoint.PpSaveAsFileType.ppSaveAsDefault,
Office.MsoTriState.msoTrue);
See this page for references on other powerpoint automation capabilities.
Upvotes: 2
Reputation: 2735
The following resources include how to save file and also many other code samples on how to manipulate Ms - Power Point
presentation files using C#
:
http://code.msdn.microsoft.com/office/CSAutomatePowerPoint-b312d416
http://www.eggheadcafe.com/community/csharp/2/10068596/create-ppt-slides-through-cnet.aspx
Hope this helps
Edit:
The following includes details about adding references:
http://support.microsoft.com/kb/303718
Upvotes: 1
Reputation: 39049
Create such a file using PowerPoint, and embed it as a resource in your C# application. Then copy it to a file whenever you need to.
Upvotes: 0