注册 登录
编程论坛 Delphi论坛

求助大神,用delphi7 怎样替换wrod文档所有文本框中相同内容

tzdliutao 发布于 2017-08-02 14:32, 2652 次点击
需要用delphi代码把所有文本框中的“数量”替换成“产品量”
只有本站会员才能查看附件,请 登录


unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleServer, Word2000,comobj;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
 msword : Variant ;
begin
  MSWord:=CreateOLEObject('Word.Application');
  MSWord.Documents.Open(FileName:='G:\商务文件.doc');
  MSWord.Visible := 1;
  msword.selection.find.clearformatting;
  msword.selection.find.replacement.clearformatting;
  msword.selection.find.text:=‘数量’ ;
  msword.selection.find.replacement.text:=‘产品量’ ;
  msword.Selection.Find.Execute(Replace:=wdreplaceall);
end;
end.
为什么图上黑色框住的两个“数量”能替换,文本框中的数量就不能替换呢?
求大神指教
1 回复
#2
wzqoo2017-08-04 15:53
文本框和文档中的文本应该是2个不同的对象吧,查找一下文本框然后替换。
1