[英]Python ExcelWriter adding conditional formatting to multiple tables/dataframes
I try to add conditional formatting to more than one table in excel. For one table this line works我尝试向 excel 中的多个表添加条件格式。对于一个表,此行有效
worksheet.conditional_format('B3:K9', {'type':'2_color_scale', 'min_color':'yellow', 'max_color':'green'})
But I want to add conditional formatting also to the tables in the specified range: M3:O9, P3:X9, B11:K17, M11:O17但我也想为指定范围内的表格添加条件格式:M3:O9、P3:X9、B11:K17、M11:O17
I tried to pass the ranges in a list but i get the following error:我试图传递列表中的范围,但出现以下错误:
int() argument must be a string, a bytes-like object or a number, not 'list'
I managed to do it with a workaround with a loop.我设法通过一个循环的解决方法来做到这一点。
for i in range(0,9): for j in range(0,8): worksheet.conditional_format(2+i*10,1+j*6,8+i*10,4+j*6, {'type':'2_color_scale', 'min_color':'green', 'max_color':'yellow'})
The ranges changed a bit.范围发生了一些变化。 So I start at row 3 and column 2 and color the following 7 rows and 4 columns.
所以我从第 3 行和第 2 列开始,并为以下 7 行和 4 列着色。 Then i skip the empty rows and columns.
然后我跳过空行和列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.