阅读多个excel工作表selenium webdriver、java、eclipse

阅读多个excel工作表selenium webdriver、java、eclipse,java,excel,eclipse,Java,Excel,Eclipse,我想运行selenium webdriver java eclipse,使用excel文件包含多个不同名称的excel工作表(sheet1、sheet2、sheet3,…),我需要一个for循环来帮助我这样做并从这些工作表中读取。 公共类ExcelDataConfig{ XSSFWorkbook wb; XSSFSheet sheet = null; public ExcelDataConfig(String Excelpath) throws IOException { // TOD

我想运行selenium webdriver java eclipse,使用excel文件包含多个不同名称的excel工作表(sheet1、sheet2、sheet3,…),我需要一个for循环来帮助我这样做并从这些工作表中读取。 公共类ExcelDataConfig{

XSSFWorkbook wb;
XSSFSheet sheet = null;

public ExcelDataConfig(String Excelpath) throws IOException {
    // TODO Auto-generated method stub

    try {
        File file = new File(Excelpath);

        // Create an object of FileInputStream class to read excel file

        FileInputStream fis = new FileInputStream(file);
        wb = new XSSFWorkbook(fis);

    } catch (Exception e) {

    }
}

public String GetData(int sheetNumber, int Row, int Column) {

    Iterator<Row> rowIt=sheet.rowIterator();

    DataFormatter formatter = new DataFormatter();
    XSSFCell cell = sheet.getRow(Row).getCell(Column);

    String data = formatter.formatCellValue(cell);
    return data;
}

public int GetRowCount(String sheetNumber) {

    int row = wb.getSheet(sheetNumber).getLastRowNum();

    row = row + 1;

    return row;

}
xssfwb;
XSSFSheet=null;
公共ExcelDataConfig(字符串Excelpath)引发IOException{
//TODO自动生成的方法存根
试一试{
文件文件=新文件(Excelpath);
//创建FileInputStream类的对象以读取excel文件
FileInputStream fis=新的FileInputStream(文件);
wb=新XSSF工作簿(fis);
}捕获(例外e){
}
}
公共字符串GetData(int sheetNumber、int行、int列){
迭代器rowIt=sheet.rowIterator();
DataFormatter formatter=新的DataFormatter();
XSSFCell cell=sheet.getRow(行).getCell(列);
字符串数据=formatter.formatCellValue(单元格);
返回数据;
}
public int GetRowCount(字符串编号){
int row=wb.getSheet(sheetNumber.getLastRowNum();
行=行+1;
返回行;
}

}

请尝试写类似以下内容:

for (int i = startRow; i < endRow + 1; i++) {
                for (int j = startCol; j < endCol + 1; j++) {
                    testData[i - startRow][j - startCol] = ExcelWSheet.getRow(i).getCell(j).getStringCellValue();
                    Cell cell = ExcelWSheet.getRow(i).getCell(j);
                    testData[i - startRow][j - startCol] = formatter.formatCellValue(cell);
                }
            }
for(int i=startRow;i

该方法中使用的术语是非常不言自明的。如果您遇到问题或需要更多信息,请告诉我们。

尝试类似的方法,这对我很有效。您需要在k和j处添加工作表编号和单元格编号

enter code here

    String filePath="C:\\Users\\USER\\Desktop\\Book1.xlsx";// file path
    FileInputStream fis=new FileInputStream(filePath);
    Workbook wb=WorkbookFactory.create(fis);
    ArrayList<String> ls=new ArrayList<String>();
    for(int k=0; k<=3;k++)//k =sheet no
    {
        Sheet sh=wb.getSheetAt(k);
        System.out.println(sh);
//      int count=0;
        for(int i=0;i<=sh.getLastRowNum();i++)
        {
            System.out.println("row no:"+i);
            for(int j=0; j<=4;j++)//j=column no
            {
                try {
                 String values=sh.getRow(i).getCell(j).getStringCellValue().trim();
                 System.out.println(values);

}

您能告诉我们您的代码以及您的卡在哪里吗?
                /* if(values.contains("condtn1"))
                    {
                        System.out.println("Value of cell "+values+" ith row "+(i+1));
                        ls.add(values);
                        count++;
                    }   
                 if(values.contains("condn2"))
                    {
                        System.out.println("Value of cell "+values+" ith row "+(i+1));
                        ls.add(values);
                        count++;
                    }*/ 
                 }catch(Exception e){

                 }

            }

        }

    }
}