I'm currently trying to set conditional formatting on an excel document. I'm currently using interop to work with the document.
The column contains time/date values and I'm trying to create a condition that highlights values over 15 minutes.
This is what I've got so far.
range = xlWorksheet.get_Range("F2", "F" + RC);
Excel.FormatCondition condition = (Excel.FormatCondition)range.FormatConditions.Add(
XlFormatConditionType.xlExpression,
Type.Missing,
"> =0,0104166666666667",
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);
condition.Interior.ColorIndex = 3; // Red
The range selects the correct column, I think the issue is i'm not building the right formula.
This is what the condinonal formatting looks like when I do it in excel.
This is what my formula looks like when I try replicate it with my application.
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
Range("F1:F11").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="=0,0104166666666667"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
This is the macro equivalent of what I'm trying to do in C#.
Excel.FormatCondition condition = (Excel.FormatCondition)range.FormatConditions.Add(Excel.XlFormatConditionType.xlCellValue, Excel.XlFormatConditionOperator.xlGreater, "=0,0104166666666667", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
将公式条件更改为xlCellValue可以解决问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.