WPCubed Product Support

Programatically Merge Table Cells

I generate a table in code and then want to merge the entire top row. I tried:

par := wpRichText.TableAdd(numCols, numRows, [wptblActivateBorders], nil, CallBack);  for i := 0 to par.TableRow.ColCount-2 do    par.TableRow.Cols[i].MergeCell(true);

however the tableAdd function does not return the table Paragraph but some other paragraph. Therefore I tried:

wpRichText.BeginTable('TABLE', 0, 0, 0);
  wpRichText.TableAdd(numCols, numRows, [wptblActivateBorders], nil, CallBack);
  if wpRichText.MoveToCell(0,0,'TABLE') then
    for i := 0 to wpRichText.TableRow.ColCount-2 do 
      wpRichText.TableRow.Cols[i].MergeCell(true);
  wpRichText.EndTable;

But that also doesn't merge the table columns in the first row
Any suggestions?

#1 ♥ 0
3.7k Views 1 links 2 users read 2 min
support

Hi,

You can use this callback function for this:

procedure TForm1.TableAddCallBack(RowNr, ColNr: Integer; par: TParagraph);begin  // Merge first row  if RowNr=1 then  begin     if ColNr>1 then        include(par.prop, paprColMerge)     else par.SetText('Text in first column');  end;end;

or, since TableAdd returns the first cell in first row

par := wpRichText1.TableAdd(3, 5, [wptblActivateBorders], nil, nil);
    par.SetText('Text in first column');
    while par.NextPar<>nil do
    begin
       par := par.NextPar;
       include(par.prop, paprColMerge);
    end;

also see:
[](http://www.wpcubed.com/manuals/wptools5/IDH_TWPCustomRtfEdit_TableAdd.htm)

I hope this helps,

Julian

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