Excel 导入的时候判断到底是Excel2003 还是Excel 2007 ,两种的API不一样,微软很坑爹。
// 判断文件类型
public Workbook createWorkBook(String excelType, InputStream is)
throws IOException {
if ("xls".equals(excelType)) {
return new HSSFWorkbook(is);
} else if ("xlsx".equals(excelType)) {
return new XSSFWorkbook(is);
} else {
return null;
}
}
Excel 2003 和Excel 2007 的Mime信息(如果涉及对单元格进行操作,操作指的是入合并之类的,非赋值)
Excel 2003 操作的Mime信息 response.setContentType("application/vnd.ms-excel");
Excel 2007 操作的Mime信息 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
对于Excel 2007 必须添加相关的jar(其他版本雷同)
poi-3.8-20120326.jar
poi-ooxml-3.8-20120326.jar
dom4j-1.6.1.jar
stax-api-1.0.1.jar
poi-ooxml-schemas-3.8-20120326.jar
xmlbeans-2.3.0.jar