在Aspose.Cells中使用FormulaText函数
Contents
[
Hide
]
FormulaText是Excel 2013及以后的函数。不支持以前的版本,如Excel 2010或2007等。正如其名称所示,它打印给定单元格中存在的公式的文本。本文将向您展示如何使用Aspose.Cells利用此函数。
以下示例代码显示了如何使用Aspose.Cells中的FormulaText。代码首先在单元格A1中编写一个公式,然后使用FormulaText在单元格A2中打印出公式的文本。
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 a workbook object | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Put some formula in cell A1 | |
Cell cellA1 = worksheet.Cells["A1"]; | |
cellA1.Formula = "=Sum(B1:B10)"; | |
// Get the text of the formula in cell A2 using FORMULATEXT function | |
Cell cellA2 = worksheet.Cells["A2"]; | |
cellA2.Formula = "=FormulaText(A1)"; | |
// Calculate the workbook | |
workbook.CalculateFormula(); | |
// Print the results of A2, It will now print the text of the formula inside cell A1 | |
Console.WriteLine(cellA2.StringValue); |
控制台输出
这是上面示例代码的控制台输出。
=SUM(B1:B10)