问题描述
- 关于C#操作PowerPoint的问题
-
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(一)
C# 操作Powerpoint
操作powerpoint遇到的问题
时间: 2024-12-03 02:17:07