Use OLE to convert Word to text format
Function wordtotxt (sdocfile: string): string; var wordapp: variant; begin wordapp: = createoleobject ('word. basic '); if not varisempty (wordapp) then begin try wordapp. fileopen (sdocfile); Result: = changefileext (sdocfile, '.txt '); wordapp. filesaveas (result, 2); // 2 indicates the text in the format. See the following table wordapp. appclose; finally wordapp: = unassigned; end;
There is a problem, the screen will flash, because the word is opened and closed.
The definition of file format is as follows:
Wdformatdocument |
0 |
Microsoft Office Word format. |
Wdformatdostext |
4 |
Microsoft DOS text format. |
Wdformatdostextlinebreaks |
5 |
Microsoft DOS text with line breaks preserved. |
Wdformatencodedtext |
7 |
Encoded text format. |
Wdformatfilteredhtml |
10 |
Filtered HTML format. |
Wdformathtml |
8 |
Standard HTML format. |
Wdformatrtf |
6 |
Rich Text Format (RTF ). |
Wdformattemplate |
1 |
Word template format. |
Wdformattext |
2 |
Microsoft Windows text format. |
Wdformattextlinebreaks |
3 |
Windows text format with line breaks preserved. |
Wdformatunicodetext |
7 |
Unicode text format. |
Wdformatwebarchive |
9 |
Web Archive format. |
Wdformatxml |
11 |
Extensible Markup Language (XML) format. |
Wdformatdocument97 |
0 |
Microsoft Word 97 document format. |
Wdformatdocumentdefault |
16 |
Word default document file format. For Microsoft Office Word 2007, this is the docx format. |
Wdformatpdf |
17 |
PDF format. |
Wdformattemplate97 |
1 |
Word 97 template format. |
Wdformatxmldocument |
12 |
XML document format. |
Wdformatxmldocumentmacroenabled |
13 |
XML document format with macros enabled. |
Wdformatxmltemplate |
14 |
XML template format. |
Wdformatxmltemplatemacroenabled |
15 |
XML template format with macros enabled. |
Wdformatxps |
18 |
XPS format. |