static List < IA1Address > resolveCellDependencies ( IA1Address cellAddress , Sheet sheet , FormulaParsingWorkbook workbook ) { Row row = sheet . getRow ( cellAddress . row ( ) ) ; if ( row == null ) { return emptyList ( ) ; } Cell cell = row . getCell ( cellAddress . column ( ) ) ; if ( cell == null ) { return emptyList ( ) ; } if ( CELL_TYPE_FORMULA != cell . getCellType ( ) ) { return singletonList ( cellAddress ) ; } List < IA1Address > dependencies = new LinkedList <> ( ) ; for ( Ptg ptg : parse ( cell . getCellFormula ( ) , workbook , CELL , 0 ) ) { /* TODO: only one sheet is supported */ if ( ptg instanceof RefPtg ) { RefPtg ref = ( RefPtg ) ptg ; dependencies . addAll ( resolveCellDependencies ( fromRowColumn ( ref . getRow ( ) , ref . getColumn ( ) ) , sheet , workbook ) ) ; } else if ( ptg instanceof AreaPtg ) { AreaPtg area = ( AreaPtg ) ptg ; for ( int r = area . getFirstRow ( ) ; r <= area . getLastRow ( ) ; r ++ ) { for ( int c = area . getFirstColumn ( ) ; c <= area . getLastColumn ( ) ; c ++ ) { dependencies . addAll ( resolveCellDependencies ( fromRowColumn ( r , c ) , sheet , workbook ) ) ; } } } dependencies . add ( cellAddress ) ; } return dependencies ; }
For given cell address gives a list of this cell s dependencies .