2010-11-27 5 views
0

Je suis à la recherche d'aide pour le vidage de document Word (* .doc) en texte? J'utilise Delphi 2010.Décharger le document Word (* .doc) en texte?

Si la solution est un composant ou une bibliothèque, il doit s'agir d'une bibliothèque de composants ou de code libre ou opensource.

Répondre

5

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; 
+0

Ça marche! Merci beaucoup! – IElite