我正在尝试将以下代码转换为python:
Columns("C:C").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
, Formula1:="=50"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
我有以下python代码:
wb.ActiveSheet.Columns("F:AA").Select
formula1 = "=50"
wb.ActiveSheet.Columns("F:AA").FormatConditions.Add(excel.XlFormatConditionType.xlCellValue, excel.XlFormatConditionOperator.xlGreaterEqual, formula1,formula2)
wb.ActiveSheet.Columns("F:AA").FormatConditions(excel.Selection.FormatConditions.Count).SetFirstPriority()
wb.ActiveSheet.Columns("F:AA").FormatConditions(1).Font.Bold = True
wb.ActiveSheet.Columns("F:AA").FormatConditions(1).Italic = False
wb.ActiveSheet.Columns("F:AA").FormatConditions(1).Font.Strikethrough = False
wb.ActiveSheet.Columns("F:AA").FormatConditions(1).Font.TintAndShade = 0
wb.ActiveSheet.Columns("F:AA").FormatConditions(1).Interior.PatternColorIndex = xlAutomatic
wb.ActiveSheet.Columns("F:AA").FormatConditions(1).Interior.Color = 5296274
wb.ActiveSheet.Columns("F:AA").FormatConditions(1).Interior.TintAndShade = 0
wb.ActiveSheet.Columns("F:AA").FormatConditions(1).StopIfTrue = False
我收到以下错误:
'<win32com.gen_py.Microsoft Excel 12.0 Object Library._Application instance at 0x174381576>' object has no attribute 'XlFormatConditionType'
答案 0 :(得分:3)
可能会改变
excel.XlFormatConditionType.xlCellValue
excel.XlFormatConditionOperator.xlGreaterEqual
到
win32com.client.constants.xlCellValue
win32com.client.constants.xlGreaterEqual