Python Openpyxl 语言俄语



我在拉取和打印俄语字符串时遇到问题

使用 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

打印时生成错误返回codecs.charmap_encode(输入,错误,encoding_map(

谢谢

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

最新更新