WPCubed Product Support

Read document from end to end and replace terms

I need to read a document from end to end, looking at each paragraph and right term to replace it without losing formatting.

Thanks,

Andreas

#1 ♥ 0
6.9k Views 3 users read 1 min

What about setting the DefaultIOFormat to WPTools, capture the document in a string using .AsString, apply your replacements using StringReplace and then return to the document again using .AsString

#2 ♥ 0
support

Hi,

I recommend to create a loop like

par := WPRichText.FirstPar;
while par<>nil do
begin
par.SetText ...
par := par.Next;
end;

Inbetween you can uzse all the low level functions in TParagraph, set attributes, insert or change text etc.

#3 ♥ 0

I thank all the answers.

Solved the problem as follows.

repeat
   WPRichText1.ActiveParagraph;
   WPRichText1.SelectParagraph;

   if (WPRichText1.ActiveParagraph.GetText <>'') then
     ...
   begin
not until WPRichText1.CPMoveDownPar;
#4 ♥ 0
support

Hello,

CPMoveDownPar moves the cursor - it is not a good way for programatic changes in the document.

If you want to work with the ActiveParagraph, you can still do

if WPRichText1.ActiveParagraph.next <> nil then
WPRichText1.ActiveParagraph := WPRichText1.ActiveParagraph.next
else break;

#5 ♥ 0
This category is archived. No new posts are possible.