问题:
Python3中使用xltuils进行Excel保存报错:TypeError: descriptor 'decode' requires a 'bytes' object but received a 'NoneType'
具体错误如下:
代码如下:
# *===================================*
# -*- coding: utf-8 -*-
# * Time : 2020-03-28 22:05
# * Author : zhangsf
# *===================================*
import xlrd
from xlutils.copy import copy
source = r"./excel_1.xls"
print("hi")
# open excel
old_excel = xlrd.open_workbook(source, formatting_info=True)
# copy excel
new_excel = copy(old_excel)
# save
new_excel.save("./new.xls")
报错信息中已经提到了进入 anaconda3/lib/python3.7/site-packages/xlwt目录找到的UnicodeUtils.py第50行报错
解决办法:
貌似这是一个库文件的bug,应该是Unicode编码处理问题,需要Hack一下库文件,修改后即正常。
进入之后找到upack2()方法
将把里面的upack2()方法修改成
然后重新运行: