vous n'avez pas besoin d'un composant tiers. vérifier ces échantillons
Utilisation de la wich fonction Range
est livré avec un Text
propriété
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;
ou en utilisant le presse-papiers, vous devez sélectionner tout le contenu de doc, copier dans le presse-papiers et récupérer les données à l'aide 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;
Ça marche! Merci beaucoup! – IElite