/** Index mappingname originalname datatype family 0 task_id t Askindexcode STRING Info 1 task_type resourcedesctype INT32 Info 2 Camera_index_code cameraindexcode STRING info 3 camera_address Resourcelo Cation STRING Info * @param path * @return * @throws IOException*/ Public StaticList<string>readhbasexlsx (String path) throws IOException {InputStream is=NewFileInputStream (path); Xssfworkbook Xssfworkbook=NewXssfworkbook ( is); List<String> jsonlist =NewArraylist<>(); intSheetnum =xssfworkbook.getnumberofsheets (); //Read the Sheet for(intNumsheet =0; Numsheet < Sheetnum; numsheet++) {Xssfsheet Xssfsheet=Xssfworkbook.getsheetat (Numsheet); if(Xssfsheet = =NULL) { Continue; } //Read the Row for(intRowNum =1; RowNum <= xssfsheet.getlastrownum (); rownum++) {Xssfrow Xssfrow=Xssfsheet.getrow (RowNum); if(Xssfrow! =NULL) {Xssfcell Indexcell= Xssfrow.getcell (0); if(Indexcell = =NULL)Continue; Xssfcell Mappingnamecell= Xssfrow.getcell (1); Xssfcell Originalnamecell= Xssfrow.getcell (2); Xssfcell Datatypecell= Xssfrow.getcell (3); Xssfcell Familycell= Xssfrow.getcell (4); String Index=Indexcell.getstringcellvalue (); String Originalname; Try{originalname=Originalnamecell.getstringcellvalue (); }Catch(NullPointerException e) {originalname=""; } if(NULL==originalname) {Originalname=""; } String MappingName=Mappingnamecell.getstringcellvalue (); String datatype=Datatypecell.getstringcellvalue (); String Family=Familycell.getstringcellvalue (); String JSON=index+","+originalname+","+mappingname+","+datatype+","+family; Jsonlist.add (JSON); }} xssfworkbook.clonesheet (Numsheet); } is. Close (); returnjsonlist; } /** Index mappingname originalname datatype family 0 task_id t Askindexcode STRING Info 1 task_type resourcedesctype INT32 Info 2 Camera_index_code cameraindexcode STRING info 3 camera_address Resourcelo Cation STRING Info * @param path * @return * @throws IOException*/ Public StaticList<string>readesxlsx (String path) throws IOException {InputStream is=NewFileInputStream (path); Xssfworkbook Xssfworkbook=NewXssfworkbook ( is); List<String> jsonlist =NewArraylist<>(); intSheetnum =xssfworkbook.getnumberofsheets (); //Read the Sheet for(intNumsheet =0; Numsheet < Sheetnum; numsheet++) {Xssfsheet Xssfsheet=Xssfworkbook.getsheetat (Numsheet); if(Xssfsheet = =NULL) { Continue; } //Read the Row for(intRowNum =1; RowNum <= xssfsheet.getlastrownum (); rownum++) {Xssfrow Xssfrow=Xssfsheet.getrow (RowNum); if(Xssfrow! =NULL) {Xssfcell Indexcell= Xssfrow.getcell (0); if(Indexcell = =NULL)Continue; Xssfcell Mappingnamecell= Xssfrow.getcell (1); Xssfcell Originalnamecell= Xssfrow.getcell (2); Xssfcell Datatypecell= Xssfrow.getcell (3); String Index=Indexcell.getstringcellvalue (); String Originalname; Try{originalname=Originalnamecell.getstringcellvalue (); }Catch(NullPointerException e) {originalname=""; } if(NULL==originalname) {Originalname=""; } String MappingName=Mappingnamecell.getstringcellvalue (); String datatype=Datatypecell.getstringcellvalue (); String JSON=index+","+originalname+","+mappingname+","+datatype; Jsonlist.add (JSON); }} xssfworkbook.clonesheet (Numsheet); } is. Close (); returnjsonlist; } /** * @param xssfrow Excel cell * @return cell data * @Method Description 2010excel cells data, cell data is divided into: Boolean, numeri C, String*/ Private StaticObject getValue (Xssfcell xssfrow) {if(Xssfrow.getcelltype () = =Xssfrow.cell_type_boolean) { returnXssfrow.getbooleancellvalue (); } Else if(Xssfrow.getcelltype () = =xssfrow.cell_type_numeric) { returnXssfrow.getnumericcellvalue (); } Else { returnXssfrow.getstringcellvalue (); } }
Write the string to the file
Public Staticboolean writestringtofile (String filepath,string str) {Boolean success=true; if(!NewFile (FilePath). Exists ()) { Try { NewFile (FilePath). CreateNewFile (); } Catch(IOException e) {e.printstacktrace (); } }Else{ NewFile (filePath). Delete (); Try { NewFile (FilePath). CreateNewFile (); } Catch(IOException e) {e.printstacktrace (); }} FileWriter FileWriter=NULL; Try{FileWriter=NewFileWriter (FilePath); } Catch(IOException e) {e.printstacktrace (); } if(NULL!=fileWriter) { Try{filewriter.write (str); } Catch(IOException e) {e.printstacktrace (); }finally { Try{filewriter.close (); } Catch(IOException e) {e.printstacktrace (); } } } returnsuccess; }
23 Reading Excel