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

    }

  • 相关阅读:
    sessionId在fragment里无法保存的问题
    android:ellipsize实现跑马灯效果总结(转)
    Android:TextView 自动滚动(跑马灯) (转)
    Failed to install on device ‘emulator-5554′: timeout
    一个类怎样引用另外一个类的成员变量或方法
    android.widget.RadioButton 单选按钮(转)
    如何实现两个Activity 之间如何通讯
    linux自学(八)之开始centos学习,安装tomcat
    linux自学(六)之开始centos学习,更换yum源
    linux自学(四)之开始centos学习,网络配置
  • 原文地址:https://www.cnblogs.com/JustinLau/p/12494019.html
Copyright © 2011-2022 走看看