poi对excel的操作(二)

二、进阶的对象

    1、CellType 枚举类 单元格类型

              CellType.STRING---文本型 等 

如何是指单元格类型:cell.setCellType(CellType.STRING)

    2、Cellstyle 单元格风格

XSSFCellStyle cellStyle = wookbook.createCellStyle(); XSSFCellStyle cellStyle = cell.getCellStyle();

如何设置单元格风格:cell.setCellStyle(cellStyle);

    3、XSSFFont   对字体的设置  字体大小、字体、是否加、颜色粗等

XSSFFont font = createFont();
  如何对字体设置: font.setFontHeightInPoints((short) 20);
                          font.setFontName("黑体");
                          font.setBold(true);font.setColor((short) 2);
                          cellStyle.setFont(font);

    4、BorderStyle 枚举类   边框风格 

         BorderStyle.THIN---细边框  BorderStyle.THICK---粗边框  等

如何是指边框风格:cellStyle.setBorderTop(BorderStyle.THIN);   cell.setCellStyle(cellStyle);

    5、FillPatternType 枚举类 枚举值,该值指示正在使用的单元格格式的填充图案的样式
如何设置:cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);扎实填充、NO_FILL没有背景

    6、HorizontalAlignment 枚举类  枚举值(水平位置:左、中间)

cellStyle.setAlignment(HorizontalAlignment.CENTER);

    7、VerticalAlignment 枚举类  枚举值(垂直位置:顶部、底部、中部)  

cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    8、XSSFDrawing(绘图)、comment(批注、注释)

  XSSFDrawing patr = sheet.createDrawingPatriarch();
  XSSFComment comment = patr.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5));
  comment.setString(new XSSFRichTextString(msg));
  cell.setCellComment(comment);

    9、XSSFDataFormat 数据格式表

XSSFDataFormat format = createDataFormat();//创建数据格式表

    10、CellRangeAddress 单元格区域(用于合并单元格)

构造器 CellRangeAddress cellRange = new CellRangeAddress(int firstROW,int lastRow,int firstCol,int lastCol);

 补充:背景色 cellStyle.setFillBackgroundColor(XSSFColor color);

          前景色 cellStyle.setFillForegroundColor(XSSFColor color);

          合并单元格 sheet.addMergedRegion(new CellRangeAddress);

原文地址:https://www.cnblogs.com/dayuruozhi/p/6667390.html