menu

Document Processing

Interface IScenario - FileFormats API Reference | Syncfusion

    Show / Hide Table of Contents

    Interface IScenario

    Represents What-If analysis scenario in the worksheet.

    Namespace: Syncfusion.XlsIO
    Assembly: Syncfusion.XlsIO.Base.dll
    Syntax
    public interface IScenario

    Properties

    ChangingCells

    Declaration
    IRange ChangingCells { get; }
    Property Value
    Type
    IRange

    Comment

    Gets or sets the comment associated with the What-If analysis scenario.

    Declaration
    string Comment { get; set; }
    Property Value
    Type
    System.String
    Examples

    Following code illustrates how to get or set the comment associated with the scenario

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
      IApplication application = excelEngine.Excel;
      IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
      IWorksheet worksheet = workbook.Worksheets[0];    
    
      //Adding a new scenario to the worksheet.
      IScenarios scenarios = sheet1.Scenarios;
      IScenario scenario1 = scenarios.Add("Scenario1", sheet.Range["C4"], 100); 
    
      //Set the comment for the scenario
      scenario1.Comment = "New comment"; 
    
       workbook.SaveAs("ScenarioManager.xlsx");
       workbook.Close();
       excelEngine.Dispose();
    }        

    Hidden

    Gets or sets a boolean value indicating whether the What-If analysis scenario is hidden or not.

    Declaration
    bool Hidden { get; set; }
    Property Value
    Type Description
    System.Boolean

    True if the scenario is hidden. Otherwise false.

    Examples

    Following code illustrates shows true if the scenario is hidden. The default value is false

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
      IApplication application = excelEngine.Excel;
      IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
      IWorksheet worksheet = workbook.Worksheets[0];    
    
      //Adding a new scenario to the worksheet.
      IScenarios scenarios = sheet1.Scenarios;
      IScenario scenario1 = scenarios.Add("Scenario1", sheet.Range["C4"], 100);
    
      //Set the scenario as hidden
      scenario1.Hidden = true; 
    
       workbook.SaveAs("ScenarioManager.xlsx");
       workbook.Close();
       excelEngine.Dispose();
    }        

    Index

    Gets the index of the What-If analysis scenario in the scenarios collection.

    Declaration
    int Index { get; }
    Property Value
    Type
    System.Int32
    Examples

    Following code illustrates how to get the scenario index for scenarios collection.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
      IApplication application = excelEngine.Excel;
      IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
      IWorksheet worksheet = workbook.Worksheets[0];    
    
      //Adding a new scenario to the worksheet.
      IScenarios scenarios = sheet1.Scenarios;
      IScenario scenario1 = scenarios.Add("Scenario1", sheet.Range["C4"], 100); 
    
      //Get the scenario index for scenarios collection.
      int index = scenario1.Index;
    
       workbook.SaveAs("ScenarioManager.xlsx");
       workbook.Close();
       excelEngine.Dispose();
    }        

    Locked

    Gets or sets a boolean value indicating whether the What-If analysis scenario is locked or not. Default value is true.

    Declaration
    bool Locked { get; set; }
    Property Value
    Type Description
    System.Boolean

    True if the scenario is locked. Otherwise false.

    Examples

    Following code illustrates shows true if the object is locked. False if the object can be modified when the sheet is protected

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
      IApplication application = excelEngine.Excel;
      IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
      IWorksheet worksheet = workbook.Worksheets[0];    
    
     //Adding a new scenario to the worksheet.
      IScenarios scenarios = sheet1.Scenarios;
      IScenario scenario1 = scenarios.Add("Scenario1", sheet.Range["C4"]);
    
      //Set the scenario as locked
      scenario1.Locked = true; 
    
      workbook.SaveAs("ScenarioManager.xlsx");
      workbook.Close();
      excelEngine.Dispose();
    }        

    Name

    Gets or sets the What-If analysis scenario name.

    Declaration
    string Name { get; set; }
    Property Value
    Type
    System.String
    Examples

    Following code illustrates how to get or set the scenario name.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
      IApplication application = excelEngine.Excel;
      IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
      IWorksheet worksheet = workbook.Worksheets[0];    
    
      //Adding a new scenario to the worksheet.
      IScenarios scenarios = sheet1.Scenarios;
      IScenario scenario1 = scenarios.Add("Scenario1", sheet.Range["C4"]); 
    
      //Set a name to the scenario
      scenario1.Name = "Scenario2";
    
      workbook.SaveAs("ScenarioManager.xlsx");
      workbook.Close();
      excelEngine.Dispose();
    }        

    Values

    Declaration
    List<object> Values { get; }
    Property Value
    Type
    System.Collections.Generic.List<System.Object>

    Methods

    Delete()

    Deletes the current scenario from What-If analysis scenarios collection.

    Declaration
    void Delete()
    Examples

    Following code illustrates how to delete the current scenario from scenarios collection.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
      IApplication application = excelEngine.Excel;
      IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
      IWorksheet worksheet = workbook.Worksheets[0];    
    
      //Add new scenarios to the worksheet.
      IScenarios scenarios = sheet1.Scenarios;
      IScenario scenario1 = scenarios.Add("Scenario1", sheet.Range["B3:B9"], 100);
      IScenario scenario2 = scenarios.Add("Scenario2", sheet.Range["B3:B9"], 200);
    
      //Delete the scenarios
      scenario2.Delete();
    
      workbook.SaveAs("ScenarioManager.xlsx");
      workbook.Close();
      excelEngine.Dispose();
    }        

    ModifyScenario(IRange, List<Object>)

    Declaration
    IScenario ModifyScenario(IRange changingCells, List<object> values)
    Parameters
    Type Name Description
    IRange changingCells
    System.Collections.Generic.List<System.Object> values
    Returns
    Type
    IScenario

    Show()

    Applies the scenario values to the worksheet and shows the updated cell values.

    Declaration
    void Show()
    Examples

    Following code illustrates how to show the scenario by inserting its values on the worksheet.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
      IApplication application = excelEngine.Excel;
      IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
      IWorksheet worksheet = workbook.Worksheets[0];    
    
      //Adding new scenarios to the worksheet.
      IScenarios scenarios = sheet1.Scenarios;
      IScenario scenario1 = scenarios.Add("Scenario1", sheet.Range["B3:B9"], 100);
      IScenario scenario2 = scenarios.Add("Scenario2", sheet.Range["B3:B9"], 200);
    
      //Delete the scenarios
      scenario2.Show();
    
      workbook.SaveAs("ScenarioManager.xlsx");
      workbook.Close();
      excelEngine.Dispose();
    }        
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved