2 回答
TA贡献1844条经验 获得超8个赞
int row = 1;
int previousRow=1; // I am assuming that first row index is 1
while(true)
{
String previousDomain = "";
String previousDashboard ="";
if(row != 1){ // check its not the first row else it will throw an exception because row doesn't exist
previousRow = row - 1;
previousDomain = sheet.getRow(previousRow ).getCell(0).getStringCellValue();
previousDashboard = sheet.getRow(previousRow ).getCell(1).getStringCellValue();
}
String domain = sheet.getRow(row).getCell(0).getStringCellValue();
String dashboard = sheet.getRow(row).getCell(1).getStringCellValue();
// String report =
sheet.getRow(row).getCell(2).getStringCellValue();
if(!domain.equals(null))
{
listOfDashboards.add(domain + ";" + dashboard);
row++;
// System.out.println("" + domain + "" + dashboard +"" +
report);
}
else
{
break;
}
}
TA贡献1776条经验 获得超12个赞
假设“域”和“仪表板”是表头(th)。
这是您可以使用的 xpath
简单:硬编码的 td 索引(如果在仪表板单元之前添加了新单元,则会中断)
"//td[normalize-space(.)='" + dashboard + "']/ancestor::tr/preceding-sibling::tr//td[2]//a"
基于列名称的返回值:无论仪表板单元格的位置如何(首选)都有效
"//td[normalize-space(.)='" + dashboard + "']/ancestor::tr/preceding-sibling::tr//td[position()=count(//th[normalize-space(.)='Dashboard']/preceding-sibling::th)+1]//a"
添加回答
举报