Cannot embed the interoperability type "ApplicationClass". Please use the applicable interface instead-Microsoft.Office.Interop.Excel.ApplicationClass

When we are currently doing a conversion of data in the database to Excel, when Microsoft.Office.Interop.Excel is introduced, the interoperability type ApplicationClass "cannot be embedded" appears. Please use the applicable interface instead.

The error is as follows:

 

I also understand a little bit by looking for information. First, let me talk about its meaning:

1. Embedding in "embedded interoperability type" means introduction and import, similar to the role of using<> in c# and include<> in c. The purpose is to tell the compiler whether to introduce interoperability types.

2. "Interoperability type" actually refers to the assembly of a series of COM components, which are library files in the common runtime library, similar to compiled classes, interfaces, etc.

3. "Embedded interoperability type" is set to true, in fact, does not introduce interoperability set (com assembly is abandoned when compiling), only the assembly of user code is compiled. If it is set to false, it is actually necessary to obtain the type information of the COM type from the interoperability assembly.

 

The solution is:

In the project application, find Microsoft.Office.Interop.Excel, right-click the reference, and modify the property "Embedded Interop Type" to false.

Guess you like

Origin blog.csdn.net/weixin_44684272/article/details/110728661