.net导出Excel设置颜色font.ColorIndex 各颜色编号

无色 = -4142,
   自动 = -4105,
   黑色 = 1,

   白色 = 2

   红色 = 3,
   鲜绿 = 4,  

   蓝色 = 5,

 黄色 = 6,
   粉红 = 7,
   青绿 = 8,

   深红 = 9,
  绿色 = 10,

   深蓝 = 11,
 深黄 = 12,

   紫罗兰 = 13,
   青色 = 14,

  灰色25 = 15,

  褐色 = 53,
   橄榄 = 52,
   深绿 = 51,
   深青 = 49,
   靛蓝 = 55,
   灰色80 = 56,
   橙色 = 46,
     蓝灰 = 47,
   灰色50 = 16,
   浅橙色 = 45,
   酸橙色 = 43,
   海绿 = 50,
   水绿色 = 42,
   浅蓝 = 41,   
   灰色40 = 48,
   金色 = 44,

   天蓝 = 33,
   梅红 = 54,
    玫瑰红 = 38,
   茶色 = 40,
   浅黄 = 36,
   浅绿 = 35,
   浅青绿 = 34,
   淡蓝 = 37,
   淡紫 = 39,

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是对代码进行优化的建议: 1. 在循环前将需要用到的变量提前声明和初始化,避免在循环中重复声明和初始化,提高代码执行效率。 2. 将字符串的比较操作 InStr() 替换为直接比较字符串,避免函数调用和字符串转换的开销。 3. 将字符串的分割操作 Split() 替换为直接取子串,避免函数调用和数组创建的开销。 4. 将多个判断条件合并为一个复合条件,避免重复判断和逻辑判断的开销。 5. 避免在循环中使用 Excel 自动刷新功能,可以在循环结束后再刷新整个工作簿。 下面是我对代码进行优化后的实现: Sub 一键检查明细数据() On Error Resume Next Application.ScreenUpdating = False Dim ws As Worksheet Set ws = Worksheets("报表1") Dim lastRow As Long lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row Dim i As Long Dim val As Double, judgeVal As String, v2 As Double, v3 As String Dim item() As String, firstVal As Double, secondVal As Double Dim item2() As String, S1 As Double, S2 As Double For i = 2 To lastRow val = CDbl(ws.Cells(i, 10).Value) judgeVal = ws.Cells(i, 11).Value v2 = CDbl(ws.Cells(i, 12).Value) v3 = ws.Cells(i, 13).Value If judgeVal Like "*-*" Then firstVal = CDbl(Left(judgeVal, InStr(judgeVal, "-") - 1)) secondVal = CDbl(Right(judgeVal, Len(judgeVal) - InStr(judgeVal, "-"))) If v3 Like "*-*" Then S1 = CDbl(Left(v3, InStr(v3, "-") - 1)) S2 = CDbl(Right(v3, Len(v3) - InStr(v3, "-"))) If (val < firstVal Or val > secondVal) And (v2 < S1 Or v2 > S2) Then ws.Cells(i, 9).Value = ws.Cells(i, 10).Value ws.Cells(i, 9).Font.Color = 255 ws.Cells(i, 10).Font.Color = 255 ws.Cells(i, 12).Font.Color = 255 ElseIf val < firstVal Or val > secondVal Then ws.Cells(i, 9).Value = ws.Cells(i, 10).Value ws.Cells(i, 9).Font.Color = 255 ws.Cells(i, 10).Font.Color = 255 ws.Cells(i, 12).Font.ColorIndex = xlAutomatic ElseIf v2 < S1 Or v2 > S2 Then ws.Cells(i, 9).Value = ws.Cells(i, 10).Value ws.Cells(i, 9).Font.Color = 255 ws.Cells(i, 10).Font.ColorIndex = xlAutomatic ws.Cells(i, 12).Font.Color = 255 Else ws.Cells(i, 9).Value = "" ws.Cells(i, 9).Font.ColorIndex = xlAutomatic ws.Cells(i, 10).Font.ColorIndex = xlAutomatic ws.Cells(i, 12).Font.ColorIndex = xlAutomatic End If ElseIf val < firstVal Or val > secondVal Then ws.Cells(i, 9).Value = ws.Cells(i, 10).Value ws.Cells(i, 9).Font.Color = 255 ws.Cells(i, 10).Font.Color = 255 ws.Cells(i, 12).Font.ColorIndex = xlAutomatic ElseIf v2 < CDbl(v3) Or v2 > CDbl(v3) Then ws.Cells(i, 9).Value = ws.Cells(i, 10).Value ws.Cells(i, 9).Font.Color = 255 ws.Cells(i, 10).Font.ColorIndex = xlAutomatic ws.Cells(i, 12).Font.Color = 255 Else ws.Cells(i, 9).Value = "" ws.Cells(i, 9).Font.ColorIndex = xlAutomatic ws.Cells(i, 10).Font.ColorIndex = xlAutomatic ws.Cells(i, 12).Font.ColorIndex = xlAutomatic End If ElseIf v2 < CDbl(v3) Or v2 > CDbl(v3) Then ws.Cells(i, 9).Value = ws.Cells(i, 10).Value ws.Cells(i, 9).Font.Color = 255 ws.Cells(i, 10).Font.ColorIndex = xlAutomatic ws.Cells(i, 12).Font.Color = 255 ElseIf ws.Cells(i, 12).Value = ws.Cells(i, 13).Value Then ws.Cells(i, 12).Font.ColorIndex = xlAutomatic Else ws.Cells(i, 9).Value = "" ws.Cells(i, 9).Font.ColorIndex = xlAutomatic ws.Cells(i, 10).Font.ColorIndex = xlAutomatic ws.Cells(i, 12).Font.ColorIndex = xlAutomatic End If Next i ActiveWorkbook.RefreshAll Application.ScreenUpdating = True End Sub 希望对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值