Browse Source

修改poi工具类

tiaosheng
zy_Java 5 years ago
parent
commit
8817c953bc
  1. 75
      util/src/main/java/com/ccsens/util/PoiUtil.java

75
util/src/main/java/com/ccsens/util/PoiUtil.java

@ -161,31 +161,34 @@ public class PoiUtil {
}
List<PoiUtilCell> cells = rows.get(i);
for (int j = 0; j < cells.size(); j++) {
CellStyle style = wb.createCellStyle();
//将内容按顺序赋给对应的列对象
PoiUtilCell cell = cells.get(j);
//如果value是cell_null代表次单元格不需要赋值
if (cell.value.equals(WebConstant.CELL_NULL)){
continue;
//查找当前单元格
Cell newCell = row.getCell(j);
if(ObjectUtil.isNull(newCell)){
newCell = row.createCell(j);
}
//查找当前单元格的样式
CellStyle style = newCell.getCellStyle();
if(ObjectUtil.isNull(style)){
style = wb.createCellStyle();
}
//设置内容
if (!cell.value.equals(WebConstant.CELL_NULL)){
if(cell.num == 1){
newCell.setCellValue(Integer.parseInt(cell.value));
}else {
newCell.setCellValue(cell.value);
}
}
Cell newCell = row.createCell(j);
//设置行高
if (ObjectUtil.isNotNull(cell.height)) {
if (j == 0) {
row.setHeight(cell.height.shortValue());
}
}
if(cell.num == 1){
// newCell.setCellType(cell.cellType);
newCell.setCellValue(Integer.parseInt(cell.value));
}else {
newCell.setCellValue(cell.value);
}
//设置水平居中和垂直居中
style.setAlignment(cell.style);
style.setVerticalAlignment(cell.verticalAlignment);
//设置跳转路径
if (StrUtil.isNotEmpty(cell.path)) {
XSSFCreationHelper createHelper = (XSSFCreationHelper) wb.getCreationHelper();
@ -203,7 +206,49 @@ public class PoiUtil {
}
//设置自动换行
style.setWrapText(true);
//将样式添加至单元格
newCell.setCellStyle(style);
// CellStyle style = wb.createCellStyle();
// 将内容按顺序赋给对应的列对象
// 如果value是cell_null代表次单元格不需要赋值
// if (cell.value.equals(WebConstant.CELL_NULL)){
// continue;
// }
// Cell newCell = row.createCell(j);
// //设置行高
// if (ObjectUtil.isNotNull(cell.height)) {
// if (j == 0) {
// row.setHeight(cell.height.shortValue());
// }
// }
//
// if(cell.num == 1){
// newCell.setCellValue(Integer.parseInt(cell.value));
// }else {
// newCell.setCellValue(cell.value);
// }
// style.setAlignment(cell.style);
// style.setVerticalAlignment(cell.verticalAlignment);
// //设置跳转路径
// if (StrUtil.isNotEmpty(cell.path)) {
// XSSFCreationHelper createHelper = (XSSFCreationHelper) wb.getCreationHelper();
// XSSFHyperlink link = createHelper.createHyperlink(HyperlinkType.URL);
// link.setAddress(cell.path);
// newCell.setHyperlink(link);
// //设置字体颜色
// Font font = wb.createFont();
// font.setColor(Font.COLOR_RED);
// style.setFont(font);
// }
// //添加函数
// if(StrUtil.isNotEmpty(cell.getFunction())) {
// newCell.setCellFormula(cell.getFunction());
// }
// //设置自动换行
// style.setWrapText(true);
// newCell.setCellStyle(style);
}
}
return wb;

Loading…
Cancel
Save