Jar Package
Excel data
Java code
PackageExceltojson;ImportJXL. Cell;ImportJXL. Sheet;ImportJXL. Workbook;ImportNet.sf.json.JSONArray;ImportNet.sf.json.JSONObject;ImportJava.io.File; Public classExcel { Public Static voidMain (string[] args) {Sheet Sheet; Workbook Book; Cell cell1, Cell2, Cell3, Cell4, Cell5,cell6,cell7,cell8; Jsonarray Array=NewJsonarray (); Try { //is the Excel file name to readBook = Workbook.getworkbook (NewFile ("F://a.xls")); //get the first sheet object (sheet's number in Ecxel starts with 0, 0,1,2,3,....)Sheet = book.getsheet (0); for(inti = 1; I < sheet.getrows (); i++) { //get the cells for each rowCell1 = Sheet.getcell (0, I);//(column, row)Cell2 = Sheet.getcell (1, i); Cell3= Sheet.getcell (2, i); CELL4= Sheet.getcell (3, i); CELL5= Sheet.getcell (4, i); CELL5= Sheet.getcell (5, i); CELL5= Sheet.getcell (6, i); CELL5= Sheet.getcell (7, i); if("". Equals (Cell1.getcontents ())) {//if the data being read is empty Break; } Jsonobject Object=NewJsonobject (); Object.put ("The problem is dry", Cell1.getcontents ()); Object.put (Type, Cell2.getcontents ()); Object.put ("A option", Cell3.getcontents ()); Object.put ("B Option", Cell4.getcontents ()); Object.put ("C Option", Cell5.getcontents ()); Object.put ("D option", Cell5.getcontents ()); Object.put (Answer, Cell5.getcontents ()); Object.put (Resolution, Cell5.getcontents ()); Array.add (object); } System.out.println (Array.tostring ()); Book.close (); } Catch(Exception e) {e.printstacktrace (); } }}
[{"Dry": "1 Questions dry", "Type:" select "," A Option ":" Low voltage distribution cabinet "," b option ":" Production "," C Option ":" Low voltage distribution Cabinet "," D option ":" Low voltage distribution Cabinet "," Answer ":" Low voltage distribution Cabinet "," Resolution ":" Low voltage distribution Cabinet "},{ "Dry": "2 questions dry", "Type:" select "," A Option ":" Low voltage distribution cabinet "," b option ":" Production "," C Option ":" Low voltage distribution Cabinet "," D option ":" Low voltage distribution Cabinet "," Answer ":" Low voltage distribution Cabinet "," Resolution ":" Low voltage distribution Cabinet "},{" Dry ":" 3 questions dry "," Type: "select", "A Option": "Low voltage distribution cabinet", "b option": "Outsourcing", "C Option": "Low voltage distribution Cabinet", "D option": "Low voltage distribution Cabinet", "Answer": "Low voltage distribution Cabinet", "Resolution": "Low voltage Distribution Cabinet"}]
Java reads Excel into JSON string and then translates to Java object