WPCubed Product Support

Mailmerge insert HTML table - repeat header, borders

I am using mailmerge in WPTools 7 to insert HTML tables into a document, it works very good except for two things that just wouldn't work:

  1. Repeat header of the table on subsequent pages
  2. paint borders only between rows not around the table.

Any hint is very appreciated!

Thanks

Michael

#1 ♥ 0
17.5k Views 2 users 1 ♥ read 5 min
wpsupport

HTML does not support headers of tables - this is only supported by WPTools and a few RTF consumers.

I don't know what border flags you need. In special cases it makes sense to change the code in WPIOHTML.pas to writen the CSS styles you need. I do not exactly know which one you need-

#2 ♥ 0

Thanks. I would like to have the inner table lines in light grey. I will have a look at wpiohtml.pas.

#3 ♥ 0

Would it be possible to access the created table from within the implementation of wpMailMergeGetText? Then I could code styles into the bookmarks and implement them on the resulting table object using the power of WPTools.

#4 ♥ 0
wpsupport

The table can be accessed through Contents.MergePar

You can access the ...ParentRow and ...ParentTable to modify the parameters there.

#5 ♥ 0

As this is not processed on in wpMailMergeGetText I will collect the objects while merging and process them after the megre process is complete. This should work. Thanks.

#6 ♥ 0

Unfortunately it just wouldnt work:

I store all content.mergepar in wpMailMergeGetText for all tables I insert. Either in wpMailMergeGetText and after completion of the merge both parentRow and parentTable are NIL.

How can I find the table objects I merged into?

#7 ♥ 0
wpsupport

I think I need more information.

parentRow is valid IF the field is in a table cell. If you are inserting a table inside the event, it does not help of course.

#8 ♥ 0

Sorry that I did not make it clear.

A template is loaded as docx, all the variables are just test phrases and are marked as bookmarks and get overwritten. One of the variables will be overwritten by a complete table served as html. I was hoping to find that table (or tables) later in the process along with theit bookmark names to do additional formatting like repeating headers and cell lines.

It would be great if I could somehow access the (table-)object that was created by the merge process.

Thanks

Michael

#9 ♥ 0
wpsupport

You have access to all the paragraphs and tables, rows and cells after the text was created or modified.

You can enumerate the paragraphs in a loop with

par := WPRichText.FirstPar;

while par<>nil do

begin

..

par := par.NextPar;

end;

This will find all first level paragraphs and tables (not the rows). The rows are inside a table paragraph - use the ChildPar reference.

For example see the wptools code, i.e. procedure TWPCustomRtfEdit.GetSelectedCells(All, Outer: TList); in WPCtrMemo.

#10 ♥ 0

Thanks. I created this loop and found the table(s). Sorry for bugging again, but I can not find out how to reformat the table to make the frst row recurring on subsequent pages and how to create grey lines between the rows. The examples worked with callbacks on page creation, this I cannot use here.

Would you mind helping me out and showing how to:

  • using the "par" below make the first row recurring
  • optinally draw lines between the rows

Thanks in advance

par := wp.firstPar;
while par <> nil do
  begin
    if par.IsTable then begin
       // And now, what's next?
    end;
    par := par.nextPar;
  end; 

Sorry

#11 ♥ 0
wpsupport

When you have a table you can loop the rows:

row := par.ChildPar;

while row<>nil do

begin

...

row := row.ParNext;

end;

Inside a row it is the same with cells, they are the children of the row.

This are all references to TParagraph so you can use the sample code from the example (callback).

BTW - in HTML there are no repeating headers.

#12 ♥ 1

So finally I nearly got everything how I want it. The last thing I need help with: How do I make the first row of the table the repeating header.?I did not find a WPAT code for that. Would you mind helping me with this? Thanks in Advance!

par := wp.firstPar;
  while par <> nil do
  begin
    if par.IsTable then
    begin
      first := true;
      row := par.Childpar;
      while row <> nil do
      begin
        //
        if not first then
        begin
          cell := row.Childpar;
          while cell <> nil do
          begin
            cell.ASet(WPAT_BORDERFLAGS, WPBRD_DRAW_TOP);
            cell.ASetColor(WPAT_BORDERCOLORT, clSilver);
            cell := cell.nextPar;
          end;
        end
        else
        begin
          begin
            row.ASetColor(WPAT_BGColor, clSilver);
            row.ASet(WPAT_ShadingValue, 30);
            first := false;
          end;
        end;
        row.ASet(WPAT_ParKeepN, 1);
        row := row.nextPar;
      end;
    end;
    par := par.nextPar;
  end;
  wp.ReformatAll;

P.S. I am aware of the fact, that HTML does not support repeating headers, I was jiust thining that one could use <th> for Headers that are repeated in the document.

#13 ✎ ♥ 0

After writing the last entry I found it out, it is amazingly easy:

row.IncludeProp(paprIsHeader);
#14 ♥ 0
This category is archived. No new posts are possible.