简体   繁体   中英

Python Docx add output of simple math equation

How do I add the output of a simple math equation to my docx doc?

For example

math = 2+2

math

add_paragraph can only do strings and not integers. Is there a work around for this?

p = document.add_paragraph(math)
document.save('doc.docx')

Use casting

math_string = str(math)
p = document.add_paragraph(math_string)
document.save('doc.docx')

将int转换为字符串吗?

p = document.add_paragraph(str(math))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM