Excel

ぐ巨炮叔叔 提交于 2019-12-11 16:16:01

一、

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;

    }

}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!