使用C#保存PowerPoint文件 [英] Saving a powerpoint file using C#
本文介绍了使用C#保存PowerPoint文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只需要使用C#创建一个带有1个虚拟幻灯片的 .pptx
文件,并将其保存到当前目录即可。谁能告诉我该怎么做?
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?
到目前为止,我已经使用以下代码创建了Powerpoint演示文稿:
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;
推荐答案
此代码段创建了一个新的演示文稿:
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();
}
此代码段将其保存:
// 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自动化功能的参考。
See this page for references on other powerpoint automation capabilities.
这篇关于使用C#保存PowerPoint文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文