python-docx创建Word文档报错ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes
python-docx创建Word文档报错ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters
这个怎么解决?
网友回复
方法一:
字符前加u,例如:
p = document.add_paragraph(u"哈哈 ")
方法二:编码转换
p = document.add_paragraph(p.encode('utf-8').decode("utf-8"))
方法三:
s = re.sub(u"[\\x00-\\x08\\x0b\\x0e-\\x1f\\x7f]", "", s)p = document.add_paragraph(s)