编程语言
首页 > 编程语言> > Python中的Excel VBA FormatConditions

Python中的Excel VBA FormatConditions

作者:互联网

我试图将以下代码转换为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'

解决方法:

可能会改变

excel.XlFormatConditionType.xlCellValue
excel.XlFormatConditionOperator.xlGreaterEqual

win32com.client.constants.xlCellValue
win32com.client.constants.xlGreaterEqual

标签:python,excel,excel-vba,vba
来源: https://codeday.me/bug/20190630/1340314.html