|
|
|
@ -21,12 +21,12 @@ public class ImportUtil {
|
|
|
|
|
/**
|
|
|
|
|
* 功能:移除小括号,以及小括号内的文字内容
|
|
|
|
|
*
|
|
|
|
|
* @param input
|
|
|
|
|
* @param str
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String removeKuoHao(String input) {
|
|
|
|
|
input = input.replace("\n", "");
|
|
|
|
|
String output = input.replaceAll("\\(.*?\\)", "");
|
|
|
|
|
public static String removeKuoHao(String str) {
|
|
|
|
|
str = str.replace("\n", "");
|
|
|
|
|
String output = str.replaceAll("\\(.*?\\)", "");
|
|
|
|
|
output = output.replaceAll("\\(.*?\\)", "");
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
@ -38,7 +38,7 @@ public class ImportUtil {
|
|
|
|
|
* @param cell 单元格
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private static String getCellColor(Cell cell) {
|
|
|
|
|
private static String getColor(XSSFCell cell) {
|
|
|
|
|
if (cell != null) {
|
|
|
|
|
//背景颜色
|
|
|
|
|
CellStyle cellStyle = cell.getCellStyle();
|
|
|
|
@ -64,15 +64,15 @@ public class ImportUtil {
|
|
|
|
|
// 遍历行
|
|
|
|
|
for (int i = 0; i <= sheet.getLastRowNum(); i++) {
|
|
|
|
|
//获得行
|
|
|
|
|
Row row = sheet.getRow(i);
|
|
|
|
|
XSSFRow row = sheet.getRow(i);
|
|
|
|
|
//遍历列
|
|
|
|
|
if (row != null) {
|
|
|
|
|
Map<String, Integer> _map = new HashMap<>();
|
|
|
|
|
for (int j = 0; j < row.getLastCellNum(); j++) {
|
|
|
|
|
//获取单元格
|
|
|
|
|
Cell cell = row.getCell(j);
|
|
|
|
|
XSSFCell cell = row.getCell(j);
|
|
|
|
|
if (cell == null) continue;
|
|
|
|
|
String color = getCellColor(cell);
|
|
|
|
|
String color = getColor(cell);
|
|
|
|
|
//记录背景颜色数量
|
|
|
|
|
if (_map.containsKey(color))
|
|
|
|
|
_map.put(color, _map.get(color) + 1);
|
|
|
|
@ -105,7 +105,7 @@ public class ImportUtil {
|
|
|
|
|
* @param sheet_index
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static Record getExcelSheetInfo(String upload_excel_filename, int sheet_index) {
|
|
|
|
|
public static Record getSheetConfig(String upload_excel_filename, int sheet_index) {
|
|
|
|
|
String sql = "select * from t_importexcel_config where upload_excel_filename=? and sheet_index=?";
|
|
|
|
|
return Db.findFirst(sql, upload_excel_filename, sheet_index);
|
|
|
|
|
}
|
|
|
|
@ -116,7 +116,7 @@ public class ImportUtil {
|
|
|
|
|
* @param upload_excel_filename
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static int getExcelSheetCount(String upload_excel_filename) {
|
|
|
|
|
public static int getSheetCount(String upload_excel_filename) {
|
|
|
|
|
String sql = "select * from t_importexcel_config where upload_excel_filename=?";
|
|
|
|
|
List<Record> list = Db.find(sql, upload_excel_filename);
|
|
|
|
|
return list.size();
|
|
|
|
@ -129,7 +129,7 @@ public class ImportUtil {
|
|
|
|
|
* @param sheet_index
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static List<Record> getExcelSheetColumnsInfo(String upload_excel_filename, int sheet_index) {
|
|
|
|
|
public static List<Record> getSheetMapping(String upload_excel_filename, int sheet_index) {
|
|
|
|
|
String sql = "select * from t_importexcel_mapping where upload_excel_filename=? and sheet_index=?";
|
|
|
|
|
return Db.find(sql, upload_excel_filename, sheet_index);
|
|
|
|
|
}
|
|
|
|
@ -143,7 +143,7 @@ public class ImportUtil {
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public static List<Map.Entry<Integer, Integer>> checkYiZhi(String f1, String f2, int sheetIdx) throws IOException {
|
|
|
|
|
Record record = getExcelSheetInfo(FileUtil.getName(f1), sheetIdx);
|
|
|
|
|
Record record = getSheetConfig(FileUtil.getName(f1), sheetIdx);
|
|
|
|
|
int start_row = record.getInt("start_row");
|
|
|
|
|
int end_row = record.getInt("end_row");
|
|
|
|
|
int start_column = record.getInt("start_column");
|
|
|
|
@ -401,13 +401,13 @@ public class ImportUtil {
|
|
|
|
|
String colType = _map.get(j).getStr("column_type");
|
|
|
|
|
String colName = _map.get(j).getStr("column_name");
|
|
|
|
|
if (colType.equals("Integer"))
|
|
|
|
|
writeRecord.set(colName, (int) Double.parseDouble(getCellValue(cell).toString()));
|
|
|
|
|
writeRecord.set(colName, (int) Double.parseDouble(getValue(cell).toString()));
|
|
|
|
|
else if (colType.equals("String"))
|
|
|
|
|
writeRecord.set(colName, getCellValue(cell).toString());
|
|
|
|
|
writeRecord.set(colName, getValue(cell).toString());
|
|
|
|
|
else if (colType.equals("Double"))
|
|
|
|
|
writeRecord.set(colName, Double.parseDouble(getCellValue(cell).toString()));
|
|
|
|
|
writeRecord.set(colName, Double.parseDouble(getValue(cell).toString()));
|
|
|
|
|
else if (colType.equals("Date")) {
|
|
|
|
|
String dateString = getCellValue(cell).toString();
|
|
|
|
|
String dateString = getValue(cell).toString();
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
Date date = dateFormat.parse(dateString);
|
|
|
|
|
writeRecord.set(colName, date);
|
|
|
|
@ -508,7 +508,7 @@ public class ImportUtil {
|
|
|
|
|
* @param wb
|
|
|
|
|
* @param sheet
|
|
|
|
|
*/
|
|
|
|
|
public static void resetCellStyle(XSSFWorkbook wb, XSSFSheet sheet, int dataStartRow) {
|
|
|
|
|
public static void resetStyle(XSSFWorkbook wb, XSSFSheet sheet, int dataStartRow) {
|
|
|
|
|
// 遍历所有行和单元格,移除批注
|
|
|
|
|
for (int row = dataStartRow; row <= sheet.getLastRowNum(); row++) {
|
|
|
|
|
for (int col = 0; col < sheet.getRow(row).getLastCellNum(); col++) {
|
|
|
|
@ -583,8 +583,7 @@ public class ImportUtil {
|
|
|
|
|
* @param cell
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static Object getCellValue(XSSFCell cell) {
|
|
|
|
|
|
|
|
|
|
public static Object getValue(XSSFCell cell) {
|
|
|
|
|
switch (cell.getCellType()) {
|
|
|
|
|
case CellType.STRING:
|
|
|
|
|
String cellValueString = cell.getStringCellValue();
|
|
|
|
|