Search code examples
javaexcelxlsrft

Java XLS get cell through columnname


I'm currently working on a project where I need to edit XLS with Java. The first row of the xls is a row with columnnames. I want to use the columnname to insert data in the cells below. Instead of using getCell to insert a prefix number, I want the application to use a variable string to insert the data. (The comment part is info I scribbled for myself; it might be useful).


Solution

  • I would done like this:

    • create a Map object
    • store the index value of each column into Map
    • then, row.getCell (theNameIndexMap.get("A_COLUMN_NAME")) would meet your requirement

    And, make sure each column name is UNIQUE...