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

Fig. 302 Calc Format Cell dialog Direct Cell Alignment
Text Alignment
The style_align_text()
method is called to set the text alignment of a cell or range.
Setup
General setup for the examples in this section.
from __future__ import annotations
import uno
from ooodev.calc import CalcDoc
from ooodev.loader import Lo
from ooodev.format.calc.direct.cell.alignment import HoriAlignKind, VertAlignKind
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = CalcDoc.create_doc(visible=True)
sheet = doc.sheets[0]
Lo.delay(500)
doc.zoom_value(400)
cell = sheet["A1"]
cell.value = "Hello"
cell.style_align_text(
hori_align=HoriAlignKind.CENTER, vert_align=VertAlignKind.MIDDLE
)
Lo.delay(1_000)
doc.close()
return 0
if __name__ == "__main__":
SystemExit(main())
Apply to a cell
Setting the text alignment
# ... other code
cell = sheet["A1"]
cell.value = "Hello"
cell.style_align_text(
hori_align=HoriAlignKind.CENTER,
vert_align=VertAlignKind.MIDDLE,
)
Running the above code will produce the following output in Fig. 303 and Fig. 304.

Fig. 303 Calc Cell

Fig. 304 Calc Format Cell dialog Text Alignment set
Getting the text alignment from a cell
# ... other code
f_style = cell.style_align_text_get()
assert f_style is not None
Apply to a range
Setting the text alignment
# ... other code
cell = sheet["A1"]
cell.value = "Hello"
cell = cell.get_cell_right()
cell.value = "World"
cell_rng = sheet.get_range(range_name="A1:B1")
cell_rng.style_align_text(
hori_align=HoriAlignKind.CENTER,
indent=3,
vert_align=VertAlignKind.MIDDLE,
)
Running the above code will produce the following output in Fig. 305 and Fig. 306.

Fig. 305 Calc Cell Range

Fig. 306 Calc Format Range dialog Text Alignment set
Getting the text alignment from a Cell Range
# ... other code
f_style = cell_rng.style_align_text_get()
assert f_style is not None
Text Orientation
The style_align_orientation()
method is called to set the text orientation of a cell or range.
Setup
General setup for the examples in this section.
from __future__ import annotations
import uno
from ooodev.calc import CalcDoc
from ooodev.loader import Lo
from ooodev.format.inner.direct.calc.alignment.text_orientation import EdgeKind
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = CalcDoc.create_doc(visible=True)
sheet = doc.sheets[0]
Lo.delay(500)
doc.zoom_value(400)
cell = sheet["A1"]
cell.value = "Hello"
cell.style_align_orientation(
vert_stack=False,
rotation=-10,
edge=EdgeKind.INSIDE,
)
f_style = cell.style_align_orientation_get()
assert f_style is not None
Lo.delay(1_000)
doc.close()
return 0
if __name__ == "__main__":
SystemExit(main())
Apply to a cell
Setting the text orientation
# ... other code
cell = sheet["A1"]
cell.value = "Hello"
cell.style_align_orientation(
vert_stack=False,
rotation=-10,
edge=EdgeKind.INSIDE,
)
Running the above code will produce the following output in Fig. 307 and Fig. 308.

Fig. 307 Calc Cell

Fig. 308 Calc Format Cell dialog Text Orientation set
Getting the text orientation from a cell
# ... other code
f_style = cell.style_align_orientation_get()
assert f_style is not None
Apply to a range
Setting the text orientation
# ... other code
rng = sheet.rng("A1:B1")
sheet.set_array(values=[["Hello", "World"]], range_obj=rng)
cell_rng = sheet.get_range(range_obj=rng)
cell_rng.style_align_orientation(vert_stack=True)
Running the above code will produce the following output in Fig. 309 and Fig. 310.

Fig. 309 Calc Cell Range

Fig. 310 Calc Format Cell dialog Text Orientation set
Getting the text orientation from a range
# ... other code
f_style = cell_rng.style_align_orientation_get()
assert f_style is not None
Text Properties
The style_align_properties()
method is called to set the text properties of a cell or range.
Setup
General setup for the examples in this section.
from __future__ import annotations
import uno
from ooodev.calc import CalcDoc
from ooodev.loader import Lo
from ooodev.format.inner.direct.calc.alignment.properties import TextDirectionKind
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = CalcDoc.create_doc(visible=True)
sheet = doc.sheets[0]
Lo.delay(500)
doc.zoom_value(400)
cell = sheet["A1"]
cell.value = "Hello World! Sunny Day!"
cell.style_align_properties(
wrap_auto=True,
hyphen_active=True,
direction=TextDirectionKind.PAGE,
)
Lo.delay(1_000)
doc.close()
return 0
if __name__ == "__main__":
SystemExit(main())
Apply to a cell
Setting the text properties
# ... other code
cell = sheet["A1"]
cell.value = "Hello World! Sunny Day!"
cell.style_align_properties(
wrap_auto=True,
hyphen_active=True,
direction=TextDirectionKind.PAGE,
)
Running the above code will produce the following output in Fig. 311 and Fig. 312.

Fig. 311 Calc Cell

Fig. 312 Calc Format Cell dialog Text Orientation set
Getting the text properties from a cell
# ... other code
f_style = cell.style_align_properties_get()
assert f_style is not None
Apply to a range
Setting the text properties
# ... other code
rng = sheet.rng("A1:B1")
sheet.set_array(
values=[["Hello World! See the Shine", "Sunny Days are great!"]],
range_obj=rng
)
cell_rng = sheet.get_range(range_obj=rng)
cell_rng.style_align_properties(shrink_to_fit=True)
Running the above code will produce the following output in Fig. 313 and Fig. 314.

Fig. 313 Calc Cell Range

Fig. 314 Calc Format Cell dialog Text Orientation set
Getting the text properties from a cell range
# ... other code
f_style = cell_rng.style_align_properties_get()
assert f_style is not None