Calc Direct Cell Alignment (Static)

Calc has a dialog, as seen in Fig. 357, that sets cell alignment. In this section we will look the various classed that set the same options.

Calc Format Cell dialog Direct Cell Alignment

Fig. 357 Calc Format Cell dialog Direct Cell Alignment

Text Alignment

The ooodev.format.calc.direct.cell.alignment.TextAlign class sets the text alignment of a cell or range.

Setup

General setup for the examples in this section.

import uno
from ooodev.office.calc import Calc
from ooodev.gui.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.calc.direct.cell.alignment import TextAlign
from ooodev.format.calc.direct.cell.alignment import HoriAlignKind, VertAlignKind


def main() -> int:
    with Lo.Loader(connector=Lo.ConnectSocket()):
        doc = Calc.create_doc()
        sheet = Calc.get_sheet()
        GUI.set_visible(True, doc)
        Lo.delay(500)
        Calc.zoom_value(doc, 400)

        cell = Calc.get_cell(sheet=sheet, cell_name="A1")
        style = TextAlign(hori_align=HoriAlignKind.CENTER, vert_align=VertAlignKind.MIDDLE)
        Calc.set_val(value="Hello", cell=cell, styles=[style])

        f_style = TextAlign.from_obj(cell)
        assert f_style is not None

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


if __name__ == "__main__":
    SystemExit(main())

Apply to a cell

Setting the text alignment

# ... other code
cell = Calc.get_cell(sheet=sheet, cell_name="A1")
style = TextAlign(hori_align=HoriAlignKind.CENTER, vert_align=VertAlignKind.MIDDLE)
Calc.set_val(value="Hello", cell=cell, styles=[style])

Running the above code will produce the following output in Fig. 358 and Fig. 359.

Calc Cell

Fig. 358 Calc Cell

Calc Format Cell dialog Text Alignment set

Fig. 359 Calc Format Cell dialog Text Alignment set

Getting the text alignment from a cell

# ... other code

f_style = TextAlign.from_obj(cell)
assert f_style is not None

Apply to a range

Setting the text alignment

# ... other code
Calc.set_val(value="Hello", sheet=sheet, cell_name="A1")
Calc.set_val(value="World", sheet=sheet, cell_name="B1")
rng = Calc.get_cell_range(sheet=sheet, range_name="A1:B1")

style = TextAlign(hori_align=HoriAlignKind.LEFT, indent=3, vert_align=VertAlignKind.TOP)
style.apply(rng)

Running the above code will produce the following output in Fig. 360 and Fig. 361.

Calc Cell Range

Fig. 360 Calc Cell Range

Calc Format Range dialog Text Alignment set

Fig. 361 Calc Format Range dialog Text Alignment set

Getting the text alignment from a cell range

# ... other code

f_style = TextAlign.from_obj(rng)
assert f_style is not None

Text Orientation

The ooodev.format.calc.direct.cell.alignment.TextOrientation class sets the text orientation of a cell or range.

Setup

General setup for the examples in this section.

import uno
from ooodev.office.calc import Calc
from ooodev.gui.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.calc.direct.cell.alignment import TextOrientation, EdgeKind


def main() -> int:
    with Lo.Loader(connector=Lo.ConnectSocket()):
        doc = Calc.create_doc()
        sheet = Calc.get_sheet()
        GUI.set_visible(True, doc)
        Lo.delay(500)
        Calc.zoom_value(doc, 400)

        cell = Calc.get_cell(sheet=sheet, cell_name="A1")
        style = TextOrientation(vert_stack=False, rotation=-10, edge=EdgeKind.INSIDE)
        Calc.set_val(value="Hello", cell=cell, styles=[style])

        f_style = TextOrientation.from_obj(cell)
        assert f_style is not None

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


if __name__ == "__main__":
    SystemExit(main())

Apply to a cell

Setting the text orientation

# ... other code
cell = Calc.get_cell(sheet=sheet, cell_name="A1")
style = TextOrientation(vert_stack=False, rotation=-10, edge=EdgeKind.INSIDE)
Calc.set_val(value="Hello", cell=cell, styles=[style])

Running the above code will produce the following output in Fig. 362 and Fig. 363.

Calc Cell

Fig. 362 Calc Cell

Calc Format Cell dialog Text Orientation set

Fig. 363 Calc Format Cell dialog Text Orientation set

Getting the text orientation from a cell

# ... other code

f_style = TextAlign.from_obj(cell)
assert f_style is not None

Apply to a range

Setting the text orientation

# ... other code
Calc.set_val(value="Hello", sheet=sheet, cell_name="A1")
Calc.set_val(value="World", sheet=sheet, cell_name="B1")
rng = Calc.get_cell_range(sheet=sheet, range_name="A1:B1")

style = TextOrientation(vert_stack=True)
style.apply(rng)

Running the above code will produce the following output in Fig. 364 and Fig. 365.

Calc Cell Range

Fig. 364 Calc Cell Range

Calc Format Cell dialog Text Orientation set

Fig. 365 Calc Format Cell dialog Text Orientation set

Getting the text orientation from a range

# ... other code

f_style = TextOrientation.from_obj(rng)
assert f_style is not None

Text Properties

The ooodev.format.calc.direct.cell.alignment.Properties class sets the text properties of a cell or range.

Setup

General setup for the examples in this section.

import uno
from ooodev.office.calc import Calc
from ooodev.gui.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.calc.direct.cell.alignment import Properties, TextDirectionKind


def main() -> int:
    with Lo.Loader(connector=Lo.ConnectSocket()):
        doc = Calc.create_doc()
        sheet = Calc.get_sheet()
        GUI.set_visible(True, doc)
        Lo.delay(500)
        Calc.zoom_value(doc, 400)

        cell = Calc.get_cell(sheet=sheet, cell_name="A1")
        style = Properties(wrap_auto=True, hyphen_active=True, direction=TextDirectionKind.PAGE)
        Calc.set_val(value="Hello World! Sunny Day!", cell=cell, styles=[style])

        f_style = Properties.from_obj(cell)
        assert f_style is not None

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


if __name__ == "__main__":
    SystemExit(main())

Apply to a cell

Setting the text properties

# ... other code
cell = Calc.get_cell(sheet=sheet, cell_name="A1")
style = Properties(wrap_auto=True, hyphen_active=True, direction=TextDirectionKind.PAGE)
Calc.set_val(value="Hello World! Sunny Day!", cell=cell, styles=[style])

Running the above code will produce the following output in Fig. 366 and Fig. 367.

Calc Cell

Fig. 366 Calc Cell

Calc Format Cell dialog Text Orientation set

Fig. 367 Calc Format Cell dialog Text Orientation set

Getting the text properties from a cell

# ... other code

f_style = Properties.from_obj(cell)
assert f_style is not None

Apply to a range

Setting the text properties

# ... other code
cell = Calc.get_cell(sheet=sheet, cell_name="A1")
style = Properties(wrap_auto=True, hyphen_active=True, direction=TextDirectionKind.PAGE)
Calc.set_val(value="Hello World! Sunny Day!", cell=cell, styles=[style])

Running the above code will produce the following output in Fig. 368 and Fig. 369.

Calc Cell Range

Fig. 368 Calc Cell Range

Calc Format Cell dialog Text Orientation set

Fig. 369 Calc Format Cell dialog Text Orientation set

Getting the text properties from a cell

# ... other code

f_style = Properties.from_obj(rng)
assert f_style is not None