Table Size and Position, Column Width

<< Click to Display Table of Contents >>

Navigation:  Appendix > WPAT_codes >

Table Size and Position, Column Width

A table usually uses the complete text area, this is the page width minus the left and right margins.

 

Property to set the width in twips: WPAT_BoxWidth

 

Property to set the width in percent * 100  of the page width

WPAT_BoxWidth_PC

 

Offset from the left margin. Can be negative to be to the lefgt of the text area.

WPAT_BoxMarginLeft

 

Offset from the left margin. If negative the table is extended into the margin area

WPAT_BoxMarginRight

 

Horizontal Alignment of the table: WPAT_Box_Align:

 possible values are WPBOXALIGN_RIGHT and WPBOXALIGN_HCENTERTEXT

 

The column width is defined by the properties WPAT_ColWidth and WPAT_ColWidth_PC. The first is the width in twips, the latter is the width in percent * 10 (Example: 1000 sets a width of 10%).

 

WPAT_ColWidth has priority over WPAT_ColWidth_PC. You will need to delete the WPAT_ColWidth flag if you need to set the width in percent.

 

 Cell.ADel(WPAT_ColWidth)

 Cell.ASet(WPAT_ColWidth_PC, 1000); // 10%

 

You can read the current width of a cell using the method cell.IsWidthTW. The text must be formatted. Once the user resizes columns in a table all widths which are defined by a percent value will be converted into exact WPAT_ColWidth values. You can force this conversion for the complete text using the function WPRichText.TableFixAllCellWidths. This method can also round the width values suing a 'snap value'. The method TableAdjustCellWidth can be used to recalculate the width of all columns to keep them visible.

 

The property WPAT_BoxMinHeight can be used with table rows to set the minium height of a table row. WPAT_BoxMaxHeight is used to set the maximum width. Both properties will be ignored in cells which are merged vertically. They can be used together.

 

You can use reference Cell.ParentRow to set or read a property in a row. The editor allows the modification of row heights if this mode has been enabled in the property EditOptions.

 

Example: Apply row height to all rows in current table

 

var par : TParagraph;

 

if WPRichText1.Table<>nil then

begin

  par := WPRichText1.Table.ChildPar;

  while par<>nil do

  begin

    par.ASet( WPAT_BoxMinHeight, twips_value );

    par.ASet( WPAT_BoxMaxHeight, twips_value );

    par := par.NextPar;

  end;

end;

 

Example: Apply row height to selected rows only

 

var par : TParagraph;

 

if WPRichText1.Table<>nil then

begin

  par := WPRichText1.Table.ChildPar;

  while par<>nil do

  begin

    if par.HasProp( paprCellIsSelected ) then

    begin

      par.ASet( WPAT_BoxMinHeight, twips_value );

      par.ASet( WPAT_BoxMaxHeight, twips_value );

    end;

    par := par.NextPar;

  end;

end;

 

Note: The rows are the children of the table, the cells the children on the row. Also see "Datastructures".