• java—poi设置单元格样式


     /**
         * 功能描述: 设置单元格样式
         * @Param: [wb, cellIndex]
         * @Return: org.apache.poi.xssf.usermodel.XSSFCellStyle
         * @Author: shibaobei
         * @Date: 2020/8/14 0014 10:02
         */
        private XSSFCellStyle setBorderStyle(XSSFWorkbook wb,int cellIndex,String backWidth){
            XSSFCellStyle cellStyle = wb.createCellStyle();
            XSSFFont font = null;
            switch (cellIndex){
                case 0:
                    cellStyle.setBorderBottom(BorderStyle.DASHED); //下边框
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.DASHED);//上边框
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    break;
                case 1:
                    cellStyle.setBorderBottom(BorderStyle.MEDIUM); //下边框
                    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
                    cellStyle.setBorderLeft(BorderStyle.MEDIUM_DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.MEDIUM);//上边框
                    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
                    cellStyle.setBorderRight(BorderStyle.MEDIUM_DASHED);//右边框
                    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//设置前景填充样式
                    cellStyle.setFillForegroundColor(HSSFColor.BLACK.index);//前景填充色
                    break;
                case 2:
                    cellStyle.setBorderBottom(BorderStyle.MEDIUM); //下边框
                    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.MEDIUM);//上边框
                    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    break;
                case 3:
                    cellStyle.setBorderBottom(BorderStyle.MEDIUM); //下边框
                    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.MEDIUM);//上边框
                    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    font = wb.createFont();
                    font.setFontName("宋体");
                    if("20".equals(backWidth)){
                        font.setFontHeightInPoints((short) 14);//设置字体大小
                    }else if("30".equals(backWidth)){
                        font.setFontHeightInPoints((short) 16);//设置字体大小
                    }else if("40".equals(backWidth)){
                        font.setFontHeightInPoints((short) 18);//设置字体大小
                    }else if("50".equals(backWidth)){
                        font.setFontHeightInPoints((short) 20);//设置字体大小
                    }else if("60".equals(backWidth)){
                        font.setFontHeightInPoints((short) 22);//设置字体大小
                    }else{
                        font.setFontHeightInPoints((short) 14);//设置字体大小
                    }
                    cellStyle.setFont(font);//选择需要用到的字体格式
                    cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
                    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
                    break;
                case 4:
                    cellStyle.setBorderBottom(BorderStyle.MEDIUM); //下边框
                    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.MEDIUM);//上边框
                    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    font = wb.createFont();
                    font.setFontName("宋体");
                    font.setFontHeightInPoints((short) 14);//设置字体大小
                    cellStyle.setFont(font);//选择需要用到的字体格式
                    cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
                    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
                    cellStyle.setWrapText(true);//设置自动换行
                    break;
                case 5:
                    cellStyle.setBorderBottom(BorderStyle.MEDIUM); //下边框
                    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.MEDIUM);//上边框
                    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    font = wb.createFont();
                    font.setFontName("宋体");
                    if("20".equals(backWidth)){
                        font.setFontHeightInPoints((short) 12);//设置字体大小
                    }else if("30".equals(backWidth)){
                        font.setFontHeightInPoints((short) 14);//设置字体大小
                    }else if("40".equals(backWidth)){
                        font.setFontHeightInPoints((short) 16);//设置字体大小
                    }else if("50".equals(backWidth)){
                        font.setFontHeightInPoints((short) 18);//设置字体大小
                    }else if("60".equals(backWidth)){
                        font.setFontHeightInPoints((short) 20);//设置字体大小
                    }else {
                        font.setFontHeightInPoints((short) 12);//设置字体大小
                    }
                    cellStyle.setFont(font);//选择需要用到的字体格式
                    cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
                    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
                    break;
                case 6:
                    cellStyle.setBorderBottom(BorderStyle.MEDIUM); //下边框
                    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.MEDIUM);//上边框
                    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    font = wb.createFont();
                    font.setFontName("宋体");
                    if(StringUtils.isBlank(backWidth)  || "20".equals(backWidth)){
                        font.setFontHeightInPoints((short) 14);//设置字体大小
                    }else{
                        font.setFontHeightInPoints((short) 16);//设置字体大小
                    }
                    cellStyle.setFont(font);//选择需要用到的字体格式
                    cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
                    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
                    cellStyle.setWrapText(true);//设置自动换行
                    cellStyle.setRotation((short)255); //设置文字竖向排列
                    break;
                case 7:
                    cellStyle.setBorderBottom(BorderStyle.MEDIUM); //下边框
                    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.MEDIUM);//上边框
                    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    break;
                case 8:
                    cellStyle.setBorderBottom(BorderStyle.MEDIUM); //下边框
                    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.MEDIUM);//上边框
                    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//设置前景填充样式
                    cellStyle.setFillForegroundColor(HSSFColor.BLACK.index);//前景填充色
                    break;
                case 9:
                    cellStyle.setBorderBottom(BorderStyle.DASHED); //下边框
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.DASHED);//上边框
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    break;
                default:
                    cellStyle.setBorderBottom(BorderStyle.DASHED); //下边框
                    cellStyle.setBorderLeft(BorderStyle.DASHED);//左边框
                    cellStyle.setBorderTop(BorderStyle.DASHED);//上边框
                    cellStyle.setBorderRight(BorderStyle.DASHED);//右边框
                    break;
    
            }
            return cellStyle;
        }
    

      

  • 相关阅读:
    营山护照办理
    非北京人员 办理护照
    护照填写注意事项
    美国会议签证——我是正当理由去美国,我能支付(或有人为我支付)我在美国期间的所有费用,办完事我肯定回来, 邀请信,行程表这些材料齐全即可
    urllib2使用2
    python 异常
    python urllib和urllib2 区别
    python类继承
    gcc编译4个阶段
    Vim中如何全选并复制?
  • 原文地址:https://www.cnblogs.com/bao-bei/p/13517421.html
Copyright © 2020-2023  润新知