Sie benötigen keine Drittanbieter-Komponente. überprüfen diese Proben
Mit der Range
Wich-Funktion mit einem Text
Eigenschaft kommt
uses
ComObj;
function ExtractTextFromWordFile(const FileName:string):string;
var
WordApp : Variant;
CharsCount : integer;
begin
WordApp := CreateOleObject('Word.Application');
try
WordApp.Visible := False;
WordApp.Documents.open(FileName);
CharsCount:=Wordapp.Documents.item(1).Characters.Count;//get the number of chars to select
Result:=WordApp.Documents.item(1).Range(0, CharsCount).Text;//Select the text and retrieve the selection
WordApp.documents.item(1).Close;
finally
WordApp.Quit;
end;
end;
oder die Zwischenablage verwenden, müssen Sie alle doc Inhalt auswählen, in die Zwischenablage kopieren und Abrufen von Daten unter Verwendung von Clipboard.AsText
uses
ClipBrd,
ComObj;
function ExtractTextFromWordFile(const FileName:string):string;
var
WordApp : Variant;
CharsCount : integer;
begin
WordApp := CreateOleObject('Word.Application');
try
WordApp.Visible := False;
WordApp.Documents.open(FileName);
CharsCount:=Wordapp.Documents.item(1).Characters.Count; //get the number of chars to select
WordApp.Selection.SetRange(0, CharsCount); //make the selection
WordApp.Selection.Copy;//copy to the clipboard
Result:=Clipboard.AsText;//get the text from the clipboard
WordApp.documents.item(1).Close;
finally
WordApp.Quit;
end;
end;
Das funktioniert! Ich danke dir sehr! – IElite