NPOI2.0学习(三)

HSSFWorkbook wk = new HSSFWorkbook();//你用来操作的HSSFWorkbook的实例  
ICellStyle cellStyle = wk.CreateCellStyle(); 
ICellStyle cellStyle = wk.CreateCellStyle();  
//设置单元格上下左右边框线  
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;  
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;  
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;  
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;  
//文字水平和垂直对齐方式  
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;  
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;  
//是否换行  
//cellStyle.WrapText = true;  
//缩小字体填充  
cellStyle.ShrinkToFit = true; 


 ICellStyle style2 = wb.CreateCellStyle();//样式
    IFont font1 = wb.CreateFont();//字体
    font1.FontName = "楷体";
    font1.Color = HSSFColor.Red.Index;//字体颜色
    font1.Boldweight = (short)FontBoldWeight.Normal;//字体加粗样式
    style2.SetFont(font1);//样式里的字体设置具体的字体样式
    //设置背景色
    style2.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index;
    style2.FillPattern = FillPattern.SolidForeground;
    style2.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index;
    style2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;//文字水平对齐方式
    style2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;//文字垂直对齐方式
ICell Cell = sheet.CreateRow(0).CreateCell(0);  
Cell.CellStyle = cellStyle;  
Cell.SetCellValue("测试格式效果");  
ICellStyle newCellStyle = wk.CreateCellStyle();  
newCellStyle.CloneStyleFrom(cellStyle);  
newCellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; 
原文地址:https://www.cnblogs.com/shy1766IT/p/5357670.html