Ask Your Question
0

Formatting data cell from macro in calc

asked 2017-02-14 14:02:24 +0200

Fede gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-02-14 15:26:49 +0200

karolus gravatar image

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
edit flag offensive delete link more

Comments

Thank you, Karolus :) I will try

Fede gravatar imageFede ( 2017-02-16 09:33:50 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-02-14 14:02:24 +0200

Seen: 957 times

Last updated: Feb 14 '17