日期:2014-05-20 浏览次数:20794 次
public Workbook readExcel(String filePath){
logger.info("开始执行readExcel方法!");
FileInputStream fis = null;
BufferedInputStream bis = null;
Workbook wb = null;
File file;
try {
file = new File(filePath);
if( !file.exists() )
{
logger.info("程序报错-文件不存在");
throw new RuntimeException("文件不存在");
}else{
logger.info("正在读取文件"+filePath);
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
wb = WorkbookFactory.create(bis);
}
fis.close();
bis.close();
} catch (IOException e) {
logger.info(e);
e.printStackTrace();
} catch (InvalidFormatException e) {
logger.info(e);
e.printStackTrace();
} finally {
if(bis != null){
try {
fis.close();
bis.close();
} catch (IOException e) {
logger.info(e);
e.printStackTrace();
}
}
}
logger.info("readExcel方法执行结束!");
return wb;
}