先行および従属
紹介
- 先行セル は、他のセルの式で参照されるセルです。たとえば、セル D10 に式 =B5 が含まれている場合、セル B5 がセル D10 の先行セルです。
- 従属セル は、他のセルを参照する式を含んでいます。たとえば、セル D10 に式 =B5 が含まれている場合、セル D10 はセル B5 の従属セルです。
スプレッドシートをわかりやすくするために、スプレッドシートに含まれるセルが式で使用されているかを明確に表示することがあります。同様に、他のセルの従属セルを抽出することがあります。
Aspose.Cells を使用すると、セルをトレースしてリンクされているセルを特定することができます。
先行および従属セルのトレース: Microsoft Excel
例えば、セル C1 が式を含む C3 および C4 に依存しており、C1 が変更される場合(つまり式が上書きされる場合)、C3 および C4 などの他のセルは、ビジネスルールに基づいてスプレッドシートをバランスさせるために変更する必要があります。
同様に、C1 に式 “=(B122)/(M2N32)” を含むとします。C1 が依存しているセルである先行セル B1、M2、N32 を見つけたいとします。
特定のセルの依存関係を他のセルにトレースする必要があるかもしれません。ビジネスルールが式に埋め込まれている場合、依存関係を見つけ、それに基づいていくつかのルールを実行したいと思うかもしれません。同様に、特定のセルの値が変更される場合、その変更に影響を受けるワークシート内のセルを見つけたいと思うかもしれません。
Microsoft Excel を使用すると、先行および従属をトレースすることができます。
- ビューツールバー で 式監査 を選択します
- 先行をトレース:
- 先行セルを特定したい式を含むセルを選択します。
- 直接データを提供する各セルにトレーサーアローを表示するには、 式監査 ツールバーの 先行をトレース をクリックします。
- 特定のセルを参照する式をトレースする(従属)
- 従属セルを特定したいセルを選択します。
- アクティブセルに依存している各セルにトレーサーアローを表示するには、 式監査 ツールバーの 従属をトレース をクリックします。
先行および従属セルをトレース: Aspose.Cells
先行をトレース
Aspose.Cells を使用すると、先行セルを取得することが容易になります。シンプルな式の先行セルに提供されているセルだけでなく、名前付き範囲で複雑な式の先行セルに提供されているセルを見つけることもできます。
Aspose::Cells::Startup(); | |
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input | |
U16String dirPath(u""); | |
//Path of output | |
U16String outPath(u""); | |
//Path of input excel file | |
U16String samplePrecedentsAndDependents = dirPath + u"samplePrecedentsAndDependents.xlsx"; | |
//Load source Excel file | |
Workbook workbook(samplePrecedentsAndDependents); | |
//Calculate workbook formula | |
workbook.CalculateFormula(); | |
//Access first worksheet | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
//Access cell F6 | |
Cell cell = worksheet.GetCells().Get(u"F6"); | |
//Get precedents of the cells and print them on console | |
std::cout << "Printing Precedents of Cell: "; | |
std::cout << cell.GetName().ToUtf8() << std::endl; | |
std::cout << u"-------------------------------" << std::endl; | |
ReferredAreaCollection refac = cell.GetPrecedents(); | |
int count = refac.GetCount(); | |
for (int i = 0; i < count; i++) | |
{ | |
ReferredArea refa = refac.Get(i); | |
int row = refa.GetStartRow(); | |
int col = refa.GetStartColumn(); | |
cell = worksheet.GetCells().GetCell(row, col); | |
std::cout<<cell.GetName().ToUtf8() << std::endl; | |
} | |
Aspose::Cells::Cleanup(); |
従属をトレース
Aspose.Cells を使用すると、スプレッドシート内の従属セルを取得することができます。Aspose.Cells は、単純な式に関するデータを提供するセルだけでなく、名前付き範囲で複雑な式の従属セルに提供されているセルを見つけることもできます。
Aspose::Cells::Startup(); | |
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input | |
U16String dirPath(u""); | |
//Path of output | |
U16String outPath(u""); | |
//Path of input excel file | |
U16String samplePrecedentsAndDependents = dirPath + u"samplePrecedentsAndDependents.xlsx"; | |
//Load source Excel file | |
Workbook workbook(samplePrecedentsAndDependents); | |
//Calculate workbook formula | |
workbook.CalculateFormula(); | |
//Access first worksheet | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
//Access cell F6 | |
Cell cell = worksheet.GetCells().Get(u"F6"); | |
//Get dependents of the cells and print them on console | |
std::cout << "Printing Dependents of Cell: "; | |
std::cout << cell.GetName().ToUtf8() << std::endl; | |
std::cout << "-------------------------------" << std::endl; | |
//Parameter false means we do not want to search other sheets | |
Vector<Cell> depCells = cell.GetDependents(false); | |
//Get the length of the array | |
int len = depCells.GetLength(); | |
//Print the names of all the cells inside the array | |
for (int i = 0; i < len; i++) | |
{ | |
Cell dCell = depCells[i]; | |
std::cout << dCell.GetName().ToUtf8() << std::endl; | |
} | |
Aspose::Cells::Cleanup(); |