最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Error on numberFormatLocal on Office Scripts - Stack Overflow

matteradmin6PV0评论

I want to automize some format work in one of my excel files. Therefore I used macros for a long time - now it's time to move to scripts I thought.

In the old world the cutsom style formating was done the following way:

    With Range(SB_TABLE_NAME + "[Menge Geliefert]")
        .NumberFormat = "## \Stk\."
    End With

With scripts its nearly the same

    cellColumn = sbOrderTable.getColumnByName("Menge Geliefert").getRange()
    cellColumn.setNumberFormatLocal("## \S\tk\.");

I also used the recording to be sure the number format is correct (!) but as soon as I do run the script I get the following error: Range setNumberFormatLocal: The argument is invalid, missing, or in incorrect format.

Do anyone has an idea why the recording is storing the user defined format but the running script failes with it? I also used the getNumberFormatLocal() to get the current formating - result: "## \S\tk." - so I get a little confused...

As described I wanted to set a range of cells (a column in a table) to a specifig fomrat.

I want to automize some format work in one of my excel files. Therefore I used macros for a long time - now it's time to move to scripts I thought.

In the old world the cutsom style formating was done the following way:

    With Range(SB_TABLE_NAME + "[Menge Geliefert]")
        .NumberFormat = "## \Stk\."
    End With

With scripts its nearly the same

    cellColumn = sbOrderTable.getColumnByName("Menge Geliefert").getRange()
    cellColumn.setNumberFormatLocal("## \S\tk\.");

I also used the recording to be sure the number format is correct (!) but as soon as I do run the script I get the following error: Range setNumberFormatLocal: The argument is invalid, missing, or in incorrect format.

Do anyone has an idea why the recording is storing the user defined format but the running script failes with it? I also used the getNumberFormatLocal() to get the current formating - result: "## \S\tk." - so I get a little confused...

As described I wanted to set a range of cells (a column in a table) to a specifig fomrat.

Share Improve this question asked Nov 18, 2024 at 16:11 PascalPascal 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

The backslash in ## \Stk\. is an escape character. Pls change it to ! in OfficeScript.

cellColumn.setNumberFormatLocal("## !Stk!.");

Pls try below code, it creates same number format ## !Stk!. on my pc.

selectedSheet.getRange("a1").setNumberFormatLocal("## \\S\\tk\\.");
Post a comment

comment list (0)

  1. No comments so far