First, the POI read Excel file (in Excel2003 version, for example, version 2007 is based on the file extension xlsx will hssfworkbook to Xssfworkbook, and its sheet, Row, cell and corresponding replacement)
FilePath full path to Excel file
1.//Create a File object
File File = new file (FilePath);
2,//To determine whether the file exists, there is no direct exit function
if (!file.exists ()) {return null}
3.//Read the file into the file stream
InputStream InputStream = new FileInputStream (file);
4.//Create a Hssfworkbook object and save the file stream in the object
Hssfworkbook Hssfworkbook = new Hssfworkbook (InputStream);
5,//Get Excel File Sheet page, you can get the number of all sheet pages in the file by Hssfworkbook.getnumberofsheets ()
Take only the first one below
Hssfsheet sheet = hssfworkbook.getsheetat (0);
6,///Get the data row in sheet page, can get the last line number of data row in the file by Sheet.getlastrownum ()
Take only the first line below
Hssfrow row = sheet.getrow (0);
7.//Get each row of data cells
The following gets the first cell
Hssfcell cell0 = Row.getcell (0);
8,//based on the cell data type to obtain the corresponding data type value
Take the numeric type as an example cell.getcelltype () = = Cell. Cell_type_numeric
String value=string.valueof (Cell.getnumericcellvalue ());
9.//Release Resources
Inputstream.close ();
Hssfworkbook. Close ();
10, it is best to use try Catch
Read a summary of the POI read and write Excel