Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
=B5, cell B5 is a precedent to cell D10.=B5, cell D10 is dependent on cell B5.To make the spreadsheet easy to read, you might want to clearly show which cells on a spreadsheet are used in a formula. Similarly, you may want to extract the dependent cells of other cells.
Aspose.Cells allows you to trace cells and find out which are linked.
Formulas may change based on modifications made by a client. For example, if cell C1 depends on C3 and C4, and C1 is changed (so the formula is overridden), C3 and C4—or other cells—need to change to balance the spreadsheet based on business rules.
Similarly, suppose C1 contains the formula =(B1*22)/(M2*N32). I want to find the cells that C1 depends on, that is, the precedent cells B1, M2, and N32.
You might need to trace the dependency of a particular cell to other cells. If business rules are embedded in formulas, we would like to find out the dependency and execute some rules based on it. Likewise, if the value of a particular cell is modified, which cells in the worksheet are impacted by that change?
Microsoft Excel allows users to trace precedents and dependents.
Aspose.Cells makes it easy to get precedent cells. Not only can it retrieve cells that provide data to simple‑formula precedents, but it can also find cells that provide data to complex‑formula precedents with named ranges.
In the example below, a template Excel file, Book1.xls, is used. The spreadsheet has data and formulas on the first worksheet.
Aspose.Cells provides the Cell class’s GetPrecedents method, which returns a ReferredAreaCollection. As you can see, in Book1.xls cell B7 contains the formula =SUM(A1:A3). Thus, cells A1:A3 are the precedent cells to cell B7. The following example demonstrates the tracing‑precedents feature using the template file Book1.xls.
Aspose.Cells lets you get dependent cells in spreadsheets. Not only can it retrieve cells that provide data for a simple formula, but it can also find cells that provide data for a complex‑formula dependent with named ranges.
Aspose.Cells provides the Cell class’s GetDependents method. For example, in Book1.xlsx there are formulas =A1+20 and =A1+30 in cells B2 and C2, respectively. The following example demonstrates how to trace the dependents for cell A1 using the template file Book1.xlsx.
The above APIs for tracing precedents and dependents are based on the formula expression itself. They simply provide a convenient way for the user to trace inter‑dependencies for a few formulas. If there are a large number of formulas in the workbook and the user needs to trace precedents and dependents for every cell, performance may suffer. In such situations, the user should consider using the GetPrecedentsInCalculation and GetDependentsInCalculation methods.
These two methods trace dependencies according to the calculation chain. To use them:
Workbook.Settings.FormulaSettings.EnableCalculationChain.Workbook.CalculateFormula().For some formulas, the resultant precedents may differ between GetPrecedents and GetPrecedentsInCalculation, and the resultant dependents may differ between GetDependents and GetDependentsInCalculation. For example, if cell A1’s formula is =IF(TRUE,B2,C3), GetPrecedents will return B2 and C3 as A1’s precedents. Accordingly, both B2 and C3 have the dependent A1 when checked by GetDependents. However, for the actual calculation of this formula, only B2 can affect the result. Therefore, GetPrecedentsInCalculation will not return C3 for A1, and GetDependentsInCalculation will not return A1 for C3.
Sometimes a user may simply have the requirement to trace only those inter‑dependencies that actually affect the calculated result of formulas based on the current data in the workbook; in such cases, they should use GetDependentsInCalculation/GetPrecedentsInCalculation instead of GetDependents/GetPrecedents.
The following example demonstrates how to trace precedents and dependents according to the calculation chain for specific cells:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.