.Net 脚本设置Excel的条件格式

来源:互联网 发布:linux下安装配置jdk 编辑:程序博客网 时间:2024/05/16 07:44

‘//创建Excel实例

        Dim AppExcel As Excel.Application = New Excel.Application

’//创建Excel单元格区域实例

        Dim theRang As Excel.Range = AppExcel.Range(AppExcel.Cells(10, 10), AppExcel.Cells(10, 10))

‘//创建第一个条件格式
        Dim fm1 As Excel.FormatCondition = theRang.FormatConditions.Add(Excel.XlFormatConditionType.xlCellValue, Excel.XlFormatConditionOperator.xlEqual, Formula1:="Pass")

’//创建第二个条件格式

       Dim fm2 As Excel.FormatCondition = theRang.FormatConditions.Add(Excel.XlFormatConditionType.xlCellValue, Excel.XlFormatConditionOperator.xlEqual, Formula1:="Fail")

‘//输出格式
        fm1.Interior.ColorIndex = 4 ’//如果单元格的值为“Pass”,则用绿色填充此格背景
        fm2.Interior.ColorIndex = 3 ‘//如果单元格的值为“Fail”,则用红色填充此格背景