Excel Interop条件格式 [英] Excel Interop Conditional Formatting

查看:64
本文介绍了Excel Interop条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现了以下页面:在Excel 2007中设置条件格式与我想做的事情非常相似,但是我似乎找不到合适的功能来做稍微不同的事情.

I've just spotted the following page: Setting Conditional Formatting in Excel 2007 which is very similar to something I'd like to do, but I can't seem to find appropriate functions to do something slightly different.

我想知道是否有人知道一种基于一组文本值将条件格式应用于范围的方法.例如.我想说:

I'm wondering if anyone knows a way to apply conditional formatting to a range, based upon a set of textual values. E.g. I want to say:

如果看到"InvalidValue1"或"InvalidValue2",请突出显示红色 否则,如果您看到警告",请突出显示黄色

If you see "InvalidValue1" OR "InvalidValue2" Highlight RED else if you see "WARNING" Highlight YELLOW

我有整个范围的无效值,可能还有警告值.对于大型数据集,我还需要逐列进行此操作,因此在可能的情况下,我想使用内置的Excel功能突出显示该范围内的错误.

I have a whole range of invalid values, and possibly warning values. I also need to do this on a column by column basis for very large datasets, so where possible I'd like to use built in Excel features to highlight errors within the range.

有人知道这是否完全可能吗?

Does anyone know if this is at all possible?

致谢

推荐答案

我相信我已经设法找到了解决问题的方法(尽管单元格选择相当奇怪,而且我还没有完全解决.例如,我的公式由于选择的范围,使用A1实际上表示C1.

I believe I have managed to find a solution to the problem (although Cell selection is rather bizarre and I haven't quite sorted that out yet. e.g. my formula uses A1 which actually means C1 because of the selected range).

这是我用于其他感兴趣的人的代码:

Here is the code I used for anyone else interested:

string condition = @"=OR(ERROR1, ERROR2, ERROR3)";
var cfOR = (FormatCondition)targetSheet.get_Range("C1", "C10").FormatConditions.Add(XlFormatConditionType.xlExpression, Type.Missing,condition), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

cfOR.Interior.Color = 0x000000FF;
cfOR.Font.Bold = true;
cfOR.Font.Color = 0x00FFFFFF;

请注意,对于不同版本的Excel互操作,FormatConditions.Add()方法具有不同的签名.

Note that the FormatConditions.Add() method has a different signature for different versions of the Excel interop.

这篇关于Excel Interop条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆