Python
1color1 = [sheet1, sheet2, sheet3, sheet4, sheet5, sheet6, sheet7, sheet10] 2searchlist1 = ['M','O','Q','S'] 3 4def originalXML(color, searchlist): 5 for i in searchlist: 6 red_fill = PatternFill(bgColor="FFC7CE") 7 red_dxf = DifferentialStyle(fill=red_fill) 8 red_r = Rule(type="expression", dxf=red_dxf, stopIfTrue=True) 9 AAA = str('=K1=VLOOKUP(K1,$' + i + '$1:$' + i + '$300,1,0)') 10 red_r.formula = [AAA] 11 color.conditional_formatting.add("K1:K3000", red_r) 12 13def originalXML_color(colors, searchlist): 14 for color in colors: 15 originalXML(color, searchlist) 16 17originalXML_color(color1, searchlist1) 18 19 20color2 = [sheet8] 21searchlist2 = ['M','O','Q','S','U','W','Y','AA','AC','AE','AG','AI','AK','AM','AO','AQ','AS','AU','AW','AY'] 22 23def originalXML(color, searchlist): 24 for i in searchlist: 25 red_fill = PatternFill(bgColor="FFC7CE") 26 red_dxf = DifferentialStyle(fill=red_fill) 27 red_r = Rule(type="expression", dxf=red_dxf, stopIfTrue=True) 28 AAA = str('=K1=VLOOKUP(K1,$' + i + '$1:$' + i + '$4500,1,0)') 29 red_r.formula = [AAA] 30 color.conditional_formatting.add("K1:K4500", red_r) 31 32def originalXML_color(colors, searchlist): 33 for color in colors: 34 originalXML(color, searchlist) 35 36originalXML_color(color2, searchlist2) 37 38 39color4 = [sheet11] 40searchlist4 = ['R','T','V','X','Z','AB','AD', 'AF','AH','AJ','AL','AN','AP','AR','AT'] 41 42 43def originalXML(color, searchlist): 44 for i in searchlist: 45 red_fill = PatternFill(bgColor="FFC7CE") 46 red_dxf = DifferentialStyle(fill=red_fill) 47 red_r = Rule(type="expression", dxf=red_dxf, stopIfTrue=True) 48 AAA = str('=P1=VLOOKUP(P1,$' + i + '$1:$' + i + '$4500,1,0)') 49 red_r.formula = [AAA] 50 color.conditional_formatting.add("P1:P4500", red_r) 51 52def originalXML_color(colors, searchlist): 53 for color in colors: 54 originalXML(color, searchlist) 55 56originalXML_color(color4, searchlist4) 57 58 59wb.save(LLD_save_name)
上記はエラー無くエクセルに条件付き書式が設定されるのですが、
それを下記のようにifでまとめようとしたところ、エクセルのシートの一部が破損してしまいました。
ifの分岐が悪いのかご教授いただければ幸いです。よろしくお願いいたします。
Python
1color1 = [sheet1, sheet2, sheet3, sheet4, sheet5, sheet6, sheet7, sheet10] 2searchlist1 = ['M','O','Q','S'] 3 4color2 = [sheet8] 5searchlist2 = ['M','O','Q','S','U','W','Y','AA','AC','AE','AG','AI','AK','AM','AO','AQ','AS','AU','AW','AY'] 6 7color4 = [sheet11] 8searchlist4 = ['R','T','V','X','Z','AB','AD', 'AF','AH','AJ','AL','AN','AP','AR','AT'] 9 10 11def originalXML(color, searchlist): 12 for i in searchlist: 13 red_fill = PatternFill(bgColor="FFC7CE") 14 red_dxf = DifferentialStyle(fill=red_fill) 15 red_r = Rule(type="expression", dxf=red_dxf, stopIfTrue=True) 16 if(color == sheet11): 17 AAA = str('=P1=VLOOKUP(P1,$' + i + '$1:$' + i + '$4500,1,0)') 18 red_r.formula = [AAA] 19 color.conditional_formatting.add("P1:P4500", red_r) 20 elif(color == sheet8): 21 BBB = str('=K1=VLOOKUP(K1,$' + i + '$1:$' + i + '$4500,1,0)') 22 red_r.formula = [BBB] 23 color.conditional_formatting.add("K1:K4500", red_r) 24 else: 25 BBB = str('=K1=VLOOKUP(K1,$' + i + '$1:$' + i + '$3000,1,0)') 26 red_r.formula = [BBB] 27 color.conditional_formatting.add("K1:K3000", red_r) 28 29 30def originalXML_color(colors, searchlist): 31 for color in colors: 32 originalXML(color, searchlist) 33 34originalXML_color(color1, searchlist1) 35originalXML_color(color2, searchlist2) 36 37originalXML_color(color4, searchlist4) 38
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。