Python 3.x python:如何通过一些重复的关键字拆分大的.docx文件

Python 3.x python:如何通过一些重复的关键字拆分大的.docx文件,python-3.x,python-docx,Python 3.x,Python Docx,我想根据一些重复的关键字将.docx文件拆分成小的.docx文件。比如,我的文件有数据 ABCD: KJNDLF jfnkajnfak KJNLKL fwefagasdg ABCD: 广告 asdafvdfv 非洲 ABCD: sdfqerf 力量 埃勒 我想将两个“ABCD”内的内容复制到名为ABCD1…ABCD(n)的不同文件中 我的代码是 def writeFiles(): '''User defined string to search and split the doc, Doc

我想根据一些重复的关键字将.docx文件拆分成小的.docx文件。比如,我的文件有数据

ABCD: KJNDLF jfnkajnfak KJNLKL fwefagasdg

ABCD: 广告 asdafvdfv 非洲

ABCD: sdfqerf 力量 埃勒

我想将两个“ABCD”内的内容复制到名为ABCD1…ABCD(n)的不同文件中

我的代码是

def writeFiles():
  '''User defined string to search and split the doc, Doc will get
     split after searching this string as a starting line for the 
     doc till one line before the string appers again'''

    feature = input (" Please provide the Feature ID \n : ")  /*asking keyword from user

  #Asking user to select desired file 
    print ("Please select file to split")

    path=get_path();  /*function for file browsing



    i =1;
    document = Document(docx=path)      
    for paragraph in document.paragraphs:
      if feature in paragraph.text:
        document.add_paragraph()
        document.add_page_break()
        name = feature+repr(i)+".docx"
        document.save(name);
        i= i+1;
如果文件多次使用关键字“N”,但没有在两个重复关键字之间复制数据,则代码正在生成和复制完整数据“N”个文件

下面的代码现在正在用关键字分割文件,但是格式、字体和表格都没有出现

try:
    if feature in paragraph.text:
      name = feature + repr(i) + ".docx"
      i = i + 1
      doc.add_paragraph(paragraph.text.split(feature)[0])
      doc.save(name);
      doc = Document()
      doc.add_paragraph(paragraph.text.split(feature)[1])

else:
      doc.add_paragraph(paragraph.text)

请帮我解决……

您的代码格式不正确,即for循环和if station后没有缩进。我已经做了更改,现在可以了吗?您是否看到了感谢链接…但在使用二进制和ZIP操作后,我仍然无法拆分文件。我不是python方面的专业人士,所以在我的水平上我正在做什么。