Inputting a line - duplicate tables

  • Hello

    I am trying to copy a row from a table and place it directly underneath the row I copied from. Here is the layout of my letter

    Table 1 - contains titles etc..
    Table 2 - contains the data
    Table 3 - contains the totals

    I am trying to copy table 2 and place it before table 3 so it looks like this

    Table 1 - contains titles etc..
    Table 2 - contains the data
    Table 2 - contians the data for a second person
    Table 3 - contains the totals

    However it is doing one of two things.


    Here is the code for my first result. When I run this code it places the row I copied into the last cell of row I copied from.

    Table 1 - contains titles etc..
    Table 2 - contains the dataTable 2 - contians the data for a second person
    Table 3 - contains the totals


    //'035' is the value in the first cell of the row
    if WPRichText_3.Finder.Next('035') then
    begin

    // once '035' found, go to start of line and start selection
    WPRichText_3.Finder.MoveToFoundPositionStart;

    if paprIsTable in WPRichText_3.ActiveParagraph.prop then
    WPRichText_3.SelectThisRow
    else
    WPRichText_3.SelectLine;

    //'140' is the value in the last cell of the row I copied from
    If WPRichText_1.Finder.Next('140') then begin

    WPRichText_1.Finder.MoveToFoundPositionEnd;
    WPRichText_1.CPPosition :=
    WPRichText_1.Finder.FoundPosition;

    WPRichText_1.SelectionAsString :=
    WPRichText_3.SelectionAsString; // copy in this row
    WPRichText_1.ReformatAll;

    WPRichText_3.CPPosition := 0;
    End;
    end;

    Here is the code for my second result. When I run this code, it places the row I copied after the very last table in the letter.

    Table 1 - contains titles etc..
    Table 2 - contains the data
    Table 3 - contains the totals
    Table 2 - contians the data for a second person

    //'035' is the value in the first cell of the row
    if WPRichText_3.Finder.Next('035') then
    begin

    // once '035' found, go to start of line and start selection
    WPRichText_3.Finder.MoveToFoundPositionStart;

    if paprIsTable in WPRichText_3.ActiveParagraph.prop then
    WPRichText_3.SelectThisRow
    else
    WPRichText_3.SelectLine;

    //'140' is the value in the last cell of the row I copied from
    If WPRichText_1.Finder.Next('140') then begin

    WPRichText_1.Finder.MoveToFoundPositionEnd;
    WPRichText_1.CPPosition :=
    WPRichText_1.Finder.FoundPosition;

    WPRichText_1.ActiveParagraph :=
    WPRichText_1.FastAppendParagraph;
    WPRichText_1.SelectParagraph
    (WPRichText_1.ActiveParagraph);

    WPRichText_1.SelectionAsString :=
    WPRichText_3.SelectionAsString; // copy in this row
    WPRichText_1.ReformatAll;

    WPRichText_3.CPPosition := 0;
    End;
    end;

    Can you help me figure out what I am doing wrong?

    • Offizieller Beitrag
    Zitat

    I am trying to copy table 2 and place it before table 3 so it looks like this

    Table 1 - contains titles etc..
    Table 2 - contains the data
    Table 2 - contians the data for a second person
    Table 3 - contains the totals

    Since the paragraphs and tables are all objects you can do this very easily:

    Code
    var   par, copy : TParagraph;  // Locate the table, for example use the finder ...  // ...  // now use duplicate    par := WPRichText1.Table;  if par<>nil then  begin    copy := par.Duplicate(false, true);    WPRichText1.ActiveParagraph := copy.ColFirst;    WPRichText1.InputString('Some new Text');    WPRichText1.DelayedReformat;end;

    Of course you can also duplicate the current tablerow or, if you need some text between the tables, do this:

    Code
    par := WPRichText1.Table;
      if par<>nil then
      begin
        copy := par.Duplicate(false, true);
        par := par.AppendNewPar(false);
        par.SetText('This text comes between the tables');
        WPRichText1.ActiveParagraph := copy.ColFirst;
        WPRichText1.InputString('Some new Text');
        WPRichText1.DelayedReformat;
      end;

    Note that the text is not copied because of the first "false" in Duplicate()

    Hope this helps,

    Julian