jxl读取excel表格

jackie_Ga 2013-05-16 01:44:41
我用jxl读取excel时发现,excel表格中的日期格式我用sheet1.getCell(10, i).getType()获取到的类型是Lable(表格中对应的单元格确定是日期类型),这个会是什么原因导致的呢?
...全文
91 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
a82759082 2013-05-16
  • 打赏
  • 举报
回复
试试我这些代码,亲测能用 public static ArrayList generateStationBugSql(File formFile) throws Exception { InputStream in = null; Workbook wb = null; ArrayList list = new ArrayList(); try { if (formFile == null) { throw new Exception("文件为空!"); } in = new FileInputStream(formFile); wb = Workbook.getWorkbook(in); Sheet sheet[] = wb.getSheets(); if (sheet != null) { for (int i = 0; i < sheet.length; i++) { if (!sheet[i].getName().equalsIgnoreCase("User")) { throw new Exception("指定文件中不包含名称为User的sheet,请重新指定!"); } for (int j = 1; j < sheet[i].getRows(); j++) { String[] valStr = new String[8]; for (int k = 0; k < sheet[i].getColumns(); k++) { Cell cell = sheet[i].getCell(k, j); String content = ""; if (cell.getType() == CellType.DATE) { DateCell dateCell = (DateCell) cell; java.util.Date importdate = dateCell.getDate();/**如果excel是日期格式的话需要减去8小时*/ long eighthour = 8*60*60*1000; SimpleDateFormat simpledate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); /**在当前日期上减8小时*/ long time = importdate.getTime()-eighthour; java.util.Date date = new java.util.Date(); date.setTime(time); content = simpledate.format(date); } else { String tempcontent = (cell.getContents() == null ? "" : cell.getContents()); content = tempcontent.trim().replace('\'', ' '); } valStr[k] = content; } list.add(j-1,valStr); } } } return list; } catch (Exception e) { e.printStackTrace(); throw e; } finally { if (wb != null) { wb.close(); } if (in != null) { try { in.close(); } catch (Exception e) { e.printStackTrace(); } } } }
jackie_Ga 2013-05-16
  • 打赏
  • 举报
回复
额,这样子的。 那用哪个方法可以判断咧
跳蚤图 2013-05-16
  • 打赏
  • 举报
回复
sheet1.getCell(10, i).getType()取到的是这个单元格的类型,而不是单元格内值的类型。 就像单元格可以是radio类型的,但是radio所代表的值也可以是日期。 像这样 。20130101 。20130102 不知道我说明白没有

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧