首页 > 代码库 > spingmvc 上传文件, poi解析xls,xlsx

spingmvc 上传文件, poi解析xls,xlsx

前台jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>数据导入</title>
 	<style type="text/css">
	</style>
</head>
<body>
<div align="right"> 
	<form action="<%=request.getContextPath()%>/loanData" method="POST" enctype="multipart/form-data">  
		<table class="table" id="queryCondition">
			<tbody  class="tbd">
			<tr>
				<td align="right" style="padding-right: 2px">
					<input type="file" name="myfiles" id="myfiles" style="display: none;" onchange="document.getElementById('filePath').value=http://www.mamicode.com/this.value" />>
java代码,使用的包为poi3.5,commons-io2.1

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class HdImporController {

	@RequestMapping("/initLoanData")
	public String initLoanData(HttpServletRequest request) {

		return "views/service/import/loanData";
	}

	@RequestMapping(value = http://www.mamicode.com/"/loanData", method = RequestMethod.POST)>

spingmvc 上传文件, poi解析xls,xlsx