From: http://www.cnblogs.com/Mainz/archive/2009/11/11/microsoft_office_interop_excel.html
Operation background: Asp.net Excel operation
Problems: Add reference locally (COM): Microsoft Office 11.0 Object Library, write the program, debug it properly, and deploy itServerThe Excel. application is not an object.
Initial Diagnosis: The Office and Excel components are not installed on the server.
Step 1: try to solve the problem: Install Excel and other office components on the server to test the program: failed!
Step 2 try to solve the problem: Generate InterOP. Excel. dll from excel.exe and reference the DLL with SDK. The program is compiled successfully. The test program is successful!
Cause: The locally referenced com will not generate DLL files in the bin directory of the program, but the program is searching for DLL files based on the path. when deployed on the server, if Excel and other DLL files are inconsistent with the local path, an exception will be thrown, and the defined Excel Object certainly does not exist.
Method:
1. How to generate InterOP. Excel. dll?
Go to the bindirectory of your Visual Studio sdkand find the tlbimp.exe file. If not, install this file on a CD. For details, see msdn.
Run the command line (CMD) to enter the bin directory and run tlbimp/out: InterOP. Excel. dll officeinstallation directory +excel.exe.
At this time, the following error may be reported: tlbimp error: unable to locate input Type Library: 'C:/program files/mcrosoft offi.
Ce/office/Excel. EXE'
Copy the notebook to the bin directory and run tlbimp/out: InterOP. Excel. dll excel.exe directly. The prompt "Type Library imported to InterOP. Excel. dll path" is displayed"
Find the InterOP. Excel. dll file in the bin directory. Reference it in your Visual Studio.
2. What if it is excel2000 or excel2002?
If excel2000, change excel.exe to excel9.olb.
Excel2002 same as 2003
3. Parameters of Reference Components of different versions are as follows:
File/version |
InterOP. Excel. dll |
InterOP. Office. dll |
InterOP. vbide. dll |
Add reference/COM components |
2000 |
V1.3.0.0 |
V2.1.0.0 |
V5.3.0.0 |
Microsoft Excel 9.0 Object Library (excel9.olb) |
2002 (XP) |
V1.4.0.0 |
V2.2.0.0 |
V5.3.0.0 |
Microsoft Excel 10.0 Object Library (Excel. EXE file) |
2003 |
V1.5.0.0 |
V2.3.0.0 |
V5.3.0.0 |
Microsoft Excel 11.0 Object Library (Excel. EXE file) |
(Another method: http://www.codeproject.com/KB/office/ExcelReader.aspx that neither requires a client to install Excel nor Microsoft. Jet. oledb.4.0)