Get cell by its content

David

Is there a way to get the cell object or coordinate by the data the cell contains?

For example if the cell with coordinates (1;5) contains the string "FINDME", i'd like to do something like Workbook.GetCellByData("FINDME") and it should return the Cell object or (1;5).

I have found a code snippet on the Apache POI website that could be useful. I could just read the whole workbook and find the data with an IF-statement, but that's kind of dirty...

EDIT: I have coded the "dirty" solution as follows:

public Cell getCellByContent(String data) {
    for (Row row : wb.getSheetAt(0)) {
        for (Cell cell : row) {           
            if (cell.getCellType() == Cell.CELL_TYPE_STRING){
                System.out.println(String.format("Found String type at (%s,%s) and read: %s", row.getRowNum(), cell.getColumnIndex(), cell.getStringCellValue()));
                if (cell.getStringCellValue() == data) { //HERE
                    return cell;                         //HERE
                }                                        //HERE
            }
        }
    }
    System.out.println("Can't find it bruh!");
    return null;

For some reason it fails at the if-statement. Id like to get the Cell with the content "%title%".

Output:

Found String type at (0,0) and read: %title% <------ IT'S RIGHT HERE!
Found String type at (2,0) and read: Test Information
...
Can't find it bruh!

Does someone have an idea why this is not working?

Gary Forbis

To fix the dirty solution replace

if (cell.getStringCellValue() == data)

with

if (cell.getStringCellValue().equals(data))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get selected cell content

From Dev

Excel: Remove only true cell content if its in a other cell

From Dev

QML - get tableview cell content

From Java

Get the size of a directory (not its content)

From Dev

Get table cell content based on content of cell in neighbourhood

From Dev

EXCEL - How do I find a cell with specific content, and then reference that CELL (not its content) in another formula? (example within)

From Dev

Moving tables and its content to the top and bottom of a bigger cell

From Dev

find middle cell in a collection view and change its content

From Dev

How to get the cell content of DatagridTemplateColumn in wpf datagrid?

From Dev

How to get average by cell content on VBA

From Dev

Get Cell Content in one sheet to another

From Dev

UICollectionView with dynamic cell content - get cell to remember state

From Dev

_UIReplicantView and snapshotViewAfterScreenUpdates how to get its content?

From Dev

Get content of <div> knowing its id

From Dev

Loop through each cell in a table and get its respective title

From Dev

Open specific excel file/sheet to get a specific content cell location

From Dev

Javascript: get content of table's cell (inside div)

From Dev

Get html content of a cell having a checbox with value jquery

From Dev

Open specific excel file/sheet to get a specific content cell location

From Dev

Get content of specific Table cell and change text color

From Dev

Get the content of first cell in the column after onEdit() activeCell trigger

From Dev

How to get a text content to a variable of a cell using onclick

From Dev

Get Cell according to its number in Board data structure Cell[][] without passing 2 FOR loops

From Dev

How to get the content of the bottom element of a flexbox to be 100% height its container

From Dev

jquery : Get html content between child and end of its parent

From Dev

How to get the height of a div after its content is loaded?

From Dev

How do i get the new html content and its ID to work?

From Dev

How to get a border to size to its content with varying data and footer to adjust

From Dev

How can I get the extension(s) of a file based on its content?

Related Related

  1. 1

    Get selected cell content

  2. 2

    Excel: Remove only true cell content if its in a other cell

  3. 3

    QML - get tableview cell content

  4. 4

    Get the size of a directory (not its content)

  5. 5

    Get table cell content based on content of cell in neighbourhood

  6. 6

    EXCEL - How do I find a cell with specific content, and then reference that CELL (not its content) in another formula? (example within)

  7. 7

    Moving tables and its content to the top and bottom of a bigger cell

  8. 8

    find middle cell in a collection view and change its content

  9. 9

    How to get the cell content of DatagridTemplateColumn in wpf datagrid?

  10. 10

    How to get average by cell content on VBA

  11. 11

    Get Cell Content in one sheet to another

  12. 12

    UICollectionView with dynamic cell content - get cell to remember state

  13. 13

    _UIReplicantView and snapshotViewAfterScreenUpdates how to get its content?

  14. 14

    Get content of <div> knowing its id

  15. 15

    Loop through each cell in a table and get its respective title

  16. 16

    Open specific excel file/sheet to get a specific content cell location

  17. 17

    Javascript: get content of table's cell (inside div)

  18. 18

    Get html content of a cell having a checbox with value jquery

  19. 19

    Open specific excel file/sheet to get a specific content cell location

  20. 20

    Get content of specific Table cell and change text color

  21. 21

    Get the content of first cell in the column after onEdit() activeCell trigger

  22. 22

    How to get a text content to a variable of a cell using onclick

  23. 23

    Get Cell according to its number in Board data structure Cell[][] without passing 2 FOR loops

  24. 24

    How to get the content of the bottom element of a flexbox to be 100% height its container

  25. 25

    jquery : Get html content between child and end of its parent

  26. 26

    How to get the height of a div after its content is loaded?

  27. 27

    How do i get the new html content and its ID to work?

  28. 28

    How to get a border to size to its content with varying data and footer to adjust

  29. 29

    How can I get the extension(s) of a file based on its content?

HotTag

Archive