var
v: variant;
begin
v := CreateOleObject('word');
v.read('C:\Documents and Settings\Administrator.10F4582867B7477\桌面\1.doc');
我做到这一步,读取了一个指定的word文档,我想获取读取的word内容并在form中的label中显示,接下来应该怎样做?
v: variant;
begin
v := CreateOleObject('word');
v.read('C:\Documents and Settings\Administrator.10F4582867B7477\桌面\1.doc');
我做到这一步,读取了一个指定的word文档,我想获取读取的word内容并在form中的label中显示,接下来应该怎样做?
var
fword,fdoc,ftable,frng,fcell: Variant;
s,z: Integer;
OldCursor: TCursor;
FActive: Boolean;
begin
OldCursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
FActive := false;
// try to find running Word OLE server
try
FWord := GetActiveOleObject('word.application');
FActive := true;
except
try
FWord := CreateOLEObject('word.application');
except
Screen.Cursor := OldCursor;
raise EAdvGridError.Create('Word OLE server not found');
Exit;
end;
end; try
if SysUtils.FileExists(filename) then
FDoc := FWord.Documents.Open(filename)
else
begin
if CreateNewDocument or (FWord.Documents.Count = 0) then
FDoc := FWord.Documents.Add
else
FDoc := FWord.ActiveDocument;
end; FDoc.ShowSpellingErrors := False;
FRng := FWord.Selection;
FRng.TypeText(Caption);
FRng.TypeParaGraph;
FRng := FDoc.Range(start:=0,end:=0);
{//示例代码: 将Grid内容插入Word的代码. RowCount为Grid行数, ColCount为列数 FTable := FDoc.Tables.Add(frng,numRows:= RowCount,numColumns:=ColCount); for s := 1 to RowCount do
for z := 1 to ColCount do
begin
FCell := FTable.Cell(Row:=s,Column:=z);
FCell.Range.InsertAfter('你的内容,如Grid.Cells[z,s]');
end;
}
FDoc.SaveAs(FileName);
finally
if not FActive then
FWord.Quit;
FWord := Unassigned;
Screen.Cursor := OldCursor;
end;
end;