Search and set the cursor as edit point

Questions and answers on how to use DOCXReadWrite
Post Reply
MaxChan
Posts: 19
Joined: Sat Sep 03, 2016 6:38 am

Search and set the cursor as edit point

Post by MaxChan »

I want to find the 'Tag string', then replace the Tag string with Para Bullet. I cannot location the cursor to the "Tag String', any idea?

DOCX.Editor.Selections.Clear;
DOCX.Editor.FindReplace.BeginFind('Tag string');

// What code for the cursor to point at the search tag index?

// Start bullets. The next paragraph added will be a bullet paragraph.
DOCX.Editor.BeginBullet;
// Add paragraphs with bullets.
DOCX.Editor.AppendPara('First bullet row');
DOCX.Editor.AppendPara('Bullet 2');
DOCX.Editor.AppendPara('Bullet 3');
// Stop bullet paragraphs. The next paragraph added will not have a bullet.
DOCX.Editor.EndBulletNumbering;
DOCX.Editor.Selections.Clear;
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Search and set the cursor as edit point

Post by larsa »

Hello

Here is a sample:

Code: Select all

var
  i   : integer;
  Para: TAXWLogPara;
begin
  DOCX.Editor.MainDoc.Selections.Clear;
  DOCX.Editor.MainDoc.FindReplace.BeginFind('MyFindText');

  if DOCX.Editor.MainDoc.FindReplace.FindNext then begin
    // Will insert paras after the found text. To insert before, remove: + 1
    i := DOCX.Editor.MainDoc.FindReplace.CurrPos.Para.Index + 1;

    DOCX.Editor.MainDoc.BeginBullet;

    Para := DOCX.Editor.MainDoc.Paras.Insert(i);
    Para.PlainText := 'First bullet row';

    Para := DOCX.Editor.MainDoc.Paras.Insert(i + 1);
    Para.PlainText := 'Bullet 2';

    Para := DOCX.Editor.MainDoc.Paras.Insert(i + 2);
    Para.PlainText := 'Bullet 3';

    DOCX.Editor.MainDoc.EndBulletNumbering;
  end;
end;
Lars Arvidsson, Axolot Data
Post Reply