zoukankan      html  css  js  c++  java
  • C#_NPOI_Excel各种设置

    //设置单元格

    public ICellStyle SetStyle(ref IWorkbook workbook,short background,short color)
            {
                ICellStyle style = workbook.CreateCellStyle();
                {
                    style.Alignment = HorizontalAlignment.Center;//水平居中
                    style.VerticalAlignment = VerticalAlignment.Center;//垂直居中
                    IFont font = workbook.CreateFont();//文字设置
                    font.FontName = "微软雅黑";
                    font.Boldweight = short.MaxValue;//加粗
                    font.FontHeightInPoints = 11;//文字大小
                    if (color > 0)//文字颜色
                        font.Color = color;
                    else
                    font.Color = NPOI.HSSF.Util.HSSFColor.Black.Index;
                    style.SetFont(font);
                    if (background>0)//背景色
                        style.FillForegroundColor = background;
                    else
                        style.FillForegroundColor = short.Parse(GetRandomString());

                    #region 边框设置
                    style.FillPattern = FillPattern.SolidForeground;
                    style.BorderBottom = BorderStyle.Thin;
                    style.BorderLeft = BorderStyle.Thin;
                    style.BorderRight = BorderStyle.Thin;
                    style.BorderTop = BorderStyle.Thin;
                    style.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
                    style.LeftBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
                    style.RightBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
                    style.TopBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
                    #endregion
                    style.WrapText = true;//文字换行
                }
                return style;
            }

    ///设置表格宽高、单元格部分代码

    {

                  ICellStyle style = SetStyle(ref workbook, 44, 0);

                   ISheet sheet = workbook.CreateSheet();
                    ICellStyle borderStyle = workbook.CreateCellStyle();
                    sheet.SetColumnWidth(0, 8 * 256);//设置列宽
                    sheet.SetColumnWidth(1, 30 * 256);
                    sheet.SetColumnWidth(2, 8 * 256);
                    workbook.SetSheetName(sheetIndex, name + "日报");
                    IRow ir1 = sheet.CreateRow(0);
                    ir1.Height = 400;//设置单元格高度
                    ICell cel0 = ir1.CreateCell(0);
                    cel0.SetCellValue("");
                    cel0.CellStyle = style;//设置单元格

    }

  • 相关阅读:
    media query不一致
    数据库设计三范式
    异步概念及使用场景
    关于webservice框架CXF的总结
    通过bash文件(shell命令)对文件进行修改
    shell命令相关问题
    shell对文本进行操作命令
    虚拟机安装系统常见问题
    安装autotools系列工具
    Centos和Ubuntu下打包项目
  • 原文地址:https://www.cnblogs.com/JustinLau/p/12494019.html
Copyright © 2011-2022 走看看