我现在将word文档以流的形式存入数据库中,如何实现word文档内字符查找?
可以通过Delphi读取word转化成Txt格式吗?

解决方案 »

  1.   

    Function WordRepOK(WordFilename:String;Merfnbr:Integer):Boolean;
    var wordapp,workbook:variant;
        sText,rText:String ;
    begin    try
           wordApp:=CreateOleObject('word.Application');
           WorkBook:=CreateOleobject('Word.Document');
        except
           application.MessageBox('您的机器里未安装Microsoft Word 2000!','错误',0);
           Exit;
        end;
        try
           Application.ProcessMessages;
           workbook:=WordApp.Documents.Open(WordFilename);
           workBook.select;
           Application.ProcessMessages;
           With Form1.Query2 do
           begin
             Close;
             SQL.Clear;
             SQL.Add('Select * from bidname where merfnbr='+IntToStr(Merfnbr));
             Open;
             First;
           end;
           //替换文号
           sText:='<#VAR_ZBID>';
           rText:=FormatFloat('000',Form1.Query2.FieldValues['merfnbr']);
           WorkBook.Range.Find.Execute(sText,,,,,,,,,rText,True) ;
           //替换名称
           sText:='<#VAR_ZBNAME>';
           rText:=Form1.Query2.FieldValues['mename'];
           WorkBook.Range.Find.Execute(sText,,,,,,,,,rText,True) ;
           
           Application.ProcessMessages;
           WorkBook.Close;
           wordApp.Quit;
           wordApp:=Unassigned;
         except
           application.MessageBox('不能正确操作word文件。可能是该文件已被其他程序打开,或系统错误。','提示',0);
           WorkBook.close;
           wordApp.Quit;
           wordApp:=Unassigned;
      end;
    end;以上希望对你有所帮助