使用C#保存powerpoint文件
我只需要使用C#创建一个带有1个虚拟幻灯片的.pptx
文件,并将其保存到当前目录中。 谁能告诉我怎么做?
到目前为止,我有这个代码来创建一个Powerpoint演示文稿:
Microsoft.Office.Interop.PowerPoint.Application obj = new Application(); obj.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
以下资源包括如何保存文件以及如何使用C#
操作Ms - Power Point
演示文件的许多其他代码示例:
http://code.msdn.microsoft.com/office/CSAutomatePowerPoint-b312d416
http://www.eggheadcafe.com/community/csharp/2/10068596/create-ppt-slides-through-cnet.aspx
希望这可以帮助
编辑:
以下包括有关添加引用的详细信息:
此代码段创建了一个新的演示文稿:
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(); }
这段代码保存了它:
// 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);
有关其他powerpoint自动化function的参考,请参阅此页面 。
使用PowerPoint创建此类文件,并将其作为资源嵌入C#应用程序中。 然后在需要时将其复制到文件中。