欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java利用Excel文件批量导入数据进入数据库

程序员文章站 2022-06-11 13:28:57
...

直接放代码,其中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 D