HSSFWorkbook workbook = new HSSFWorkbook(); MemoryStream ms = new MemoryStream(); ISheet sheet = workbook.CreateSheet(); IRow headerRow = sheet.CreateRow(0); HSSFCellStyle HeaderCellStyle = (HSSFCellStyle)workbook.CreateCellStyle(); HeaderCellStyle.BorderTop = BorderStyle.Thin; HeaderCellStyle.BorderLeft = BorderStyle.Thin; HeaderCellStyle.BorderRight = BorderStyle.Thin; HeaderCellStyle.BorderBottom = BorderStyle.Thin; HeaderCellStyle.Alignment = HorizontalAlignment.Center;
//使用自带背景颜色 //HeaderCellStyle.FillForegroundColor = HSSFColor.Lavender.Index; //HeaderCellStyle.FillPattern = FillPattern.SolidForeground; IFont font = workbook.CreateFont(); font.FontHeightInPoints = 9;//9号字体 font.Boldweight = (short)FontBoldWeight.Bold; font.Color = NPOI.HSSF.Util.HSSFColor.Black.Index; HSSFPalette palette = ((HSSFWorkbook)workbook).GetCustomPalette(); palette.SetColorAtIndex(HSSFColor.Lime.Index, (byte)204, (byte)204, (byte)255);//使用自定义背景颜色 HeaderCellStyle.FillForegroundColor = HSSFColor.Lime.Index; HeaderCellStyle.FillPattern = FillPattern.SolidForeground; HeaderCellStyle.SetFont(font); // handling header. foreach (DataColumn column in SourceTable.Columns) { ICell cell = headerRow.CreateCell(column.Ordinal); cell.CellStyle = HeaderCellStyle; cell.SetCellValue(column.ColumnName); }
标签:Index,示例,样式,NPOI,FillPattern,workbook,BorderStyle,font,HeaderCellStyle From: https://www.cnblogs.com/jizhong/p/17805162.html