简体   繁体   中英

Saving a powerpoint file using C#

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;

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

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.

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.

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