White Whale Studio

Excel Cell Border 및 배경색, 폰트 색상, 데이터 형식 지정 본문

IT Engineering/C#.net

Excel Cell Border 및 배경색, 폰트 색상, 데이터 형식 지정

glorymind 2023. 2. 8. 14:19
반응형

해당 내용은 Microsoft.Office.Interop.Excel DLL을 사용했을때의 사용법입니다.

Cell Border 스타일 지정하기

Cell Border는 Microsoft.Office.Interop.Excel.Range 개체에 대해 지정 가능합니다.

아래와 같이 Cell 범위로 range를 지정한 뒤 해당 range에 대해 LineStyle을 지정할수 있습니다.

 

특정 셀에 배경을 입히거나 텍스트 색상을 변경하는 경우 또는 셀의 데이터 형식을 바꾸고자 하는 경우에는

아래 코드를 참고하시기 바랍니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
private void SetBorderStyle()
{
    //// 범위 Border 선 스타일
    Microsoft.Office.Interop.Excel.Range range = xlWorksheet.Cells[12];
    range.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
    range.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlDash;
    range.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlDashDot;
    range.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlDashDotDot;
    
    //// 범위 내 배경색 지정
    range.Interior.Color = Color.LightGreen;
    
    //// 범위 내 텍스트 색상 지정
    range.Font.Color = Color.Red;
    //// 범위 내 데이터 형식 _ 숫자, 소숫점이 필요한 경우는 0.00
    range.NumberFormat = "0";
    //// 범위 내 데이터 형식 _ 텍스트
    range.NumberFormat = "@";
    //// 범위 내 데이터 형식 _ 날짜
    range.NumberFormat = "yyyy-MM-dd";
}
cs

 

반응형
Comments