如何使用JavaPOI从Excel中获取有关行和列值的特定单元格值

如何使用JavaPOI从Excel中获取有关行和列值的特定单元格值,java,excel,jakarta-ee,apache-poi,javafx-2,Java,Excel,Jakarta Ee,Apache Poi,Javafx 2,我有一张excel表格 i) 我想搜索第一个元素,根据图片假设第一个元素是“double” ii)然后在相同的迭代中,我迭代第一行(即第0行),发现“大小(字节)”。然后,我需要特定的单元格值,相对于我在上面用迭代搜索的行和列值,即“Primitive”。我如何使用ApachePOI获得它。 请帮忙。 非常感谢 1-表示第一次搜索列值 2-表示第二次搜索行值 3-表示我需要的输出 FileInputStream excelFile = new FileInputStream(new

我有一张excel表格

i) 我想搜索第一个元素,根据图片假设第一个元素是“double”

ii)然后在相同的迭代中,我迭代第一行(即第0行),发现“大小(字节)”。然后,我需要特定的单元格值,相对于我在上面用迭代搜索的行和列值,即“Primitive”。我如何使用ApachePOI获得它。 请帮忙。 非常感谢

1-表示第一次搜索列值

2-表示第二次搜索行值

3-表示我需要的输出

      FileInputStream excelFile = new FileInputStream(new File(str));
        Workbook workbook = new XSSFWorkbook(excelFile);
        Sheet datatypeSheet = workbook.getSheetAt(0);
        Sheet sheet = workbook.getSheetAt(0);

        //Iterator<Row> iterator = datatypeSheet.iterator();
        for(Row row : sheet)
        {
            Cell cell = row.getCell(0);
            System.out.println(cell.getStringCellValue());
           boolean e = EngineList.add(cell.getStringCellValue());
           System.out.println(e);
        }
                Row currentRow = datatypeSheet.getRow(0);
                Cell cell = currentRow.getCell(1);
               // System.out.println("crow"+currentRow);

                System.out.println("crow"+cell);
                System.out.println("crowlastcellnum"+currentRow.getLastCellNum());

            if(currentRow.getRowNum()==0)
            {                 
              for(int i=1;i<currentRow.getLastCellNum();i++)  
              {

                if (currentRow.getCell(i).getCellTypeEnum() == CellType.STRING) {
                    System.out.println(currentRow.getCell(i).getStringCellValue());
                parameterList.add(currentRow.getCell(i).getStringCellValue());
                } 
            }
              System.out.println();
            }

//am getting the row values and column values and stored them into arraylist for search.
FileInputStream excelFile=newfileinputstream(新文件(str));
工作簿=新XSSF工作簿(Excel文件);
工作表数据类型工作表=工作簿。getSheetAt(0);
工作表=工作簿。getSheetAt(0);
//迭代器迭代器=datatypeSheet.Iterator();
用于(行:页)
{
Cell Cell=row.getCell(0);
System.out.println(cell.getStringCellValue());
布尔值e=EngineList.add(cell.getStringCellValue());
系统输出打印ln(e);
}
Row currentRow=datatypeSheet.getRow(0);
Cell Cell=currentRow.getCell(1);
//系统输出打印项次(“crow”+当前行);
System.out.println(“crow”+单元格);
System.out.println(“crowlastcellnum”+currentRow.getLastCellNum());
如果(currentRow.getRowNum()==0)
{                 

对于(inti=1;i我没有完全理解您的问题。但是,下面的代码是您所期望的吗

FileInputStream excelFile;
Workbook workbook;
try {
    excelFile = new FileInputStream(new File(fileName));
    workbook = new XSSFWorkbook(excelFile);

    Sheet datatypeSheet = workbook.getSheetAt(0);
    for (Row currentRow : datatypeSheet) {
        for (Cell cell : currentRow) {
            if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                System.out.print(cell.getStringCellValue() + "||");
            } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                System.out.print(cell.getNumericCellValue() + "||");
            }
        }
        System.out.println();
    }
} catch (IOException e) {
    e.printStackTrace();
}

让我们看看你为你的努力尝试了什么问题,但我已经解决了:)