2016-07-06 9 views
2

を使用してnpoiを使用してcell backgroudnにRGBカラーを設定するにはどうすればよいですか?xssfworkbook npoiを使用してRGBカラーを設定するには

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の色のプロパティへのアクセスを提供していません。 。

次に、XSSColorを使用して色を設定できます。これは、バイト配列またはSystem.Drawing.Colorオブジェクトから作成できます。

例コード、コメントにコンストラクタの異なる品種:

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; 
関連する問題