- 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.
Code
procedure TWPTBXForm.SetLinkInCellClick(Sender: TObject);
var tblpar : TParagraph;
hyperobj : TWPTextObj;
begin
tblpar := WPRichText1.FirstPar.Tables[1]; // [0...]
if tblpar<>nil then
begin
hyperobj := tblpar.Rows[1].Cols[1].AppendNewObjectPair(
wpobjHyperlink,
'WPCubed GmbH',
WPRichText1.WritingAttr.CharAttr // current attribute
);
hyperobj.Source := 'http://www.wpcubed.com';
WPRichText1.DelayedReformat;
end;
end;
Alles anzeigen