Python Openpyxl语言俄语

时间:2017-03-27 07:53:48

标签: python openpyxl translate cyrillic

当我拉动并打印俄语字符串

时,我遇到了问题

使用Python 2.7和Lib Openpyxl

代码使用是:

workbook = load_workbook(filename ='sample.xlsx')
first_sheet = workbook.get_sheet_names()[0]
worksheet = workbook.get_sheet_by_name(first_sheet)

ws = workbook.active

riga = 0;
id_cell = 0;
lenght_word = 0;

for row in worksheet.iter_rows():
    riga+=1
    id_cell=0;
    if riga > 4:
        for cell in row:
            id_cell+=1
            if id_cell == 3:
                lenght_word = cell.value
                print lenght_word
            if id_cell > 3:   
                try:
                    #print cell
                    str_lenght = len(cell.value)
                    print cell.value, str_lenght

打印时生成错误 return codecs.charmap_encode(input,errors,encoding_map)

谢谢

1 个答案:

答案 0 :(得分:0)

问题在于您的print语句和Python 2.所有非数字单元格值都是unicode,因此您的代码必须管理从unicode到系统的合适编码的转换。