ericremoreynolds / excelpython

An open source, easy to use interface for calling Python code from Excel
http://ericremoreynolds.github.io/excelpython
BSD 2-Clause "Simplified" License
234 stars 58 forks source link

Not support UTF8 Encoding? #42

Closed legendxcheng closed 9 years ago

legendxcheng commented 9 years ago

I tried to use ExcelPython in a xlsm file containing Asian Characters, it didn't work. ExcelPython is a very promising tool for people play with numbers, good job!

sjobeek commented 9 years ago

No unicode is unfortunately a deal-breaker =/

Otherwise looks very promising.

fzumstein commented 9 years ago

unicode is supported but you may you have to declare the encoding at the top of your source file. Also make sure that the string is marked as unicode by prepending a u on Python 2:

# -*- coding:utf-8 -*-
from xlpython import xlfunc

@xlfunc
def unicode_test():
    return u'öü'

Called from Excel, this will work correctly. Note that often, you will want to declare the encoding while reading in some data. For example when reading in a csv file:

import csv
with open('some.csv', newline='', encoding='utf-8') as f:
    reader = csv.reader(f)
    for row in reader:
        print(row)

Using pandas, this would look something like this:

df = pd.read_csv('some.csv', encoding='utf-8')