packagetest;importjava.io.FileInputStream;importjava.io.IOException;importjava.io.InputStream;importjava.util.ArrayList;importjava.util.List;importorg.apache.poi.xssf.usermodel.XSSFCell;importorg.apache.poi.xssf.usermodel.XSSFRow;importorg.apache.poi.xssf.usermodel.XSSFSheet;importorg.apache.poi.xssf.usermodel.XSSFWorkbook;public classT {public static void main(String[] args) throwsIOException {new T().readXlsx("D:\\data\\parse_result.xlsx", 1);
}/***
*@parampath xlsx文件路径
*@paramnumSheet 读取第几张表(从 0 开始)
*@return*@throwsIOException*/
public List readXlsx(String path, int numSheet) throwsIOException {
InputStream is= newFileInputStream(path);
XSSFWorkbook xssfWorkbook= newXSSFWorkbook(is);
DeviceInfo deviceInfo= null;
List list = new ArrayList();//读取第几张表
XSSFSheet xssfSheet =xssfWorkbook.getSheetAt(numSheet);//读取行
for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
XSSFRow xssfRow=xssfSheet.getRow(rowNum);if (xssfRow != null) {
deviceInfo= newDeviceInfo();
XSSFCell SN= xssfRow.getCell(0);
XSSFCell cpu= xssfRow.getCell(1);
XSSFCell ram= xssfRow.getCell(2);
XSSFCell times= xssfRow.getCell(3);
XSSFCell WAN= xssfRow.getCell(4);
XSSFCell value= xssfRow.getCell(5);
XSSFCell PPPOEStatus= xssfRow.getCell(3);try{
deviceInfo.setSN(SN.toString());
deviceInfo.setCpu(cpu.toString());
deviceInfo.setRam(ram.toString());
deviceInfo.setTimes(times.toString());
deviceInfo.setWAN(WAN.toString());
deviceInfo.setValue(value.toString());
deviceInfo.setPPPOEStatus(PPPOEStatus.toString());
}catch(NullPointerException e) {
}
list.add(deviceInfo);
}
}for(DeviceInfo d: list) {
System.out.println(d.getSN());
}returnlist;
}privateString getValue(XSSFCell sN) {return null;
}
}