ExcelImport
This commit is contained in:
35
maxkey-common/src/main/java/org/maxkey/util/ExcelUtils.java
Normal file
35
maxkey-common/src/main/java/org/maxkey/util/ExcelUtils.java
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user