Microsoft Excelフォーミュラ監視ウィンドウにセルを追加する
可能な使用シナリオ
Microsoft Excelの式ウォッチウィンドウは、セルの値と式を便利にウォッチするための便利なツールです。Formulas > Watch WindowをクリックしてMicrosoft Excelでウォッチウィンドウを開きます。そこにはウォッチを追加するボタンがあり、それを使用してセルを検査することができます。同様に、Aspose.Cells APIを使用してWatch Windowにセルを追加するために、Worksheet.CellWatches.Add()メソッドを使用できます。
Microsoft Excelフォーミュラ計算エンジンのAspose.Cells
次のサンプルコードは、セルC1とE1の数式を設定し、両方をWatchウィンドウに追加します。その後、ブックを出力Excelファイル として保存します。出力Excelファイルを開き、Watch Windowを表示すると、このスクリーンショットに示すように両方のセルが表示されます。
サンプルコード
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Create empty workbook. | |
Workbook wb = new Workbook(); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Put some integer values in cell A1 and A2. | |
ws.Cells["A1"].PutValue(10); | |
ws.Cells["A2"].PutValue(30); | |
// Access cell C1 and set its formula. | |
Cell c1 = ws.Cells["C1"]; ; | |
c1.Formula = "=Sum(A1,A2)"; | |
// Add cell C1 into cell watches by name. | |
ws.CellWatches.Add(c1.Name); | |
// Access cell E1 and set its formula. | |
Cell e1 = ws.Cells["E1"]; ; | |
e1.Formula = "=A2*A1"; | |
// Add cell E1 into cell watches by its row and column indices. | |
ws.CellWatches.Add(e1.Row, e1.Column); | |
// Save workbook to output XLSX format. | |
wb.Save("outputAddCellsToMicrosoftExcelFormulaWatchWindow.xlsx", SaveFormat.Xlsx); |