Python Openpyxl语言俄语

Python Openpyxl语言俄语,python,openpyxl,translate,cyrillic,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_wo

我拉并打印俄语字符串时遇到问题

使用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
打印时生成错误 返回编解码器.charmap\u encode(输入、错误、编码\u映射)


谢谢

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

但我使用的代码是:stringa=cell.value stru=stringa.encode('utf-8')查看与源代码不同的字符串还有什么?当您读取该值时,您将始终获得unicode。请使用win7,标准输出的格式为cp850