zoukankan      html  css  js  c++  java
  • C# Excel设置单元格边框 之 NPOI

    很多表格中都要使用边框,本节将为你重点讲解NPOI中边框的设置和使用。

    边框和其他单元格设置一样也是调用ICellStyle接口,ICellStyle有2种和边框相关的属性,分别是:

    边框相关属性 说明 范例
    Border+方向 边框类型 BorderTop, BorderBottom,BorderLeft, BorderRight
    方向+BorderColor 边框颜色 TopBorderColor,BottomBorderColor, LeftBorderColor, RightBorderColor

    其中边框类型分为以下几种:

    边框范例图 对应的静态值
    image CellBorderType.DOTTED
    image CellBorderType.HAIR
    image CellBorderType.DASH_DOT_DOT
    image CellBorderType.DASH_DOT
    image CellBorderType.DASHED
    image CellBorderType.THIN
    image CellBorderType.MEDIUM_DASH_DOT_DOT
    image CellBorderType.SLANTED_DASH_DOT
    image CellBorderType.MEDIUM_DASH_DOT
    image CellBorderType.MEDIUM_DASHED
    image CellBorderType.MEDIUM
    image CellBorderType.THICK
    image CellBorderType.DOUBLE

     

    至于颜色那就很多了,全部在HSSFColor下面,如HSSFColor.GREEN, HSSFColor.RED,都是静态实例,可以直接引用。

    下面我们假设我们要把一个单元格的四周边框都设置上,可以用下面的代码:

        //创建单元格样式
        ICellStyle cellStyle = workbook.CreateCellStyle();
       //设置为文本格式,也可以为 text,即 dataFormat.GetFormat("text");
        cellStyle.DataFormat = dataFormat.GetFormat("@");
        cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;    //下边框线
        cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;      //左边框线
        cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;     //右边框线
        cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;       //上边框线
  • 相关阅读:
    [苹果maccms] MACCMS苹果cms宝塔定时任务添加教程说明
    [苹果cmsV10]新版本演员库分类报无权限问题和解决方法!
    CentOS 6.8安装Python2.7.13
    [HOWTO] Install Sphinx for A Script Pro
    A Script Pro nginx URL重写规则无法播放MP4解决方法
    随机跳转
    UI库
    vuex
    vue 数据请求
    vue守卫、储存与路由模式
  • 原文地址:https://www.cnblogs.com/RCJL/p/12579900.html
Copyright © 2011-2022 走看看