|
@ -161,31 +161,34 @@ public class PoiUtil { |
|
|
} |
|
|
} |
|
|
List<PoiUtilCell> cells = rows.get(i); |
|
|
List<PoiUtilCell> cells = rows.get(i); |
|
|
for (int j = 0; j < cells.size(); j++) { |
|
|
for (int j = 0; j < cells.size(); j++) { |
|
|
CellStyle style = wb.createCellStyle(); |
|
|
|
|
|
//将内容按顺序赋给对应的列对象
|
|
|
|
|
|
PoiUtilCell cell = cells.get(j); |
|
|
PoiUtilCell cell = cells.get(j); |
|
|
//如果value是cell_null代表次单元格不需要赋值
|
|
|
//查找当前单元格
|
|
|
if (cell.value.equals(WebConstant.CELL_NULL)){ |
|
|
Cell newCell = row.getCell(j); |
|
|
continue; |
|
|
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 (ObjectUtil.isNotNull(cell.height)) { |
|
|
if (j == 0) { |
|
|
if (j == 0) { |
|
|
row.setHeight(cell.height.shortValue()); |
|
|
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.setAlignment(cell.style); |
|
|
style.setVerticalAlignment(cell.verticalAlignment); |
|
|
style.setVerticalAlignment(cell.verticalAlignment); |
|
|
|
|
|
|
|
|
//设置跳转路径
|
|
|
//设置跳转路径
|
|
|
if (StrUtil.isNotEmpty(cell.path)) { |
|
|
if (StrUtil.isNotEmpty(cell.path)) { |
|
|
XSSFCreationHelper createHelper = (XSSFCreationHelper) wb.getCreationHelper(); |
|
|
XSSFCreationHelper createHelper = (XSSFCreationHelper) wb.getCreationHelper(); |
|
@ -203,7 +206,49 @@ public class PoiUtil { |
|
|
} |
|
|
} |
|
|
//设置自动换行
|
|
|
//设置自动换行
|
|
|
style.setWrapText(true); |
|
|
style.setWrapText(true); |
|
|
|
|
|
//将样式添加至单元格
|
|
|
newCell.setCellStyle(style); |
|
|
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; |
|
|
return wb; |
|
|