Java implements simple read operation for Excel forms
To implement simple read operations for Excel forms, first import the relevant jar packages:
:
Put the code here:
public static list<list<string>> Readexcel (String path) {list<list<string>> list=new Arraylist<list<string>> (); try {Workbook wb;inputstream is=null;try{is=new fileinputstream (path);// Read version 2007 Excelwb=new Xssfworkbook (IS);} catch (Exception e) {//prevents an exception from causing the input stream to close is=new fileinputstream (path);//Read Version 2003 Excelwb=new Hssfworkbook (is);} for (int i = 0; i < wb.getnumberofsheets (); i++) {//Read Sheetsheet sheet=wb.getsheetat (i); if (sheet==null) {continue;} Processes the current page, looping through each line for (int j = 0; J < Sheet.getphysicalnumberofrows (), j + +) {//Get the current row row Row=sheet.getrow (j);//current row first cell int Mincells=row.getfirstcellnum ();//The last cell of the current row int maxcells=row.getlastcellnum (); List<string> sl=new arraylist<string> (); for (int k = mincells; k < maxcells; k++) {//cells per cell cell=row.ge Tcell (k); if (cell==null) {continue;} Sl.add (Cell.tostring ());} List.add (SL);}} if (is!=null) {is.close ();}} catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();} return List;}
Java implements simple read operations for Excel