前一篇文章导出EXCEL,这一篇为导入EXCEL到库:
一.解析前端导入的EXCEL
/*
* 导入操作日志
*
*/
public ActionForward importInckAdslDevNeLogExcel(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException, BiffException{
InckAdslDevNeForm inckAdslDevNeForm = (InckAdslDevNeForm) form;
FormFile xlsFile = xlsFile=inckAdslDevNeForm.getExcelPath();
List list = new ArrayList();
jxl.Workbook rwb = Workbook.getWorkbook(xlsFile.getInputStream());
Sheet rs = rwb.getSheet(0);
int rowNum = rs.getRows();
for (int row = 1; row < rowNum; row++) {
String a = TPubFunction.formatStringNull(rs.getCell(0, row).getContents());
String b= TPubFunction.formatStringNull(rs.getCell(1, row).getContents());
String c= TPubFunction.formatStringNull(rs.getCell(2, row).getContents());
String d= TPubFunction.formatStringNull(rs.getCell(3, row).getContents());
String e= TPubFunction.formatStringNull(rs.getCell(4, row).getContents());
String f= TPubFunction.formatStringNull(rs.getCell(5, row).getContents());
String g= TPubFunction.formatStringNull(rs.getCell(6, row).getContents());
String h= TPubFunction.formatStringNull(rs.getCell(7, row).getContents());
String operaTime = TPubFunction.formatStringNull(rs.getCell(8, row).getContents());
String operaId = TPubFunction.formatStringNull(rs.getCell(9, row).getContents());
String loginID = TPubFunction.formatStringNull(rs.getCell(10, row).getContents());
String operaName = TPubFunction.formatStringNull(rs.getCell(11, row).getContents());
String operaType = TPubFunction.formatStringNull(rs.getCell(12, row).getContents());
String sql=dao.importLogExcelSql(a, b, c, d, e, f,
g, h,operaTime,operaId,loginID,operaName,operaType);
list.add(sql);
}
try{
dao.importExcel(list);
request.setAttribute("iFlag", "2");
}catch(Exception ex){
request.setAttribute("iFlag", "1");
}
return showExcel(mapping,form,request,response);
}
二 importLogExcelSql
public String importLogExcelSql(String a,String b,String c,
String d,String e,String f,String g,String h,
String operaTime,String operaId,String loginID,String operaName,String operaType){
StringBuffer aSql = new StringBuffer();
aSql.append("insert into inck_log(a,b,c,d,e,");
aSql.append("f,g,h,operaTime,operaId,loginID,operaName,operaType) values('"+a+"','"+b+"','"+c+"','"
+d+"','"+e+"','"+f+"','"+g+"','"+h+"','"+operaTime+"','"+operaId+"','"+loginID+"','"+operaName+"','"+operaType+"')");
return aSql.toString();
}
三importExcel方法为批量执行SQL语句