使用java通过Excel工作表搜索特定字符

时间:2016-02-13 03:03:25

标签: java excel

我有一个excel文件,表格从第一行和第三列开始。在第一行和第三行中有字母。

我想要做的是在第一行找到一个字母,然后在第三列中找到另一个字母,然后找到它们交叉点的int值(我使用Apache POI)。

我已经

cell.getRichStringCellValue().getString().trim().equals(cellContent)

获取引用,但它一直返回默认值。

谢谢。

1 个答案:

答案 0 :(得分:0)

有类似字母的问题,所以代码会找到两个单元格,然后什么都不返回。所以在excel文件中,我在第3列中的单元格中添加了一个字母,在第1列中添加了另一个字母,以便区分它们。

    for (Row row : sheet) 
    {
        for (Cell cell : row)
            {
                if (cell.getCellType() == Cell.CELL_TYPE_STRING) 
                    if (cell.getRichStringCellValue().getString().trim().equals(targetLetter))
                        row1= row.getRowNum();  
                if (cell.getCellType() == Cell.CELL_TYPE_STRING) 
                    if (cell.getRichStringCellValue().getString().trim().equals(displayLetter)) 
                        col1= cell.getColumnIndex();  
                c= sheet.getRow(row1).getCell(col1); // c is of type Cell
            }
    }