Java implements simple read operations for Excel

Source: Internet
Author: User

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

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.