Loading text from .docx to MySQL using Python-docx

雨燕双飞 提交于 2019-12-12 06:06:33

问题


As of now, I am using Python-docx to convert the text in a .docx file into a single string.

f = open(os.path.expanduser("~/documents/myFile.docx"))

document = opendocx(f)

docString = ''.join(getdocumenttext(document))

I am then parsing the string using simple built-in Python split methods. Once the string is parsed into a list, I am loading that list into a MySQL database. This works great, but my only problem is I want to preserve the special characters.

The database supports these special character (utf-8) but a lot of characters and formatting (italics, bold, etc.) are lost when I convert the .docx into a string.

I want to be able to parse and load text with the formatting intact from the .docx file.

来源:https://stackoverflow.com/questions/31006794/loading-text-from-docx-to-mysql-using-python-docx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!