|
|
@@ -45,6 +45,9 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
SXSSFWorkbook workbook = new SXSSFWorkbook();
|
|
|
DataTemplet dataTemplet = dataTempletMapper.selectByCaller(caller, companyId);
|
|
|
+ if (null == dataTemplet) {
|
|
|
+ throw new BizException(9876, "没有查询到对应的excel配置");
|
|
|
+ }
|
|
|
//列
|
|
|
String cols = dataTemplet.getDt_columns();
|
|
|
JSONArray array = (JSONArray) JSONArray.parse(cols);
|
|
|
@@ -70,7 +73,6 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
public Integer parseTemplet(Workbook wb, String caller) {
|
|
|
if (wb == null || StringUtils.isEmpty(caller)) {
|
|
|
throw new BizException(BizExceptionCode.NULL_DATA);
|
|
|
@@ -182,7 +184,7 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
}
|
|
|
}
|
|
|
//检测日期类型是否规范
|
|
|
- if ("date".equals(set.getType())) {
|
|
|
+ if ("date".equals(set.getType()) && !StringUtils.isEmpty(value)) {
|
|
|
flag = validateDateFormat(value);
|
|
|
if (!flag) {
|
|
|
err.append("第" + (i + 2) + "行 " + set.getDescription() + " 日期格式不正确! ");
|
|
|
@@ -257,7 +259,7 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
if (StringUtils.isEmpty(date)) {
|
|
|
return false;
|
|
|
}
|
|
|
- String regEx1 = "[0-9]{8}";
|
|
|
+ String regEx1 = "[0-9]{4}/[0-9]{2}/[0-9]{2}";
|
|
|
String regEX2 = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
|
|
|
// 编译正则表达式
|
|
|
Pattern pattern1 = Pattern.compile(regEx1);
|
|
|
@@ -290,6 +292,10 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
switch(cell.getCellType()){
|
|
|
case Cell.CELL_TYPE_NUMERIC:{
|
|
|
cellValue = String.valueOf(cell.getNumericCellValue());
|
|
|
+ //判断是否为INT类型
|
|
|
+ if (Double.valueOf(cellValue.toString()).intValue() - Double.valueOf(cellValue.toString()) == 0) {
|
|
|
+ return Double.valueOf(cellValue.toString()).intValue();
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
case Cell.CELL_TYPE_FORMULA:{
|
|
|
@@ -336,9 +342,10 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
*/
|
|
|
private void createWorkbook(SXSSFWorkbook workbook, int sheetIdx, JSONArray cols, JSONArray datas, String remark){
|
|
|
Sheet sheet = workbook.createSheet("sheet" + sheetIdx);
|
|
|
- CellStyle style = getCellStyle(workbook);
|
|
|
- //sheet.autoSizeColumn((short) 2);
|
|
|
- sheet.createFreezePane(0, 1);// 固定列
|
|
|
+ CellStyle style = getCellStyle(workbook, true);
|
|
|
+ CellStyle detailStyle = getCellStyle(workbook, false);
|
|
|
+ //sheet.autoSizeColumn(2);
|
|
|
+ // sheet.createFreezePane(0, 1);// 固定列
|
|
|
Cell cell = null;
|
|
|
int rIdx = 0;
|
|
|
int cIdx = 0;
|
|
|
@@ -347,8 +354,8 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
Row row = null;
|
|
|
if (remark != null) {
|
|
|
row = sheet.createRow(rIdx);
|
|
|
- row.setHeightInPoints((short) 100);
|
|
|
- sheet.setColumnWidth(cIdx, 1000);
|
|
|
+ row.setHeightInPoints((short) 50);
|
|
|
+ sheet.setColumnWidth(cIdx, 500);
|
|
|
cell = getCell(sheet, rIdx, cIdx);
|
|
|
cell.setCellValue(remark);
|
|
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, cols.size() - 1));
|
|
|
@@ -365,19 +372,23 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
width = (short) (obj.get("width") == null ? 0 : (int)obj.get("width")*35.7);
|
|
|
width = width == 0 ? 4000 : width;
|
|
|
sheet.setColumnWidth(cIdx, width);
|
|
|
- sheet.createFreezePane(cols.size() + 1, 2);
|
|
|
+ // sheet.createFreezePane(cols.size() + 1, 2);
|
|
|
cell = getCell(sheet, rIdx, cIdx);
|
|
|
value = obj.get("description") == null ? value : obj.get("description").toString();
|
|
|
if ("true".equals(obj.get("necessary"))) {
|
|
|
value = "*" + value;
|
|
|
}
|
|
|
- cell.setCellValue(value);
|
|
|
- keys.add(String.valueOf(obj.get("description")));
|
|
|
if ("date".equals(obj.get("type"))) {
|
|
|
short df= workbook.createDataFormat().getFormat("yyyy-MM-dd");
|
|
|
style.setDataFormat(df);
|
|
|
}
|
|
|
- cell.setCellStyle(style);
|
|
|
+ if ("main".equals(obj.get("position"))) {
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ } else {
|
|
|
+ cell.setCellStyle(detailStyle);
|
|
|
+ }
|
|
|
+ cell.setCellValue(value);
|
|
|
+ keys.add(String.valueOf(obj.get("description")));
|
|
|
cIdx++;
|
|
|
value = "";
|
|
|
}
|
|
|
@@ -410,7 +421,7 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private CellStyle getCellStyle(SXSSFWorkbook workbook) {
|
|
|
+ private CellStyle getCellStyle(SXSSFWorkbook workbook, boolean main) {
|
|
|
CellStyle style = workbook.createCellStyle();
|
|
|
style.setFillBackgroundColor((short) 18);
|
|
|
style.setFillPattern(FillPatternType.LEAST_DOTS);
|
|
|
@@ -421,7 +432,7 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
style.setFont(font);
|
|
|
style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
style.setFillForegroundColor(HSSFColor.GREEN.index);
|
|
|
- style.setFillBackgroundColor(HSSFColor.PALE_BLUE.index);
|
|
|
+ style.setFillBackgroundColor(main ? HSSFColor.LIGHT_YELLOW.index : HSSFColor.PALE_BLUE.index);
|
|
|
style.setBorderBottom(BorderStyle.MEDIUM);
|
|
|
style.setBorderLeft(BorderStyle.MEDIUM);
|
|
|
style.setBorderRight(BorderStyle.MEDIUM);
|