shunelly 2020-03-03
如何迈出最难的第一步,把word导入python?
其实很简单,以下是代码:
import docx,os #将word文本导入 def getText(filename): doc=docx.Document(filename) fullText=[] for para in doc.paragraphs: fullText.append(para.text) return ‘\n\n‘.join(fullText) if __name__=="__main__": filename1=r‘/Users/fangluping/Desktop/数据分析笔试试题/长亮数据-咨询部笔试题目-附件/03.docx‘ text1=getText(filename1) print(text1)