4
votes

I am using XSSF to access the .xlsx format. Extracting row data and cell data is being done by

Row.getCell(1) // to get the first cell data. 

Is there a way to access cells like

Row.getCell(A) or Row.getCell(AC). 

This will be very helpfull for me to access columns. Can any one tell me the way to do this?

2

2 Answers

4
votes

I think the main class you're looking for is CellReference - it handles converting between user facing references such as "B2" into file format references like row=1,col=1 . There's a static method on there that handles your exact use case, convertColStringToIndex

For your use case, you'd want code something like

 Cell c = row.getCell( CellReference.convertColStringToIndex("G") );
3
votes

The question is regarding reaching out a cell using its references, if I am not wrong.

Sheet referenceSheet = workbook.getsheet("Sheet name your intrested in");

CellReference ref = new CellReference("C24");
Row row = referenceSheet.getRow(ref.getRow());
 // null check for the row
if(row != null)
{
Cell cell = row.getCell(ref.getCol());
}

In this way we can refer a cell using its reference.