當前位置:編程學習大全網 - 編程軟體 - python編程,將壹個docx文件中所有‘a’替換為‘b’,然後保存為zip格式,解壓之後可以看到處理後的結果

python編程,將壹個docx文件中所有‘a’替換為‘b’,然後保存為zip格式,解壓之後可以看到處理後的結果

# -*- coding: utf-8 -*-

#!/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()

中間缺少壹個函數,這個自己找吧

  • 上一篇:我想學習計算機編程,因為剛畢業,專業是藝術類,數學英語都不好,編程只學過c,所以怕投身編程後沒有更
  • 下一篇:數控銑問題 我在學習數控銑床,老師要求壹個100*200鋁板畫z是-5.的壹個五角星。請問程序怎麽編
  • copyright 2024編程學習大全網