The key code is as follows:
public void Importpostgroupquality () throws Exception {//inputstream fis=new fileinputstream ("e:\\ employee annual assessment. xls"); InputStream Fis=this.path (); Parse out the data of Excel to store the list of the entities//parse out every data in Excel encapsulated entity try {//create Excel workbook Hssfworkbook HWB = new Hssfworkbook (FIS); Get the first worksheet hssfsheet sheet = hwb.getsheetat (0); Hssfrow row = null; System.out.println ("Altogether:" +HWB.GETNU); Iterating through all the worksheets in the table, I represents the number of worksheets Getnumberofsheets represents the total number of worksheets for (int i = 0; i < hwb.getnumberofsheets (); i++) { Sheet = Hwb.getsheetat (i); System.out.println ("Altogether how many lines:" +sheet.getphysicalnumberofrows ()); Traverse all rows of the row, J represents the total number of rows getphysicalnumberofrows for (int j = 1; J < Sheet.getphysicalnumberofrows (); {row = Sheet.getrow (j); System.out.println ("A total column:" +row.getphysicalnumberofcells ()); int Total=row.getphysicalnumberofcells (); for (int a=0;a<total;a++) {if (Getcellvalue (Row.getcell (a))! = "") {System.out.print ( Getcellvalue (Row.getcell (a)) + ":"); }}}}} catch (Exception e) { Fis.close (); E.printstacktrace (); }}//To determine the format of the data parsed from the Excel file public String getcellvalue (Hssfcell cell) {string value = null; Simple search column type switch (Cell.getcelltype ()) {case hssfcell.cell_type_string://string Value = Cell.getrichstringcellvalue (). getString (); Break Case hssfcell.cell_type_numeric://digit long DD = (long) cell.getnumericcellvalue (); Value = dd+ ""; Break Case Hssfcell.cell_type_blank: Value = ""; Break Case HSSFCell.CELL_TYPE_FORMULA:value = string.valueof (Cell.getcellformula ()); Break Case Hssfcell.cell_type_boolean://boolean value = string.valueof (Cell.getbooleancellvalue ()); Break Case HSSFCell.CELL_TYPE_ERROR:value = string.valueof (Cell.geterrorcellvalue ()); Break Default:break; } return value; }
Among them InputStream Fis=this.path (); Get the file stream, modify according to the actual situation, get the input stream code of the local file is: InputStream fis=new fileinputstream ("e:\\ employee annual assessment. xls");
To read a excle file using the POI component