0

I'm trying to make my program import data from xlsx file. Here's the part of code:

def Volunteer_list_show():
    volunteer_list = load_workbook('Volunteer_list.xlsx')
    surnames = volunteer_list['A']
    names = volunteer_list['B']
    ...
    identificator = volunteer_list['K']

And have this type (UnicodeDecodeError) of error message:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xec in position 1: invalid continuation byte

I tried this solution from other thread:

def Volunteer_list_encoding_check(volunteer_list):
    encodings = ['utf-8', 'iso-8859-1', 'windows-1251', 'windows-1252']
    for encoding in encodings:
        try:
            decoded_file = volunteer_list.decode(encoding)
        except UnicodeDecodeError:
            pass
        else:
            decoded_file = decoded_file.encode("utf-8")
            break
    else:
        print('Not approved encoding')  

But, I have the same error as first time, even if def Volunteer_list_show() is deleted. Opening of workbook via load_workbook function alone does not cause problem. Other code checked and does not cause problem.

How to decode-encode xlsx here in UTF-8?

  • The traceback is unclear where the problem occurs but it looks unrelated tot he code. The second function looks like nonsense: sequences don't have encodings. – Charlie Clark Sep 06 '22 at 10:23
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 06 '22 at 10:29

1 Answers1

0

I've found my mistake: you have to work with active sheet to take cells or their values, so I've just added this code:

volunteer_list_act = volunteer_list.active

It works now.