将单元格添加到Microsoft Excel公式监视窗口
Contents
[
Hide
]
可能的使用场景
Microsoft Excel观察窗口是一个方便查看单元格值和其公式的工具。您可以通过单击公式 > 观察窗口在Microsoft Excel中打开观察窗口。它有添加观察按钮,可用于将单元格添加到观察窗口中。类似地,您可以使用Aspose.Cells API的Worksheet.getCellWatches().add()方法将单元格添加到观察窗口中。
将单元格添加到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-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); |