Calc Modify Cell Font Only

The ooodev.format.calc.modify.cell.font.FontOnly class is used to modify the font values seen in Fig. 423 of a cell style.

Before Settings

Calc dialog style font default

Fig. 423 Calc dialog style font default

Setting the font name and size

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.font import FontOnly, 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)

        font_style = FontOnly(name="Consolas", size=14, style_name=StyleCellKind.DEFAULT)
        font_style.apply(doc)

        style_obj = FontOnly.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())

After applying the font name and size

Calc dialog style font default changed

Fig. 424 Calc dialog style font default changed

Getting the font from a style

We can get the font name and size from the document.

# ... other code

style_obj = FontOnly.from_style(doc=doc, style_name=StyleCellKind.DEFAULT)
assert style_obj.prop_style_name == str(StyleCellKind.DEFAULT)