Write Direct Table TableProperties Class

The ooodev.format.writer.direct.table.properties.TableProperties is used to set the properties of a table.

Setup

General function used to run these examples.

from ooodev.format.writer.direct.table.properties import TableProperties, TableAlignKind
from ooodev.write import WriteDoc
from ooodev.units import UnitMM
from ooodev.utils.color import StandardColor
from ooodev.utils.data_type.intensity import Intensity
from ooodev.loader import Lo
from ooodev.utils.table_helper import TableHelper


def main() -> int:
    with Lo.Loader(Lo.ConnectPipe()):
        doc = WriteDoc.create_doc(visible=True)
        Lo.delay(300)
        doc.zoom(ZoomKind.ZOOM_100_PERCENT)
        cursor = doc.get_cursor()

        tbl_data = TableHelper.make_2d_array(num_rows=5, num_cols=5)
        # bdr_style = Borders(border_side=Side())
        props_style = TableProperties(name="My_Table", relative=False, align=TableAlignKind.AUTO)

        table = cursor.add_table(
            table_data=tbl_data,
            first_row_header=False,
            tbl_bg_color=CommonColor.LIGHT_BLUE,
            tbl_fg_color=CommonColor.BLACK,
            styles=[bdr_style],
        )

        # getting the table properties
        tbl_props_style = TableProperties.from_obj(table)
        assert tbl_props_style.prop_name == "My_Table"

        Lo.delay(1_000)
        Lo.close_doc(doc)

        Lo.close_doc(doc)

    return 0


if __name__ == "__main__":
    sys.exit(main())

Examples

Absolute Position

Auto Position

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    )

table.style_direct.style_table_props(
    relative=False, align=TableAlignKind.AUTO
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table", relative=False, align=TableAlignKind.AUTO
)
table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Auto Absolute Position

Fig. 1025 Auto Absolute Position

Table Properties Dialog

Fig. 1026 Table Properties Dialog

Align Center Position setting width

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=False,
    align=TableAlignKind.CENTER,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=False,
    align=TableAlignKind.CENTER,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align Center Position setting width

Fig. 1027 Align Center Position setting width

Table Properties Dialog

Fig. 1028 Table Properties Dialog

Align Center Position setting left

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=False,
    align=TableAlignKind.CENTER,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=UnitMM(40.0),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=False,
    align=TableAlignKind.CENTER,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=UnitMM(40.0),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align Center Position setting left

Fig. 1029 Align Center Position setting left

Table Properties Dialog

Fig. 1030 Table Properties Dialog

Align From Left Position setting width

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=False,
    align=TableAlignKind.FROM_LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=False,
    align=TableAlignKind.FROM_LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)

table = cursor.add_table(
    cursor=cursor,
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align From Left Position setting width

Fig. 1031 Align From Left Position setting width

Table Properties Dialog

Fig. 1032 Table Properties Dialog

Align Left Position setting width

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=False,
    align=TableAlignKind.LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=False,
    align=TableAlignKind.LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)

table = cursor.add_table(
    cursor=cursor,
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align Left Position setting width

Fig. 1033 Align Left Position setting width

Table Properties Dialog

Fig. 1034 Table Properties Dialog

Align Left Position setting right

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=False,
    align=TableAlignKind.LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    right=UnitMM(60.0),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=False,
    align=TableAlignKind.LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    right=UnitMM(60.0),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align Left Position setting right

Fig. 1035 Align Left Position setting right

Table Properties Dialog

Fig. 1036 Table Properties Dialog

Align Right Position setting width

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=False,
    align=TableAlignKind.RIGHT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=False,
    align=TableAlignKind.RIGHT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align Right Position setting width

Fig. 1037 Align Right Position setting width

Table Properties Dialog

Fig. 1038 Table Properties Dialog

Align Right Position setting left

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=False,
    align=TableAlignKind.RIGHT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=UnitMM(60.0),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=False,
    align=TableAlignKind.RIGHT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=UnitMM(60.0),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align Right Position setting left

Fig. 1039 Align Right Position setting left

Table Properties Dialog

Fig. 1040 Table Properties Dialog

Align Manual Position setting width

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=False,
    align=TableAlignKind.MANUAL,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=False,
    align=TableAlignKind.MANUAL,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=UnitMM(60.0),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
)
Align Manual Position setting width

Fig. 1041 Align Manual Position setting width

Table Properties Dialog

Fig. 1042 Table Properties Dialog

Align Manual Position setting left & right

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=False,
    align=TableAlignKind.MANUAL,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=UnitMM(66.0),
    right=UnitMM(55.0),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=False,
    align=TableAlignKind.MANUAL,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=UnitMM(66.0),
    right=UnitMM(55.0),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
)
Align Manual Position setting left & right

Fig. 1043 Align Manual Position setting left & right

Table Properties Dialog

Fig. 1044 Table Properties Dialog

Relative Position

Align From Left Position setting left & width

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=True,
    align=TableAlignKind.FROM_LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=Intensity(20),
    width=Intensity(40),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=True,
    align=TableAlignKind.FROM_LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=Intensity(20),
    width=Intensity(40),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align Relative From Left Position setting left & width

Fig. 1045 Align Relative From Left Position setting left & width

Table Properties Dialog

Fig. 1046 Table Properties Dialog

Align Left Position setting width

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=True,
    align=TableAlignKind.LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=Intensity(40),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=True,
    align=TableAlignKind.LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=Intensity(40),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
)
Align Relative Left Position setting width

Fig. 1047 Align Relative Left Position setting width

Table Properties Dialog

Fig. 1048 Table Properties Dialog

Align Left Position setting right

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=True,
    align=TableAlignKind.LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    right=Intensity(40),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=True,
    align=TableAlignKind.LEFT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    right=Intensity(40),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align Relative Left Position setting right

Fig. 1049 Align Relative Left Position setting right

Table Properties Dialog

Fig. 1050 Table Properties Dialog

Align Right Position setting width

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=True,
    align=TableAlignKind.RIGHT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=Intensity(40),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=True,
    align=TableAlignKind.RIGHT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    width=Intensity(40),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
    )
Align Relative Right Position setting width

Fig. 1051 Align Relative Right Position setting width

Table Properties Dialog

Fig. 1052 Table Properties Dialog

Align Right Position setting left

Set using style_direct
# ... other code
table = cursor.add_table(
    name="My_Table",
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
)

table.style_direct.style_table_props(
    relative=True,
    align=TableAlignKind.RIGHT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=Intensity(40),
)
Set using styles
# ... other code
props_style = TableProperties(
    name="My_Table",
    relative=True,
    align=TableAlignKind.RIGHT,
    above=UnitMM(2.0),
    below=UnitMM(1.8),
    left=Intensity(40),
)

table = cursor.add_table(
    table_data=tbl_data,
    first_row_header=False,
    tbl_bg_color=CommonColor.LIGHT_BLUE,
    tbl_fg_color=CommonColor.BLACK,
    styles=[props_style],
)
Align Relative Right Position setting left

Fig. 1053 Align Relative Right Position setting left

Table Properties Dialog

Fig. 1054 Table Properties Dialog

Getting the Properties from the table

# ... other code
# getting the table properties
tbl_props_style = TableProperties.from_obj(table.component)
# or tbl_props_style = table.style_direct.style_table_props_get()
assert tbl_props_style.prop_name == "My_Table"