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