通过apache poi以excel方式获取索引值

问题描述 投票:0回答:1

我正在尝试开发桌面应用程序并使用excel作为数据库。为使用桌面应用程序但无法执行此操作的特定用户编写登录和注销代码。

我想要实现的是,我在excel表中有两列像

Username | Password A | a B | b C | c

A是用户名,'a'是密码,所以我到目前为止所做的是我已经将A的值与用户输入的值和匹配的位置进行了比较我获取了行和列索引。

这样我就可以获取驻留在它旁边的密码。对于ex A有行和列索引0,0所以密码将在索引0,1

我不知道如何通过索引获取值。我的代码:

if(m1.equals(cell.getStringCellValue())){
 index=cell.getRowIndex();
 indexc=cell.getColumnIndex();
 System.out.println(index+" "+indexc);
 String s3=cell.getStringCellValue();
 if(m2.equals(?????????????)){
  // index2=cell.getRowIndex();
 counter=1;   
   }
excel apache-poi
1个回答
0
投票

您可以使用此方法。

public boolean checkCredentials(String userName, String password, Sheet credentialsSheet) {
        //Assuming username is in column1 and password is in column2 
        int usernameColumnNo = 0;
        int passwordColumnNo =1;
        Boolean isCredentialCorrect = false;
        for(Row row:credentialsSheet) {
            if(row.getCell(usernameColumnNo).getStringCellValue().equals(userName)){
isCredentialCorrect = row.getCell(passwordColumnNo).getStringCellValue().equals(password);
                break;
            }
        }
        return isCredentialCorrect;
    }
© www.soinside.com 2019 - 2024. All rights reserved.