C# Excel单元格设置

1.设置单元格字体格式:IFont

IFont ifont = hssfworkbook.CreateFont();
ifont1.Boldweight=(short)FontBoldWeight.Bold;//加粗
字体:ifont .fontname
字体颜色:ifont.color
字号:ifont.FontHightInpoints=(short)数字;

2.设置单元格背景颜色:

//创建单元格样式
XSSFCellStyle backgroundstyle =(XSSFCellStyle) hssfworkbook.CreateCellStyle();
//填充模式
backgroundstyle.FillPattern = FillPattern.SolidForeground;
//创建颜色
XSSFColor xssfcolor = new XSSFColor();
rbg值
byte[] rgb ={147,147,147};
//写入rgb
xssfcolor.SetRgb(rgb);
//设置颜色值
backgroundstyle.SetFillForegroundColor(xssfcolor);
sheet.getrow(行号).getcell(列号).cellstyle=backgroundstyle;

3.单元格边框:

sheet1.GetRow(i).GetCell(j).CellStyle.BorderTop=NPOI.SS.UserModel.BorderStyle.Thin;

4.创建sheet分页

XSSFWorkbook xss= new XSSFWorkbook(file);

Isheet isheet=xss.getsheet(分页名称);

posted @ 2021-05-13 10:21  Bill-Lee  阅读(827)  评论(0编辑  收藏  举报