word 查找 所在页行列

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ComObj, ComConst,ShellAPI,Word2000 ;

 

procedure TForm1.Button1Click(Sender: TObject);
var
  WordApp: Variant;//word对象
  Jpath:string;//word文件路径
  Jword:string;//要查询的字段
  myrange:variant;
  flag:integer;//文档中是否有所查字段的判断标志
  i:integer;//字段所在的当前页号
  a,b,c,aaa:integer;
begin
 try
  Jpath:=edit1.text;//获得WORD文件路径
  Jword:=edit2.Text;//获得所查字段
  WordApp:=CreateOleObject('Word.Application');
  WordApp.Documents.Open(Jpath);
  memo1.Lines.clear;

  a := WordApp.Selection.Information[wdActiveEndPageNumber] ;
  b := WordApp.Selection.Information[wdFirstCharacterLineNumber];
  c := WordApp.Selection.Information[wdFirstCharacterColumnNumber] ;
  Memo1.Lines.Add(IntToStr(a));
  Memo1.Lines.Add(IntToStr(b));
  Memo1.Lines.Add(IntToStr(c));

  aaa := WordApp.Selection.Information[wdNumberOfPagesInDocument] ;
  Memo1.Lines.Add(IntToStr(aaa));

  myRange:=WordApp.ActiveDocument.Content;
  flag:=0;
  while myRange.Find.Execute('sub') <> False do//查询     //(FindText:=Jword,Forward:=True
    begin
      i:=myRange.Information[wdActiveEndPageNumber];//获得字段所在页号
      b := myRange.Information[wdFirstCharacterLineNumber];
      c := myRange.Information[wdFirstCharacterColumnNumber] ;
      memo1.Lines.add(Jword+'在第'+inttostr(i)+'页,'+inttostr(b)+'行,'+inttostr(c)+'列。');
      flag:=flag+1;
    end;
  if flag=0 then
    application.messagebox('没有找到。','查询结果',mb_ok);
 finally
  wordApp.Quit;
  wordApp:=unassigned;
 end;

end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值