直接放代码,其中getValue和getWorkbook方法可直接使用。
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
@RequestMapping(value = "/savePointExecl", method = { RequestMethod.POST, RequestMethod.GET })
public void savePointExecl(@RequestParam(value = "attachment[]", required = false) MultipartFile file,
HttpServletRequest request, HttpServletResponse response) throws Exception {
com.sfy.system.StringUtil.BeforeInvoke(request);
try {
if (!file.isEmpty()) {
Map<String, Object> result = new HashMap<String, Object>();
String originalFilename = file.getOriginalFilename();
String fileName = sdf.format(new Date()) + JavaEEFrameworkUtils.getRandomString(3)
+ originalFilename.substring(originalFilename.lastIndexOf("."));
//切换到当前的文件夹
File filePath = new File(
getClass().getClassLoader().getResource("/").getPath().replace("/WEB-INF/classes/",
"/static/attachment/di/" + DateFormatUtils.format(new Date(), "yyyyMM")));
if (!filePath.exists()) {
filePath.mkdirs();
}
file.transferTo(new File(filePath.getAbsolutePath() + "\\" + fileName));
String destinationFilePath = "/static/attachment/di/"
+ DateFormatUtils.format(new Date(), "yyyyMM") + "/" + fileName;
com.sfy.system.StringUtil._DEBUG("s