I try to use python-docx to read a ms word document, and I don't found a function or method in API.If I wanna read formula in ms word, any advice? update: I try to print all text attribute of document object with follow code,it can't show any formula information at all.
from docx import Document
from docx.shared import Inches
import collections
def object_walk(obj,stack):
result=set()
id_hex=hex(id(obj))
if id_hex in id_set:
return result
else:
id_set.add(id_hex)
if len(stack)==8 or obj is None:
return result
for attr in (name for name in dir(obj) if not name.startswith('_')):
if attr=="text":
print(getattr(obj,attr),"============",stack)
if isinstance(obj, collections.Iterable):
i=0
for item in obj:
stack.append(attr+str(i))
object_walk(item,stack)
stack.pop()
i+=1
else:
stack.append(attr)
try:
object_walk(getattr(obj,attr),stack)
except:
pass
stack.pop()
document=Document("demo.docx")
id_set=set()
object_walk(document,["root"])