2016-06-01 9 views
0

Ich versuche, die Schriftfarbe einer Excel-Zelle mit NPOI 2.2.1 oder 2.1.3.1 zu lesen Es ist egal, was die Schriftfarbe ist NPOI sagt immer, dass es 8 (schwarz) ist. Codefragment unterNPOI Zelle Schriftfarbe Bug?

IWorkbook workbook = WorkbookFactory.Create(new FileStream(txtFileName.Text, FileMode.Open, FileAccess.Read)); 
    ISheet worksheet = workbook.GetSheet("sheet1"); 
    IRow row = worksheet.GetRow(0); 
    lblFontColor.Text = row.GetCell(0).CellStyle.GetFont(workbook).Color.ToString(); 

Ist das ein Fehler oder mache ich etwas falsch?

Update: Dies scheint nur ein Problem zu sein beim Lesen von Dateien .xlsx nicht die älteren .xls-Dateien

Antwort

0

Sie eine beliebige Farbe in Schrift Hintergrund einstellen:

 hstyle =(XSSFCellStyle) wb.CreateCellStyle(); 
       color = new XSSFColor(new byte[] { 191,191,191}); 
       hstyle.VerticalAlignment = VerticalAlignment.Center; 
       hstyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; 
       hfont = (XSSFFont)wb.CreateFont(); 
       hfont.FontHeightInPoints = 12; 
       hfont.FontName = "Calibri"; 
       hfont.Boldweight = (short)FontBoldWeight.Bold; 
       hfont.SetColor(color); 
       hstyle.SetFont(hfont); 
     crow = sheet.CreateRow(rowindex); 
    ccel = crow.CreateCell(0); 
       ccel.SetCellValue(Title); 
       ccel.CellStyle = hstyle; 
+2

In der letzten NPOI Version. .. Ich finde nicht SetColor() ... die Schriftart haben nur eine kurze Eigenschaft namens Color. – Romias