Poi read XLSX

Source: Internet
Author: User

As you know, when I use poi to read xls, sometimes I have to read XLSX. Now I will share my testing demo with you.


Package COM. lt. main; import Java. io. file; import Java. io. fileinputstream; import Java. io. inputstream; import Java. SQL. connection; import Java. SQL. preparedstatement; import Java. util. arraylist; import Java. util. list; import Org. apache. poi. hssf. usermodel. hssfcell; import Org. apache. poi. hssf. usermodel. hssfrow; import Org. apache. poi. hssf. usermodel. hssfsheet; import Org. apache. poi. hssf. usermodel. hssfworkbook; impor T Org. apache. poi. xssf. usermodel. xssfcell; import Org. apache. poi. xssf. usermodel. xssfrow; import Org. apache. poi. xssf. usermodel. xssfsheet; import Org. apache. poi. xssf. usermodel. xssfworkbook; import COM. lt. util. dbutil; import COM. lt. util. oracle; public class readmain {public static void readfile (File file) {connection con = NULL; preparedstatement PS = NULL; string SQL = "insert into t_xls (mobile) values (?) "; Int COUNT = 0; try {con = dbutil. getconnection (); PS = con. preparestatement (SQL); inputstream is = new fileinputstream (File); xssfworkbook WB = new xssfworkbook (is); xssfcell cell = NULL; For (INT sheetindex = 0; sheetindex <WB. getnumberofsheets (); sheetindex ++) {xssfsheet ST = WB. getsheetat (sheetindex); For (INT rowindex = 0; rowindex <= ST. getlastrownum (); rowindex ++) {xssfrow ROW = ST. getrow (rowindex); cell = row. getcell (0); cell. setcelltype (xssfcell. cell_type_string); count ++; PS. setstring (1, cell. getstringcellvalue (); PS. addbatch (); If (count % 10000 = 0) {ps.exe cutebatch () ;}} ps.exe cutebatch ();} catch (exception e) {e. printstacktrace ();} finally {dbutil. close (PS); dbutil. close (CON) ;}} public static void main (string [] ARGs) {dbutil. startproxool (); readfile (new file ("C: \ Documents and Settings \ Administrator \ Desktop \ 22.xlsx "));}}

It will involve writing content to the database

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.