简单问题:如何将输出内容生成.doc文件?(50分)

  • 主题发起人 主题发起人 piao321
  • 开始时间 开始时间
P

piao321

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将输出内容生成.doc文件?
 
嫌分少?
 
很简单,
下面的代码你看看就知道了,
strxxxxxxxxxxx就是你要写的内容。
___________________________________
var
FWord: Variant;
FDoc: Variant;
// FRange: Variant;
begin
Screen.Cursor := crHourGlass;
try
FWord := CreateOleObject('Word.Application');
FWord.Visible := True;//显示word,如果想在后台处理则不要这句

except
Screen.Cursor := crDefault;
ShowMessage('创建word对象失败!');
Exit;
end;

try
FDoc := FWord.Documents.Add;
FWord.Selection.TypeText(Text := strxxxxxxxxxxxxxxx);//你要写的文本
FWord.ChangeFileOpenDirectory('C:/Documents and Settings/Administrator/桌面/');//你要存入的目录
FWord.ActiveDocument.SaveAs(
FileName:='1111111111.doc',
FileFormat:=wdFormatDocument,
LockComments:=False,
Password:='',
AddToRecentFiles:=True,
WritePassword:='',
ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:=False,
SaveNativePictureFormat:=False,
SaveFormsData:=False,
SaveAsAOCELetter:=False);
finally
Screen.Cursor := crDefault;
//如果是在后台处理的,还要关闭word,用Fword.quit就就可以了
end;
 
看看delphi的demo好了
 
多人接受答案了。
 
谢谢二位!
 
后退
顶部