Eve
Eve

Reputation: 514

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

Upvotes: 0

Views: 1369

Answers (2)

Amit Gupta
Amit Gupta

Reputation: 577

Create a Map to store the ColumnName and Index.

You can use objMap.get(columnName) whenever you need the index to passed to the cell.

Upvotes: 1

LiuYan 刘研
LiuYan 刘研

Reputation: 1624

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

Upvotes: 3

Related Questions