NPOI设置Excel单元格字体、边框、对齐、背景色_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > NPOI设置Excel单元格字体、边框、对齐、背景色

NPOI设置Excel单元格字体、边框、对齐、背景色

 2017/8/10 11:31:26  秋荷雨翔  程序员俱乐部  我要评论(0)
  • 摘要:代码:ICellStylecellStyle=workbook.CreateCellStyle();cellStyle.BorderBottom=BorderStyle.Thin;cellStyle.BorderLeft=BorderStyle.Thin;cellStyle.BorderRight=BorderStyle.Thin;cellStyle.BorderTop=BorderStyle.Thin;cellStyle.VerticalAlignment=NPOI.SS.UserModel
  • 标签:excel

代码:

class="code_img_closed" src="/Upload/Images/2017081011/0015B68B3C38AA5B.gif" alt="" />logs_code_hide('ddcfbe49-7624-483b-95a1-4676cacd5482',event)" src="/Upload/Images/2017081011/2B1B950FA3DF188F.gif" alt="" />
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 palette = ((HSSFWorkbook)workbook).GetCustomPalette();
palette.SetColorAtIndex((short)9, 98, 185, 106);
var color = palette.FindColor(98, 185, 106);
//下面两行设置单元格背景色
cellStyleTitle.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

 

发表评论
用户名: 匿名