[]
        
(Showing Draft Content)

IScenario

Interface IScenario


public interface IScenario
A scenario is a group of input values (called changing cells) that's named and saved.

An IScenario represents a saved What-If analysis input set for a worksheet. It stores a scenario name together with the changing cells and can be shown, updated, hidden, locked, or deleted.


 worksheet.getRange("B2:B3").setValue(new Object[][] {
     {100},
     {120}
 });
 IScenario scenario = worksheet.getScenarios().add("Forecast", worksheet.getRange("B2:B3"));
 scenario.setComment("Projected sales inputs");
 
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    changeScenario(IRange changingCells)
    Changes the scenario to have a new set of changing cells.
    void
    changeScenario(IRange changingCells, List<Object> values)
    Changes the scenario to have a new set of changing cells and scenario values.
    void
    Deletes this scenario.
    Gets a IRange object that represents the changing cells for the scenario.
    Gets the comment text associated with the scenario.
    boolean
    Gets whether the scenario is hidden.
    int
    Returns the index of this scenario in the worksheet's scenario collection.
    boolean
    Gets whether the scenario is locked.
    Gets the scenario name.
    Returns a list that contains the current values of the changing cells for the scenario.
    void
    setComment(String comment)
    Sets a String value that represents the comment associated with the scenario.
    void
    setHidden(boolean hidden)
    Sets a Boolean value that indicates if the scenario is hidden.
    void
    setLocked(boolean locked)
    Sets a Boolean value that indicates if the scenario is locked.
    void
    Sets the scenario name.
    void
    Applies the values saved in this scenario to the worksheet.
  • Method Details

    • getIndex

      int getIndex()
      Returns the index of this scenario in the worksheet's scenario collection.

      Use this method to get the scenario's position within the worksheet's scenario collection.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       int index = scenario.getIndex();
       
      Returns:
      The index of this scenario in the worksheet's scenario collection.
    • getName

      String getName()
      Gets the scenario name.

      The returned value is the scenario name used to identify the scenario in the worksheet.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       String name = scenario.getName();
       
      Returns:
      The scenario name.
    • setName

      void setName(String name)
      Sets the scenario name.

      Use this method to rename the scenario in the worksheet's scenario collection.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       scenario.setName("Updated Sales Plan");
       
      Parameters:
      name - The scenario name.
    • getComment

      String getComment()
      Gets the comment text associated with the scenario.

      Use this method to retrieve the descriptive text assigned to the scenario.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       scenario.setComment("Created by Document Solutions for Excel");
       String comment = scenario.getComment();
       
      Returns:
      The comment associated with the scenario.
    • setComment

      void setComment(String comment)
      Sets a String value that represents the comment associated with the scenario.

      Use this method to update the descriptive text assigned to the scenario.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       scenario.setComment("Updated sales inputs");
       
      Parameters:
      comment - The comment associated with the scenario.
    • getHidden

      boolean getHidden()
      Gets whether the scenario is hidden.

      This property indicates whether the scenario is marked as hidden. It can be used together with setHidden(boolean) when configuring scenario behavior.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       scenario.setHidden(true);
       boolean hidden = scenario.getHidden();
       
      Returns:
      True if the scenario is hidden; otherwise, false.
    • setHidden

      void setHidden(boolean hidden)
      Sets a Boolean value that indicates if the scenario is hidden.
      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       scenario.setHidden(true);
       
      Parameters:
      hidden - True if the scenario is hidden; otherwise, false.
    • getLocked

      boolean getLocked()
      Gets whether the scenario is locked.

      A locked scenario is marked as protected from changes. This setting corresponds to setLocked(boolean).

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       scenario.setLocked(true);
       boolean locked = scenario.getLocked();
       
      Returns:
      True if the scenario is locked; otherwise, false.
    • setLocked

      void setLocked(boolean locked)
      Sets a Boolean value that indicates if the scenario is locked.
      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       scenario.setLocked(true);
       
      Parameters:
      locked - True if the scenario is locked; otherwise, false.
    • getChangingCells

      IRange getChangingCells()
      Gets a IRange object that represents the changing cells for the scenario.

      Use the returned range to access the cells whose values are stored and applied by the scenario.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       IRange changingCells = scenario.getChangingCells();
       worksheet.getRange("B2:B3").setValue(new Object[][] {{30}, {40}});
       scenario.show();
       Object appliedValues = changingCells.getValue();
       
      Returns:
      The changing cells for a scenario.
    • getValues

      List<Object> getValues()
      Returns a list that contains the current values of the changing cells for the scenario.

      Use show() to apply these scenario values to the worksheet, or getChangingCells() to retrieve the cells associated with the returned values.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       List<Object> values = scenario.getValues();
       
      Returns:
      A list of objects representing the current values of the changing cells.
    • delete

      void delete()
      Deletes this scenario.

      Use this method to remove a scenario that is no longer needed.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       scenario.delete();
       
    • show

      void show()
      Applies the values saved in this scenario to the worksheet.

      The affected cells are the changing cells of the scenario. This method replaces the current values in those cells with the values stored in the scenario. Formulas that reference the changing cells are recalculated when the calculation engine is enabled.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       worksheet.getRange("B2:B3").setValue(new Object[][] {{30}, {40}});
       scenario.show();
       
    • changeScenario

      void changeScenario(IRange changingCells)
      Changes the scenario to have a new set of changing cells.

      When you use this overload, the scenario values are assumed to be the current values in the cells in changingCells. Use changeScenario(IRange,List) to specify the scenario values explicitly.

      
       worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
       IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
       worksheet.getRange("D2:D3").setValue(new Object[][] {{100}, {200}});
       scenario.changeScenario(worksheet.getRange("D2:D3"));
       
      Parameters:
      changingCells - An IRange object that refers to the changing cells for the scenario. The scenario values are assumed to be the current values in the cells in changingCells.
    • changeScenario

      void changeScenario(IRange changingCells, List<Object> values)
      Changes the scenario to have a new set of changing cells and scenario values.

      The values correspond to the cells in changingCells one by one. For example, if changingCells is "B2:C3", the values should be supplied in the order B2, C2, B3, and C3.

      
       List<Object> values = Arrays.asList(0.05, 0.04, 0.03, 0.02, 0.05);
       IScenario scenario = worksheet.getScenarios().add(
           "Less Discount Rates", worksheet.getRange("D2:D6"), values);
       scenario.changeScenario(worksheet.getRange("D2:D6"),
           Arrays.asList(0.05, 0.06, 0.03, 0.02, 0.05));
       
      Parameters:
      changingCells - An IRange object that refers to the changing cells for the scenario.
      values - A list that contains the scenario values for the cells in ChangingCells. The values should be provided in the same order as the cells in changingCells.