For example, how to use CIDR to read .doc

Source: Internet
Author: User

I haven't been studying c ++ for a long time. I went to the forum yesterday and encountered such a question. I found the relevant content on the Internet.

My experience is summarized.

First, create a win32 console program. Be sure to select the support for MFC option.

Select View> Class Wizard, click Add Class, select Import from Type Library, and open MSWORD. OLB in the installation directory of Office. The following dialog box is displayed:

Import four classes: _ Application, Documents, _ Document, and Range.

Add the following code to the else statement of the main function.

_ Application wordApp; // the top-level object in the Object Inheritance structure. You can use the method to access other work-type objects (in this example, word)
Documents docs; // indicates all open document objects.
_ Document doc;
Range aRange;

COleVariant vTrue (short) TRUE ),
VFalse (short) FALSE ),
VOpt (long) DISP_E_PARAMNOTFOUND, VT_ERROR );

WordApp. CreateDispatch ("Word. Application", NULL );
WordApp. SetVisible (FALSE );
Docs = wordApp. GetDocuments ();
Doc = docs. open (COleVariant (filename ...), vFalse, vTrue, vFalse, vOpt, vOpt );
ARange = doc. Range (vOpt, vOpt );

String str (aRange. GetText ());
Cout <str <endl;
Doc. Close (vOpt, vOpt, vOpt );
WordApp. Quit (vOpt, vOpt, vOpt );
CoUninitialize (); // close the COM Object Library and release resources.

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.