def _insert_paragraph_before(item, text, style=None): p = CT_P.add_p_before(item._element) p2 = Paragraph(p, item._parent) p2.text = text p2.style = style return p2
sets = source_document.element.body.xpath('w:p | w:tbl') # print(query_list) for pointer in range(len(query_list)): # print('this query:', query_list[pointer].split('、')[1]) for i in range(len(sets)): if isinstance(sets[i], CT_P): para = Paragraph(sets[i], source_document) if query_list[pointer].split('、')[1] in para.text: # print('Found:') # 获取接下来迭代的内容 temp_list = [] for j in range(i + 1, len(sets)): # 遇到标题则break if isinstance(sets[j], CT_P): paragraph_temp = Paragraph(sets[j], source_document) paragraph_temp.text = paragraph_temp.text.replace( '【', '').replace('】', '') # print(paragraph_temp.text) # print('------------------->') temp_list.append(paragraph_temp) # if re.findall('\([一|二|三|四|五|六|七|八|九|十]*\)', paragraph_temp.text) or re.findall('[一|二|三|四|五|六|七|八|九|十]*、', paragraph_temp.text): # break # if re.findall('[一|二|三|四|五|六|七|八|九|十]*、', paragraph_temp.text): if re.findall("\([一|二|三|四|五|六|七|八|九|十]\)", paragraph_temp.text) or re.findall( '[一|二|三|四|五|六|七|八|九|十]\、', paragraph_temp.text): del (temp_list[-1]) break if isinstance(sets[j], CT_Tbl): table_temp = Table(sets[j], source_document) temp_list.append(table_temp)