@Override PublicResultbean tximportdqkpi (String filePath) {Resultbean RB=NewResultbean (); intSuccess = 0, fail = 0; StringBuffer SB=NewStringBuffer (); Try{File File=NewFile (Fsconfig.getfsroot () +FilePath); Workbook WB= Workbook.getworkbook (Newfileinputstream (file)); Sheet Sheet= Wb.getsheet (0); introws =sheet.getrows (); List<SchDqKpiHead> dqkpiheadlist =NewArraylist<schdqkpihead>(); Schdqkpihead Dqkpihead=NULL; for(introw = 2; Row < rows; row++) { if(! Toputil.isvalidvalue (Sheet.getcell (0, Row). getcontents ())) {Continue; } Try{Dqkpihead=NewSchdqkpihead (); Dqkpihead.setheadid (NewLong ( This. Checkifnulltozero (Sheet.getcell (0, Row). getcontents ())); Dqkpihead.setdqkpicode (Sheet.getcell (1, Row). getcontents ()); Dqkpihead.setdqkpiname (Sheet.getcell (2, Row). getcontents ()); Dqkpihead.setdqkpidesc (Sheet.getcell (3, Row). getcontents ()); Dqkpihead.setcalculatesql (Sheet.getcell (4, Row). getcontents ()); Dqkpihead.setaltercondition (Sheet.getcell (5, Row). getcontents ()); Dqkpihead.setaltermsg (Sheet.getcell (6, Row). getcontents ()); Dqkpihead.setobjecttype (Sheet.getcell (7, Row). getcontents ()); Dqkpihead.setdqkpitype (Sheet.getcell (8, Row). getcontents ()); Dqkpihead.setkpistatus (Sheet.getcell (9, Row). getcontents ()); Dqkpihead.setobjectcode (Sheet.getcell (10, Row). getcontents ()); Dqkpihead.setrunposition (Sheet.getcell (11, Row). getcontents ()); Dqkpihead.setrunorder (Sheet.getcell (12, Row). getcontents ()); Dqkpihead.setponderance (Sheet.getcell (13, Row). getcontents ()); Dqkpihead.setenabledflag (Sheet.getcell (14, Row). getcontents ()); Dqkpihead.setcreatedby ("Import"); Dqkpihead.setcreateddate (NewDate ()); Dqkpihead.setlastupdatedby ("Import"); Dqkpihead.setlastupdateddate (NewDate ()); Dqkpiheadlist.add (Dqkpihead); Success++; } Catch(Exception e) {log.error (e); E.printstacktrace (); Fail++; Continue; }} sb.append ("Table: Sch_dq_kpi_head success:" + Success + "bar, failed:" + fail + "Bar </br>"); Success= fail = 0; Coredao.saveorupdate (dqkpiheadlist); Rb.setdata (dqkpiheadlist); Sheet= Wb.getsheet (1); Rows=sheet.getrows (); List<SchDqKpiLine> dqkpilinelist =NewArraylist<schdqkpiline>(); Schdqkpiline Dqkpiline=NULL; for(introw = 2; Row < rows; row++) { if(! Toputil.isvalidvalue (Sheet.getcell (0, Row). getcontents ())) {Continue; } Try{dqkpiline=NewSchdqkpiline (); Dqkpiline.setlineid (NewLong ( This. Checkifnulltozero (Sheet.getcell (0, Row). getcontents ())); Dqkpiline.setheadid (NewLong ( This. Checkifnulltozero (Sheet.getcell (1, Row). getcontents ())); Dqkpiline.setdtlcode (Sheet.getcell (2, Row). getcontents ()); Dqkpiline.setdtlname (Sheet.getcell (3, Row). getcontents ()); Dqkpiline.setexecsql (Sheet.getcell (4, Row). getcontents ()); Dqkpiline.setattribute1 (Sheet.getcell (5, Row). getcontents ()); Dqkpiline.setattribute2 (Sheet.getcell (6, Row). getcontents ()); Dqkpiline.setattribute3 (Sheet.getcell (7, Row). getcontents ()); Dqkpiline.setattribute4 (Sheet.getcell (8, Row). getcontents ()); Dqkpiline.setattribute5 (Sheet.getcell (9, Row). getcontents ()); Dqkpiline.setattribute6 (Sheet.getcell (10, Row). getcontents ()); Dqkpiline.setattribute7 (Sheet.getcell (11, Row). getcontents ()); Dqkpiline.setattribute8 (Sheet.getcell (12, Row). getcontents ()); Dqkpiline.setattribute9 (Sheet.getcell (13, Row). getcontents ()); Dqkpiline.setattribute10 (Sheet.getcell (14, Row). getcontents ()); Dqkpiline.setenabledflag (Sheet.getcell (15, Row). getcontents ()); Dqkpiline.setcreatedby ("Import"); Dqkpiline.setcreateddate (NewDate ()); Dqkpiline.setlastupdatedby ("Import"); Dqkpiline.setlastupdateddate (NewDate ()); Dqkpilinelist.add (Dqkpiline); Success++; } Catch(Exception e) {log.error (e); E.printstacktrace (); Fail++; Continue; }} sb.append ("Table: Sch_dq_kpi_line success:" + Success + "bar, failed:" + fail + "Bar </br>"); Success= fail = 0; Coredao.saveorupdate (dqkpilinelist); Rb.setmessage (Sb.tostring ()); } Catch(Exception e) {log.error (e); E.printstacktrace (); Rb.setsuccess (false); Rb.setmessage (E.getmessage ()); } returnRB; }
This is JXL parsing Excel (multiple child tables) of the code, right when the record, afraid to forget.
JXL parsing multiple Excel worksheets-java code