需求:‘需要将本地的Excel中的数据经过验证之后导入数据库,在导入数据库之前在页面上展示出来

思路:将Excel导入存到session里面 去判断有没有不合法数据  如果有阻止提交

工具类:

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
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.ss.usermodel.WorkbookFactory; public class PoiUtils {
private static int titleCellCount = ; /**
* 解析Excel
*
* @throws IOException
*
* @throws IOException
* @throws InvalidFormatException
* fileName: 文件名称 firstRow: 从第几行开始解析 firstColum: 从第几列开始解析 RowTotal:解析工作表的索引
* firstSheet : 从第几个sheet页开始解析
*/
public static List<String[][]> excelToMap(File file,
int firstRow, int firstColum, int RowTotal)
throws IOException {
FileInputStream is = null;// 创建文件流
Workbook workbook = null;// 创建Excel对象
// List<Map<String, String>> rowMapList = null;
List<String[][]> list = null;
Map<String, String> map = null;
int rowCount = ;
int cellCount = ;
String[][] arr = null;
try {
is = new FileInputStream(file);
workbook = WorkbookFactory.create(is);
int sheetCount = workbook.getNumberOfSheets(); // Sheet的数量
list = getArrsList(workbook, RowTotal);
for (int s = ; s < list.size(); s++) {
Sheet sheet = workbook.getSheetAt(s);// 获取当前sheet页
rowCount = sheet.getPhysicalNumberOfRows(); // 获取当前页的总行数
for (int r = firstRow; r < rowCount; r++) {
Row row2 = sheet.getRow(r);
if (row2 == null) {
continue;
}
arr = list.get(s);
cellCount = row2.getPhysicalNumberOfCells(); // 获取总列数 for (int c = firstColum; c < cellCount; c++) {
Cell cell = row2.getCell(c);
if (cell == null) {
continue;
}
try {
String cellValue = getCellValue(cell).trim();// 获取某一个单元格里面的数据
arr[r][c] = cellValue;
} catch (Exception e) {
e.printStackTrace();
}
} }
}
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
}
return list;
}
/**
* 返回list里面装的二维数组
*/
private static List<String[][]> getArrsList(Workbook workbook,
Integer RowTotal) {
// 获取总的sheet页数
List<String[][]> list = new ArrayList<String[][]>();
int sheetCount = workbook.getNumberOfSheets(); // Sheet的数量
for (int i = ; i < sheetCount; i++) {// i就是有多少页
// 获取每个sheet页的行数和列数
Sheet sheetAt = workbook.getSheetAt(i);
int rowCount1 = sheetAt.getPhysicalNumberOfRows();// 获取出总行数
// 取某一行创建行对象来获取总列数(取开始行就行)
Row row3 = sheetAt.getRow(RowTotal);
if (row3 == null) {
continue;
}
int cells = row3.getPhysicalNumberOfCells();// 总列数
// 根据每个sheet页的行数和列数创建二维数组并且装入list中返回
String[][] arr = new String[rowCount1][cells];
list.add(arr);
}
return list;
} /**
* 获取单元格信息
*/
private static String getCellValue(Cell cell) {
String cellValue = null;
switch (cell.getCellType()) {
// Excel存储日期、时间均以数值类型进行存储,读取时POI先判断是是否是数值类型,再进行判断转化
case Cell.CELL_TYPE_NUMERIC:
/*
* POI对Excel自定义日期格式的读取的万能处理方案: 所有日期格式都可以通过getDataFormat()值来判断
* yyyy-MM-dd----- 14 yyyy年m月d日--- 31 yyyy年m月------- 57 m月d日
* ---------- 58 HH:mm----------- 20 h时mm分 ------- 32 yyyy-m
*/
// 1、判断是否是日期格式
boolean isDateFormat = false;
short format = cell.getCellStyle().getDataFormat();
SimpleDateFormat sdf = null;
if (format == || format == || format == || format ==
|| format == || format == ) {
isDateFormat = true;
// 时间
sdf = new SimpleDateFormat("yyyyMMddHHmm");
}
// 2.1若是日期格式,则调用日期单元格值获取方法得到日期单元格的值
if (isDateFormat) {
double value = cell.getNumericCellValue();
Date date = org.apache.poi.ss.usermodel.DateUtil
.getJavaDate(value);
cellValue = sdf.format(date);
// 2.2若不是日期格式,则将单元格格式设置为字符串格式,调用字符串单元格值获取方法得到字符串单元格的值
} else {
cell.setCellType(Cell.CELL_TYPE_STRING);
cellValue = cell.getStringCellValue();
}
break;
default:
// 将单元格格式设置为字符串格式,调用字符串单元格值获取方法得到字符串单元格的值
cell.setCellType(Cell.CELL_TYPE_STRING);
cellValue = cell.getStringCellValue();
}
return cellValue; }
/**
* 根据情况解析
* @param
* @return
* @throws IOException
*/
public Map<String, Object> packMath2(File file)
throws IOException {
Map<String, Object> allMap = new HashMap<String, Object>();
List<Map<String, String>> rowMapList = new ArrayList<Map<String, String>>();
List<Map<String, String>> rowpList = new ArrayList<Map<String, String>>();
List<String[][]> list = PoiUtils.excelToMap(file, , ,
);
//获取sheet页
/*for (int x = 0; x < list.size(); x++) {*/
String[][] arr = list.get();// 获取EXCEL第一页的数据(可改为X遍历获取)
int rowLength = arr.length;// 总行数
int lieLength = arr[].length;// 总列数
for (int i = ; i < rowLength; i++) {
Map<String, String> map = new HashMap<String, String>();
for (int j = ; j < lieLength; j++) {
//第几行为表头 以表头为key 获取下面的数据
map.put(arr[][j], arr[i][j]);
}
Pattern pattern1 = Pattern.compile("^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
// 身份证号规则
Pattern pattern = Pattern.compile("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$");
// 手机号规则
//Pattern pattern1 = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$");
// 默认不满足规格
Matcher isNum1 = pattern.matcher("a");
Matcher isNum = null;
//判断标识位(数字位),满足规则保存,不满足不保存
if (arr[i][] != null && !"".equals(arr[i][])) {
if (arr[i][] != null && !"".equals(arr[i][])) {
// 匹配序号是否满足
isNum = pattern.matcher(arr[i][].trim());
isNum1 = pattern1.matcher(arr[i][].trim()); }
}
if(!isNum1.matches()){
continue;// 不满足退出
}else {
if (!isNum.matches()) {
rowpList.add(map);
continue;// 不满足退出
} else {
rowMapList.add(map);// 满足添加
}
}
}
/* }*/
allMap.put("success",rowMapList);
allMap.put("fail",rowpList);
return allMap;
}
}

jxl的工具类

package  com.lf.common.utils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set; import org.springframework.stereotype.Service; import com.lf.utils.DateUtils; import jxl.CellView;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.UnderlineStyle;
import jxl.read.biff.BiffException;
import jxl.write.Border;
import jxl.write.BorderLineStyle;
import jxl.write.Colour;
import jxl.write.Label;
import jxl.write.NumberFormats;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
@Service
public class JxlWriteExcel {
public boolean createTable(String header, String[] body, String filePath) {
boolean createFlag = true;
WritableWorkbook book;
try {
// 根据路径生成excel文件
book = Workbook.createWorkbook(new File(filePath)); // 创建一个sheet名为"表格"
WritableSheet sheet = book.createSheet("表格", );
// 设置NO列宽度 // 去掉整个sheet中的网格线
sheet.getSettings().setShowGridLines(false);
Label tempLabel = null;
// 表头输出
String[] headerArr = header.split(",");
int headerLen = headerArr.length;
// 循环写入表头内容
for (int i = ; i < headerLen; i++) {
tempLabel = new Label( i, , headerArr[i],
getHeaderCellStyle());
sheet.addCell(tempLabel);
sheet.setColumnView(i, );
}
// 表体输出
int bodyLen = body.length;
// 循环写入表体内容
for (int j = ; j < bodyLen; j++) {
String[] bodyTempArr = body[j].split(",");
for (int k = ; k < bodyTempArr.length; k++) {
WritableCellFormat tempCellFormat = null;
tempCellFormat = getBodyCellStyle();
if (tempCellFormat != null) {
if (k == || k == (bodyTempArr.length - )) {
tempCellFormat.setAlignment(Alignment.CENTRE);
}
}
tempLabel = new Label( k, + j, bodyTempArr[k],
tempCellFormat);
sheet.addCell(tempLabel);
}
}
book.write();
book.close();
} catch (IOException e) {
createFlag = false;
System.out.println("EXCEL创建失败!");
e.printStackTrace();
} catch (RowsExceededException e) {
createFlag = false;
System.out.println("EXCEL单元设置创建失败!");
e.printStackTrace();
} catch (WriteException e) {
createFlag = false;
System.out.println("EXCEL写入失败!");
e.printStackTrace();
} return createFlag;
}
public boolean createErroeTable(String header, String[] body, String filePath ,String sheetName,int sheetNum) {
boolean createFlag = true;
WritableWorkbook book ;
WritableSheet sheet = null ;
File errorFile = new File(filePath);
try {
if (errorFile.exists()) {
Workbook workbook = Workbook.getWorkbook(errorFile);
book = workbook.createWorkbook(errorFile,workbook);
sheet = book.createSheet(sheetName, );
}else {
// 根据路径生成excel文件
book = Workbook.createWorkbook(errorFile); // 创建一个sheet名为"表格"
sheet = book.createSheet(sheetName, sheetNum);
}
// 设置NO列宽度 // 去掉整个sheet中的网格线
sheet.getSettings().setShowGridLines(false);
Label tempLabel = null;
// 表头输出
String[] headerArr = header.split(",");
int headerLen = headerArr.length;
// 循环写入表头内容
for (int i = ; i < headerLen; i++) {
tempLabel = new Label( i, , headerArr[i],
getHeaderCellStyle());
sheet.addCell(tempLabel);
sheet.setColumnView(i, );
}
// 表体输出
int bodyLen = body.length;
// 循环写入表体内容
for (int j = ; j < bodyLen; j++) {
String[] bodyTempArr = body[j].split(",");
for (int k = ; k < bodyTempArr.length; k++) {
WritableCellFormat tempCellFormat = null;
tempCellFormat = getBodyCellStyle();
if (tempCellFormat != null) {
if (k == || k == (bodyTempArr.length - )) {
tempCellFormat.setAlignment(Alignment.CENTRE);
}
}
tempLabel = new Label( k, + j, bodyTempArr[k],
tempCellFormat);
sheet.addCell(tempLabel);
}
}
book.write();
book.close();
} catch (IOException e) {
createFlag = false;
System.out.println("EXCEL创建失败!");
e.printStackTrace();
} catch (RowsExceededException e) {
createFlag = false;
System.out.println("EXCEL单元设置创建失败!");
e.printStackTrace();
} catch (WriteException e) {
createFlag = false;
System.out.println("EXCEL写入失败!");
e.printStackTrace();
} catch (BiffException e) {
System.out.println("读取EXCEL对象失败!");
e.printStackTrace();
} return createFlag;
}
public WritableCellFormat getHeaderCellStyle() {
WritableFont font = new WritableFont(WritableFont.createFont("宋体"), ,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE);
WritableCellFormat headerFormat = new WritableCellFormat(
NumberFormats.TEXT);
try {
// 添加字体设置
headerFormat.setFont(font);
// 设置单元格背景色:表头为黄色
headerFormat.setBackground(Colour.YELLOW);
// 设置表头表格边框样式
// 整个表格线为粗线、黑色
headerFormat.setBorder(Border.ALL, BorderLineStyle.THICK,
Colour.BLACK);
// 表头内容水平居中显示
headerFormat.setAlignment(Alignment.CENTRE);
} catch (WriteException e) {
System.out.println("表头单元格样式设置失败!");
}
return headerFormat;
} public WritableCellFormat getBodyCellStyle() {
WritableFont font = new WritableFont(WritableFont.createFont("宋体"), ,
WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE);
WritableCellFormat bodyFormat = new WritableCellFormat(font);
try {
// 设置单元格背景色:表体为白色
bodyFormat.setBackground(Colour.WHITE);
// 设置表头表格边框样式
// 整个表格线为细线、黑色
bodyFormat
.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
} catch (WriteException e) {
System.out.println("表体单元格样式设置失败!");
}
return bodyFormat;
}
public void deleteFile(String fileName){
File file = new File(fileName);
if(file.exists()){
file.delete();
System.out.println("删除文件成功");
}else{
System.out.println("文件不存在");
}
}
/**
* 创建表格
* @module:
* @author: ZhangK
* @date: Aug 1, 2016
*/
public String createTableByZk(String header, String[] body, String filePath) {
WritableWorkbook book; String date = DateUtils.convertDateToString(new Date(), "yyyyMMddHHmmssSSS");
String fileName=date+".xls";
File file = null;
if (fileName !=null|| "".equals(fileName)) {
file = new File(fileName);
}else{
return null;
}
try {
// 根据路径生成excel文件
book = Workbook.createWorkbook(file);
// 创建一个sheet名为"表格"
WritableSheet sheet = book.createSheet("发货情况", );
// 去掉整个sheet中的网格线
sheet.getSettings().setShowGridLines(false);
Label tempLabel = null;
// 表头输出
String[] headerArr = header.split(",");
int headerLen = headerArr.length;
// 循环写入表头内容
CellView cv = null;
for (int i = ; i < headerLen; i++) {
tempLabel = new Label(i, , headerArr[i],
getHeaderCellStyle());
sheet.addCell(tempLabel);
// 设置NO列宽度
sheet.setColumnView(i, );
}
// 表体输出
int bodyLen = body.length; // 循环写入表体内容
for (int j = ; j < bodyLen; j++) {
String[] bodyTempArr = body[j].split(",");
for (int k = ; k < bodyTempArr.length; k++) {
WritableCellFormat tempCellFormat = null;
tempCellFormat = getBodyCellStyle();
if (tempCellFormat != null) {
if (k == || k == (bodyTempArr.length - )) {
tempCellFormat.setAlignment(Alignment.CENTRE);
}
}
tempLabel = new Label( k, + j, bodyTempArr[k],
tempCellFormat);
sheet.addCell(tempLabel);
}
}
book.write();
book.close();
} catch (IOException e) {
fileName = null;
System.out.println("EXCEL创建失败!");
e.printStackTrace();
} catch (RowsExceededException e) {
fileName = null;
System.out.println("EXCEL单元设置创建失败!");
e.printStackTrace();
} catch (WriteException e) {
fileName = null;
System.out.println("EXCEL写入失败!");
e.printStackTrace();
} return fileName;
} /**
* list<map>去重
* @param list
* @param param_list
* @return
*/
public String[] RemoveDuplicate(List<Map<String, String>> list,List<String> param_list) {
List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
Set<Map> setMap = new HashSet<Map>();
for (Map<String, String> map1 : list) {
if (setMap.add(map1)) {
listMap.add(map1);
}
}
String[] rowData_retail = new String[listMap.size()];
for (int i = ; i < listMap.size(); i++) {
Map<String, String> map = listMap.get(i);
for (int j = ; j < param_list.size(); j++) {
String param_i = map.get(param_list.get(j));
param_i = map.get(param_list.get(j)) == null ? "" : map
.get(param_list.get(j));
if (j == param_list.size() -) {
rowData_retail[i] = rowData_retail[i] + param_i ;
}else if (j==) {
rowData_retail[i] = param_i + ",";
}else {
rowData_retail[i] = rowData_retail[i] + param_i + ",";
} } }
return rowData_retail;
}
public static void main(String[] args) {
JxlWriteExcel jxl = new JxlWriteExcel();
String goodsHeader = "缺少商品对照编码,缺少商品对照名称";
List<Map<String, String>> error_goods_list = new ArrayList<Map<String, String>>();
List<String> list = new ArrayList<String>();
Map<String, String> error_map = new HashMap<String, String>();
error_map.put("测试", "测试");
error_map.put("测试1", "测试");
error_goods_list.add(error_map);
int sheetNum = ;
list.add("测试");
list.add("测试1");
String[] rowData_goods = jxl.RemoveDuplicate(error_goods_list,
list);
if (rowData_goods.length != ) {
jxl.createErroeTable(goodsHeader, rowData_goods, "C:\\Users\\Administrator\\Desktop\\ceshi(1).xls","商品",sheetNum);
}
}
}

上传的controller

 @RequestMapping("/saveExcel")
public ModelAndView saveExcel(HttpServletRequest request,@RequestParam(value = "file") MultipartFile file) throws IOException {
ModelAndView mav = new ModelAndView();
if (!file.isEmpty()) {
File excelFil = new File(file.getOriginalFilename());
FileUtils.copyInputStreamToFile(file.getInputStream(),excelFil);
PoiUtils utils = new PoiUtils();
try {
Map<String, Object> excellist = utils.packMath(excelFil);
List<Map<String, String>> rowMapList = new ArrayList<Map<String, String>>();
List<Map<String, String>> rowpList = new ArrayList<Map<String, String>>();
rowMapList= (List<Map<String, String>>) excellist.get("success");
rowpList= (List<Map<String, String>>) excellist.get("fail");
request.getSession().setAttribute("successList",rowMapList);
request.getSession().setAttribute("failList",rowpList);
mav.setViewName("redirect:lookExcel");
} catch (IOException e) {
e.printStackTrace();
}
} else {
mav.setViewName("error");
}
return mav;
}

保存的controller

@RequestMapping("/saveAllExcel")
@ResponseBody
public Object saveAllExcel(HttpServletRequest request){
JSONObject jo = new JSONObject();
List<Map<String,String>> mapList = (List<Map<String, String>>) request.getSession().getAttribute("successList");
List<Map<String,String>> failList = (List<Map<String, String>>) request.getSession().getAttribute("failList");
try{
if(failList.size()>){
jo.put("msg","存在失败数据");
jo.put("data","");
}else{ Integer sex = ;
Integer i = ;
for(int count = ;count<mapList.size();count++){
EmployeeTemp employeeTemp = new EmployeeTemp();
            //解析和封装到实体类里面
employeeTemp.setName(mapList.get(count).get("姓名"));
i = employeeTempService.insertExcel(employeeTemp);
}
if(i>){
jo.put("msg","成功");
jo.put("msgcode","");
}else{
jo.put("msg","修改错误");
jo.put("msgcode","");
}
jo.put("msg","成功");
jo.put("msgcode","");
}
}catch (Exception e){
LoggerUtils.error(getClass(),"系统错误",e);
jo.put("msg","系统错误");
jo.put("msgcode","");
}
return jo;
}

另外一种方法

@RequestMapping(value = "planImport",method = RequestMethod.POST)
public ModelAndView planImport(HttpServletRequest request, @RequestParam("file") MultipartFile file){
ModelAndView mav = new ModelAndView();
try { File excelFil = new File(file.getOriginalFilename());
FileUtils.copyInputStreamToFile(file.getInputStream(),excelFil);
List<WorkPlan> workPlanList = workPlanService.importPlan(excelFil);
if(workPlanList.size()>=){
request.getSession().setAttribute("wpList", workPlanList);
mav.addObject("wpList", workPlanList);
mav.setViewName("plan/plan_import_result");
}else{
mav.addObject("url", "planImportInit.do");
mav.addObject("info","导入的Excel文件有误,请确认格式和数据!");
mav.setViewName("error");
}
} catch (Exception e) {
mav.addObject("url", "planImportInit.do");
mav.addObject("info","导入的Excel文件有误,请确认格式和数据!");
mav.setViewName("error");
}
return mav;
}

service

@Override
public List<WorkPlan> importPlan(File file) throws Exception{
List<WorkPlan> workPlanList = new ArrayList<WorkPlan>(); /*使用jxl导入*/
// Workbook wb = Workbook.getWorkbook(file);
// Sheet sheet = wb.getSheet(0);
// int rows = sheet.getRows();
// WorkPlan workPlan = null;
// Cell cell1 = null;
// DateCell dc1 = null;
// Cell cell2 = null;
// DateCell dc2 = null;
// for(int i=4;i<rows;i++){
// workPlan = new WorkPlan();
// workPlan.setEquip(sheet.getCell(0, i).getContents());
// workPlan.setPlanContent(sheet.getCell(1,i).getContents());
// workPlan.setArea(sheet.getCell(2,i).getContents());
// workPlan.setRiskContent(sheet.getCell(3,i).getContents());
// workPlan.setWorkType(sheet.getCell(4,i).getContents());
// workPlan.setInspect(sheet.getCell(5,i).getContents());
// cell1 = sheet.getCell(6, i);
// if((cell1.getContents()).equals("")){
// workPlan.setPlanTime1(null);
// }else if(cell1.getType() == CellType.DATE){
// dc1 = (DateCell)cell1;
// System.out.println(dc1.getDate()+"-------------");
// System.out.println(cell1.getContents()+"---------------");
// workPlan.setPlanTime1(dc1.getDate());
// }else{
// workPlan.setPlanTime1(CommonUtil.convertStringToDate(cell1.getContents(), "yyyy-MM-dd HH:mm"));
// }
// cell2 = sheet.getCell(7, i);
// if((cell2.getContents()).equals("")){
// workPlan.setPlanTime2(null);
// }else if(cell2.getType() == CellType.DATE){
// dc2 = (DateCell)cell2;
// System.out.println(dc2.getDate()+"===========");
// workPlan.setPlanTime2(dc2.getDate());
// }else{
// workPlan.setPlanTime2(CommonUtil.convertStringToDate(cell2.getContents(), "yyyy-MM-dd HH:mm"));
// }
// workPlan.setDutyDept(sheet.getCell(8, i).getContents());
// workPlan.setDutyMan(sheet.getCell(9, i).getContents());
// workPlan.setCooperate(sheet.getCell(10, i).getContents());
// workPlan.setIntendPlan(sheet.getCell(11, i).getContents());
// if(!workPlan.getEquip().equals("")||
// !workPlan.getPlanContent().equals("")||
// !workPlan.getArea().equals("")||
// !workPlan.getPlanContent().equals("")||
// workPlan.getPlanTime1()!=null||
// workPlan.getPlanTime2()!=null||
// !workPlan.getDutyDept().equals("")||
// !workPlan.getDutyMan().equals("")||
// !workPlan.getWorkType().equals(""))
// {
// workPlanList.add(workPlan);
// }
// }
/*使用poi导入*/
try {
InputStream is = new FileInputStream(file);
POIFSFileSystem fs = new POIFSFileSystem(is);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt();
int rowNum = sheet.getLastRowNum();
HSSFRow row = null;
HSSFCell cell = null;
WorkPlan workPlan = null;
for(int i=;i<=rowNum;i++){
row = sheet.getRow(i);
workPlan = new WorkPlan();
workPlan.setEquip(row.getCell().getStringCellValue());
workPlan.setPlanContent(row.getCell().getStringCellValue());
workPlan.setArea(row.getCell().getStringCellValue());
workPlan.setRiskContent(row.getCell().getStringCellValue());
workPlan.setWorkType(row.getCell().getStringCellValue());
workPlan.setInspect(row.getCell().getStringCellValue());
workPlan.setDutyDept(row.getCell().getStringCellValue());
workPlan.setDutyMan(row.getCell().getStringCellValue());
workPlan.setCooperate(row.getCell().getStringCellValue());
workPlan.setIntendPlan(row.getCell().getStringCellValue());
cell = row.getCell();
if(cell.getCellType() == HSSFCell.CELL_TYPE_BLANK){
workPlan.setPlanTime1(null);
}else if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC&&
HSSFDateUtil.isCellDateFormatted(cell)){
workPlan.setPlanTime1(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
}else{
workPlan.setPlanTime1(CommonUtil.convertStringToDate(cell.getStringCellValue(), "yyyy-MM-dd HH:mm"));
}
cell = row.getCell();
if(cell.getCellType() == HSSFCell.CELL_TYPE_BLANK){
workPlan.setPlanTime2(null);
}else if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC&&
HSSFDateUtil.isCellDateFormatted(cell)){
workPlan.setPlanTime2(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
}else{
workPlan.setPlanTime2(CommonUtil.convertStringToDate(cell.getStringCellValue(), "yyyy-MM-dd HH:mm"));
}
if(!workPlan.getEquip().equals("")||
!workPlan.getPlanContent().equals("")||
!workPlan.getArea().equals("")||
!workPlan.getPlanContent().equals("")||
workPlan.getPlanTime1()!=null||
workPlan.getPlanTime2()!=null||
!workPlan.getDutyDept().equals("")||
!workPlan.getDutyMan().equals("")||
!workPlan.getWorkType().equals(""))
{
workPlanList.add(workPlan);
}
}
return workPlanList;
} catch (Exception e) {
return null;
}
}
[@t.head][/@t.head] [@t.menu][/@t.menu] [@t.body]
<section class="wrapper">
<div class="row">
<div class="col-lg-12">
<ul class="breadcrumb">
<li><a href="index.html"><i class="icon-home"></i>主页</a></li>
<li>增员</li>
<li class="active">增员</li>
</ul>
</div>
</div>
<div class="row">
<div class="col-md-12">
<section class="panel">
<header class="panel-heading">
<label>增员</label>
</header>
<div class="panel-body">
<form id ="pageForm" class="form-inline" role="form">
[#if failList ?size==0]
<button type="button" class="btn btn-danger" onclick="addCo();">保存</button>
[#elseif failList ?size>]
<button type="button" class="btn btn-danger" onclick="again();">重新上传</button>
[/#if]
<table class="table table-striped table-advance table-hover">
<thead>
<tr>
<th>序号</th>
<th>社会保障号码</th>
<th>姓名</th>
<th>身份证号码</th>
<th>性别</th>
<th>出生日期</th>
<th>缴费基数</th>
<th>用工形式</th>
<th>增员年月</th>
<th>增员原因</th>
<th>参加工作日期</th>
<th>联系人</th>
<th>联系电话</th>
<th>家庭住址</th>
<th>通讯地址省级</th>
<th>通讯地址市级</th>
<th>通讯地址区县级</th>
<th>通讯地址补充信息</th>
<th>户口所在地省级</th>
<th>户口所在地市级</th>
<th>户口所在地区县级</th><th>户口所在地补充信息</th>
<th>报名费</th>
<th>查体费</th>
</tr>
</thead>
<tbody>
[#if (failList) ??]
[#list failList as em]
<tr style="color:red" >
<td>${em_index + }</td>
<td>${(em.社会保障号码)!'' }</td>
<td>${(em.姓名)!''}</td>
<td>${(em.身份证号码)!'' }</td>
<td>${(em.性别)!'' }</td>
<td>${(em.出生日期)!'' }</td>
<td>${(em.缴费基数)!'' }</td>
<td>${(em.用工形式)!'' }</td>
<td>${(em.增员年月)!'' }</td>
<td>${(em.增员原因)!'' }</td>
<td>${(em.参加工作日期)!'' }</td>
<td>${(em.联系人)!'' }</td>
<td>${(em.联系电话)!'' }</td>
<td>${(em.家庭住址)!'' }</td>
<td>${(em.通讯地址省级)!'' }</td>
<td>${(em.通讯地址市级)!'' }</td>
<td>${(em.通讯地址区县级)!'' }</td>
<td>${(em.通讯地址补充信息)!'' }</td>
<td>${(em.户口所在地省级)!'' }</td>
<td>${(em.户口所在地市级)!'' }</td>
<td>${(em.户口所在地区县级)!'' }</td>
<td>${(em.户口所在地补充信息)!'' }</td>
<td>${(em.报名费)!'' }</td>
<td>${(em.查体费)!'' }</td> </tr>
[/#list]
[/#if]
[#if (Session.successList) ??]
[#list Session.successList as em]
<tr>
<td>${em_index + }</td>
<td>${(em.社会保障号码)!'' }</td>
<td>${(em.姓名)!''}</td>
<td>${(em.身份证号码)!'' }</td>
<td>${(em.性别)!'' }</td>
<td>${(em.出生日期)!'' }</td>
<td>${(em.缴费基数)!'' }</td>
<td>${(em.用工形式)!'' }</td>
<td>${(em.增员年月)!'' }</td>
<td>${(em.增员原因)!'' }</td>
<td>${(em.参加工作日期)!'' }</td>
<td>${(em.联系人)!'' }</td>
<td>${(em.联系电话)!'' }</td>
<td>${(em.家庭住址)!'' }</td>
<td>${(em.通讯地址省级)!'' }</td>
<td>${(em.通讯地址市级)!'' }</td>
<td>${(em.通讯地址区县级)!'' }</td>
<td>${(em.通讯地址补充信息)!'' }</td>
<td>${(em.户口所在地省级)!'' }</td>
<td>${(em.户口所在地市级)!'' }</td>
<td>${(em.户口所在地区县级)!'' }</td>
<td>${(em.户口所在地补充信息)!'' }</td>
<td>${(em.报名费)!'' }</td>
<td>${(em.查体费)!'' }</td> </tr>
[/#list]
[/#if]
</tbody>
</table>
</form>
</div>
</section>
</div>
</div>
</section>
<script>
function addCo(){
$.ajax({
type: "post",
url: "emp_temp/saveAllExcel",
dataType: "json",
success: function(data){
if(data.msgcode==""){
layer.alert(data.msg,function(index){
layer.close(index);
});
}else{
layer.alert(data.msg,function(index){
layer.close(index);
});
}
loadPage("emp_temp/getEmpTemp");
}
});
} </script>
[/@t.body] [@t.foot] [/@t.foot]

利用poi,jxl将Excel数据导入数据库的更多相关文章

  1. 利用TOAD实现把EXCEL数据导入oracle数据库

    利用TOAD实现把EXCEL数据导入oracle数据库 工具:   Toad11.7z(百度搜索,直接下载) 1.将Excel文件中某些字段导入到Oracle数据库的对应表 连接想要导入的数据库 ,然 ...

  2. 使用python将excel数据导入数据库

    使用python将excel数据导入数据库 因为需要对数据处理,将excel数据导入到数据库,记录一下过程. 使用到的库:xlrd 和 pymysql (如果需要写到excel可以使用xlwt) 直接 ...

  3. [Asp.net]常见数据导入Excel,Excel数据导入数据库解决方案,总有一款适合你!

    引言 项目中常用到将数据导入Excel,将Excel中的数据导入数据库的功能,曾经也查找过相关的内容,将曾经用过的方案总结一下. 方案一 NPOI NPOI 是 POI 项目的 .NET 版本.POI ...

  4. Excel数据导入数据库

    maven依赖 <!--excel相关依赖--> <dependency> <groupId>org.apache.poi</groupId> < ...

  5. 转:[Asp.net]常见数据导入Excel,Excel数据导入数据库解决方案,总有一款适合你!

    引言 项目中常用到将数据导入Excel,将Excel中的数据导入数据库的功能,曾经也查找过相关的内容,将曾经用过的方案总结一下. 方案一 NPOI NPOI 是 POI 项目的 .NET 版本.POI ...

  6. 如何把excel数据导入数据库

    这里介绍2种把excel数据导入oracle数据库的方法. 1. 在excel中生成sql语句. 1)在数据列的右侧,第一行的任何位置输入="insert into table(xx,yyy ...

  7. C#将Excel数据导入数据库(MySQL或Sql Server)

    最近一直很忙,很久没写博客了.今天给大家讲解一下如何用C#将Excel数据导入Excel,同时在文章最后附上如何用sqlserver和mysql工具导入数据. 导入过程大致分为两步: 1.将excel ...

  8. PHPExcel将Excel数据导入数据库

    <?php //PHPExcel读取导入Excel数据到数据库(2003,2007通用)使用方法: //先用excel2array()方法将excel表中的数据存储到数组,在从遍历二维数组将数据 ...

  9. 将Excel数据导入数据库

    Excel如下,这页工作表名叫“线路” 数据库表如下 using System; using System.Collections.Generic; using System.Linq; using ...

随机推荐

  1. 为.net mvc core 启用 https

    引用nuget包:Microsoft.AspNetCore.Server.Kestrel.Https这是一个服务器测试ssl密钥,密码如代码里面所示 using System; using Syste ...

  2. querySelector

     this.el.nativeElement.querySelector import {Component, ElementRef, OnInit} from '@angular/core'; 

  3. HTML5易漏知识点锦集

    本文通过对w3schoolHTML5基础教程,整理出比较常见的却又容易遗忘或者忽略的HTML5相关知识点.本文的标题顺序与w3school中的HTML5基础教程标题顺序保持一致.适合翻阅和复习. 1. ...

  4. 关于static关键字的思考

    静态方法是否能调用非静态成员变量?    static关键字具有如下特点:        一.static关键字修饰的属性/方法可以通过类名直接调用,而不必先new一个对象.        二.sta ...

  5. js可以随意拖拽的div的实现

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. TensorFlow 学习笔记(2)----placeholder的使用

    此系列将会每日持续更新,欢迎关注 在TensorFlow中输入值的方式是通过placeholder来实现 例如:做两个数的乘法时,是先准备好两个place, 再将输出值定义成两数的乘法 最后利用ses ...

  7. 内存管理(malloc和free的用法)

    内存管理 1.堆和栈的区别: 1>栈的特征 1).执行的速度相对较快: 2).空间较小: 3).生存期由系统决定: 4).作用域较小: 5).有名空间,可以通过变量名或者数据名访问: 2> ...

  8. C# 派生类的XmlSerializer序列化XML

    近段对XML 序列化进行处理,用XmlSerializer这个挺好用的. 但是对于派生类对象的XML的生成总会报错.因为同一个节点名称,不能反射为不同的对象.这个在网上找了好久,都说要利用反射来处理. ...

  9. Linux系统自带服务罗列

    /ect/services 文件列出了系统详细的服务 红色字体为常用服务 acpid ACPI(全称 Advanced Configuration and Power Interface)服务是电源管 ...

  10. 精彩的linux shell 命令

      1. Star Wars (telnet) telnet是基于Telnet协议的远程登录客户端程序,经常用来远程登录服务器.除此还可以用它来观看星球大战: telnet towel.blinken ...