1.前言:
新增一個PPT檔案,將圖片檔插入到簡報中,並另存新檔。
2.說明:
加入參考
版本:12.0.0.0
Microsoft.Office.Interop.PowerPoint
Office
加入命名空間
using PPT = Microsoft.Office.Interop.PowerPoint; using Office = Microsoft.Office.Core;
程式碼:
int idx = 0; //使用Application類別,開啟PowerPoint應用程式 PPT.ApplicationClass app = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); //PowerPoint文件開啟可見 app.Visible = Office.MsoTriState.msoTrue; //開啟簡報 PPT.Presentation prst = app.Presentations.Add(Office.MsoTriState.msoTrue); //加入空白Slide idx = prst.Slides.Count + 1; prst.Slides.Add(idx, PPT.PpSlideLayout.ppLayoutBlank); //加入圖片 prst.Slides[idx].Shapes.AddPicture(@"d:\tmp\picture.jpg", Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue, 0, 0, 720, 540); //另存檔案 prst.SaveAs(@"d:\tmp\MyPpt.pptx", PPT.PpSaveAsFileType.ppSaveAsDefault, Office.MsoTriState.msoTrue); //關閉檔案 prst.Close(); app.Quit(); //釋放資源 prst = null; app = null; GC.Collect();
文章標籤
全站熱搜
留言列表