WPCubed Product Support

Border around a single table element

It seems this should be a simple task but I can't find how to set a border around the outside of a table with no borders inside the table, around a row without placing borders on the cells, and around a single cell while other cells are borderless.

Any help appreciated!

Tom

#1 ♥ 0
6.3k Views 2 users read 4 min
support

If you use the new WPTools V6.16 you can use select the table and use the Inner and Outer Border actions of the toolbar.

Using code you can do this:

WPRichText1.AddTable(5,10, false);
  WPRichText1.SetInnerCellBorders(false, 1, wpapTable);
  WPRichText1.SetOuterCellBorders(true, 1, wpapTable);
#2 ♥ 0

I forgot to mention that I am building and loading the tables in code.

Version 6.14 is the latest available in my download area. I don't know if that affects the following.

I'm creating my tables using CreateTable. I tried using SetInnerCellBorders and SetOuterCellBorders as shown but no borders were created. I couldn't find any documentation so I don't know if the TWPParagraphBordApply type should also allow these methods to border a row and a single cell as well.

Is there a working demo using these methods? Any more information that will help me to place an outer border on a table and on a row within the table.

Thanks.

#3 ♥ 0
support

Hi,

the download area should now show 6.16. It always shows the date of the last upload.

To understand the borders you need to know:

  • tables dont have borders
  • rows dont have borders
  • only cells have borders, left, top right and bottom.

They are activated through the bitfield WPAT_BorderFlags, i.e.
cell.ASetAdd(WPAT_BorderFlags, WPBRD_DRAW_Right)

When you create the table you need to set the left border in the first cell, the righjt in the last in one row. And only in the cells in first row and last row the top and bottom border. All those are "outer" cells.

The methods SetInnerCellBorders and SetOuterCellBorders are (in V6.16) just a shortcut to the method

procedure SetBorderProperties(Inner, Outer: TWPTextStyle;         ApplyMode :   TWPParagraphBordApply;         Mode : TWPUpdateBorderProperties =         [wpSetBorderFlags,   wpSetBorderType,   wpSetBorderWidth,  wpSetBorderColor,  wpSetParColor,  wpSetParShading]);

It will apply the selected attributes (Mode!) stored in "Outer" to the outer cell borders, and the attributes stored for Left and Top borders in "Inner" to the inner cells.

If it is applied to one cell only it just uses the "Outer" definition.

Since SetInnerCellBorders is a shortcut, it also serves as a good example to how to use the SetBorderProperties method:

procedure TWPCustomRtfEdit.SetInnerCellBorders(Activate: Boolean; BorderWidth: Integer = -1; Mode : TWPParagraphBordApply = wpapSelection);
var Inner, Outer: TWPTextStyle;
begin
   Inner := TWPTextStyle.Create(RTFData.RTFProps);
   Outer := TWPTextStyle.Create(RTFData.RTFProps);
   try
       if Activate then Inner.ASet(WPAT_BorderFlags, 15);
       if BorderWidth>=0 then
       begin
           Inner.ASet(WPAT_BorderWidthL, BorderWidth);
           Inner.ASet(WPAT_BorderWidthT, BorderWidth);
           SetBorderProperties(Inner, Outer, Mode, [wpSetInnerBorderFlags,wpSetBorderWidth]);
       end else
       SetBorderProperties(Inner, Outer, Mode, [wpSetInnerBorderFlags]);
   finally
     Inner.Free;
     Outer.Free;
   end;
end;

Here you see how it prepares the "Inner" Style, "Outer" is just empty.

By default it works like the "Border Inner" action, it applies only the inner lines to a selection in a table. It was designbed to leave the outer lines alone.

If you create your table in code You could of course create it without any lines and, at the end, when you are in the last cell, call

SetOuterCellBorders(true, -1, wpapTable).

Regards,

Julian

#4 ♥ 0

Julian,

Your explanation furthered my understanding of borders and how they're applied but I still cannot build a working example setting the inner and outer borders.

This is one of many trials. Can you tell me what I am missing in my attempt to place an outer border on a 2x2 table?

Thanks again.

procedure TfrmMain.CreateATable;
begin
  with rteMain.ActiveText.CreateTable(nil) do
  begin
    with CreateRow(nil, True) do
    begin
      InputCell.SetText('Cell 5');
      InputCell.SetText('Cell 6');
      EndRow(ThisRowStyle)
    end;
    with CreateRow(nil, true) do
    begin
      InputCell.SetText('Cell 7');
      InputCell.SetText('Cell 8');
      EndRow(ThisRowStyle)
    end;
  end;
  rteMain.SetInnerCellBorders(false, 10, wpapTable);
  rteMain.SetOuterCellBorders(true, 10, wpapTable);
end;
#5 ♥ 0
support

Hi,

You didn't move the cursor to the table, use this

rteMain.CPPosition := MaxInt;

or

with CreateRow(nil, True) do
begin
InputCell.SetText('Cell 5');
InputCell.SetText('Cell 6');
rteMain.ActiveParagraph := ColFirst;

only then the Set method knows which table to manipulate.

Julian

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