关于POI3.17的一些操作
单元格居中
HSSFCellStyle tableStyle=workbook.createCellStyle();
tableStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
tableStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
加边框
HSSFCellStyle tableStyle=workbook.createCellStyle();
tableStyle.setBorderTop(BorderStyle.MEDIUM);//上边框
tableStyle.setBorderBottom(BorderStyle.MEDIUM);//下边框
tableStyle.setBorderLeft(BorderStyle.MEDIUM);//左边框
tableStyle.setBorderRight(BorderStyle.MEDIUM);//右边框
设置边框颜色
可以这样:
tableStyle.setBottomBorderColor(HSSFColorPredefined.BLUE.getIndex());//下边框颜色
tableStyle.setLeftBorderColor(HSSFColorPredefined.BLUE.getIndex());//左边框颜色
tableStyle.setRightBorderColor(HSSFColorPredefined.BLUE.getIndex());//右边框颜色
因为颜色都是short值,不妨把常用颜色的short值封装起来,方便使用,就像这样:
这样代码就简洁多了
tableStyle.setTopBorderColor(HSSFDiyColor.BLACK);