import docx
import xlwt
file = docx.Document("1.docx")
work_book = xlwt.Workbook()
work_sheet = work_book.add_sheet('Test')
set_a = []
set_b = []
for i in range(len(file.paragraphs)):
line = str(file.paragraphs[i].text)
if line.startswith('{A}'):
set_a.append(i)
if line.startswith('{B}'):
set_b.append(i)
content_=""
for i in range(0,len(set_a)):
start_index = set_a[i]
end_index = set_b[i]
work_sheet.write(i, 0, file.paragraphs[start_index].text)
for j in range(start_index+1,end_index):
content_ = content_+file.paragraphs[j].text
work_sheet.write(i, 1, content_)
work_sheet.write(i, 2, file.paragraphs[end_index].text)
content_ = ""
work_book.save('Test.xls')
word分行写入Exlcel
最新推荐文章于 2022-11-17 14:23:29 发布