Dealing with mobile phone number format issues in Excel files
- Use the POI library to load Excel files and get cell data.
- Check the data type of the cell. If it is numeric, format conversion may be required.
- If the cell's data type is numeric, you can convert scientific notation format to string format by following these steps:
- a. Use the DecimalFormat class to create a formatting pattern, for example: "0".
- b. Convert the cell value to string format and use the format() method of DecimalFormat for conversion.
- Process the converted string as a mobile phone number and continue with subsequent operations.
code show as below:
public static String getCellValue(Cell cell) {
switch (cell.getCellType()) {
case BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case STRING:
return cell.getStringCellValue();
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return timeFormatter.format(cell.getLocalDateTimeCellValue());
} else {
if (!String.valueOf(cell.getNumericCellValue()).contains("E")) {
return String.valueOf(cell.getNumericCellValue());
} else {
return new DecimalFormat("#").format(cell.getNumericCellValue());
}
}
case FORMULA:
return cell.getCellFormula() + EMPTY;
default:
return EMPTY;
}
}