Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-01-2019, 10:57 PM
tcsh tcsh is offline
Member
 
Join Date: Sep 2016
Posts: 37
Arrow Open .doc - search and copy some text

Hi,

I have a few thousand .doc files all filled in with data following a pretty simple pattern/template.

Example:
Code:
NAME:
SURNAME:
AGE:
ADDRESS:
DATE:
I'd like to open the .doc in my delphi application, search for NAME: then identify, select and copy to clipboard EVERY BIT of text that starts right after NAME: all the way to where SURNAME: starts.

Example:
Code:
NAME: JOSH
SURNAME: JIM
It should copy JOSH to the clipboard.

Example #2:

Code:
NAME: JOSH 
JOSH
SURNAME: JIM
It should copy JOSH JOSH to the clipboard.

Example #3:
Code:
NAME: JOSH          JOSH
JOSH
SURNAME: JIM
It should copy JOSH JOSH JOSH to the clipboard.

Basically, should start copying everything starting right after : from the NAME: and stop right before S from/where SURNAME: starts.

Code so far:

Code:
procedure TForm1.Button2Click(Sender: TObject);
var
  WordApp : Variant;
  TextToFind : String;
  i: integer;
  fname: string;

 begin
  WordApp := CreateOleObject('Word.Application');
  WordApp.Visible := True;
  for i := 1 to 3 do

   begin
   fname := Memo1.Lines[i - 1];
   Wordapp.Documents.Open('C:\Users\tcsh\Desktop\A\'+fname);
   TextToFind :='NAME:';
   WordApp.Selection.Find.Execute(TextToFind);
   WordApp.Selection.Copy;
   Memo2.SetFocus;
   Memo2.PasteFromClipboard;
   end;

 end;
Managed to locate the .doc, open it, find NAME: and select it, copy it and paste it in Memo2 from the clipboard. Obviously, I need the text after NAME: as explained above and that's where I'm stuck.

Could anyone add to the code so I can get this done ?

Appreciate it.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:05 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.