xlsxwriter - avoid repeating code in xlsxwritter -
i want create time sheet xlsxwritter, find process , going tremendously long code below:
worksheet.set_column('b6:b6', 3) worksheet.write('c9', "day") worksheet.write('c7', "date") worksheet.write('e7', "start") worksheet.write('f7', "end") worksheet.write('c7', "sun") worksheet.write('c8', "mon") worksheet.write('c9', "tue") worksheet.write('c10', "wed") worksheet.write('c11', "thu") worksheet.write('c12', "fri") worksheet.write('c13', "sat") worksheet.write('j7', "sun") worksheet.write('j8', "mon") worksheet.write('j9', "tue") worksheet.write('j10', "wed") worksheet.write('j11', "thu") worksheet.write('j12', "fri") worksheet.write('j13', "sat") worksheet.write('n7', "sun") worksheet.write('n8', "mon") worksheet.write('n9', "tue") worksheet.write('n10', "wed") worksheet.write('n11', "thu") worksheet.write('n12', "fri") worksheet.write('n13', "sat")
to result in pic:
question : there way achieve such task without keep repeating code >?
does fit need?
you need adjust some_max1 , some_max2 vars
days = ["sun","mon","tue","wed","thu","fri","sat"] rows = range(7,some_max1) cols = range(3,some_max2,10) + range(9,some_max2,10) r in rows: c in cols: worksheet.write( r, c, days[ r % 7 ] )
edit: day, date, start, end: can similar
Comments
Post a Comment