日期:2014-05-20  浏览次数:20844 次

POI选中excel的某个已经存在的数据的区域,并且设置为日期格式yyyy-m-d
我现在是已经有数据,要进行转换格式的,求助一下java的POI代码:

POI选中excel的某个已经存在的数据的区域,
例如是A7:B12 (12是已经使用的行数)。
并且设置为日期格式yyyy-m-d。

求打救,谢谢。

------解决方案--------------------
代码里实现,或者  设置excel 的格式
------解决方案--------------------
setCellType

public void setCellType(int cellType)
Set the cells type (numeric, formula or string)
Specified by:
setCellType in interface Cell
Throws:
java.lang.IllegalArgumentException - if the specified cell type is invalid
See Also:
Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_STRING, Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_BLANK, Cell.CELL_TYPE_BOOLEAN, Cell.CELL_TYPE_ERROR

没发现有日期格式,日期格式化字符串传吧- -
------解决方案--------------------
单元格0,0 已经手动设为日期格式--
        FileInputStream fin = new FileInputStream(xlsx0);
        Workbook wb = new XSSFWorkbook(fin);
        
        Sheet sheet = wb.getSheetAt(0);
        Row row = sheet.getRow(0);
        Cell cell = row.getCell(0);
        System.out.println(cell.getCellType());

结果为:0  代表:Cell.CELL_TYPE_NUMERIC  
so 楼主自己看着办吧