#!/usr/bin/env python
import docx
import zipfile
from StringIO import StringIO
from processing_units.xml_processing_unit import XmlProcessingUnit
import doc_utils
if __name__ == '__main__':
m = docx.opendocx('e:/test.docx')
p = XmlProcessingUnit('docx')
process = p.process(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_docx_file, out_txt_file)
'''
out_file = StringIO()
with zipfile.ZipFile(out_file, 'w', compression=zipfile.ZIP_DEFLATED) as 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_DEFLATED)
zfile2.writestr('test.docx', out_docx_file.getvalue())
#zfile2.writestr('test.txt', out_txt_file.getvalue())
#result = out_file.getvalue()
#print result
out_docx_file.close()
out_txt_file.close()
#out_file.close()
中間缺少壹個函數,這個自己找吧