如何在号码后添加欧元符号/符号?

时间:2013-12-27 06:41:18

标签: excel python-2.7 excel-formula

如何在Excel中使用Python在数字后面添加欧元货币符号?

1)如果我在u'this is a string'之后添加str(object["price_1"]),那么它可以正常运行:

worksheet.merge_range(17, 6, 17, 8, '=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT("'
    + str(objEct["price_1"])
    + u'this is a string' 
    + '","#,###.00"),",","@"),".",","),"@",".")', format10)
# in European format

2)但是如果我为欧元符号添加u'\u20AC',那么它不会显示在excel表中:

worksheet.merge_range(17, 6, 17, 8, '=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT("'
    + str(objEct["price_1"])
    + u'\u20AC' 
    + '","#,###.00"),",","@"),".",","),"@",".")', format10) 

有什么建议吗?

其他例子:

>>> print unicode(u'\u20ac')
Traceback (most recent call last):
  File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver\_sandbox.py", line 1, in <module>
    # Used internally for debug sandbox under external interpreter
  File "C:\Program Files (x86)\Wing IDE 3.2\bin\2.7\src\debug\tserver\dbgutils.py", line 1280, in write
  File "C:\Python27\Lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac' in position 0: character maps to <undefined>

1 个答案:

答案 0 :(得分:0)

worksheet.merge_range(17, 6, 17, 8, '=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT("' + str(objEct["price_1"]) + '","#,###.00'+ u"\u20AC" +'"),",","@"),".",","),"@",".")', format10) # in European format