2015-02-05 2 views

답변

3

다음 코드는 원하는 것을 정확하게 수행하는 코드이지만 아이콘을 기반으로 변경할 수있는 3 가지 아이콘 세트입니다. 값이 4보다 크면 붉은 색 화살표를 설정하고, 값이 1과 4 사이라면 노란색 색 화살표를, 1보다 작 으면 녹색을 설정합니다. 아이콘에 "AddThreeIconSet"을 변경하면됩니다. 이것으로 아이디어를 얻어야합니다.

for(int j =2; j <=9; j++) //Loop through columns 
{ 
    for(int i = 3; i <= 12; i++) // Loop through rows 
    { 
     // gets only the current cell as range 
     ExcelRange rng = worksheet.Cells[i, j, i, j]; 
     ExcelAddress address = new ExcelAddress(rng.Address); 
     // Get the value of the current cell 
     if(Convert.ToDouble(worksheet.Cells[i, j].Value) >= 4.0) 
     { 
      var v = worksheet.ConditionalFormatting.AddThreeIconSet(address, eExcelconditionalFormatting3IconSetType.Arrows); 
      v.Reverse = true; 
      v.Icon1.Type = eExcelConditionalFormattingValueObjectType.Num; 
     } 
     else if(Convert.ToDouble(workSheet.Cells[i, j].Value) > 1.0 && Convert.ToDouble(workSheet.Cells[i, j].Value) < 4.0) 
     { 

      var v = worksheet.ConditionalFormatting.AddThreeIconSet(address , eExcelconditionalFormatting3IconsSetType.Arrows); 
      v.Icon3.Type = eExcelConditionalFormattingValueObjectType.Num; 

     } 
     else (Convert.ToDouble(workSheet.Cells[i, j].Value) < 1.0) 
     { 
      var v = worksheet.ConditionalFormatting.AddThreeIconSet(address , eExcelconditionalFormatting3IconsSetType.Arrows); 
      v.Icon2.Type = eExcelConditionalFormattingValueObjectType.Num; 
     } 
    } 
} 
+0

감사합니다. sanmis that helped. – MikeFerrer

+0

또한 http://stackoverflow.com/questions/28493050/importing-excel-file-with-all-the-conditional-formatting-rules-to-epplus를 사용할 수도 있습니다.이 도구를 사용하면 Excel에서 처음부터 형식을 지정할 수 있습니다 , xml로 가져온 다음 사용하십시오. 이렇게하면 모든 유형의 규칙과 함께 모든 종류의 조건부 서식을 가질 수 있습니다. – sanmis

관련 문제