Due to the wide application of. net, the interoperability problem between C # and COM is often encountered in daily work. To be more complete, This article summarizes the situation of C # Processing com as follows:
In C #, It is very convenient to interoperate with COM, specifically as follows:
No Pia |
C #4.0 dynamic features introduced Guid ID; Id = new GUID ("D7D0B2E8-1795-4E23-96BF-F07EC28FB44C "); Dynamic complug = activator. createinstance (type. gettypefromclsid (ID )); String T = "DLR", R; Complug. dowork (T, out R ); Console. writeline (R ); |
Pia |
First, add a referncereference group in the IDE to automatically generate a database (you can also manually generate a database using tlbimp.exe) Compluglib. mykit kit = new compluglib. mykit (); Kit. dowork (T, out R ); You can use Marshal. *** processes COM objects |
The following is a comparison of C # different versions of office operations
Due to the wide application of. net, the interoperability problem between C # and COM is often encountered in daily work. To be more complete, This article summarizes the situation of C # Processing com as follows:
In C #, It is very convenient to interoperate with COM, specifically as follows:
| NO Pia |
C #4.0 introduces dynamic features guid ID; id = new GUID ("D7D0B2E8-1795-4E23-96BF-F07EC28FB44C"); dynamic complug = activator. createinstance (type. gettypefromclsid (ID); string T = "DLR", R; complug. dowork (T, out R); console. writeline (r); |
Pia |
First, add a referncereference group in the IDE to automatically generate a database (you can also manually generate a database using tlbimp.exe) Compluglib. mykit kit = new compluglib. mykit (); Kit. dowork (T, out R ); You can use Marshal. *** processes COM objects |
The following is a comparison of C # different versions of office operations
/// C #4.0
Dynamic word = activator. createinstance (type. gettypefromprogid ("Word. Application"); Word. Visible =True; Var wordapplication =NewMicrosoft. Office. InterOP. Word. Application (); wordapplication. Visible =True;ObjectMissing = system. reflection. Missing. value;ObjectFile = @"C: \ test.txt";ObjectVisible =True;ObjectReadonly =False;
// You need to introduce Microsoft. Office. InterOP. Word. dll (vs installation)
// C #4.0 named and optional parameters
VaR betterway = wordapplication. Documents. Open (file, readonly: True, visible: True );
Betterway. Activate ();
Betterway. Close ();
// C #1.0 ~ 3.5 (. net3.0 has a simplified operating library office) http://www.microsoft.com/downloads/details.aspx? Familyid = 46b6bf86-e35d-4870-b214-4d7b72b02bf9 & displaylang = EN vsto_ptextlibs.exe
Document adoc = wordapplication. Documents. Open (
Ref file, ref missing, ref readonly, ref missing,
Ref missing, ref missing,
Ref missing, ref visible,
Ref missing, ref missing );
Adoc. Close ();