我用jxl读取excel时发现,excel表格中的日期格式我用sheet1.getCell(10, i).getType()获取到的类型是Lable(表格中对应的单元格确定是日期类型),这个会是什么原因导致的呢?jxlexclelable
解决方案 »
- llinux 运行tomcat时JRE_HOME显示不对 怎么办?
- 关于毕业设计。。。我选了个基本上完成不了的课题
- 请大家介绍几本书看看!
- tomcat5.028,程序运行偶尔会出现javax.naming.NameNotFoundException。。。
- 关于My SQL汉字问题
- 简单问题,HQL查日期为空的记录
- JAVA对象序列化成XML与C++通信的问题
- 在JSP里如何做一个时钟(即在jsp页面显示2005年12月27日 15:28:30,秒钟不停的改变)
- 跪求 Java Mail达人
- 为什么我把jar包放在myeclipse的lib的子包下面就会报错?
- 急求MyEclipse_6_0_1GA_E3_3_1_Installer.bin 文件
- java调用shell获取返回值,求前辈高手解答
。20130102不知道我说明白没有
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();
}
}
}
}