读取word文档里某段文字,查找字符所在位置,提取改文字。
注意中文需要转化。name = old_text.encode("gbk")
def sen(i, str1, str2,x,y):
old_text = doc.paragraphs[i].text
name = old_text.encode("gbk")
older1 = old_text.find(u'{}'.format(str1))+x
older2 = old_text.find(u'{}'.format(str2),older1+y)
older = old_text[older1:older2]
return older
older_sum_sub = sen(31, "周末", "天",3,1)
print(older_sum_sub)