[SoapUI] 在SoapUI里获取Excel中多行数据并存入List

时间:2022-10-20 07:06:25
ArrayList<ArrayList<String>> getCellValuesH( String filePath, String sheetName,int tr1,int tr2,int td1,int td2){
ArrayList<ArrayList<String>> cellValues = new ArrayList<ArrayList<String>>();
try{
File file = new File(filePath);
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(filePath));
XSSFSheet sheet = wb.getSheet(sheetName);
int trLength = sheet.getLastRowNum();
Row row = sheet.getRow(0);
int tdLength = row.getLastCellNum();
String cellValue;
if(sheet != null){
for(int i=tr1; i<=tr2; i++){
ArrayList<String> rowCellValue = new ArrayList<String>();
Row row1 = sheet.getRow(i);
for(int j=td1; j<=td2; j++){
cellValue = row1.getCell(j);
rowCellValue.add(cellValue.trim());
}
cellValues.add(rowCellValue);
}
}
return cellValues;
}
catch (Exception e){
e.printStackTrace();
return null;
}
}