优化excel工具类

This commit is contained in:
季圣华
2022-07-01 01:04:01 +08:00
parent d353664600
commit 22eac10bc7

View File

@@ -1,15 +1,11 @@
package com.jsh.erp.utils; package com.jsh.erp.utils;
import java.io.File; import java.io.File;
import java.util.HashSet; import java.text.SimpleDateFormat;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.Set;
import jxl.*;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.*; import jxl.format.*;
import jxl.write.Label; import jxl.write.Label;
import jxl.write.WritableCellFormat; import jxl.write.WritableCellFormat;
@@ -211,6 +207,21 @@ public class ExcelUtils {
} }
} }
public static String getDateContent(Sheet src, int rowNum, int colNum) {
// 日期 类型的处理
Cell c = src.getRow(rowNum)[colNum];
if(CellType.DATE.equals(c.getType())) {
DateCell dc = (DateCell) c;
Date jxlDate = dc.getDate();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return sdf.format(jxlDate);
} else {
String dateStr = c.getContents().trim();
return dateStr;
}
}
/** /**
* 从第i行开始到最后检测指定列的唯一性 * 从第i行开始到最后检测指定列的唯一性
* *