Go to: use the office component to read the Excel file and reference the Microsoft. Office. InterOP. Excel file.

Source: Internet
Author: User

 

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)

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.