Packagetest;ImportJava.io.FileInputStream;Importjava.io.IOException;ImportJava.io.InputStream;Importjava.util.ArrayList;Importjava.util.List;ImportOrg.apache.poi.xssf.usermodel.XSSFCell;ImportOrg.apache.poi.xssf.usermodel.XSSFRow;ImportOrg.apache.poi.xssf.usermodel.XSSFSheet;ImportOrg.apache.poi.xssf.usermodel.XSSFWorkbook; Public classT { Public Static voidMain (string[] args)throwsIOException {NewT (). READXLSX ("D:\\data\\parse_result.xlsx", 1); } /** * * @parampath xlsx file paths *@paramNumsheet Read the first few tables (starting from 0) *@return * @throwsIOException*/ PublicList<deviceinfo> readxlsx (String path,intNumsheet)throwsIOException {InputStream is=NewFileInputStream (path); Xssfworkbook Xssfworkbook=NewXssfworkbook (IS); DeviceInfo DeviceInfo=NULL; List<DeviceInfo> list =NewArraylist<deviceinfo>(); //read the first few tablesXssfsheet Xssfsheet =Xssfworkbook.getsheetat (Numsheet); //Read Rows for(intRowNum = 1; RowNum <= xssfsheet.getlastrownum (); rownum++) {Xssfrow Xssfrow=Xssfsheet.getrow (RowNum); if(Xssfrow! =NULL) {deviceinfo=Newdeviceinfo (); Xssfcell SN= Xssfrow.getcell (0); Xssfcell CPU= Xssfrow.getcell (1); Xssfcell Ram= Xssfrow.getcell (2); Xssfcell Times= Xssfrow.getcell (3); Xssfcell WAN= Xssfrow.getcell (4); Xssfcell value= Xssfrow.getcell (5); Xssfcell Pppoestatus= Xssfrow.getcell (3); Try{DEVICEINFO.SETSN (sn.tostring ()); DEVICEINFO.SETCPU (Cpu.tostring ()); Deviceinfo.setram (Ram.tostring ()); Deviceinfo.settimes (Times.tostring ()); Deviceinfo.setwan (Wan.tostring ()); Deviceinfo.setvalue (Value.tostring ()); Deviceinfo.setpppoestatus (Pppoestatus.tostring ()); } Catch(NullPointerException e) {} list.add (deviceinfo); } } for(DeviceInfo d:list) {System.out.println (D.GETSN ()); } returnlist; } PrivateString getValue (Xssfcell sN) {return NULL; }}
Java Read xlsx