2015-06-24 84 views
-3

我只是想通過這樣做,使一個空的幻燈片對象 -如何創建一個空的幻燈片對象?

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 . . . 

我希望得到一些幫助。

+4

你爲什麼把它設置爲null? null與空幻燈片不同!什麼是錯誤? – dotctor

+0

這就像'沒有設置爲對象的實例'。好的,我應該怎麼做? – user1394252

+0

'var empty_slide = new Microsoft.Office.Interop.PowerPoint.Slide();' – dotctor

回答

0

只需從您的第一個代碼中刪除empty_slide = null;部分即可。這應該做到這一點。 使用下列 -

Microsoft.Office.Interop.PowerPoint.Slide empty_slide = new Microsoft.Office.Interop.PowerPoint.Slide(); 
+0

請參閱最新的代碼。它仍然會給出錯誤 – user1394252

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平臺的目標。