#!/usr/bin/env python
導入docx
導入zip文件
從斯特林堡進口斯特林堡
從processing _ units . XML _ processing _ unit導入XmlProcessingUnit
導入文檔_工具
if __name__ == '__main__ ':
m = docx.opendocx('e:/test.docx ')
p = XmlProcessingUnit('docx ')
過程= p .過程(m)
zfile = zipfile。ZipFile('e:/test.docx ')
out_docx_file = StringIO()
doc_utils.save_docx(zfile,process,out_docx_file)
out_txt_file = StringIO()
doc_utils.docx_to_txt(輸出文件,輸出文件)
'''
out_file = StringIO()
用zipfile。ZipFile(out_file,' w ',compression=zipfile。ZIP_DEFLATED)為f:
f.writestr('test123.docx ',out_docx_file.getvalue())
#f.writestr('%s.txt' % out_file,out_txt_file.getvalue())
'''
zfile2 = zipfile。ZipFile('e:/test.zip ',' w ',ZipFile。ZIP _放氣)
zfile2.writestr('test.docx ',out_docx_file.getvalue())
#zfile2.writestr('test.txt ',out_txt_file.getvalue())
#result = out_file.getvalue()
#打印結果
out_docx_file.close()
out_txt_file.close()
#out_file.close()
中間少了壹個功能。自己找吧。