[英]Saving a powerpoint file using C#
我只需要使用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自動化功能的參考,請參閱此頁面 。
使用PowerPoint創建此類文件,並將其作為資源嵌入C#應用程序中。 然后在需要時將其復制到文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.