How can I obtain the position of a cell with an specific text(NPOI)?


  • HI

    I would like to search the position of the cell which has the text: "Dia de Pago".

    I use NPOI libraries.

    The similar solution could be:

    private static int findRow(HSSFSheet sheet, String cellContent) {
        for (Row row : sheet) {
            for (Cell cell : row) {
                if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                    if (cell.getRichStringCellValue().getString().trim().equals(cellContent)) {
                        return row.getRowNum();  
        return 0;

    But the problem is that it has to go through many cells.

    • Diedit oleh neonash Kamis, 07 Juni 2018 03.18
    • Dipindahkan oleh CoolDadTxMVP Kamis, 07 Juni 2018 18.36 Third party product
    Kamis, 07 Juni 2018 03.16

Semua Balasan

  • I don't believe the NPIO libraries have any global "search" functions.  The only option is to do what you are doing.

    If you need to do a lot of manipulation like this, you could read the whole sheet into a 2D string array.  The string array would be quicker to search, but I'll wager it isn't worth the trouble.

    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Kamis, 07 Juni 2018 04.51
  • These forums are for MS products only. Questions related to third party libraries need to be posted in their forums.

    Michael Taylor

    Kamis, 07 Juni 2018 18.35