简体   繁体   中英

Microsoft interop to Word does not work after uprade to Office 365

I had Word templates in my database that are used for mail merge.

I used Office 2013 when I created this code with.Net 4.6:

 Object theTemplateFile = theWordFileName =  Path.Combine(Path.GetTempPath(), _selectedCIPTemplate.Name + ".dotx");
            byte[] theTemplate = _selectedCIPTemplate.Template;
            using (FileStream stream = new FileStream(theTemplateFile.ToString(), FileMode.Create))
            {
                stream.Write(theTemplate, 0, theTemplate.Length);
            }

            Object oMissing = System.Reflection.Missing.Value;

            //Create an instance of Word
            Process.Start(theWordFileName);
            System.Threading.Thread.Sleep(2000);
           

            wrdApp = Marshal.GetActiveObject("Word.Application") as Microsoft.Office.Interop.Word.Application;
            wrdApp.Visible = false;

I recently upgraded to Office 365 64 bits en this code now breaks on te line:

wrdApp = Marshal.GetActiveObject("Word.Application") as Microsoft.Office.Interop.Word.Application;

With the following error (sorry, Dutch): Het ophalen van de COM-classfactory voor het onderdeel met CLSID {000209FF-0000-0000-C000-000000000046} is mislukt vanwege de volgende fout: 80040154 Klasse is niet geregistreerd (Uitzondering van HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

I tried reregister the class with regasm Microsoft.Office.Interop.Word.dll

I compiled the project as Any CPU

But it keeps failing.

Any tips how to solve this?

Het ophalen van de COM-classfactory voor het onderdeel met CLSID {000209FF-0000-0000-C000-000000000046} is mislukt vanwege de volgende fout: 80040154 Klasse is niet geregistreerd (Uitzondering van HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

This is a good indication that your windows registry keys were messed up. You need to remove old keys that were left after upgrading to Office 365.

If you try to install O365 on a clean machine you should get the code working correctly independently of the Office bitness whether it is x86 or x64 platform is used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM