Calc Modify Cell Alignment
Overview
Calc has a dialog, as seen in Fig. 412, that sets cell alignment. In this section we will look the various classes that set the same options.
Text Alignment
The ooodev.format.calc.modify.cell.alignment.TextAlign
class sets the text alignment of a style.
Setup
General setup for the examples in this section.
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.calc.modify.cell.alignment import TextAlign, StyleCellKind
from ooodev.format.calc.modify.cell.alignment import HoriAlignKind, VertAlignKind
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = Calc.create_doc()
GUI.set_visible(True, doc)
Lo.delay(500)
Calc.zoom(doc, GUI.ZoomEnum.ZOOM_100_PERCENT)
style = TextAlign(
hori_align=HoriAlignKind.CENTER,
vert_align=VertAlignKind.MIDDLE,
style_name=StyleCellKind.DEFAULT,
)
style.apply(doc)
style_obj = TextAlign.from_style(doc=doc, style_name=StyleCellKind.DEFAULT)
assert style_obj.prop_style_name == str(StyleCellKind.DEFAULT)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Setting the text alignment
# ... other code
style = TextAlign(
hori_align=HoriAlignKind.CENTER,
vert_align=VertAlignKind.MIDDLE,
style_name=StyleCellKind.DEFAULT,
)
style.apply(doc)
Running the above code will produce the following output in Fig. 413.
Getting the text alignment from a style
# ... other code
style_obj = TextAlign.from_style(doc=doc, style_name=StyleCellKind.DEFAULT)
assert style_obj.prop_style_name == str(StyleCellKind.DEFAULT)
Text Orientation
The ooodev.format.calc.modify.cell.alignment.TextOrientation
class sets the text alignment of a style.
Setup
General setup for the examples in this section.
import uno
from ooodev.office.calc import Calc
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.calc.modify.cell.alignment import TextOrientation
from ooodev.format.calc.modify.cell.alignment import EdgeKind, StyleCellKind
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = Calc.create_doc()
GUI.set_visible(True, doc)
Lo.delay(500)
Calc.zoom(doc, GUI.ZoomEnum.ZOOM_100_PERCENT)
style = TextOrientation(
vert_stack=False,
rotation=-10,
edge=EdgeKind.INSIDE,
style_name=StyleCellKind.DEFAULT,
)
style.apply(doc)
style_obj = TextOrientation.from_style(doc=doc, style_name=StyleCellKind.DEFAULT)
assert style_obj.prop_style_name == str(StyleCellKind.DEFAULT)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Setting the text alignment
# ... other code
style = TextOrientation(
vert_stack=False,
rotation=-10,
edge=EdgeKind.INSIDE,
style_name=StyleCellKind.DEFAULT,
)
style.apply(doc)
Running the above code will produce the following output in Fig. 414.
Getting the text orientation from a style
# ... other code
style_obj = TextOrientation.from_style(doc=doc, style_name=StyleCellKind.DEFAULT)
assert style_obj.prop_style_name == str(StyleCellKind.DEFAULT)
Text Properties
The ooodev.format.calc.modify.cell.alignment.Properties
class sets the text properties of a style.
Setup
General setup for the examples in this section.
import uno
from ooodev.office.calc import Calc
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.calc.modify.cell.alignment import Properties
from ooodev.format.calc.modify.cell.alignment import TextDirectionKind, StyleCellKind
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = Calc.create_doc()
GUI.set_visible(True, doc)
Lo.delay(500)
Calc.zoom(doc, GUI.ZoomEnum.ZOOM_100_PERCENT)
style = Properties(
wrap_auto=True,
hyphen_active=True,
direction=TextDirectionKind.PAGE,
style_name=StyleCellKind.DEFAULT,
)
style.apply(doc)
style_obj = Properties.from_style(doc=doc, style_name=StyleCellKind.DEFAULT)
assert style_obj.prop_style_name == str(StyleCellKind.DEFAULT)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Setting the text properties
# ... other code
style = Properties(
wrap_auto=True,
hyphen_active=True,
direction=TextDirectionKind.PAGE,
style_name=StyleCellKind.DEFAULT,
)
style.apply(doc)
Running the above code will produce the following output in Fig. 415.
Getting the text properties from a style
# ... other code
style_obj = Properties.from_style(doc=doc, style_name=StyleCellKind.DEFAULT)
assert style_obj.prop_style_name == str(StyleCellKind.DEFAULT)