UnicodeDecodeError utf8 codec can’t decode byte 0xff in position 0 invalid start byte

Python error при запуске script openpyxl

value = unicode(value, self.encoding)
UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xff in position 0: invalid start byte

Script Python

# -*- coding: 1251 -*-

from openpyxl import Workbook

if __name__ == '__main__':
    excell = Workbook()
    sheet = excell.active
    sheet["A1"] = "ячейка на кириллице"
    excell.save(filename="excell.xlsx")

Для устранения ошибки необходимо добавить кодировку windows-1251

# -*- coding: 1251 -*-

from openpyxl import Workbook

if __name__ == '__main__':
    excell = Workbook()
    sheet = excell.active
    sheet["A1"] = "ячейка на кириллице".decode('windows-1251')
    excell.save(filename="excell.xlsx")

excell python ячейка

742

Leave a Reply

Ваш адрес email не будет опубликован.