当前位置:首页 > Windows程序 > 正文

C# 之 用NPOI类库操作Excel

2021-03-26 Windows程序

/// <summary> /// 获取单元格样式 /// </summary> /// <param>Excel操作类</param> /// <param>单元格字体</param> /// <param>图案的颜色</param> /// <param>图案样式</param> /// <param>单元格背景</param> /// <param>垂直对齐方式</param> /// <param>垂直对齐方式</param> /// <returns></returns> public static ICellStyle GetCellStyle(HSSFWorkbook hssfworkbook, IFont font, HSSFColor fillForegroundColor, FillPatternType fillPattern,
     HSSFColor fillBackgroundColor, HorizontalAlignment ha, VerticalAlignment va) { ICellStyle cellstyle
= hssfworkbook.CreateCellStyle(); cellstyle.FillPattern = fillPattern; cellstyle.Alignment = ha; cellstyle.VerticalAlignment = va; if (fillForegroundColor != null) { cellstyle.FillForegroundColor = fillForegroundColor.GetIndex(); } if (fillBackgroundColor != null) { cellstyle.FillBackgroundColor = fillBackgroundColor.GetIndex(); } if (font != null) { cellstyle.SetFont(font); } //有边框 cellstyle.BorderBottom = CellBorderType.THIN; cellstyle.BorderLeft = CellBorderType.THIN; cellstyle.BorderRight = CellBorderType.THIN; cellstyle.BorderTop = CellBorderType.THIN; return cellstyle; }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/67633.html