要實現PPT轉圖片,首先需要引用兩個DLL。
我這裡用的這個這個版本
Microsoft.Office.Interop.PowerPoint 12.0
Microsoft Office 12.0 object Library
如下圖:
程式碼如下:
private void pptToImg(string pptPath, string imgPath) { var app = new Microsoft.Office.Interop.PowerPoint.Application(); var ppt = app.Presentations.Open(pptPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); var index = 0; var fileName = Path.GetFileNameWithoutExtension(pptPath); foreach (Microsoft.Office.Interop.PowerPoint.Slide slid in ppt.Slides) { ++index; //設定圖片大小 slid.Export(imgPath+string.Format("page{0}.png",index.ToString()), "png", 1024, 768); //根據螢幕尺寸。設定圖片大小 //slid.Export(imgPath+string.Format("page{0}.jpg",index.ToString()), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); } //釋放資源 ppt.Close(); app.Quit(); GC.Collect(); }