简体   繁体   中英

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?

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());
}
   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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM