Excel中有各式各样的日期类型,如何用java取得你想要的类型呢?
(jxl)代码如下:
Sheet[] sheets = book.getSheets();
Sheet sheet = sheets[0];
String birthday = sheet.getCell(1, 1).getContents().trim(); Cell c = sheet.getCell(1, 1);
CellType ct = c.getType();
if(ct==CellType.DATE)
{
DateCell dc = (DateCell)c;
Date dd = dc.getDate();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
birthday = df.format(dd);
}
(jxl)代码如下:
Sheet[] sheets = book.getSheets();
Sheet sheet = sheets[0];
String birthday = sheet.getCell(1, 1).getContents().trim(); Cell c = sheet.getCell(1, 1);
CellType ct = c.getType();
if(ct==CellType.DATE)
{
DateCell dc = (DateCell)c;
Date dd = dc.getDate();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
birthday = df.format(dd);
}
本文介绍了一种使用Java从Excel中读取特定单元格并判断其类型为日期的方法,并展示了如何将日期格式化为yyyy-MM-dd的形式。
2419

被折叠的 条评论
为什么被折叠?



