-2

I have a problem when I pull and print the Russian-language strings

Use Python 2.7 and Lib Openpyxl

Code use is :

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

Error generate when print return codecs.charmap_encode(input,errors,encoding_map)

thanks

Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
Bonni
  • 41
  • 2
  • 10

1 Answers1

0

The problem is with your print statement and Python 2. All non-numerical cell values are unicode so your code must manage the conversion from unicode to a suitable encoding for your system.

Charlie Clark
  • 18,477
  • 4
  • 49
  • 55