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