2016-07-06 15 views
2

npoi를 사용하여 cell backgroudn에서 RGB 색상을 어떻게 설정합니까?글꼴에서 RGB 색상을 설정하는 방법 xssfworkbook npoi를 사용하여

byte[] rgb = new byte[3] { 192, 50, 90 }; 
XSSFCellStyle HeaderCellStyle1 = (XSSFCellStyle)wb.CreateCellStyle(); 
HeaderCellStyle1.SetFillForegroundColor(new XSSFColor(new Color(255, 255, 255))); 

나는이 패턴을 사용하고 싶지 않은 : 당신은 확인해야

titlestyle.BottomBorderColor = IndexedColors.Grey25Percent.Index; 

답변

0
solution of your problem is here 

    here simply define new xssfcolor and assign it to xssfcellstyle  


var color = new XSSFColor(new byte[] { 0,255, 0 }); 
var rowstyle =(XSSFCellStyle)wb.CreateCellStyle(); 
rowstyle.SetFillForegroundColor(color) 
0

당신이 XSSFFont 첫째로 글꼴을 캐스팅 IFont 글꼴의 RGB 컬러 속성에 대한 액세스를 제공하지 않습니다 확인 .

그런 다음 바이트 배열 또는 System.Drawing.Color 개체로 구성 할 수있는 XSSColor을 사용하여 색을 설정할 수 있습니다.

예제 코드, 주석 생성자의 다른 종류 :

var wb = new XSSFWorkbook(); 
var sheet = wb.CreateSheet("Sheet 1"); 

// Create a colored font 
var font = (XSSFFont) wb.CreateFont(); 
// var color = new XSSFColor(ColorTranslator.FromHtml("#C88C14")); 
// var color = new XSSFColor(new Color(255, 255, 255)); 
var color = new XSSFColor(new byte[] {200, 140, 20}); 
font.SetColor(color); 

// Create a dedicated cell style using that font 
var style = wb.CreateCellStyle(); 
style.SetFont(font); 

// Create some cell values 
var row = sheet.CreateRow(0); 
row.CreateCell(0).SetCellValue("Standard text"); 
var cell = row.CreateCell(1); 
cell.SetCellValue("Colored text"); 

// Apply the cellstyle we created 
cell.CellStyle = style;