Java programming poi reads the contents of an Excel table

Source: Internet
Author: User
Tags dateformat

The 07 version of Excel requires a separate jar package. Xbean.jar's jar Package

Read the code template. Using templates to read some of the POI's APIs in Excel this is the point

1 /**2 * Read Excel file3 * @Title: Readexcel4 * @Description: TODO (here is a word describing the effect of this method)5     * @authorShang6 * @date 2014-11-10 a.m. 8:58:017     * @paramReadpath Read the absolute path to an Excel on your computer's hard drive for example: c://20141110 PetroChina. xlsx8     * @seeCom.bjsxt.sxf.service.readexcelservice#readexcel (java.lang.String)]9 * Cell_type_numeric Numeric 0Ten cell_type_string String Type 1 One Cell_type_formula equation Type 2 A Cell_type_blank Null value 3 - Cell_type_boolean Boolean Type 4 - cell_type_error Error 5 the      */ - @Override -      Public voidReadexcel (String readpath) { -         Try { +             //input stream for generating files -InputStream inexcel=NewFileInputStream (readpath); +             //build the memory model of the input Excel file AWorkbook wb=workbookfactory.create (inexcel); at             //object that gets the specific table name -Sheet Sheet=wb.getsheet ("Shang"); -             //Sheet sheet2=wb.getsheetat (0); Gets the Table object that specifies the subscript. Row and column subscripts start at 0 -              -              -             //define a value that records one row of data inDate date=NULL;//Time -             Doublejiage=0;//Price toInteger xianliang=0;//Current Volume +String bors=NULL;//type -              the             //to get an iterator for a row object that has values in an Excel table *Iterator<row> iterator=sheet.iterator (); $              while(Iterator.hasnext ()) {Panax NotoginsengRow row=Iterator.next (); -                 //gets an iterator to the column object of a row in an Excel table that has a value theIterator<cell> citerator=row.celliterator (); +                  while(Citerator.hasnext ()) { ACell cell=Citerator.next (); the                     if(Cell.getcelltype () = =cell. Cell_type_blank) { +                         //pause this loop to continue the next loop if the cell is a null value -                         Continue; $                     } $                     //Gets the column index of the current cell. Starting from 0 -Integer columnindex=Cell.getcolumnindex (); -                     //gets the row index of the current cell. Starting from 0 theInteger rowindex=Cell.getrowindex (); -                     Wuyi                     if(Cell.getcelltype () ==cell. Cell_type_numeric) {//determining the value of a cell is a number format the                          -                         if(hssfdateutil.iscelldateformatted (cell)) {//determine if a cell is a date format WuSimpleDateFormat DateFormat =NewSimpleDateFormat ("hh-mm"); -                             //Time AboutDate = Hssfdateutil.getjavadate (Cell.getnumericcellvalue ());//get into Date type $String fdate =Dateformat.format (date); -System.out.println ("rowindex-->" +rowindex+ "columnindex-->" +columnindex+ "value-->" +fdate); -                             -}Else{ A                              +                             if(Cell.getcolumnindex () ==1){ the                                 //Price -Jiage=Cell.getnumericcellvalue (); $System.out.println ("rowindex-->" +rowindex+ "columnindex-->" +columnindex+ "value-->" +jiage); the}Else if(Cell.getcolumnindex () ==2){ the                                 //Current Volume theXianliang= (int) Cell.getnumericcellvalue (); theSystem.out.println ("rowindex-->" +rowindex+ "columnindex-->" +columnindex+ "value-->" +Xianliang); -                             } in                         } the                          the                     } About                      the                     if(Cell.getcelltype () ==cell. cell_type_string) {//the value of the cell is a string the                             //type thebors=Cell.getstringcellvalue (); +System.out.println ("rowindex-->" +rowindex+ "columnindex-->" +columnindex+ "value-->" +bors); -                         } the                     }    Bayi             }     the}Catch(Exception e) { the             //TODO auto-generated Catch block - e.printstacktrace (); -         } the          the}
View Code

Java programming poi reads the contents of an Excel table

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.