Example #1
0
        static void Main(string[] args)
        {
            // Tracing Precedents

            //Instantiating a Workbook object
            Workbook workbook = new Workbook("C:\\book1.xls");
            Cells    cells    = workbook.Worksheets[0].Cells;

            Aspose.Cells.Cell cell = cells["B7"];

            //Tracing precedents of the cell B7.
            //The return array contains ranges and cells.
            ReferredAreaCollection ret = cell.GetPrecedents();

            //Printing all the precedent cells' name.
            if (ret != null)
            {
                for (int m = 0; m < ret.Count; m++)
                {
                    ReferredArea  area          = ret[m];
                    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());
                }
            }
        }