Find out more about C + + reading Excel form data on the Internet

Source: Internet
Author: User

Use the Microsoft-supplied COM component to read Excel

First, read the Excel file COM class related environment to build:

1, first create a new MFC dialog box project, can be named Readwriteexcel

2. In the Add Class option,

Select MFC from Typelib, such as:

3, then find the corresponding Office version of the Excel.exe file directory, and open Excel.exe,

C:\Program Files\Microsoft Office\office15\excel. Exe

4, add 6 interfaces interface to the right of the generated class generated classes,

5, finish after completion. Include the relevant header file in the diagram at the top of the code that needs to be added to read the Excel file.

Put the contents of these 6 files: #import "C:\\Program Files\\Microsoft Office\\office15\\excel. EXE "No_namespace are commented out. Leave this section of the Applicaiton.

Second, use the existing classes and functions to read the Excel file

1. Define the following 6 classes.

CApplication Excelapp;

Cworkbooks Books;
CWorkbook Book;
CWorksheets sheets;
Cworksheet sheet;
CRange Range;

2. Create an Excel server,

Excelapp.createdispatch (_t ("Excel.Application")

Use the Excelapp.get_version () function to determine the version of Office that is installed natively

3, get the workbook container books. AttachDispatch (Excelapp.get_workbooks ()), followed by books. Open (...) function to open the selected file, which requires a file path such as CString Bookpath.

4. Then through the range.get_value2 () function, the read Excel file is converted to variant type, and finally the data is read out by setting the loop.

PS: This article is only for individuals to learn some of the content of other blog essays, many of which are using the results of others. This article is for personal use only for future reference.

The attachment will have the source code, the inside has the more detailed thought explanation. There is also code written by the Excel file. Welcome the Great God of the road to criticize.

Link: https://pan.baidu.com/s/1pLDdKxl Password: 8CHV

Find out more about C + + reading Excel form data on the Internet

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.