Class RevisionDefinedName

RevisionDefinedName class

Represents a revision record of a defined name change.

public class RevisionDefinedName : Revision

Properties

NameDescription
Id { get; }Gets the number of this revision.(Inherited from Revision.)
NewFormula { get; }Gets the formula.
OldFormula { get; }Gets the old formula.
Text { get; }Gets the text of the defined name.
override Type { get; }Represents the type of revision.
Worksheet { get; }Gets the worksheet.(Inherited from Revision.)

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Revisions;
    using System;

    public class RevisionsClassRevisionDefinedNameDemo
    {
        public static void Run()
        {
            try
            {
                // Create a new workbook
                Workbook workbook = new Workbook();
                Worksheet worksheet = workbook.Worksheets[0];

                // Add a defined name to the workbook
                int nameIndex = workbook.Worksheets.Names.Add("TestDefinedName");
                Name definedName = workbook.Worksheets.Names[nameIndex];
                definedName.RefersTo = "=Sheet1!$A$1";

                // Modify the defined name to create a revision
                definedName.RefersTo = "=Sheet1!$B$1";

                // Save the workbook to generate revision logs
                string filePath = "RevisionDefinedNameDemo.xlsx";
                workbook.Save(filePath);

                // Reopen the workbook to access revision information
                Workbook revisionWorkbook = new Workbook(filePath);

                // Iterate through revision logs to find RevisionDefinedName entries
                foreach (RevisionLog log in revisionWorkbook.Worksheets.RevisionLogs)
                {
                    foreach (Revision revision in log.Revisions)
                    {
                        if (revision.Type == RevisionType.DefinedName)
                        {
                            RevisionDefinedName revisionDefinedName = (RevisionDefinedName)revision;

                            // Display the properties of the RevisionDefinedName
                            Console.WriteLine($"Revision Type: {revisionDefinedName.Type}");
                            Console.WriteLine($"Defined Name Text: {revisionDefinedName.Text}");
                            Console.WriteLine($"Old Formula: {revisionDefinedName.OldFormula}");
                            Console.WriteLine($"New Formula: {revisionDefinedName.NewFormula}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
    }
}

See Also