using Ppt = Microsoft.Office.Interop.PowerPoint;
private static bool ConvertPptToXps(string pptFilename, string xpsFilename)
{
Ppt.Application pptApp;
Ppt.Presentations presentations = null;
Ppt.Presentation presentation = null;
pptApp = new Ppt.Application();
try
{
presentations = pptApp.Presentations;
presentation = presentations.Open(pptFilename);
pptApp.WindowState = Ppt.PpWindowState.ppWindowMinimized;
presentation.SaveAs(xpsFilename, Ppt.PpSaveAsFileType.ppSaveAsXPS);
return true;
}
catch (Exception ex)
{
return false;
}
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执行相似的操作,就不会关闭原先打开的窗口。
求教如何做到执行完转换后不关闭原先的窗口?
关于C#操作PowerPoint的问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-