Calc Direct Cell Font Only

The ooodev.format.calc.direct.cell.font.FontOnly class gives you the same options as Calc’s Font Dialog, but without the dialog. as seen in Fig. 350.

Calc Format Cell dialog Font Effects

Fig. 350 Calc Format Cell dialog Font Effects

Apply the font to a cell

Setup

from __future__ import annotations
import uno
from ooodev.calc import CalcDoc
from ooodev.loader import Lo

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_font(
            name="Lucida Calligraphy",
            size=20,
            font_style="italic",
        )

        f_style = cell.style_font_get()
        assert f_style is not None

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

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

Setting the font

# ... other code
cell = sheet["A1"]
cell.value = "Hello"
cell.style_font(
    name="Lucida Calligraphy",
    size=20,
    font_style="italic",
)

Running the above code will produce the following output in Fig. 351.

Calc Format Cell dialog Font set

Fig. 351 Calc Format Cell dialog Font set

Getting the font from a cell

# ... other code

f_style = cell.style_font_get()
assert f_style.prop_name == "Lucida Calligraphy"

Apply the font to a range

Setup

from __future__ import annotations
import uno
from ooodev.calc import CalcDoc
from ooodev.loader import Lo

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)

        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_font(
            name="Lucida Calligraphy",
            size=20,
            font_style="italic",
        )

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

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

Setting the font

# ... other code
cell_rng = sheet.get_range(range_obj=rng)
cell_rng.style_font(
    name="Lucida Calligraphy",
    size=20,
    font_style="italic",
)

Running the above code will produce the following output in Fig. 406.

Getting the font from a range

# ... other code

f_style = cell_rng.style_font_get()
assert f_style.prop_name == "Lucida Calligraphy"