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],
)
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 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 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 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 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 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 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 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 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],
)
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 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 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 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 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],
)
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"