Poi 3.7 reads XLS and XLSX

Source: Internet
Author: User
/*** Read the XLSX document column **/private string getxssfcellvalue (xssfcell cell) throws exception {string cellvalue = ""; if (cell! = NULL) {Switch (cell. getcelltype () {Case xssfcell. cell_type_boolean: cellvalue = string. valueof (cell. getbooleancellvalue (); break; Case xssfcell. cell_type_numeric: cellvalue = string. valueof (cell. getnumericcellvalue (); break; Case xssfcell. cell_type_string: cellvalue = cell. getstringcellvalue (); break; Case xssfcell. cell_type_blank: break; Case xssfcell. cell_type_error: break; Case xssfcell. CE Ll_type_formula: break;} return cellvalue;}/*** read the XLS document column **/private string gethssfcellvalue (hssfcell) throws exception {string cellvalue = ""; if (cell! = NULL) {Switch (cell. getcelltype () {Case hssfcell. cell_type_boolean: cellvalue = string. valueof (cell. getbooleancellvalue (); break; Case hssfcell. cell_type_numeric: cellvalue = string. valueof (cell. getnumericcellvalue (); break; Case hssfcell. cell_type_string: cellvalue = cell. getstringcellvalue (); break; Case hssfcell. cell_type_blank: break; Case hssfcell. cell_type_error: break; Case hssfcell. cel Rochelle type_formula: break;} return cellvalue ;} /*** XLSX document * @ Return Error Message Type 0-normal 1-there cannot be blank columns 2-Incorrect Format 3-empty file **/private int readxlsx (list <xxdto> list, inputstream) throws exception {int errtype = 0; xssfworkbook hssfworkbook = new xssfworkbook (inputstream); xssfsheet hssfsheet = hssfworkbook. getsheetat (0); // The first worksheet if (hssfsheet! = NULL) {int totalrows = hssfsheet. getphysicalnumberofrows (); // -- obtain the total number of sheet rows if (totalrows> 1) // except the title, data must exist {for (INT I = 1; I <totalrows; I ++) {xssfrow hssfrow = hssfsheet. getrow (I) ;}} else {// -- empty excel, or excelerrtype = 3;} return errtype ;} /*** XLS document * @ Return Error Message Type 0-normal 1-there cannot be blank columns 2-format incorrect 3-empty file **/private int readxlskpiyear (list <xxdto> list, inputstream) throws exception {int err Type = 0; hssfworkbook = new hssfworkbook (inputstream); hssfsheet = hssfworkbook. getsheetat (0); // The first worksheet if (hssfsheet! = NULL) {int totalrows = hssfsheet. getphysicalnumberofrows (); // -- obtain the total number of sheet rows if (totalrows> 1) // except the title, data must exist {for (INT I = 1; I <totalrows; I ++) {hssfrow = hssfsheet. getrow (I) ;}} else {// -- empty excel, or excelerrtype = 3;} return errtype ;}

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.