I format all my columns in an excel file using the xlsxwriter module:
def to_excel(video_report, feed):
writer = pd.ExcelWriter('daily_report.xlsx', engine='xlsxwriter')
video_report.to_excel(writer, sheet_name='Video Overview', na_rep="-")
workbook = writer.book
worksheet = writer.sheets['Video Overview']
integer = workbook.add_format({'num_format': '0', 'align': 'center'})
decimal = workbook.add_format({'num_format': '0.00', 'align': 'center'})
percentage = workbook.add_format({'num_format': '0.0%', 'align': 'center'})
zebra = workbook.add_format({'bold': True})
worksheet.set_column('B:B', 13, integer)
worksheet.set_column('C:C', 17, percentage)
worksheet.set_column('D:D', 19, percentage)
worksheet.set_column('E:E', 15, integer)
worksheet.set_column('F:F', 15, percentage)
worksheet.set_column('G:G', 15, decimal)
worksheet.set_column('H:H', 13, integer)
worksheet.set_column('I:I', 13, integer)
worksheet.set_column('J:J', 13, integer)
worksheet.set_column('K:K', 13, integer)
worksheet.set_column('L:L', 13, integer)
worksheet.set_row(3, 20, zebra)
feed.to_excel(writer, sheet_name='Feed Position', na_rep="-")
workbook1 = writer.book
worksheet1 = writer.sheets['Feed Position']
integer = workbook1.add_format({'num_format': '0', 'align': 'center'})
worksheet1.set_column('B:HU', 4, integer)
writer.save()
I would like to add zebra striping to my rows, but I cannot find a way to format line by line without overwriting column formatting. As a test, I created a bold format and applied it to row 3, but it replaced the column formatting. Can I add row by row formatting without overwriting my column with column formatting? Or maybe there is an idiom for a zebra stripe that avoids line-by-line formatting?
EDIT: I think my situation is getting complicated because the data is already written to excel using the pandas function. In any case, will this simplify the formatting of rows and columns?