Keywords:
Office, COM, olb
We need to operate the Office. The first thing we think of is how to add its library to our project?
Recently I have studied office. MS Office can be said to use a masterpiece of COM completely.
It is better than it. I have seen several foreign companies also use Development Kits written by COM, such as ArcGIS,
I can't help but admire it. It seems that I still need to keep practicing internal skills!
I recently posted a post on offfice cleanup on the csdn forum! These Daniel
Are you writing blogs?
Go to the topic. I will list all types of libraries of the current office version! Haha!
Office version number Library
--------------------------------------------------
Microsoft Access 97 msacc8.olb
Microsoft Jet Database 3.5 dao350.dll
Microsoft binder 97 msbdr8.olb
Microsoft Excel 97 excel8.olb
Microsoft Graph 97 graph8.olb
Microsoft Office 97 mso97.dll
Microsoft Outlook 97 msoutl97.olb
Microsoft PowerPoint 97 msppt8.olb
Microsoft Word 97 msword8.olb
Microsoft acc2000 msacc9.olb
Microsoft Jet Database 3.51 dao360.dll
Microsoft binder 2000 msbdr9.olb
Microsoft Excel 2000 excel9.olb
Microsoft Graph 2000 graph9.olb
Microsoft Office 2000 mso9.dll
Microsoft Outlook 2000 msoutl9.olb
Microsoft PowerPoint 2000 msppt9.olb
Microsoft Word 2000 msword9.olb
Microsoft Access 2002 msacc. olb
Microsoft Excel 2002 excel.exe
Microsoft Graph 2002 graph.exe
Microsoft Office 2002 MSO. dll
Microsoft Outlook 2002 msoutl. olb
Microsoft PowerPoint 2002 msppt. olb
Microsoft Word 2002 MSWord. olb
Microsoft Office Access 2003 msacc. olb
Microsoft Office Excel 2003 excel.exe
Microsoft Graph 2003 graph.exe
Microsoft Office 2003 MSO. dll
Microsoft Office Outlook 2003 msoutl. olb
Microsoft Office PowerPoint 2003 msppt. olb
Microsoft Office Word 2003 MSWord. olb
As you may have noticed above, how does office2002 and office2003 have a Type Library in EXE?
I don't know why Ms put it in, but I use the same import method.
The following example uses office2003 as an example:
# Import "C: // program files // common files // system // ADO // msado21.tlb" no_namespace/
Rename ("EOF", "adoeof ")
# Import "C: // program files // common files // Microsoft shared // Dao // dao360.dll" RENAME ("EOF", "endoffile ")/
Rename ("Bof", "begoffile ")
# Import "C:/Program Files // common files // Microsoft shared // office11 // MSO. dll" rename_namespace ("Office ")
Using namespace office;
# Import "C: // program files // common files // Microsoft shared // VBA // vba6 // vbe6ext. olb" rename_namespace ("vbe6 ")
Using namespace vbe6;
# Import "C:/program files/Microsoft Office/office11/MSWord. olb" RENAME ("exitwindows", "exitwindowsex"), named_guids, rename_namespace ("MSWord ")
Using namespace MSWord;
# Import "C:/program files/Microsoft Office/office11/msacc. olb" implementation_only, rename_namespace ("msacc ")
Using namespace msacc;
# Import "C:/program files/Microsoft Office/office11/msppt. olb" implementation_only, rename_namespace ("msppt ")
Using namespace msppt;
# Import "C: // program files // Microsoft Office // office11 // excel.exe" RENAME ("RGB", "rgbex"), rename ("dialogbox ", "dialogboxex"), rename_namespace ("MSExcel ")
Using namespace MSExcel;
Note:
1. The first four paths are default. The last four paths can be changed based on different versions!
2. Ado and Dao are used to support access. If you are not using access, you can remove them!
3. Office and vbe6 are required. We use them every time!
The following is a simple example:
Int _ tmain (INT argc, _ tchar * argv [])
{
// Initialize the com Libraries
: Coinitialize (null );
STD: cout <"begin clear! "<STD: Endl;
// Create an instance of the Word application and obtain
// Pointer to the application's idispatch interface.
CLSID clsidword;
Clsidfromprogid (L "word. Application", & clsidword );
Iunknown * punk;
Hresult hR = getactiveobject (clsidword, null, (iunknown **) & punk); // obtain the interface pointer of the currently opened Word
// You can also use cocreateinstance (...) to create it!
MSWord: _ applicationptr papplication = punk;
//...
: Couninitialize ();
STD: cout <"finish! --- Thanks! "<STD: Endl;
System ("pause ");
Return 0;
}
Author: wangweixing2000
Please indicate the source of the post! Thank you!