DELPHI 对WORD 文档的操作?????????????

guosq 2003-07-08 12:45:37
我需要在paradox数据中保存WORD 文档。我该用那种字段类型。
在DELPHI 里如何通过程序自动把WORD 文档的内容保存到数据库。
另外下面这个语名的参数那么写:
WordDocument.Range.InsertFile( );
...全文
66 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
guosq 2003-07-09
  • 打赏
  • 举报
回复
结贴:things(平) (100)
lii39611 2003-07-09
  • 打赏
  • 举报
回复
up
DWGZ 2003-07-08
  • 打赏
  • 举报
回复
二进制类型呗,用文件流写进去
第二个不知道
wangguan007 2003-07-08
  • 打赏
  • 举报
回复
关注!!
waller 2003-07-08
  • 打赏
  • 举报
回复
<电脑编程技巧与维护> 杂志 2003年6期开始专门介绍了delphi对word的操作.
去他们网站上去下载源代码看看.如果看具体的介绍可能只能买杂志了.
things 2003-07-08
  • 打赏
  • 举报
回复
如果使用SERVER控件,就使用WordApplication, 将WordDocument换成WordApplication,肯定没问题:WordDocument.Range. 使用 WordApplication.Selection.替换
----------------TWordApplication控件

WordApplication1.Selection.InsertFile('E:\aaa.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
WordApplication1.Selection.InsertFile('E:\Shi.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
zhouhaijun2 2003-07-08
  • 打赏
  • 举报
回复
如果采用我所讲的办法,就将:
word_sj.documents.item(1).saveas('第一个文件.doc');
换成word_sj.documents.item(1).saveas('第一个文件bak.doc');
tblobfield(Table1.FieldByName('xxx')).loadfromfile('第一个文件.doc');
换成tblobfield(Table1.FieldByName('xxx')).loadfromfile('第一个文件bak.doc');
guosq 2003-07-08
  • 打赏
  • 举报
回复
不行啊
最后一个文件把前边的文件给覆盖了。
things 2003-07-08
  • 打赏
  • 举报
回复
继续直接插入:
WordDocument.Range.InsertFile('E:\aaa.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
WordDocument.Range.InsertFile('E:\Shi.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
zhouhaijun2 2003-07-08
  • 打赏
  • 举报
回复
WordDocument.Range.InsertFile(filename,[range],[confirmconversion],[link],attachment])
zhouhaijun2 2003-07-08
  • 打赏
  • 举报
回复
use comobj,word97
...

var word_sj:Variant;
lastparagraph:Integer;
BEGIN
word_sj:=createoleobject('word.application');
word_sj.documents.open('第一个文件.doc');
word_sj.documents.item(1).Range.InsertAfter(#13);
word_sj.documents.open('第二个文件.doc');
word_sj.documents.item(1).range.copy;
word_sj.documents.item(1).close;
lastparagraph:=word_sj.documents.item(1).paragraphs.count;
word_sj.documents.item(1).paragraphs.item(lastparagraph).range.Paste;
word_sj.documents.item(1).saveas('第一个文件.doc');
word_sj.documents.item(1).close;
Table1.Close;
Table1.open;
Table1.Append;
tblobfield(Table1.FieldByName('xxx')).loadfromfile('第一个文件.doc');
Table1.Post;
Table1.Close;
END;
linkyou 2003-07-08
  • 打赏
  • 举报
回复
使用wordappalication 组件,代码如下
启动Word时用如下代码:
begin
try
Wordapplication.Connect;
except
MessageDlg(’Word may not be installed’, mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := ’Delphi automation’;
end;

关闭Word用如下代码。如果想保存Doc文件,请修改SaveChanges变量的内容:
var
SaveChanges, OriginalFormat, Routedocument. OleVariant;
begin
SaveChanges := WdDoNotSaveChanges;
OriginalFormat := UnAssigned;
Routedocument.nbsp:= UnAssigned;
try
WordApplication.Quit(SaveChanges, OriginalFormat, Routedocument.;
WordApplication.Disconnect;
except
on E: Exception do
begin
Showmessage(E.Message);
WordApplication.Disconnect;
end;
end;
end;

让Word打开一个指定的文件,需要先放置OpenDialog,然后调用WordApplication.document..Open:
var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
Passworddocument. PasswordTemplate, Revert,
WritePassworddocument. WritePasswordTemplate, Format: OleVariant;
begin
if not dlgOpen.Execute then
Exit;

{Open document.
FileName := dlgOpen.FileName;
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
Passworddocument.nbsp:= ’’;
PasswordTemplate := ’’;
Revert := True;
WritePassworddocument.nbsp:= ’’;
WritePasswordTemplate := ’’;
Format := wdOpenFormatdocument.

WordApplication.document..Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, Passworddocument. PasswordTemplate,
Revert, WritePassworddocument. WritePasswordTemplate, Format );

{Assign Worddocument.nbspcomponent}
ItemIndex := 1;
Worddocument.ConnectTo(WordApplication.document..Item(ItemIndex));

{Turn Spell checking of because it takes a long time if enabled and slows down Winword}
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
end;

让Word替换标记字符串要使用Worddocument.Range.Find.Execute,这里用Delphi替换了<#Name>:
var
FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike,
MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace: OleVariant;
begin
FindText := ’<#Name>’;
MatchCase := False;
MatchWholeWord := True;
MatchWildcards := False;
MatchSoundsLike := False;
MatchAllWordForms := False;
Forward := True;
Wrap := wdFindContinue;
Format := False;
ReplaceWith := ’Delphi’;
Replace := True;

Worddocument.Range.Find.Execute( FindText, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, ReplaceWith, Replace );

end;
guosq 2003-07-08
  • 打赏
  • 举报
回复
如果我在打开第一个文件之后,我希望把第二个文件插入到第一个文件的后面。
这该如何实现?
things 2003-07-08
  • 打赏
  • 举报
回复
换成你的文件名:
WordDocument.Range.InsertFile('e:\1.doc', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
things 2003-07-08
  • 打赏
  • 举报
回复
上面好象不行,试试这个:
WordDocument.Range.InsertFile('E:\aaa.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
guosq 2003-07-08
  • 打赏
  • 举报
回复
我是这样写的
WordDocument.Range.InsertFile('e:\1.doc');
出现了下列错误
[Error] Unit1.pas(85): Not enough actual parameters
things 2003-07-08
  • 打赏
  • 举报
回复
写成这样看看:
WordDocument.Range.InsertFile(FileName:='e:\1.doc');
windwather 2003-07-08
  • 打赏
  • 举报
回复
up
guosq 2003-07-08
  • 打赏
  • 举报
回复
我是这样写的
WordDocument.Range.InsertFile('e:\1.doc');
guosq 2003-07-08
  • 打赏
  • 举报
回复
楼上,
[Error] Unit1.pas(85): Not enough actual parameters
加载更多回复(3)

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧