Can TableAdd honor the current paragraph indents?

  • When I add a new paragraph, it continues the indents. However, if I add a table it sizes based on the margins, ignoring the indents. Am I missing an option that can have the newly created table honor the indents instead of the margins? Customers are having to always resize the tables and columns after adding them.

    This is the command I use to create a table:

    Code
        vTable := pWP.TableAdd(Columns, Rows, [wptblActivateBorders, wptblReuseCurrentParIfEmpty]);
    • Offizieller Beitrag

    A Table is aligned by this properties WPAT_BoxMarginLeft and WPAT_BoxWidth.

    You can use this code:

    Code
    l := WPRichText1.ActiveParagraph.AGetDef( WPAT_IndentLeft, 0 );
    r := WPRichText1.ActiveParagraph.AGetDef( WPAT_IndentRight, 0 );
    par := WPRichText1.TableAdd(3, 4, [
            wptblReturnCreatedTableObject, 
            wptblActivateBorders, 
            wptblReuseCurrentParIfEmpty]);
    par.ASet( WPAT_BoxMarginLeft, l );
    par.ASet( WPAT_BoxWidth, WPRichText1.Header.PageWidth-
    WPRichText1.Header.LeftMargin-
    WPRichText1.Header.RightMargin-l-r );

    Note the flag wptblReturnCreatedTableObject - it is mandatory for this code to work.

    Unless your system is RTF based, you can use WPAT_BoxMarginRight, too:

    Code
    l := WPRichText1.ActiveParagraph.AGetDef( WPAT_IndentLeft, 0 );
    r := WPRichText1.ActiveParagraph.AGetDef( WPAT_IndentRight, 0 );
    par := WPRichText1.TableAdd(3, 4, [
        wptblReturnCreatedTableObject, wptblActivateBorders, wptblReuseCurrentParIfEmpty]);
    par.ASet( WPAT_BoxMarginLeft, l );
    par.ASet( WPAT_BoxMarginRight, r );