public void uploadFile( HttpServletRequest request) {
JSONObject jsonObject = new JSONObject();
// 转型为MultipartHttpRequest:
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// 获得文件:
MultipartFile multipartFile = multipartRequest.getFile("file");
if (multipartFile == null) {
return jsonObject;
}
logger.info("上传文件, filename=" + multipartFile.getOriginalFilename());
InputStream inputStream;
try {
inputStream = multipartFile.getInputStream();
Workbook workbook = new XSSFWorkbook(inputStream);
Sheet sheet = workbook.getSheetAt(0);
Row row;
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
row = sheet.getRow(i);
}
} catch (Exception e) {
logger.error("error:", e);
}
}
注:
1.sheet.getLastRowNum() 下标是从0开始