NPOI

2016-05-05 21 views
5
NPOI ait
using NPOI.XSSF.UserModel; 
using NPOI.XSSF.Model; 

using NPOI.HSSF.UserModel; 
using NPOI.HSSF.Model; 

using NPOI.SS.UserModel; 
using NPOI.SS.Util; 


(...) 

XSSFWorkbook hssfwb; 

using (FileStream file = new FileStream(@"D:\VB\XLSX teste com NPOI\XLSX 1\Book1.xlsx", 
    FileMode.Open, FileAccess.Read)) 
{ 
    hssfwb = new XSSFWorkbook(file); 
    file.Close(); 
} 

ISheet sheet = hssfwb.GetSheetAt(0); 
IRow row = sheet.GetRow(0); 

ICell cell = row.CreateCell(5); 
cell.SetCellValue("test"); 
cell.CellStyle.FillBackgroundColor = IndexedColors.BrightGreen.Index; 
cell.CellStyle.FillPattern = FillPattern.SolidForeground; 

using (FileStream file = new FileStream(@"D:\VB\XLSX teste com NPOI\XLSX 1\Book1ee22.xlsx", 
    FileMode.Create, FileAccess.Write)) 
{ 
    hssfwb.Write(file); 
    file.Close(); 
} 

Sürüm ile hücre rengini değiştirmek için: 2.1.3.1 Bu kodu vardır ve bu delik sac rengini ve sadece hücreyi değişiyor ... değiştirmek için uygun yolu nedir hücrenin dolgu rengi?NPOI

XSSFWorkbook hssfwb; 
     using (FileStream file = new FileStream(@"D:\Copy D\Tech\VB\XLSX teste com NPOI\XLSX 1\Book1.xlsx", FileMode.Open, FileAccess.Read)) 
     { 
      hssfwb = new XSSFWorkbook(file); 
      file.Close(); 
     } 

     ISheet sheet = hssfwb.GetSheetAt(0); 
     IRow row = sheet.GetRow(0); 


     ICellStyle testeStyle = hssfwb.CreateCellStyle(); 
     testeStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium; 
     testeStyle.FillForegroundColor = IndexedColors.BrightGreen.Index; 
     testeStyle.FillPattern = FillPattern.SolidForeground; 


     ICell cell = row.CreateCell(5); 
     cell.SetCellValue("testeeerere"); 
     cell.CellStyle = testeStyle; 


     using (FileStream file = new FileStream(@"D:\Copy D\Tech\VB\XLSX teste com NPOI\XLSX 1\Book1ee22.xlsx", FileMode.Create, FileAccess.Write)) 
     { 
      hssfwb.Write(file); 
      file.Close(); 
     } 

cevap

9

Bu örnekte bir göz atın: Burada


aşağıdaki gibi doğru işaretlenmiş yanıta göre çalışma kodu olduğunu

using NPOI.HSSF.UserModel; 
using NPOI.SS.UserModel; 
using NPOI.SS.Util; 

(...)

Row row = sheet.CreateRow(0); 

//styling 
Font boldFont = workbook.CreateFont(); 
boldFont.Boldweight = (short)FontBoldWeight.BOLD; 
ICellStyle boldStyle = workbook.CreateCellStyle(); 
boldStyle.SetFont(boldFont); 

boldStyle.BorderBottom = CellBorderType.MEDIUM; 
boldStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.GREY_25_PERCENT.index; 
boldStyle.FillPattern = FillPatternType.SOLID_FOREGROUND; 


for (int i = 0; i < columns.Length; i++) 
{ 
    Cell cell = row.CreateCell(i); 
    cell.SetCellValue(columns[i]); 
    cell.CellStyle = boldStyle; 
} 

Buradan nasıl uygulama olduğunu görebilirsiniz Bir satırdaki her hücre için kalın, arka plan rengi ve kenarlığı. Bu örnekte columns sütun verisini temsil eden dize dizisidir; Değerlerinizi kullanın.

+0

Bir CellStyle bildirmek mümkün görünmüyor .. – meme

+0

CellStyle, "NPOI.SS.UserModel" ad alanında. Cevabımı düzenledim. – Nino

+0

hala beyan edemez. – meme