Calc Modify Cell Numbers

Overview

The ooodev.format.calc.modify.cell.numbers.Numbers class is used to programmatically set the number properties of a style as seen dialog shown in Fig. 425.

Calc Format Cell dialog Style Cell Numbers

Fig. 425 Calc Format Cell dialog Style Cell Numbers

For more examples of setting number properties see Calc Direct Cell Numbers.

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.numbers import Numbers
from ooodev.format.calc.modify.cell.numbers import StyleCellKind, NumberFormatIndexEnum

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, 100)

        style = Numbers(
            num_format_index=NumberFormatIndexEnum.CURRENCY_1000DEC2_RED,
            style_name=StyleCellKind.DEFAULT,
        )
        style.apply(doc)

        style_obj = Numbers.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 style Number properties

style = Numbers(
    num_format_index=NumberFormatIndexEnum.CURRENCY_1000DEC2_RED,
    style_name=StyleCellKind.DEFAULT,
)
style.apply(doc)

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

Calc Format Cell dialog Style Cell Numbers set

Fig. 426 Calc Format Cell dialog Style Cell Numbers set

Getting cell Number properties from a style

# ... other code

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