CellGetPrecedents Method
Gets all cells or ranges which this cell's formula depends on.

Namespace: Aspose.Cells
Assembly: Aspose.Cells (in Aspose.Cells.dll) Version: 19.11.0.0 (19.11)
Syntax
public ReferredAreaCollection GetPrecedents()

Return Value

Type: ReferredAreaCollection
Returns all cells or ranges.
Remarks
Returns null if this is not a formula cell.
Examples
[C#]

Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
cells["A1"].Formula = "= B1 + SUM(B1:B10) + [Book1.xls]Sheet1!A1";
 ReferredAreas areas = cells["A1"].GetPrecedents();
for (int i = 0; i < areas.Count; i++)
{
    ReferredArea area = areas[i];
     StringBuilder stringBuilder = new StringBuilder();
     if (area.IsExternalLink)
     {
         stringBuilder.Append("[");
          stringBuilder.Append(area.ExternalFileName);
          stringBuilder.Append("]");
      }
      stringBuilder.Append(area.SheetName);
      stringBuilder.Append("!");
      stringBuilder.Append(CellsHelper.CellIndexToName(area.StartRow, area.StartColumn));
      if (area.IsArea)
       {
           stringBuilder.Append(":");
           stringBuilder.Append(CellsHelper.CellIndexToName(area.EndRow, area.EndColumn));
       }
       Console.WriteLine(stringBuilder.ToString());
    }
 workbook.Save(@"C:\Book2.xls");

[Visual Basic]

Dim workbook As Workbook = New Workbook()
Dim cells As Cells = workbook.Worksheets(0).Cells
cells("A1").Formula = "= B1 + SUM(B1:B10) + [Book1.xls]Sheet1!A1"
 Dim areas As ReferredAreas = cells("A1").GetPrecedents()
For i As Integer = 0 To areas.Count - 1
    Dim area As ReferredArea = areas(i)
    Dim stringBuilder As StringBuilder = New StringBuilder()
    If (area.IsExternalLink) Then
        stringBuilder.Append("[")
        stringBuilder.Append(area.ExternalFileName)
       stringBuilder.Append("]")
    End If
    stringBuilder.Append(area.SheetName)
    stringBuilder.Append("!")
    stringBuilder.Append(CellsHelper.CellIndexToName(area.StartRow, area.StartColumn))
    If (area.IsArea) Then
        stringBuilder.Append(":")
        stringBuilder.Append(CellsHelper.CellIndexToName(area.EndRow, area.EndColumn))
     End If
    Console.WriteLine(stringBuilder.ToString())
 Next
 workbook.Save("C:\Book2.xls")
See Also