DELPHI 对WORD 文档的操作????????????? 我需要在paradox数据中保存WORD 文档。我该用那种字段类型。在DELPHI 里如何通过程序自动把WORD 文档的内容保存到数据库。另外下面这个语名的参数那么写:WordDocument.Range.InsertFile( ); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1。2。TBlobField(Query.FieldByName('word')).LoadFromFile(Opendialog.Filename);3。WordDocument.Range.InsertFile(FileName:=Opendialog.Filename); ------------------- 可用WordApplication.Selection.代替(如果上面语句出错) 楼上WordDocument.Range.InsertFile有五个参数,我不知道这五个参数如何设置 楼上,[Error] Unit1.pas(85): Not enough actual parameters 我是这样写的WordDocument.Range.InsertFile('e:\1.doc'); 写成这样看看:WordDocument.Range.InsertFile(FileName:='e:\1.doc'); 我是这样写的WordDocument.Range.InsertFile('e:\1.doc');出现了下列错误[Error] Unit1.pas(85): Not enough actual parameters 上面好象不行,试试这个:WordDocument.Range.InsertFile('E:\aaa.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam); 换成你的文件名:WordDocument.Range.InsertFile('e:\1.doc', EmptyParam, EmptyParam, EmptyParam, EmptyParam); 使用wordappalication 组件,代码如下启动Word时用如下代码: begintry 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; use comobj,word97...var word_sj:Variant; lastparagraph:Integer;BEGINword_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; WordDocument.Range.InsertFile(filename,[range],[confirmconversion],[link],attachment]) 继续直接插入:WordDocument.Range.InsertFile('E:\aaa.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);WordDocument.Range.InsertFile('E:\Shi.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam); 如果采用我所讲的办法,就将: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'); 如果使用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); <电脑编程技巧与维护> 杂志 2003年6期开始专门介绍了delphi对word的操作.去他们网站上去下载源代码看看.如果看具体的介绍可能只能买杂志了. 用delphi 如何实现程序间即时通信,其原理是怎样的 子类如何隐藏父类的属性 学好了软件开发,以后转做系统管理维护或网管等工作是不是易如反掌?在线等待!!!急啊! delphi5中。报表打印不能换行(字段类型不能为memo) Delphi ladar chart如何实现? 关于TABLE,DBGRID,报表的几个问题,请关注! 想问问题却苦于没有分数的朋友请进。 请教如何将C语言程序转换成DELPHI语言(关于关键路径算法的)~ 求解一下下面这段代码的意思 如何在DELPHI中打开ACCESS数据库文件? 关于密码修改问题!!!! database問題
-------------------
可用WordApplication.Selection.代替(如果上面语句出错)
WordDocument.Range.InsertFile
有五个参数,
我不知道这五个参数如何设置
[Error] Unit1.pas(85): Not enough actual parameters
WordDocument.Range.InsertFile('e:\1.doc');
WordDocument.Range.InsertFile(FileName:='e:\1.doc');
WordDocument.Range.InsertFile('e:\1.doc');
出现了下列错误
[Error] Unit1.pas(85): Not enough actual parameters
WordDocument.Range.InsertFile('E:\aaa.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
WordDocument.Range.InsertFile('e:\1.doc', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
启动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;
...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;
WordDocument.Range.InsertFile('E:\aaa.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
WordDocument.Range.InsertFile('E:\Shi.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
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');
----------------TWordApplication控件 WordApplication1.Selection.InsertFile('E:\aaa.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
WordApplication1.Selection.InsertFile('E:\Shi.txt', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
去他们网站上去下载源代码看看.如果看具体的介绍可能只能买杂志了.