- Offizieller Beitrag
Q: I need to repeat one row in a letter which contains merge fields N times to add data from a query.
A: You can use this procedure. It locates the first row by searching for the text "repeatrow".
Code
procedure TForm1.MultiplyRowClick(Sender: TObject);
var i,j,n, pos : Integer;
s : string;
begin
WPRichText1.BeginUpdate;
try
WPRichText1.Finder.ToStart;
N := 10;
if WPRichText1.Finder.Next('repeatrow') then
begin
// Repeat this row N times ----------------------------------
// First we copy the text
WPRichText1.CPPosition := WPRichText1.Finder.FoundPosition;
WPRichText1.SelectRow;
s := WPRichText1.SelectionAsString;
WPRichText1.HideSelection;
// Now we append N rows and insert the copied text
for j:=1 to N-1 do
begin
WPRichText1.InsertRow;
WPRichText1.TableColNumber := 0;
pos := WPRichText1.CPPosition;
WPRichText1.SelectionAsString := s;
WPRichText1.CPPosition := pos;
// We mark the current row to be able to locate the copy:
for i:=0 to WPRichText1.TableColCount-1 do
begin
WPRichText1.TableColNumber := i;
WPRichText1.CurrAttr.CellCommand := 'ROW' + IntToStr(j);
end;
end;
// The text replacement can now be made but the
// WPRichText1.CurrAttr.CellCommand can be used to detect multiple rows.
end;
finally
WPRichText1.EndUpdate;
end;
end;
Alles anzeigen