我只是想通过这样做来制作一个空的幻灯片对象 -
Microsoft.Office.Interop.PowerPoint.Slide empty_slide = new Microsoft.Office.Interop.PowerPoint.Slide();
错误是:
Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the
COM class factory for component with CLSID {91493445-5A91-11CF-8700-00AA0060263
B} failed due to the following error: 80040154 Class not registered (Exception f
rom HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOn
ly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Bo
olean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipChec
kThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean s
kipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Program.GetBulletPointTransition(Application PowerPoint_App, Presentation
presentation) in c:\Users\PEAK\Documents\Peak Sourcing\Work\ppt_test\ppt_test\Pr
ogram.cs:line 539
at Program.Main(String[] args) in c:\Users\PEAK\Documents\Peak Sourcing\Work\
ppt_test\ppt_test\Program.cs:line 79
Press any key to continue . . .
我将不胜感激。
答案 0 :(得分:1)
这里是正确的答案:
您不应直接创建类Microsoft.Office.Interop.PowerPoint.Slide的新实例。相反,请使用以下代码:
Presentation ppt = pptApp.Presentations.Open(pptPath, WithWindow: MsoTriState.msoFalse);
int newSlideNumber = (ppt.Slides.Count + 1);
var slide = ppt.Slides.Add(newSlideNumber, PpSlideLayout.ppLayoutTitleOnly);
slide.Shapes[1].TextFrame.TextRange.Text = "hello!";
注意:如果您在相关论坛中查看了问题的可用答案,则不应更改项目的构建设置以使用x86的平台目标。
答案 1 :(得分:0)
只需从第一个代码中删除empty_slide = null;
部分即可。应该这样做。
使用以下 -
Microsoft.Office.Interop.PowerPoint.Slide empty_slide = new Microsoft.Office.Interop.PowerPoint.Slide();