解释 XLSX 文档中的特殊字符

发布于 2024-11-23 23:49:15 字数 86 浏览 0 评论 0原文

我正在使用 xlsx Python 库读取 XLSX 文档,但某些列数据包含特殊字符,例如 _x000D_。如何将其转换为原始形式?

I am using the xlsx Python library to read an XLSX document, but some column data contains special characters like _x000D_. How can this be converted to its original form?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦萦几度 2024-11-30 23:49:15

如果 _x000D_ 应该表示带有十六进制代码点的 unicode 字符,您可以使用正则表达式来查找它们,并使用回调函数将它们转换为适当的值。

import re

input_string = "H_x00E9_llo W_x00D8_rld!"

def parse_escaped_character_match(match):
    return unichr(int(match.group(1), 16))

print re.sub("_x([0-9A-F]{4})_", parse_escaped_character_match, input_string)
# prints "Héllo WØrld!"

If _x000D_ is supposed to represent a unicode character with a hex code point, you could use a regular expression expression to find them and a callback function to convert them to the appropriate value.

import re

input_string = "H_x00E9_llo W_x00D8_rld!"

def parse_escaped_character_match(match):
    return unichr(int(match.group(1), 16))

print re.sub("_x([0-9A-F]{4})_", parse_escaped_character_match, input_string)
# prints "Héllo WØrld!"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文