:
여기에 소스 코드를 살펴 보자. 예 코드 제발 : 위 예에서
ExcelAddress _formatRangeAddress = new ExcelAddress("B3:B10,D3:D10,F3:F10,H3:H10:J3:J10");
// fill WHITE color if previous cell or current cell is BLANK:
// B3 is the current cell because the range _formatRangeAddress starts from B3.
// OFFSET(B3,0,-1) returns the previous cell's value. It's excel function.
string _statement = "IF(OR(ISBLANK(OFFSET(B3,0,-1)),ISBLANK(B3)),1,0)";
var _cond4 = sheet.ConditionalFormatting.AddExpression(_formatRangeAddress);
_cond4.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
_cond4.Style.Fill.BackgroundColor.Color = Color.White;
_cond4.Formula = _statement;
// fill GREEN color if value of the current cell is greater than
// or equals to value of the previous cell
_statement = "IF(OFFSET(B3,0,-1)-B3<=0,1,0)";
var _cond1 = sheet.ConditionalFormatting.AddExpression(_formatRangeAddress);
_cond1.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
_cond1.Style.Fill.BackgroundColor.Color = Color.Green;
_cond1.Formula = _statement;
// fill RED color if value of the current cell is less than
// value of the previous cell
_statement = "IF(OFFSET(B3,0,-1)-B3>0,1,0)";
var _cond3 = sheet.ConditionalFormatting.AddExpression(_formatRangeAddress);
_cond3.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
_cond3.Style.Fill.BackgroundColor.Color = Color.Red;
_cond3.Formula = _statement;
,
_formatRangeAddress
표현식으로 조건부 서식 적용될 범위이다. 이 범위의 첫 번째 셀이 조건 수식에 사용됩니다. (B3).
_statement
가 조건을 계산하는데 사용되는 식이다 문자열 이 등호 (=
) (MS 엑셀에서 차이 포인트)하지 시작 않고 표현하는 데 사용되는 셀은 첫 번째 셀은 _formatRangeAddress
. (B3).
희망은 다른 사람에게 도움이되기를 바랍니다. -Han-
출처
2012-11-05 10:08:56
Han
"포함"텍스트 조건부 서식 지정을 제공 할 수 있습니까? –
Excel 기능입니다. 'ISNUMBER'및 'SEARCH'기능을 사용하고 있습니다.http://office.microsoft.com/en-kr/excel-help/check-if-a-cell-contains-text-HP003056106.aspx – Han
Excel에서 직접 조건부 서식을 사용하고 싶지만 ' 현재 '를 표현합니다. ISBLANK (OFFSET (B3,0, -1), ISBLANK (B3)), 1,0)'식으로 사용하고 코드 주석에서'// WHITE color 이전 셀 또는 현재 셀은 공백입니다. '현재'셀에 대한 참조는 어디에 있습니까? 나는 단지'B3' 만 본다. – jotapdiez