pandas to_excel IllegalCharacterError异常处理

时间:2025-04-27 07:28:21
def get_IllegalCharacter(value): # 定义文本编码 与 输入、输出文本编码保持一致 encoding = 'utf-8' if value is None: return # convert to unicode string if not isinstance(value, str): # from import unicode value = unicode(value, encoding) value = unicode(value) # string must never be longer than 32,767 characters # truncate if necessary value = value[:32767] ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]') if next(ILLEGAL_CHARACTERS_RE.finditer(value), None): return '文本异常' return value