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

    }

  • 相关阅读:
    js画矩形
    js加载pdf截屏生成图片调用ocr识别成文字
    C#List或者Set集合相同的key合并Value的值
    Oracle学习笔记读懂执行计划(十八)
    Java 阻塞队列
    SpringMVC(三):参数绑定、输入输出转换
    springMVC(二): @RequestBody @ResponseBody 注解实现分析
    Spring Security 4.2.3 Filters 解析
    MySQL 加锁处理分析
    Innodb semi-consistent 简介
  • 原文地址:https://www.cnblogs.com/JustinLau/p/12494019.html
Copyright © 2011-2022 走看看