在Aspose.Cells中使用FormulaText函数
Contents
[
Hide
]
FormulaText 是 Excel 2013 及更高版本的函数。不支持以前版本,如 Excel 2010 或 2007 等。顾名思义,它打印给定单元格中存在的公式的文本。本文将展示如何利用 Aspose.Cells 使用此函数。
在 Aspose.Cells 中使用 FormulaText 函数
以下示例代码展示了在 Aspose.Cells 中使用 FormulaText 的用法。该代码首先在单元格 A1 中写入公式,然后在单元格 A2 中使用 FormulaText 打印公式的文本。
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 | |
String dataDir = Utils.getDataDir(UsingFormulaTextfunction.class); | |
// Create a workbook object | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Put some formula in cell A1 | |
Cell cellA1 = worksheet.getCells().get("A1"); | |
cellA1.setFormula("=Sum(B1:B10)"); | |
// Get the text of the formula in cell A2 using FORMULATEXT function | |
Cell cellA2 = worksheet.getCells().get("A2"); | |
cellA2.setFormula("=FormulaText(A1)"); | |
// Calculate the workbook | |
workbook.calculateFormula(); | |
// Print the results of A2. It will now print the text of the formula inside cell A1 | |
System.out.println(cellA2.getStringValue()); |
控制台输出
这是上面示例代码的控制台输出。
=SUM(B1:B10)