本文共 2729 字,大约阅读时间需要 9 分钟。
一、说明
1、文章转载自: 原文标题====SpringMvc+POI 处理Excel的导入操作功能==== 提到了ImportExcelUtil.java(Excel解析工具类)、UploadExcelControl.java (Spring控制器)、InfoVo.java(保存Excel数据对应的对象)、main.jsp(前端代码)以及配置文件web.xml、springmvc-servlet.xml(只做简单配置)、applicationContext-base.xml等。 2、本文只提Controller层、ImportExcelUtil工具类两部分,原文中这两部分导入功能可能会有一些小问题,具体可看原文网友评论。 3、我对原文导入部分代码进行略微修改后,导入功能已实际运用当中,没发现问题。二、功能代码 首先先感谢下原文博主,然后上代码!!!!!1、Controller层// 单号信息service@Autowiredpublic OrderService orderService ; //服务层改为自己的 /** * 一键上传Excel表信息 * * @author Justin * */ @RequestMapping("order_add.action") public @ResponseBody Listuploadadd(MultipartFile myFile, HttpServletResponse res) throws IOException { List errorList = new ArrayList (); try { ImportExcelUtil util = new ImportExcelUtil(); InputStream input = null; List
2、ImportExcelUtil工具类
package poi;import java.io.InputStream;import java.text.DecimalFormat;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.List;import org.apache.poi.hssf.usermodel.HSSFDateUtil;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.ss.usermodel.Cell;import org.apache.poi.ss.usermodel.Row;import org.apache.poi.ss.usermodel.Sheet;import org.apache.poi.ss.usermodel.Workbook;import org.apache.poi.xssf.usermodel.XSSFWorkbook;public class ImportExcel { private final static String Excel_2003 =".xls";//2003版本的excel private final static String Excel_2007 =".xlsx";//2007版本的excel public List