Operation background: Asp.net Excel operation
Problems: Add reference (COM) locally: Microsoft Office 11.0 object library, and writeProgramDebugging is normal and deployedServerThe 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.
In this case, 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 component |
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)