简体   繁体   English

Excel Interop 2007中的条件格式

[英]Conditional Formatting in Excel Interop 2007

How can I get hold of the displayed format of a cell in excel interop 2007. I have a cell where the font's boldness is depending on the value in another cell. 如何在excel interop 2007中掌握单元格的显示格式。我有一个单元格,字体的粗体性取决于另一个单元格中的值。 No matter if the condition is met or not, the cell.Font.Bold and cell.Style.Font.Bold properties are always false. 无论是否满足条件,cell.Font.Bold和cell.Style.Font.Bold属性始终为false。 (cell is of type Range). (单元格的类型为Range)。 So is there a way to query the cell's style as the user would see it in Excel? 因此,有没有一种方法可以查询用户在Excel中看到的单元格样式?

workbook = application.Workbooks.Open(fileName);
var worksheet = (Worksheet)workbook.Worksheets["Test"];

var cell = (Range)worksheet.Cells[8, 3];
var style = (Style)cell.Style;
strb.AppendLine("Bold: " + cell.Font.Bold); // -> False
strb.AppendLine("Bold: " + style.Font.Bold);// -> False

I also tried using the FormatConditions, but there I haven't found a way to know whether the conditions are met. 我也尝试过使用FormatConditions,但是我还没有找到一种方法来知道是否满足条件。

Cheers 干杯
Wullie 乌利

Unfortunately Excel doesn't give you functions 'out of the box' to tell you which conditions have been met. 不幸的是,Excel并没有“开箱即用”的功能来告诉您满足了哪些条件。 The best code I've seen that will tell you which conditions are active is Chuck Pearson's ActiveCondition code. 我所见过的最好的代码可以告诉您哪些条件处于活动状态,这是Chuck Pearson的ActiveCondition代码。 You'll have to translate it from VBA to C#. 您必须将其从VBA转换为C#。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM