我写了个demo,你根据实际情况做下更改
import xlrd
import xlwt
if __name__ == "__main__":
workbook = xlrd.open_workbook('test.xlsx')
target = xlwt.Workbook(encoding='utf-8')
table = workbook.sheet_by_index(0)
rows = table.nrows
for row in range(rows):
if (row == 0):
continue
row_data = table.row_values(row)
name = row_data[0]
[start, end] = row_data[1].split("-")
sheet = target.add_sheet(name)
sheet.write(0, 0, '名称')
sheet.write(0, 1, '案卷号')
for i in range(int(end) - int(start)):
sheet.write(1 + int(i), 0, name)
sheet.write(1 + int(i), 1, 1 + i + int(start))
target.save("target.xlsx")
test.xlsx
target.xlsx
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…