|
|
|
@ -6,6 +6,7 @@ import com.jfinal.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
|
|
|
|
|
|
@ -351,6 +352,25 @@ public class ImportUtil {
|
|
|
|
|
Db.update(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:判断一个单元格是不是被合并了
|
|
|
|
|
*
|
|
|
|
|
* @param sheet
|
|
|
|
|
* @param row
|
|
|
|
|
* @param col
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isMerged(XSSFSheet sheet, XSSFCell cell) {
|
|
|
|
|
// 判断单元格是否被合并
|
|
|
|
|
for (CellRangeAddress range : sheet.getMergedRegions()) {
|
|
|
|
|
if (cell.getRowIndex() >= range.getFirstRow() && cell.getRowIndex() <= range.getLastRow()
|
|
|
|
|
&& cell.getColumnIndex() >= range.getFirstColumn() && cell.getColumnIndex() <= range.getLastColumn()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:导入数据
|
|
|
|
|
*
|
|
|
|
@ -400,17 +420,32 @@ public class ImportUtil {
|
|
|
|
|
XSSFCell cell = row.getCell(j);
|
|
|
|
|
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(getValue(cell).toString()));
|
|
|
|
|
else if (colType.equals("String"))
|
|
|
|
|
writeRecord.set(colName, getValue(cell).toString());
|
|
|
|
|
else if (colType.equals("Double"))
|
|
|
|
|
writeRecord.set(colName, Double.parseDouble(getValue(cell).toString()));
|
|
|
|
|
else if (colType.equals("Date")) {
|
|
|
|
|
String dateString = getValue(cell).toString();
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
Date date = dateFormat.parse(dateString);
|
|
|
|
|
writeRecord.set(colName, date);
|
|
|
|
|
|
|
|
|
|
//cell可能是被合并的单元格
|
|
|
|
|
if (isMerged(sheet, cell)) {
|
|
|
|
|
String value = ImportUtil.getValue(cell).toString();
|
|
|
|
|
if (StrKit.isBlank(value)) {
|
|
|
|
|
for (int k = i - 1; ; k--) {
|
|
|
|
|
String prev = ImportUtil.getValue(sheet.getRow(k).getCell(j)).toString();
|
|
|
|
|
if (!StrKit.isBlank(prev)) {
|
|
|
|
|
writeRecord.set(colName, prev);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (colType.equals("Integer"))
|
|
|
|
|
writeRecord.set(colName, (int) Double.parseDouble(getValue(cell).toString()));
|
|
|
|
|
else if (colType.equals("String"))
|
|
|
|
|
writeRecord.set(colName, getValue(cell).toString());
|
|
|
|
|
else if (colType.equals("Double"))
|
|
|
|
|
writeRecord.set(colName, Double.parseDouble(getValue(cell).toString()));
|
|
|
|
|
else if (colType.equals("Date")) {
|
|
|
|
|
String dateString = getValue(cell).toString();
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
Date date = dateFormat.parse(dateString);
|
|
|
|
|
writeRecord.set(colName, date);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
writeList.add(writeRecord);
|
|
|
|
|