Home > front end >  Separating thousands using gspread formatting
Separating thousands using gspread formatting

Time:10-01

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?

CodePudding user response:

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.

CodePudding user response:

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:

  • Related