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

  • Question

  • 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.


    • Edited by neonash Thursday, June 7, 2018 3:18 AM
    • Moved by CoolDadTx Thursday, June 7, 2018 6:36 PM Third party product
    Thursday, June 7, 2018 3:16 AM

Answers

  • 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.

    • Marked as answer by neonash Sunday, July 29, 2018 8:47 PM
    Thursday, June 7, 2018 4:51 AM

All replies

  • 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.

    • Marked as answer by neonash Sunday, July 29, 2018 8:47 PM
    Thursday, June 7, 2018 4:51 AM
  • These forums are for MS products only. Questions related to third party libraries need to be posted in their forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, June 7, 2018 6:35 PM