2010-11-27 5 views
0

Ich suche nach Hilfe in Word-Dokument (* .doc) zu Text dumping? Ich verwende Delphi 2010.Word-Dokument (* .doc) in Text ausgeben?

Wenn die Lösung eine Komponente oder eine Bibliothek ist, sollte es eine freie oder opensource Komponente oder Codebibliothek sein.

Antwort

5

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

Das funktioniert! Ich danke dir sehr! – IElite