Formatting data cell from macro in calc

Hello!

I would like to format the number data
in a cell with macro.

My code is

oSheet.getCellByPosition(12,16).Value = format(T_rms,"###00.00")

oSheet.getCellByPosition(13,16).Value = format(n_rms,"###00.00")

But It’s not correct.

Do you have an idea?

Thank You in advance

you have to set the required Format to the output-cells, here’s an python-example close to your given code

from com.sun.star.uno import RuntimeException

def set_and_format():
    doc = XSCRIPTCONTEXT.getDocument()
    numbers = doc.NumberFormats
    locale = doc.CharLocale
    try:
        nl = numbers.addNew( "###00.00",  locale )
    except RuntimeException:
        nl = numbers.queryKey("###00.00", locale, False)
    sheet = doc.CurrentSelection.Spreadsheet
    out = sheet.getCellRangeByPosition(12, 16, 13, 16)
    out.NumberFormat = nl
    out.DataArray = ((42, 5),) #replace with you own values

Thank you, Karolus :slight_smile:
I will try