NPOI sets the Excel cell font, border, alignment, and background color. npoiexcel
Code:
ICellStyle cellStyle = workbook. createCellStyle (); cellStyle. borderBottom = BorderStyle. thin; cellStyle. borderLeft = BorderStyle. thin; cellStyle. borderRight = BorderStyle. thin; cellStyle. borderTop = BorderStyle. thin; cellStyle. verticalAlignment = NPOI. SS. userModel. verticalAlignment. center; cellStyle. alignment = NPOI. SS. userModel. horizontalAlignment. center; ICellStyle cellStyleTitle = workbook. createCellStyle (); cellStyleTitle. borderBottom = BorderStyle. thin; cellStyleTitle. borderLeft = BorderStyle. thin; cellStyleTitle. borderRight = BorderStyle. thin; cellStyleTitle. borderTop = BorderStyle. thin; cellStyleTitle. verticalAlignment = NPOI. SS. userModel. verticalAlignment. center; cellStyleTitle. alignment = NPOI. SS. userModel. horizontalAlignment. center; IFont font = workbook. createFont (); font. isBold = false; font. fontHeightInPoints = 12; cellStyleTitle. setFont (font); HSSFPalette = (HSSFWorkbook) workbook ). getCustomPalette (); palette. setColorAtIndex (short) 9, 98,185,106); var color = palette. findColor (98,185,106); // set the cell background color cellStyleTitle in the following two rows. fillPattern = FillPattern. solidForeground; cellStyleTitle. fillForegroundColor = color. indexed; ICellStyle cellStyleTitle2 = workbook. createCellStyle (); cellStyleTitle2.CloneStyleFrom (cellStyleTitle); font = workbook. createFont (); font. isBold = false; font. fontHeightInPoints = 14; cellStyleTitle2.SetFont (font );View Code