将单元格添加到Microsoft Excel公式监视窗口
Contents
[
Hide
]
可能的使用场景
Microsoft Excel 观察窗口是一个方便查看单元格值和公式的工具。您可以通过在 Microsoft Excel 中单击 公式 > 观察窗口 来打开观察窗口。它有一个添加观察按钮,可用于添加要检查的单元格。同样,您可以使用 Worksheet.CellWatches.Add() 方法使用 Aspose.Cells API 将单元格添加到 观察窗口。
将单元格添加到Microsoft Excel公式监视窗口
以下示例代码设置了单元格 C1 和 E1 的公式,并将它们都添加到观察窗口中。然后将工作簿保存为输出 Excel 文件。如果您打开输出的 Excel 文件并查看观察窗口,您将看到如此图所示的两个单元格。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |