Tables: Append row, change col width, insert hyperlink

    • Offizieller Beitrag

    1. I have document with 3 tables. How can I (with code) insert new column into table 2 (second table in the document).

    Code
    procedure TWPTBXForm.AppendRowClick(Sender: TObject);var tblpar, tblrow, newrow : TParagraph;begin   tblpar := WPRichText1.FirstPar.Tables[1]; // [0...]   if tblpar<>nil then   begin     tblrow := tblpar.LastChild; // That is the last row!     newrow := tblrow.Duplicate(false,true);  // with cells, no text     tblrow.NextPar := newrow; // Insert it at end     WPRichText1.DelayedReformat;   end;end;

    The code above can be written more compact as

    Code
    procedure TWPTBXForm.AppendRowClick(Sender: TObject);var tblpar, newrow : TParagraph;begin   tblpar := WPRichText1.FirstPar.Tables[1]; // [0...]   if tblpar<>nil then   begin     newrow := tblpar.LastChild.RowAppend;     WPRichText1.DelayedReformat;   end;end;

    "RowAppend" can be used with rows and with cell paragraphs.

    2. How can I change size (width) of some column (with code, not with mouse)?

    Code
    procedure TWPTBXForm.SetColWidthClick(Sender: TObject);var tblpar : TParagraph;begin   tblpar := WPRichText1.FirstPar.Tables[1]; // [0...]   if tblpar<>nil then   begin     tblpar.Cols[1].ASetColumn(WPAT_COLWIDTH, 1440);     WPRichText1.DelayedReformat;   end;end;

    3. How can I insert hyperlink into some cell. I found just function InputHyperlink, which add hypelink into document, not in some cell.