Package Cn.action.serviceImpl;
Import Java.io.FileInputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import 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;
public class Inputexcelservice {
public static void Inputexcel () throws ioexception{
String Path = "F:/student.xlsx";
try {
InputStream is = new FileInputStream (path); Read files in the specified directory
Xssfworkbook Hssfworkbook = new Xssfworkbook (IS); Create a workbook
for (int numsheet = 0; Numsheet < hssfworkbook.getnumberofsheets (); numsheet++) {//Loop fetch sheet
Xssfsheet Shset = Hssfworkbook.getsheetat (Numsheet);
if (Shset = = null) {
Continue
}
for (int rowNum = 0; RowNum <= shset.getlastrownum (); rownum++) {//loop all lines inside a workbook
Xssfrow Hssfrow = Shset.getrow (RowNum);
if (Hssfrow = = null) {
Continue
}
int Hssfcell = Hssfrow.getphysicalnumberofcells (); Take all the columns in a row
for (int cellnum = 0; cellnum < Hssfcell; cellnum++) {//Loop fetch column
Xssfcell HSC = Hssfrow.getcell (cellnum);
if (HSC = = null) {
Continue
}
System.out.print (GetValue (HSC) + ""); Take value
}
System.out.println ("\ n");
}
Hssfworkbook.close ();
Is.close ();
}
} catch (Exception e) {
E.printstacktrace ();
}
}
@SuppressWarnings ("Static-access")
private static String GetValue (Xssfcell Hssfcell) {
if (hssfcell.getcelltype () = = Hssfcell.cell_type_boolean) {
Returns the value of a Boolean type
Return string.valueof (Hssfcell.getbooleancellvalue ());
} else if (hssfcell.getcelltype () = = Hssfcell.cell_type_numeric) {
Hssfcell.setcelltype (hssfcell.cell_type_string);
Returns the value of a numeric type
return Hssfcell.getstringcellvalue ();
}
else {
Returns the value of a string type
Return string.valueof (Hssfcell.getstringcellvalue ()); }
}
public static void Outputexcel () {
}
}
Xssfworkbook Read xlsx