|
@@ -258,12 +258,13 @@ public class FormExecuteController {
|
|
Sheet sheet = workbook.createSheet(sheetName);
|
|
Sheet sheet = workbook.createSheet(sheetName);
|
|
|
|
|
|
// 设置第每列的列宽度
|
|
// 设置第每列的列宽度
|
|
-// for (ImportConfig importConfig : importConfigs) {
|
|
|
|
-// if(importConfig.getWidth() == 0){
|
|
|
|
-// sheet.autoSizeColumn(importConfig.getSortCode());
|
|
|
|
-// }
|
|
|
|
-// sheet.setColumnWidth(importConfig.getSortCode(), 100);
|
|
|
|
-// }
|
|
|
|
|
|
+ for (ImportConfig importConfig : importConfigs) {
|
|
|
|
+ if(importConfig.getWidth() == 0){
|
|
|
|
+ sheet.autoSizeColumn(importConfig.getSortCode());
|
|
|
|
+ }else {
|
|
|
|
+ sheet.setColumnWidth(importConfig.getSortCode(), importConfig.getWidth() * 256);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
// 表头
|
|
// 表头
|
|
createHead(workbook, sheet, importConfigs);
|
|
createHead(workbook, sheet, importConfigs);
|
|
@@ -276,7 +277,6 @@ public class FormExecuteController {
|
|
font.setBold(false);// 设置为粗体
|
|
font.setBold(false);// 设置为粗体
|
|
font.setFontName("宋体");
|
|
font.setFontName("宋体");
|
|
font.setFontHeightInPoints((short)12);
|
|
font.setFontHeightInPoints((short)12);
|
|
- font.setColor(Font.COLOR_RED);
|
|
|
|
CellStyle cellStyle = workbook.createCellStyle();
|
|
CellStyle cellStyle = workbook.createCellStyle();
|
|
cellStyle.setFont(font); // 将字体应用到样式
|
|
cellStyle.setFont(font); // 将字体应用到样式
|
|
// cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
// cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
@@ -286,7 +286,6 @@ public class FormExecuteController {
|
|
Row dataRow = sheet.createRow(dataRowNumber);
|
|
Row dataRow = sheet.createRow(dataRowNumber);
|
|
for (int i = 0; i < importConfigs.size(); i++) {
|
|
for (int i = 0; i < importConfigs.size(); i++) {
|
|
ImportConfig importConfig = importConfigs.get(i);
|
|
ImportConfig importConfig = importConfigs.get(i);
|
|
- sheet.autoSizeColumn(importConfig.getSortCode());
|
|
|
|
ColumnConfig columnConfig = columnConfigMap.get(importConfig.getFieldName());
|
|
ColumnConfig columnConfig = columnConfigMap.get(importConfig.getFieldName());
|
|
Object value = entity.get(importConfig.getFieldName());
|
|
Object value = entity.get(importConfig.getFieldName());
|
|
String componentType = columnConfig.getComponentType();
|
|
String componentType = columnConfig.getComponentType();
|
|
@@ -320,6 +319,9 @@ public class FormExecuteController {
|
|
}
|
|
}
|
|
dataRowNumber ++;
|
|
dataRowNumber ++;
|
|
}
|
|
}
|
|
|
|
+ }else {
|
|
|
|
+ // 提示必填
|
|
|
|
+ createCautionHead(workbook, sheet);
|
|
}
|
|
}
|
|
|
|
|
|
//写入文件
|
|
//写入文件
|
|
@@ -401,14 +403,13 @@ public class FormExecuteController {
|
|
normalCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
normalCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
normalCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
normalCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
|
-
|
|
|
|
// 必填样式
|
|
// 必填样式
|
|
CellStyle requiredCellStyle = workbook.createCellStyle();
|
|
CellStyle requiredCellStyle = workbook.createCellStyle();
|
|
requiredCellStyle.setFont(font); // 将字体应用到样式
|
|
requiredCellStyle.setFont(font); // 将字体应用到样式
|
|
requiredCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
requiredCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
requiredCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
requiredCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
- requiredCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
|
|
|
|
- requiredCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
|
|
+ requiredCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());//设置背景颜色
|
|
|
|
+ requiredCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//设置填充模式
|
|
|
|
|
|
// 所在行
|
|
// 所在行
|
|
Row row = sheet.createRow(rowNumber);
|
|
Row row = sheet.createRow(rowNumber);
|
|
@@ -426,6 +427,26 @@ public class FormExecuteController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void createCautionHead(Workbook workbook, Sheet sheet) {
|
|
|
|
+ int rowNumber = 1;
|
|
|
|
+ Font font = workbook.createFont();
|
|
|
|
+ font.setFontName("宋体");
|
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
|
+ font.setColor(IndexedColors.RED.getIndex());
|
|
|
|
+
|
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
|
+// cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+// cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+
|
|
|
|
+ Row row = sheet.createRow(rowNumber);
|
|
|
|
+ Cell cell = row.createCell(0);
|
|
|
|
+ String content = "红色背景为必填项,导入时请删除本行。";
|
|
|
|
+ cell.setCellValue(content);
|
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, 0, 5));
|
|
|
|
+ }
|
|
|
|
+
|
|
@PostMapping("/import")
|
|
@PostMapping("/import")
|
|
@ApiOperation(value = "导入")
|
|
@ApiOperation(value = "导入")
|
|
public R importData(@RequestParam String releaseId, @RequestParam MultipartFile file) throws IOException {
|
|
public R importData(@RequestParam String releaseId, @RequestParam MultipartFile file) throws IOException {
|