Microsoft Excelフォーミュラ監視ウィンドウにセルを追加する

可能な使用シナリオ

Microsoft ExcelのWatch Windowはセルの値とその数式を便利に監視するための有用なツールです。Microsoft Excelを開き、数式 > リスト > ウォッチ ウィンドウをクリックしてWatch Windowを開けることができます。そこでは、Add Watchボタンをクリックしてインスペクション用のセルを追加することができます。同様に、Aspose.Cells APIを使用してWatch Windowにセルを追加するためにWorksheet.getCellWatches().add()メソッドを使用することができます。

Microsoft Excelフォーミュラ計算エンジンのAspose.Cells

次のサンプルコードは、セルC1とE1の式を設定し、両者をWatch Windowに追加し、その後ワークブックを出力エクセルファイルとして保存します。出力エクセルファイルを開き、Watch Windowを表示すると、このスクリーンショットに表示されているように両方のセルが表示されます。

todo:image_alt_text

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create empty workbook.
Workbook wb = new Workbook();
// Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
// Put some integer values in cell A1 and A2.
ws.getCells().get("A1").putValue(10);
ws.getCells().get("A2").putValue(30);
// Access cell C1 and set its formula.
Cell c1 = ws.getCells().get("C1");
c1.setFormula("=Sum(A1,A2)");
// Add cell C1 into cell watches by name.
ws.getCellWatches().add(c1.getName());
// Access cell E1 and set its formula.
Cell e1 = ws.getCells().get("E1");
e1.setFormula("=A2*A1");
// Add cell E1 into cell watches by its row and column indices.
ws.getCellWatches().add(e1.getRow(), e1.getColumn());
// Save workbook to output XLSX format.
wb.save(outDir + "outputAddCellsToMicrosoftExcelFormulaWatchWindow.xlsx", SaveFormat.XLSX);