,
//Get data from Word file
PRocedure getWordStr;
var WordApp: TWordapplication;
WordDoc: TWordDocument;
DocInx,oFileName,CfCversions,oReadOnly,AddToRctFiles,PswDocument,
PswTemplate,oRevert,wpswDocument,WPswTemplate,oFormat: OleVariant;
i,iRow,iCol:integer;
myCell:Cell;
myRow:Row;
begin
memo1.Lines.Clear;
// ===== Create object =====
if not Assigned(WordApp) then
begin
WordApp:= TWordApplication.Create(nil);
WordApp.Visible := false;
end;
if not Assigned(WordDoc) then
WordDoc:= TWordDocument.Create(nil);
try
DocInx:=1;
oFileName := 'd:/test.doc';
oReadOnly:=true;
CfCversions := EmptyParam;
AddToRctFiles:= EmptyParam;
PswDocument:= EmptyParam;
PswTemplate:= EmptyParam;
oRevert:= EmptyParam;
WPswDocument:= EmptyParam;
WPswTemplate:= EmptyParam;
oFormat:= EmptyParam;
// ===== Open file =====
WordApp.Documents.open(oFileName,CfCversions,oReadOnly,AddToRctFiles,
PswDocument,PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat);
// ===== Associated files =====
WordDoc.ConnectTo(WordApp.Documents.Item(DocInx));
//Method (1): Get the character content of the entire text, including tables
s := WordDoc.Range.text;
//Method (2): Take 1 -- 4 characters, including tables
myRange:=WordDoc.Range;
myRange.Start:=0;
myRange.End_ :=4;
finally
if Assigned(WordDoc) then // ===== Close the file =====
begin
WordDoc.Close;
WordDoc.Disconnect;
WordDoc.Destroy;
WordDoc := nil;
end;
if Assigned(WordApp) then // ===== Close Word =====
begin
WordApp.Quit;
WordApp.Disconnect;
WordApp.Destroy;
WordApp := nil;
end;
end;
end;