简体   繁体   中英

Python decoding error on Excel with xlrd

I know this is a recurrent subject but I'm facing a encoding/decoding error when trying to parse an Excel file (.xlsx) opened with xlrd

    value = sheet.cell(row,col).value
    value = value.decode('utf-8') // also tried cp1252 and iso-8859-15

WARNING: 'ascii' codec can't encode character u'\\xe9' in position xx: ordinal not in range(128)

xlrd doc says that From Excel 97 onwards, the text in Excel spreadsheets has been stored as Unicode. So decoding should not even be necessary.

Any idea what should be done ?

PS My Excel file has some é and à inside.

Still using Python 2? :(

If what you're trying to do is convert from unicode to UTF-8 encoded str , you need to value.encode('utf-8') , not decode .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM