/**
* Excel上传
* */
@RequestMapping(value = "/xxx.do")
public void excelBatch(@RequestParam("file") MultipartFile file,
HttpServletResponse response, HttpServletRequest request)
throws Exception {
ByteArrayInputStream is = null;
try {
//读取流文件
is = new ByteArrayInputStream(file.getBytes());
// 打开文件
Workbook book = Workbook.getWorkbook(is);
// 得到第一个工作表对象
Sheet sheet = book.getSheet(0);
// 得到第一个工作表中的总行数
int rowCount = sheet.getRows();
Map<String, String> map = new HashMap<String, String>();
if (rowCount > 1) {
// 循环取出Excel中的内容
for (int i = 1; i < rowCount; i++) {
Cell[] cells = sheet.getRow(i);
String col1 = cells[0].getContents();//数据1
String col2 = cells[1].getContents();//数据2
String col3 = cells[2].getContents();//数据3
// 保存到数据库...
}
map.put("flag", "success");
writerJson(response, map);
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
is.close();
}
}