ExcelImport

This commit is contained in:
MaxKey
2021-11-16 21:35:53 +08:00
parent fc0a4348d7
commit ba9b6ff9f9
6 changed files with 365 additions and 567 deletions

View File

@@ -0,0 +1,35 @@
package org.maxkey.util;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
public class ExcelUtils {
/**
* 根据数据格式返回数据
*
* @param cell
* @return
*/
public static String getValue(Cell cell) {
if (cell == null) {
return "";
} else if (cell.getCellType() == CellType.BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == CellType.NUMERIC) {
if ("General".equals(cell.getCellStyle().getDataFormatString())) {
return new DecimalFormat("0").format(cell.getNumericCellValue());
} else if ("m/d/yy".equals(cell.getCellStyle().getDataFormatString())) {
return new SimpleDateFormat("yyyy-MM-dd").format(cell.getDateCellValue());
} else {
return new DecimalFormat("0").format(cell.getNumericCellValue());
}
} else {
return String.valueOf(cell.getStringCellValue().trim());
}
}
}