如何基于Java中上一行的Group size值跳过行

时间:2019-03-29 06:51:39

标签: java selenium selenium-webdriver automated-tests

我无法跳过第二行(如果第1行的组大小为2)

S.No    title_rcd   passenger_type_rcd  YoungestGroupMember GroupSize   
1   MRS ADULT   ADULT   2   Same Group
2   MR  ADULT   ADULT   2   
3   MR  CHILD   CHILD   1   Unique
4   MR  ADULT   ADULT   1   Unique
5   MR  ADULT   ADULT   2   Same Group
6   MR  INF INF 2   

代码:

for(int r=2;r<=NumberofRows;r++){

    String  getGroupSize=xlsx.getCellData(SheetName, "GroupSize", r);
    float GroupSize=Float.parseFloat(getGroupSize);
    int ActualGroupSize=(int) GroupSize;
    System.out.println("Number of Pax in Row number "+r+" is "+ActualGroupSize);
    ActualGroupSize=nextrow;

预期

Number of Pax in Row number 1 is 2
Number of Pax in Row number 3 is 1
Number of Pax in Row number 4 is 1
Number of Pax in Row number 5 is 2

如何跳过第2行和第6行。目前,使用上述代码可以从所有行中获取值。

1 个答案:

答案 0 :(得分:0)

也许这可能有效:

        int lastgroupsize = 0;
    for(int r=2;r<=NumberofRows;r++){

        String  getGroupSize=xlsx.getCellData(SheetName, "GroupSize", r);
        float GroupSize=Float.parseFloat(getGroupSize);
        int ActualGroupSize=(int) GroupSize;
        if(lastgroupsize < 2 || (lastgroupsize >= 2 && ActualGroupSize < 2)) {
            System.out.println("Number of Pax in Row number "+r+" is "+ActualGroupSize);
        }
        lastgroupsize = ActualGroupSize;
        ActualGroupSize=nextrow;