C++を使用してMicrosoft Excelの数式監視ウィンドウにセルを追加
Contents
[
Hide
]
可能な使用シナリオ
Microsoft Excelの監視ウィンドウは、セルの値や数式をウィンドウで便利に監視できるツールです。Microsoft Excelで数式 > 監視ウィンドウをクリックして監視ウィンドウを開くことができます。このウィンドウには監視の追加ボタンがあり、監視するセルを追加できます。同様に、Aspose.Cells APIのWorksheet.CellWatches.Add()メソッドを使用してセルを監視ウィンドウに追加できます。
Microsoft Excelフォーミュラ計算エンジンのAspose.Cells
次のサンプルコードは、セルC1とE1の数式を設定し、それらを監視ウィンドウに追加します。その後、ワークブックを出力Excelファイルとして保存します。出力Excelファイルを開き、監視ウィンドウを見ると、両方のセルがこのスクリーンショットのように表示されます。
サンプルコード
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main() {
Aspose::Cells::Startup();
// Create empty workbook
Workbook wb;
// Access first worksheet
Worksheet ws = wb.GetWorksheets().Get(0);
// Put some integer values in cell A1 and A2
ws.GetCells().Get(u"A1").PutValue(10);
ws.GetCells().Get(u"A2").PutValue(30);
// Access cell C1 and set its formula
Cell c1 = ws.GetCells().Get(u"C1");
c1.SetFormula(u"=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(u"E1");
e1.SetFormula(u"=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(u"outputAddCellsToMicrosoftExcelFormulaWatchWindow.xlsx", SaveFormat::Xlsx);
std::cout << "Workbook saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
return 0;
}