I. Latest poi Toolkit
Http://www.apache.org/dyn/closer.cgi/jakarta/poi/
See the documentation
Poi home: http://jakarta.apache.org/poi,
Excel Structure
Hssfworkbook Excell object Introduction
Hssfsheet Excell form
Hssfrow Excell row
Lattice unit of hssfcell Excell
Hssffont Excell font
Hssfname
Hssfdataformat Date Format
Poi1.7 contains the following two items:
Hssfheader sheet Header
End of hssffooter Sheet
And this style
Hssfcellstyle cell style
Auxiliary operations include
Hssfdateutil date
Hssfprintsetup print
Hssferrorconstants error information table
Hssfworkbook: indicates the operation of excel20031. the extension name is .xls.
Xssfworkbook: it is the worker that operates the excel2007, and the extension name is .xlsx /**
Example
/*** Read Excel (compatible with 2003, 2007) ** @ Param filepath */Public hashmap <integer, object []> loadxlsx (string filepath) {// construct the xssfworkbook object, and pass the strpath to the file path workbook = NULL; try {file = new file ("D:/poitest .xlsx"); workbook = workbookfactory. create (File);} catch (exception e) {system. out. println ("file reading error"); E. printstacktrace ();} // read the table content in Chapter 1 Sheet sheet = workbook. getsheetat (0); // xwb. getsheetat (1 );// Define row and cellrow row; cell; stringbuffer sb = NULL; // int totalrow = sheet. getlastrownum (); // total number of rows, including the middle empty row int totalrow = sheet. getphysicalnumberofrows (); // total number of rows, excluding the intermediate empty line int totalcell = 0; // The number of data columns hashmap <integer, object []> map = new hashmap <integer, object []> (); // the content in the loop output table for (INT I = sheet. getfirstrownum (); I <totalrow; I ++) {ROW = sheet. getrow (I); If (row! = NULL) {totalcell = row. getphysicalnumberofcells (); object [] dataary = new object [totalcell]; for (Int J = row. getfirstcellnum (); j <totalcell; j ++) {sb = new stringbuffer (); cell = row. getcell (j); Switch (cell. getcelltype () {Case xssfcell. cell_type_numeric: // number sb. append (cell. getnumericcellvalue (); break; Case xssfcell. cell_type_string: // string sb. append (cell. getstringcellvalue (); break; Case xssfcell. cell_type_formula: // formula sb. append (cell. getcellformula (); break; Case xssfcell. cell_type_blank: // formula sb. append (""); break; default: break;} dataary [J] = cell. tostring (); // No matter what type, convert all to string processing // system. out. print (cell + "\ t");} map. put (I, dataary);} // system. out. println ("");} return map ;}