Sh4m
Sh4m

Reputation: 1522

Apache POI - Excel Get value by given ranges

User will insert ranges value for example A1:A3 to retrieve the data. How i can get the value based on the given ranges using Apache POI?

or is there any library that i can use?

Upvotes: 0

Views: 2520

Answers (2)

Timona
Timona

Reputation: 11

   import org.apache.poi.ss.util.SheetUtil
   final Cell cell= SheetUtil.getCellWithMerges(sheet, 5, 2);

visit http://poi.apache.org/apidocs/4.1/org/apache/poi/ss/util/SheetUtil.html

Upvotes: 1

Sh4m
Sh4m

Reputation: 1522

Below is the solution that i got. Using AreaReference function.

AreaReference aref = new AreaReference(sheet.getSheetName() + "!A3:A9", SpreadsheetVersion.EXCEL2007);
CellReference[] crefs = aref.getAllReferencedCells();
for (int i=0; i<crefs.length; i++) {
    XSSFSheet s = workbook.getSheet(crefs[i].getSheetName());
    Row r = s.getRow(crefs[i].getRow());
    Cell c = r.getCell(crefs[i].getCol());
}

Upvotes: 2

Related Questions