//创建工作薄
HSSFWorkbook book = new HSSFWorkbook();
//添加一个sheet
ISheet sheet1 = book.CreateSheet("Sheet1");
//创建首行
IRow row = sheet.CreateRow(0);
//行中创建第一列.
ICell cell = row.CreateCell(0);
//创建一个样式
ICellStyle title = book.CreateCellStyle();
//背景灰色
title.FillForegroundColor = HSSFColor.Grey50Percent.Index;
title.FillPattern = FillPattern.SolidForeground;
//添加边框
title.BorderBottom = BorderStyle.Thin;
title.BorderLeft = BorderStyle.Thin;
title.BorderRight = BorderStyle.Thin;
title.BorderTop = BorderStyle.Thin;
//文本居中
title.Alignment = HorizontalAlignment.Center;
//垂直居中
title.VerticalAlignment = VerticalAlignment.Justify;
//创建一个字体
IFont font1 = book.CreateFont();
//字体加粗
font1.Boldweight = (short)FontBoldWeight.Bold;
//字体大小 16
font1.FontHeightInPoints = 16;
title.SetFont(font1);
//创建第一行数据
IRow row0 = sheet1.CreateRow(0);
//设置行高30
row0.Height = 30 * 20;
//在第一行中创建第一个格子
ICell titlecell = row0.CreateCell(0);
titlecell.SetCellValue("名称内容");
都忘记自己是copy哪个博主的了,就这样子吧!
算是自己学习NPOI操作Excel表格的一个笔记吧!