Wordapplication1 WordDocument1 删除文档内容 只有23分,全呈上 ( 积分: 23 )

  • 主题发起人 主题发起人 gongfs
  • 开始时间 开始时间
G

gongfs

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠:
将memo1 中的内容导入到word 文档中,已成功,我现在想实现这样的功能
将memo1 中的内容导入到word 文档中之前,将word 文档中内容先清空,谢谢
附上我的代码:

procedure Tmain.Button5Click(Sender: TObject);
var
ItemIndex:OleVariant; para:paragraph;//段落对象
DocIndex,ParaIndex,ShapeIndex:olevariant;
i,paracount:integer;
rang:range;//区域对象

tbl:table;//表格对象
sp:shape; //shape对象
s1,s2,tempint,k,tempint2:integer;
FileName,ConfirmConversions,ReadOnly,AddToRecentFiles,PasswordDocument,PasswordTemplate,Revert,WritePasswordDocument,WritePasswordTemplate,Format:OleVariant;


begin

try

Wordapplication1.Connect;

except
MessageDlg('您可能没有安装word', mtError, [mbOk], 0);
Abort;
end;
try

if not Wordapplication1.Visible
then
Wordapplication1.Visible:=True;
WordApplication1.Caption:='a';


FileName:='c:/a.doc'; //我硬盘里存在的word文件
ConfirmConversions:=False;
ReadOnly:=False;
AddToRecentFiles:=False;
PasswordDocument:='';
PasswordTemplate:='';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;
WordDocument1.Connectto(WordApplication1.Documents.Open(filename,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam));


ItemIndex:=1;
WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));

Wordapplication1.Visible:=true;

WordDocument1.Range.InsertAfter(Memo1.Text);

i:=1;
WordDocument1.Range.Paragraphs.Item(i).Range.Font.Size:=28;
WordDocument1.Range.Paragraphs.Item(i).Range.Font.Name:='黑体';
WordDocument1.Range.Paragraphs.Item(i).Range.Font.Bold:=3;
tempint:=1;
WordDocument1.Range.Paragraphs.Item(i).Alignment:=tempint;
i:=2;
WordDocument1.Range.Paragraphs.Item(i).Range.Font.Size:=28;
WordDocument1.Range.Paragraphs.Item(i).Range.Font.Name:='黑体';
tempint:=1;
WordDocument1.Range.Paragraphs.Item(i).Alignment:=tempint;
i:=4;
WordDocument1.Range.Paragraphs.Item(i).Range.Font.Size:=12;
WordDocument1.Range.Paragraphs.Item(i).Range.Font.Name:='黑体';
tempint:=1;
WordDocument1.Range.Paragraphs.Item(i).Alignment:=tempint;
s1:=6; s2:=100;k:=0;;
s2:=WordDocument1.Range.Paragraphs.Count;
for k:=s1 to s2 do
begin //w
WordDocument1.Range.Paragraphs.Item(k).Range.Font.Size:=18;
WordDocument1.Range.Paragraphs.Item(k).Range.Font.Name:='宋体';
end;//w
finally
WordApplication1.Disconnect;
end;
lshstr1:=''; switch1:=0;

end;
 
WordDocument1.Range.Cut;
 
接受答案了.
 
后退
顶部