to:linsb
我用了你的语句,但是还是无法解决问题,我的语句如下: 麻烦你看一下,问题在那里?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Word2000, OleServer, DB, ADODB, RxRichEd, DBRichEd,
ExtCtrls, DBCtrls, Clipbrd;
type
TForm1 = class(TForm)
wordDoc: TWordDocument;
WordApp: TWordApplication;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
RxDB: TRxDBRichEdit;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
Button3: TButton;
DBNavigator1: TDBNavigator;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure GotoDocEnd(WrdApp: TWordApplication);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Itemindex, format,TempEmpty: olevariant;
filename, passworddocument, passwordtemplate: olevariant;
writepassworddocument, writepasswordtemplate: olevariant;
confirmconversions, readonly, revert, addtorecentfiles: olevariant;
begin
wordapp.Connect;
wordapp.Visible:=true;
wordapp.Caption:='WORD的应用';
{open document}
filename :='e:/doc1.doc'; //OpenDialog1.filename;
confirmconversions := false;
readonly := false;
addtorecentfiles := false;
revert := true;
passworddocument := '';
passwordtemplate := '';
writepassworddocument := '';
writepasswordtemplate := '';
format := wdopenformatdocument;
wordapp.documents.open(filename, confirmconversions,
readonly, addtorecentfiles, passworddocument, passwordtemplate,
revert, writepassworddocument, writepasswordtemplate, format,TempEmpty,TempEmpty);
itemindex := 1;
worddoc.connectto(wordapp.documents.item(itemindex));
worddoc.Range.InsertAfter('你好!'+#13);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
wordapp.Quit;
wordapp.Disconnect;
close;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Clipboard.Clear;
rxdb.SelectAll;
rxdb.CopyToClipboard;
worddoc.Sentences.Last.Paste;
worddoc.Range.InsertAfter(''+#13);
GotoDocEnd(wordapp);
end;
//将光标移到文档最后的:
procedure TForm1.GotoDocEnd(WrdApp: TWordApplication);
var
WdUnit, WdCount, wdExtend: OleVariant;
begin
WdUnit := wdScreen;
wdCount := 10;
wdExtend := EmptyParam;
while true do
if WrdApp.Selection.MoveDown(WdUnit, wdCount, wdExtend) = 0 then break;
end;
end.