我是Java的新手,我在验证excel文件方面遇到了挑战。请帮助我。
我想验证'Hyderabad'是位置名称,'1'是来自excel的位置ID(请参见下面的截图)通过JAVA。能够读取所有单元格值。但我想验证是否位置名称是海得拉巴还是没有(同样,地点ID)。请在这里建议我。
http
答案 0 :(得分:1)
if(fileType.equalsIgnoreCase(" Excel")){ 工作手册wb =新的XSSFWorkbook(f);
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
System.out.println("Sheet name: " + wb.getSheetName(i));
Sheet sh=wb.getSheetAt(i);
if (wb.getSheetName(i).matches("A|B|C|D"))
{
int rowCount = sh.getLastRowNum() - sh.getFirstRowNum();
for (int j = 0; j < rowCount + 1; j++) {
Row row = sh.getRow(j);
if(row.getCell(0).getStringCellValue().contains("Location Name")){
{
if(row.getCell(1).getStringCellValue().equalsIgnoreCase("Hydrabad")){
System.out.print("Location name is matches with Hydrabad");
}
else{
System.out.print("Location name isn't matches with Hydrabad");
}
}
if(row.getCell(0).getStringCellValue().contains("Location ID")){
{
if(row.getCell(1).getStringCellValue().equalsIgnoreCase("1")){
System.out.print("Location id matches");
}
else{
System.out.print("Location id mismatches");
}
}
}
}