Java Read xlsx

Source: Internet
Author: User

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.