java 操作excel類型轉換


/**
* 拿到不同類型單元格中的值
* 1. 字符串: 字符串
* 2. 布爾: toString
* 3. 數值(double): 格式化后的字符串
* @param cell 獲取的單元格
* @return 單元格中的值
*/
private static String getCellValue(Cell cell) {
String resultValue = "";
// 判空
if (Objects.isNull(cell)) {
return resultValue;
}

// 拿到單元格類型
int cellType = cell.getCellType();
switch (cellType) {
// 字符串類型
case Cell.CELL_TYPE_STRING:
resultValue = StringUtils.isEmpty(cell.getStringCellValue()) ? "" : cell.getStringCellValue().trim();
break;
// 布爾類型
case Cell.CELL_TYPE_BOOLEAN:
resultValue = String.valueOf(cell.getBooleanCellValue());
break;
// 數值類型
case Cell.CELL_TYPE_NUMERIC:
resultValue = new DecimalFormat("#.######").format(cell.getNumericCellValue());
break;
// 取空串
default:
break;
}
return resultValue;
}
————————————————
版權聲明:本文為CSDN博主「cb李先生」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/liha12138/article/details/107081224/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM