Having an issue with exporting DataGridView to excel receiving Com Error

0

I have had code working in an C# .net 2013. that exports the DGV to excel. However it has stopped working as of this morning, its been about a month since I have opened the code. Now I am getting an error:

Additional information: unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D TYPE_E_LIBNOTREGISTERED)).

I have found a number of answers else ware that says to removing the Regedit key? What happend and which key do I need to remove?

c#
excel
winforms
datagridview
com
asked on Stack Overflow May 10, 2018 by Lee Hopkins • edited May 10, 2018 by TaW

1 Answer

0

In my case it was a matter of explicitly defining the use of non 32 bit version of the library. For doing so in visual studio, I had to tick and then untick the box "Prefer 32-bit" in the build section of the project configuration, which added <Prefer32Bit>false</Prefer32Bit> in the .csproj file.

answered on Stack Overflow Aug 24, 2018 by Stathis Agrapidis

User contributions licensed under CC BY-SA 3.0