Delphi open Word documents

Source: Internet
Author: User
The application can extract the text in Word as the basis for fuzzy search or other operations. In this example, click the Open Document button to extract text from the selected word document, as shown in Figure 7.27.

The createoleobject method is used to create an OLE object. The selected word document is opened using the documents. Open Method of the OLE object. The extracted text content is displayed in richedit1. The main code is as follows:
Procedure tform2.button1click (Sender: tobject );
VaR
Wordapp, DOC: olevariant;
STRs: tstringlist;
Begin
If opendialog1.execute then
Begin
STRs: = tstringlist. Create;
Wordapp: = createoleobject ('word. application ');
Try
DOC: = wordapp. Documents. Open (filename: = opendialog1.filename );
Richedit1.text: = Doc. range. text;
Doc. close;
Finally
Wordapp. Quit;
STRs. Free;
End;
End;
End;


Figure 7.27 read text from word

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.