![](/img/trans.png)
[英]How could python treat unicode and non-unicode tuple as equal?
[英]Python-docx ignoring non-unicode Symbols like 'greater than or equal to'
阅读包含表格和文本的单词 docx 时
使用 python-docx 进入 python ,所有符号都会被删除。 这些符号都是使用正常的插入符号步骤创建的。 它说它来自字体符号,字符代码179 ,来自符号(十进制)
Python-docx 只是将其显示为 ''。 左侧的“加号或减号”符号相同。
从段落中读取文本(不是表格中的文本)时,我使用以下代码:
def listText():
test = docx.Document('Problem.docx')
testp=test.paragraphs[0] #The only paragraph in the test docx
stringThatShouldHaveSymbol = testp.text
print(stringThatShouldHaveSymbol)
return stringThatShouldHaveSymbol
这仅从仅包含这些符号的文档中返回 ''。 如果它有符号,那么 10 它只会返回 10。
我也尝试了这种 xml 方法,但即使返回“”。
def get_accepted_text(p):
"""Return text of a paragraph after accepting all changes"""
xml = p._p.xml
if "w:del" in xml or "w:ins" in xml:
tree = docx.Document.XML(xml)
runs = (node.text for node in tree.getiterator(TEXT) if node.text)
return "".join(runs)
else:
return p.text
for p in doc.paragraphs:
print(p.text)
print("---")
print(get_accepted_text(p))
print("=========")
如何从这些文档中提取数据? 有没有办法以编程方式将这些符号(十进制)转换为 Unicode(十六进制)?
尝试这个
如果你现在阅读 docx 文件,你应该得到你的符号。
不知道为什么符号字体不起作用。 在 Arial 中,179 是一个 3 上标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.