Använda FormulaText funktion i Aspose.Cells
Contents
[
Hide
]
FormulaText är en funktion i Excel 2013 och senare. Den stöds inte av tidigare versioner som Excel 2010 eller 2007 etc. Som namnet antyder skriver den ut texten i formeln som finns i en given cell. Den här artikeln kommer att visa dig hur du använder den här funktionen med Aspose.Cells.
Följande exempelkod visar användningen av FormulaText med Aspose.Cells. Koden skriver först en formel i cell A1 och skriver sedan ut texten för formeln med FormulaText i cell 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); |
Konsoloutput
Här är konsoloutputen från ovanstående exempelkod.
=SUM(B1:B10)