问题描述
usingPpt=Microsoft.Office.Interop.PowerPoint;privatestaticboolConvertPptToXps(stringpptFilename,stringxpsFilename){Ppt.ApplicationpptApp;Ppt.Presentationspresentations=null;Ppt.Presentationpresentation=null;pptApp=newPpt.Application();try{presentations=pptApp.Presentations;presentation=presentations.Open(pptFilename);pptApp.WindowState=Ppt.PpWindowState.ppWindowMinimized;presentation.SaveAs(xpsFilename,Ppt.PpSaveAsFileType.ppSaveAsXPS);returntrue;}catch(Exceptionex){returnfalse;}finally{try{presentation.Close();pptApp.Quit();}catch(Exception){}if(presentation!=null){Marshal.ReleaseComObject(presentation);presentation=null;}if(presentations!=null){Marshal.ReleaseComObject(presentations);presentations=null;}if(pptApp!=null){Marshal.ReleaseComObject(pptApp);pptApp=null;}GC.Collect();}}C#调用PowerPoint把ppt转换为xps,另存完后退出PowerPoint。问题是,如果在执行上述代码之前有打开的PowerPoint窗口,代码执行完后会把原先的PowerPoint窗口关掉。对Word和Excel执行相似的操作,就不会关闭原先打开的窗口。求教如何做到执行完转换后不关闭原先的窗口?
解决方案
解决方案二:
pptApp是在哪赋值的?是不是这导致与word不一样
解决方案三:
pptApp=newPpt.Application();代码第四行,与word,excel是一样的