У меня есть довольно простой блок кода на C # ...
static void ReadMSOfficeWordFile(string file) {
Microsoft.Office.Interop.Word.Application msWordApp = new Microsoft.Office.Interop.Word.Application();
object nullobj = System.Reflection.Missing.Value;
object ofalse = false;
object ofile = file;
Microsoft.Office.Interop.Word.Document doc = msWordApp.Documents.Open(
ref ofile, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj);
string result = doc.Content.Text.Trim();
doc.Close(ref ofalse, ref nullobj, ref nullobj);
CheckLineMatch(file, result);
}
Все, что я хочу сделать, - это получить текст файла, чтобы я мог запустить с ним некоторые регулярные выражения.(Должен ли я на самом деле открыть его таким образом?)
Когда я пытаюсь запустить это, я получаю сообщение об ошибке в первой строке этой функции.
Microsoft.Office.Interop.Word.Application msWordApp = new Microsoft.Office.Interop.Word.Application();
Ошибкаэто:
System.Runtime.InteropServices.COMException was unhandled
Message="Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154."
Source="NPC_Check"
ErrorCode=-2147221164
StackTrace:
at NPC_Check.Program.ReadMSOfficeWordFile(String file) in C:\Documents and Settings\mlustfie\My Documents\Visual Studio 2008\Projects\NPC_Check\NPC_Check\Program.cs:line 83
at NPC_Check.Program.FindFiles() in C:\Documents and Settings\mlustfie\My Documents\Visual Studio 2008\Projects\NPC_Check\NPC_Check\Program.cs:line 70
at NPC_Check.Program.Main(String[] args) in C:\Documents and Settings\mlustfie\My Documents\Visual Studio 2008\Projects\NPC_Check\NPC_Check\Program.cs:line 61
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Понятия не имею, почему это не работает ...