在工作表中显示公式而不是值
Contents
[
Hide
]
可以在 Microsoft Excel 中使用公式选项卡中的显示公式选项来显示公式而不是计算出的值。显示公式时,Microsoft Excel 在工作表中显示公式。使用 Aspose.Cells 也可以实现相同的功能。
Aspose.Cells 提供了一个 Worksheet.setShowFormulas() 属性。将其设置为 true 可以设置 Microsoft Excel 显示公式。
下图显示了在单元格 A3 中有公式 =Sum(A1:A2) 的工作表。
单元格 A3 中有公式的工作表
下图显示了通过将 Worksheet.setShowFormulas() 属性设为 true,启用了计算值的公式。
工作表现在显示公式而不是计算值
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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ShowFormulas.class); | |
// Load the source workbook | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Show formulas of the worksheet | |
worksheet.setShowFormulas(true); | |
// Save the workbook | |
workbook.save(dataDir + "out.xlsx"); |