在 Aspose.Cells 中使用 FormulaText 函数

Contents
[ ]

以下示例代码显示了 FormulaText 与 Aspose.Cells 的用法。代码首先在单元格 A1 中写入公式,然后在单元格 A2 中使用 FormulaText 打印公式的文本。

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