Calc Direct Cell Font Effects (Static)
The ooodev.format.calc.direct.cell.font.FontEffects
class gives you the same options
as Calc’s Font Effects Dialog, but without the dialog as seen in Fig. 401.
See also
Apply the font effects to a cell
Setup
from ooodev.format import CommonColor
from ooodev.office.calc import Calc
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.calc.direct.cell.font import FontEffects, FontLine, FontUnderlineEnum
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket(), opt=Lo.Options(verbose=True)):
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")
font_effects = FontEffects(
color=CommonColor.RED,
underline=FontLine(line=FontUnderlineEnum.SINGLE, color=CommonColor.BLUE),
shadowed=True,
)
Calc.set_val(value="Hello", cell=cell, styles=[font_effects])
f_effects = FontEffects.from_obj(cell)
assert f_effects.prop_color == CommonColor.RED
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Setting the font effects
font_effects = FontEffects(
color=CommonColor.RED,
underline=FontLine(line=FontUnderlineEnum.SINGLE, color=CommonColor.BLUE),
shadowed=True,
)
Calc.set_val(value="Hello", cell=cell, styles=[font_effects])
Running the above code will produce the following output in Fig. 402 and Fig. 403.
Getting the font effects from a cell
# ... other code
f_effects = FontEffects.from_obj(cell)
assert f_effects.prop_color == CommonColor.RED
Apply the font effects to a range
Setup
from ooodev.format import CommonColor
from ooodev.office.calc import Calc
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.calc.direct.cell.font import FontEffects, FontLine, FontUnderlineEnum
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket(), opt=Lo.Options(verbose=True)):
doc = Calc.create_doc()
sheet = Calc.get_sheet()
GUI.set_visible(True, doc)
Lo.delay(500)
Calc.zoom_value(doc, 400)
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")
font_effects = FontEffects(
color=CommonColor.RED,
underline=FontLine(line=FontUnderlineEnum.SINGLE, color=CommonColor.BLUE),
shadowed=True,
)
font_effects.apply(rng)
f_effects = FontEffects.from_obj(rng)
assert f_effects.prop_color == CommonColor.RED
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Setting the font effects
font_effects = FontEffects(
color=CommonColor.RED,
underline=FontLine(line=FontUnderlineEnum.SINGLE, color=CommonColor.BLUE),
shadowed=True,
)
font_effects.apply(rng)
Running the above code will produce the following output in Fig. 404 and Fig. 403.
Getting the font effects from a range
# ... other code
f_effects = FontEffects.from_obj(cell)
assert f_effects.prop_color == CommonColor.RED