Excel

一、

public class ExcelUtils {


    public static String parseCellToString(Cell cell){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");

        String result = "";

        if(cell.getCellTypeEnum().equals(CellType.STRING)){

            result=cell.getStringCellValue();

        }else if(cell.getCellTypeEnum().equals(CellType.BLANK)){

            result="";

        }else if (cell.getCellTypeEnum().equals(CellType.FORMULA)){

            result = cell.getCellFormula();

        }else  if(cell.getCellTypeEnum().equals(CellType.NUMERIC)){

            if(HSSFDateUtil.isCellDateFormatted(cell)){

                Date date = cell.getDateCellValue();

                result = sdf.format(date);

            }else {

                result = cell.getNumericCellValue()+"";

                result = result.substring(0,result.indexOf("."));

            }

        }

        return result;

    }

}
posted @ 2019-12-11 16:00  呆code  阅读(1052)  评论(0编辑  收藏  举报