2012-06-21 88 views
0

我已經添加了對Microsoft.Office.Interop.Word 12.0.0.0的引用。我有Visual Studio 2008和Microsoft Word 2010(Starter)。閱讀2010 Word文件

string filePath = @"C:\PP.docx"; 
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.ApplicationClass(); 

// create object of missing value 
object miss = System.Reflection.Missing.Value; 

// create object of selected file path 
object path = filePath; 

// set file path mode 
object readOnly = false; 

// open document     
Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss); 

// select whole data from active window document 
docs.ActiveWindow.Selection.WholeStory(); 

// handover the data to cllipboard 
docs.ActiveWindow.Selection.Copy(); 

// clipboard create reference of idataobject interface which transfer the data 
System.Windows.Forms.IDataObject data = Clipboard.GetDataObject(); 

我得到的錯誤如下提到:

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154. at Microsoft.Office.Interop.Word.Application word => new Microsoft.Office.Interop.Word.ApplicationClass();

感謝, 薩欽ķ

+0

你見過此相關的問題?這可能是一個64位的問題http://stackoverflow.com/questions/1036856/retrieving-the-com-class-factory-for-component-with-clsid-xxxx-failed-due-to-t –

+0

@KevinMain - Your評論沒有意義。 「Microsoft.Office.Interop.Word 12.0.0.0」支持x64程序集。 Office 2010一般支持x64平臺。 –

+0

@Ramhound非常好的一點,沒有真正認爲通過! –

回答