How to EMBED Excel in Form

Source: Internet
Author: User
Neither. Net framework1.0 nor 1.1 implements the olecontainer component. Check msdn and get a prompt: You can use iebrowser to simulate olecontainer. This is definitely an overweight implementation. However, it is the most time-consuming method. This article briefly describes how to use the iebrowser control to embed an Excel table.

How to embed an Excel file in Form

1. First, import "Microsoft Web Browser" in the toolbar ". You can right-click the toolbar and select "Add/Remove items ". Select "COM component" in the Custom toolbox that appears, find "Microsoft Web Browser" in the component, select and confirm.

2. Create a form, select the "Microsoft Web Browser" component in the toolbar, and place it in the form.

3. Use the followingCodeTo import an Excel table:

Axwebbrowser1.navigate ( @" C: \ test \ test.xls " );

4. Add the documentcomplete event of axwebbrowser1. And obtain the Excel OLE object in the event:

Public Excel. Workbook WB;

Private   Void Axwebbrowser1_documentcomplete ( Object Sender, axshdocvw. dwebbrowserevents2_documentcompleteevent E)
{
WB=(Excel. workbook) axwebbrowser1.document;
}

5. Using WB, you can directly access the Excel table.

Although it is easy to use the IE control, it is not a good method. Currently, only third-party controls are available, or. NET 2.0 is expected. If you have a better method, share it.

Potential problems:
1. Excel exit is a problem when Office2000 is used. Excel may not be accurately exited, or an error may occur when Excel is exited. This may leave a lot of Excel processes in the system. In practice, it is found that when office2003 is used, this problem is solved. Officexp and office2002 have not been tested and do not know if they have been solved.
2. Data operations are slow. This is related to the COM interface. If you have a deep understanding of COM, you can perform many optimizations to greatly improve the efficiency.

Temporary solution:
1. Use excel2003 to exit Excel
2. Using the spreadsheet component of Office Web Components V10/V11 is currently a good solution.

Appendix:
Use owc. We recommend that you use owc10 or owc11. Owc9 is not recommended because of license issues.
Spreadsheet has a variety of acceptable data sources, including ADODB. recordset, CSV format text, HTML table format, and XML format. It is flexible to use and can be exported directly to excel on the spreadsheet toolbar.
The use of spreadsheet has manyArticleI have already introduced this article. You can search for it in Google. I hope it will help you.

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.