简体   繁体   中英

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. No matter if the condition is met or not, the cell.Font.Bold and cell.Style.Font.Bold properties are always false. (cell is of type Range). So is there a way to query the cell's style as the user would see it in 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.

Cheers
Wullie

Unfortunately Excel doesn't give you functions 'out of the box' to tell you which conditions have been met. The best code I've seen that will tell you which conditions are active is Chuck Pearson's ActiveCondition code. You'll have to translate it from VBA to C#.

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.

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