我添加了对Microsoft.Office.Interop.Word 12.0.0.0
. 我有 Visual Studio 2008 和 Microsoft Word 2010(Starter)。
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();
我收到下面提到的错误:
由于以下错误,检索具有 CLSID {000209FF-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80040154. at Microsoft.Office.Interop.Word.Application word => new Microsoft.Office.Interop.Word .ApplicationClass();
谢谢,萨钦K