我想使用 C# 和 Microsoft.Office.Interop.PowerPoint 将 pps(x) 或 ppt(x) 转换为 PDF。为此,我使用执行以下编码的方法:
Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
Microsoft.Office.Interop.PowerPoint.Application application = null;
try
{
application = new Microsoft.Office.Interop.PowerPoint.Application();
presentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
presentation.SaveAs(targetPath, PpSaveAsFileType.ppSaveAsPDF, Microsoft.Office.Core.MsoTriState.msoTrue);
result = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
result = false;
}
finally
{
if (presentation != null)
{
presentation.Close();
presentation = null;
}
if (application != null)
{
application.Quit();
application = null;
}
}
return result;
第一次调用该方法时,ppsx成功保存为pdf。但是当再次调用该方法时,会引发以下异常application = new Microsoft.Office.Interop.PowerPoint.Application();
异常消息是:Creating an instance of the COM component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} from the IClassFactory failed due to the following error: 800706b5 The interface is unknown. (Exception from HRESULT: 0x800706B5).
就在引发此异常之前,控制台显示另一个异常"System.Runtime.InteropServices.COMException" in mscorlib.dll
。
通过 F12导航到该界面时Microsoft.Office.Interop.PowerPoint.Application
,该界面的 GUID 为 9149344 2 -5A91-11CF-8700-00AA0060263B。所以它与异常消息中的 GUID 略有不同。
想请教一下,这个问题怎么解决?
PS:本笔记本安装了Microsoft Office 2010(运行Microsoft Win 7)
感谢你并致以真诚的问候