Calc Modify Cell Background Color
Overview
The ooodev.format.calc.modify.cell.background.Color
class is used to set the background color of a style.
Apply the background color to a style
Setup
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.background import Color as StyleBgColor, StyleCellKind
from ooodev.utils.color import StandardColor
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = Calc.create_doc()
GUI.set_visible(True, doc)
Lo.delay(500)
Calc.zoom_value(doc, 400)
style = StyleBgColor(
color=StandardColor.BLUE_LIGHT2, style_name=StyleCellKind.DEFAULT
)
style.apply(doc)
style_obj = StyleBgColor.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 color
style = StyleBgColor(
color=StandardColor.BLUE_LIGHT2, style_name=StyleCellKind.DEFAULT
)
style.apply(doc)
Running the above code will produce the following output in Fig. 416.
Getting the color from a style
style_obj = StyleBgColor.from_style(doc=doc, style_name=StyleCellKind.DEFAULT)
assert style_obj.prop_style_name == str(StyleCellKind.DEFAULT)