简体   繁体   中英

Separating thousands using gspread formatting

I have a number values which I am trying to format as a currency with a thousand separator in google sheets using gspread and gspread_formatting:

A

151644
56464

Desired output should look like this:

A

£ 151,644
£ 56,464

I tried:

worksheet.format('A', {'numberFormat': {'type' : 'CURRENCY', 'pattern': '£#.##0.'}})
worksheet.format('A', {'numberFormat': {'type' : 'CURRENCY', 'pattern': '£###. ###0'}})
worksheet.format('A', {'numberFormat': {'type' : 'CURRENCY', 'pattern': '£#.###'}})
worksheet.format('A', {'numberFormat': {'type' : 'CURRENCY', 'pattern': '£#.#'}})
worksheet.format('A', {'numberFormat': {'type' : 'CURRENCY', 'pattern': '£###'}})

Which none of return the expected result, I couldn't find documentation about the formatting patterns to have a thousand separators.

How could I achieve this using gspread_formatting package?

About How could I achieve this using gspread_formatting package? , in this case, how about the following sample script?

Sample script:

format_cell_range(worksheet, 'A', cellFormat(numberFormat={'type': 'CURRENCY', 'pattern': '£ #,###'}))

Note:

  • I added this answer as the additional information because I thought that when various approaches are shown, they might be useful for other users.

References:

I was able to achieve the format using:

worksheet.format('A', 
{'numberFormat': 
{'type' : 'CURRENCY', 'pattern': '£ #,###'}})

Not sure if this is the ideal format but it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM