在工作表中显示公式而不是值

Contents
[ ]

Aspose.Cells 提供了一个 Worksheet.setShowFormulas() 属性。将其设置为 true 可以设置 Microsoft Excel 显示公式。

下图显示了在单元格 A3 中有公式 =Sum(A1:A2) 的工作表。

单元格 A3 中有公式的工作表

todo:image_alt_text

下图显示了通过将 Worksheet.setShowFormulas() 属性设为 true,启用了计算值的公式。

工作表现在显示公式而不是计算值

todo:image_alt_text

// 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");