• 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;//设置单元格

    }

  • 相关阅读:
    排列组合算法
    C++内存管理——堆&&栈
    编程之美——1.2 中国象棋将帅问题
    Gentoo: fcitx的安装
    Gentoo NTFS USB盘有写权限
    Gentoo U盘无法自动挂载,打开报告Not Authorized,xfce只有logout,suspend/shutdown灰化等问题解决方法
    Kernel: 打开CONFIG_EMBEDDED从而使更多的kernel option可以更改
    Gentoo Enable framebuffer console (没有安装X,KDE的时候)
    转载:Gentoo和Ubuntu包管理命令对比集
    Gentoo Rebuild virtualboxmodules when kernel is updated
  • 原文地址:https://www.cnblogs.com/JustinLau/p/12494019.html
Copyright © 2020-2023  润新知