为了300分,我奋斗了一个上午[
]
终于~~楼主!!我来领分啦~~~300 分哦~~有钱养老了。
做成了DEMO,到http://crazycock.ys168.com 下载例程。
这里也把代码贴出来给大家:)
------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtnrs, WordXP, OleServer, ExtCtrls,clipbrd,jpeg;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
WordDocument1: TWordDocument;
WordApplication1: TWordApplication;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
DocFile:OleVariant;
//
findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
matchallwordforms, Oforward, wrap, format, replacewith, replace,
matchchashida,matchdiacritics,matchalef,matchcontrol: olevariant;
begin
WordApplication1.Connect;
WordApplication1.Visible:=true;
DocFile:=ExtractFilePath(ParamStr(0))+'记事本.doc';
//打开doc
WordApplication1.Documents.Open(DocFile,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam);
//关闭拼音查找和语法查找,以便提高程序运行的效率
WordApplication1.Options.CheckSpellingAsYouType := False;
WordApplication1.Options.CheckGrammarAsYouType := False;
//设置参数
findtext := '<#图片1>';
matchcase := false;
matchwholeword := true;
matchwildcards := false;
matchsoundslike := false;
matchallwordforms := false;
Oforward := true;
wrap := wdfindcontinue;
format := false;
replacewith := '<#图片1>';
replace := False;
matchchashida := false;
matchdiacritics := false;
matchalef := false;
matchcontrol := false;
//这种方式不会改变选择的文本
// worddocument1.range.find.execute( findtext, matchcase, matchwholeword,
// matchwildcards, matchsoundslike, matchallwordforms, Oforward,
// wrap, format, replacewith, replace,
// matchchashida,matchdiacritics,matchalef, matchcontrol );
//定位到目的地,并选中需要更换的文本
WordApplication1.Selection.Find.Execute(findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms, Oforward,
wrap, format, replacewith, replace,
matchchashida,matchdiacritics,matchalef, matchcontrol);
//加载图片
Image1.Picture.LoadFromFile(ExtractFilePath(ParamStr(0))+'MM.jpg');
ClipBoard.Open;
Clipboard.Assign(Image1.Picture);
Clipboard.Close;
//粘贴
WordApplication1.Selection.Paste;
end;
end.