WPCubed Product Support

MailMerge: Replace mail merge field with table

I would like to replace a mail merge field with a table. I do it like that:

In

OnGetTextToInsert(Sender: TObject; const inspname: String; const Contents: TWPMMInsertTextContents; var Done: Boolean)

I use Contents.MergePar.AppendNewTable() and so on.

This basically inserts the table but above the table the name of the merge field is visible. It seems that it left the paragraph with the mail merge field untouched and instead it appended a new paragraph and added the table to that new paragraph.

I would rather like the table inside the paragraph where the merge field resides. I couldn't find an "InsertNewTable" instead of an "AppendNewTable". But maybe my whole approach is wrong.

Can you please explain to me how I can insert a table in a mail merge?

Many thanks in advance,

Dirk.

#1 ♥ 0
10.1k Views 2 users read 3 min
support

Right now it works like that - the start and end field marker remain and the table is inserted between. It is not inserted INSIDE that paragraph since a table is not an object like an image but a paragraph object.

You can hide the fields though.

#2 ♥ 0

Thank you for your answer.

Can you tell me how I can hide it?

#3 ♥ 0
support

InsertPointAttr.Hidden := true should hide it.

#4 ♥ 0

I tried that already but it doesn't work. Setting this property makes the red << >> markers disappear but not the field name.

I also tried ShowMergeFieldNames:=false which sounded like the right parameter but the fields names are still shown.

So, still the question is: how to make the field name disappear?

#5 ♥ 0
support

Hi,

I read your original post incorrectly.

You used "Contents.MergePar.AppendNewTable() " which is the incorrect way to add a table inside a field because it does not add it INSIDE the field but under the paragraph which contained the field.

You need to call the TWPRichText directly.

First ClearSelection and then

function AddTable(colcount, lincount: Integer; Border: Boolean = TRUE)
: TParagraph;

#6 ♥ 0

I am afraid I still don't get it. Hier is my code:

procedure TRtfSerienbriefMgr.OnGetTextToInsert(Sender: TObject;
  const inspname: String; const Contents: TWPMMInsertTextContents;
  var Done: Boolean);
var
  lRtf: TWPRichText;
  lPar: TParagraph;
begin
  if (inspname = 'OIMMO_TABELLE_TYP1') then
  begin
    lRtf := TWPMMDataProvider(Sender).EditBox as TWPRichText;
    lRtf.ClearSelection;
    lPar := lRtf.ActivePar.AppendNewTable;
// use lPar to populate table
  end;
  Done := true;
end;

This at least doesn't show the merge field name anymore (thanks to ClearSelection) but still the table is appended below the merge field and does not replace the field itself.

I assume it's either because I call "AppendNewTable" or I use ActivePar. I don't want to use the AddTable method because I want to create the table row by row in a loop.

I would really appreciate if you could give me a few lines of code that show how you would implement OnGetTextToInsert.

Regards,
Dirk.

#7 ♥ 0
support

As I wrote, You need to call the TWPRichText directly : WPRichText1.AddTable.

Example:

procedure TForm2.WPRichText1MailMergeGetText(Sender: TObject;
  const inspname: string; Contents: TWPMMInsertTextContents);
begin
  if inspname='TEST' then
  begin
      WPRichText1.ClearSelection;
      WPRichText1.AddTable(3,3,true);
  end;
end;
#8 ♥ 0
This category is archived. No new posts are possible.