[]
        
(Showing Draft Content)

IScenarios

Interface IScenarios

All Superinterfaces:
Iterable<IScenario>

public interface IScenarios extends Iterable<IScenario>
Represents the collection of IScenario objects in the worksheet.

This interface provides access to the worksheet's What-If analysis scenarios. Use IWorksheet.getScenarios() to obtain the collection, then add, retrieve, and iterate through saved scenarios for the worksheet.


 List<Object> values = Arrays.<Object>asList(0.05, 0.10, 0.15);
 IScenarios scenarios = worksheet.getScenarios();
 scenarios.add("Discount Plan", worksheet.getRange("B1:B3"), values, "Quarterly discount rates", true, false);
 IScenario scenario = scenarios.get("Discount Plan");
 
  • Method Details

    • getCount

      int getCount()
      Returns the number of objects in the collection.

      This property returns the number of IScenario objects in the scenario collection for the current worksheet.

      
       worksheet.getRange("B2").setValue(0.05);
       worksheet.getRange("B3").setValue(0.08);
       IRange range = worksheet.getRange("B2:B3");
       worksheet.getScenarios().add("Discount Plan", range);
       int count = worksheet.getScenarios().getCount();
       
      Returns:
      The number of objects in the collection.
    • get

      IScenario get(int index)
      Gets the scenario using the index.

      Use this method to retrieve a scenario from the worksheet's scenario collection by its position.

      
       worksheet.getRange("B2").setValue(0.05);
       worksheet.getRange("B3").setValue(0.08);
       IRange range = worksheet.getRange("B2:B3");
       worksheet.getScenarios().add("Discount Plan", range);
       IScenario scenario = worksheet.getScenarios().get(0);
       
      Parameters:
      index - The index of the scenario to retrieve from the collection.
      Returns:
      The scenario at the specified index.
    • get

      IScenario get(String name)
      Gets the scenario using the name.

      Name matching is case-insensitive.

      
       worksheet.getRange("B2").setValue(0.05);
       worksheet.getRange("B3").setValue(0.08);
       IRange range = worksheet.getRange("B2:B3");
       worksheet.getScenarios().add("Discount Plan", range);
       IScenario scenario = worksheet.getScenarios().get("Discount Plan");
       
      Parameters:
      name - The scenario name.
      Returns:
      The scenario with the specified name, or null if no matching scenario exists.
    • add

      IScenario add(String name, IRange changingCells)
      Creates a new scenario and adds it to the list of scenarios in the current worksheet.

      The scenario values are assumed to be the current values in the cells in changingCells. The author's name (Document Solutions for Excel) and date are automatically added as the comment text. The scenario is locked to prevent changes.

      
       worksheet.getRange("B2").setValue(0.05);
       worksheet.getRange("B3").setValue(0.08);
       IRange range = worksheet.getRange("B2:B3");
       IScenario scenario = worksheet.getScenarios().add("Discount Plan", range);
       
      Parameters:
      name - The scenario name.
      changingCells - An IRange object that refers to the changing cells for the scenario.
      Returns:
      The new IScenario object.
    • add

      IScenario add(String name, IRange changingCells, List<Object> values)
      Creates a new scenario and adds it to the list of scenarios of the current worksheet.

      The author's name (Document Solutions for Excel) and date are automatically added as the comment text. The scenario is locked to prevent changes.

      The values in values correspond to the cells in changingCells one by one. For example, if changingCells is "B2:C3", the values are applied in the order B2, C2, B3, and C3. If values is null, the current values in changingCells are used for the scenario.

      
       worksheet.getRange("C4").setValue(0.6);
       worksheet.getRange("D7").setValue(50);
       IScenario scenario = worksheet.getScenarios().add(
               "90% highest",
               worksheet.getRange("C4, D7"),
               Arrays.asList(0.9, 60));
       
      Parameters:
      name - The scenario name.
      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; if null, the current values in changingCells are used.
      Returns:
      The new IScenario object.
    • add

      IScenario add(String name, IRange changingCells, List<Object> values, String comment)
      Creates a new scenario and adds it to the list of scenarios of the current worksheet.

      The values in values correspond to the cells in changingCells one by one. For example, if changingCells is "B2:C3", the values are applied in the order B2, C2, B3, and C3. If comment is null, Document Solutions for Excel adds the author name and date automatically.

      
       IRange range = worksheet.getRange("D2:D4");
       IScenario scenario = worksheet.getScenarios().add(
           "Reduced Rates",
           range,
           Arrays.asList(0.05, 0.03, 0.02),
           "Adjusted discount rates");
       
      Parameters:
      name - The scenario name.
      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.
      comment - The comment text for the scenario. If null, an automatic comment is added.
      Returns:
      The new IScenario object.
    • add

      IScenario add(String name, IRange changingCells, List<Object> values, String comment, boolean locked)
      Creates a new scenario and adds it to the list of scenarios of the current worksheet.

      The values in values correspond to the cells in changingCells one by one. For example, if changingCells is "B2:C3", the values are applied in the order B2, C2, B3, and C3. If values is null, the current values in changingCells are used for the scenario. If comment is null, Document Solutions for Excel adds the author name and date automatically.

      
       IRange range = worksheet.getRange("B2:B3");
       IScenario scenario = worksheet.getScenarios().add(
           "Discount Plan",
           range,
           Arrays.<Object>asList(0.05, 0.08),
           "Quarterly discount rates",
           true);
       
      Parameters:
      name - The scenario name.
      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; if null, the current values in changingCells are used.
      comment - The comment text for the scenario. If null, an automatic comment is added.
      locked - true to lock the scenario to prevent changes; otherwise, false.
      Returns:
      The new IScenario object.
      Throws:
      IllegalArgumentException - if a scenario with the same name already exists, or if changingCells does not belong to the current worksheet.
    • add

      IScenario add(String name, IRange changingCells, List<Object> values, String comment, boolean locked, boolean hidden)
      Creates a new scenario and adds it to the list of scenarios of the current worksheet.

      The values in values correspond to the cells in changingCells one by one. For example, if changingCells is "B2:C3", the values are applied in the order B2, C2, B3, and C3. If values is null, the current values in changingCells are used. If comment is null, Document Solutions for Excel adds the author name and date automatically.

      
       worksheet.getRange("B2").setValue(0.1);
       worksheet.getRange("C2").setValue(0.15);
       IScenario scenario = worksheet.getScenarios().add(
           "Target Revenue",
           worksheet.getRange("B2:C2"),
           Arrays.<Object>asList(0.12, 0.18),
           "Discount assumptions",
           true,
           false);
       worksheet.getRange("B2:C2").setValue(new Object[][] {{0.2, 0.25}});
       scenario.show();
       Object appliedValues = worksheet.getRange("B2:C2").getValue();
       
      Parameters:
      name - The scenario name.
      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; null uses the current values in those cells.
      comment - A string that specifies comment text for the scenario; null adds the author name and date automatically.
      locked - true to lock the scenario to prevent changes; otherwise, false.
      hidden - true to hide the scenario; otherwise, false.
      Returns:
      The new IScenario object.
      Throws:
      IllegalArgumentException - if a scenario with the same name already exists, or if changingCells does not belong to the current worksheet.
    • iterator

      Iterator<IScenario> iterator()
      Returns an iterator over the scenarios in this collection.

      Use this method to traverse the scenarios currently stored on the worksheet in collection order.

      
       worksheet.getRange("B2").setValue(0.05);
       worksheet.getRange("B3").setValue(0.08);
       IRange range = worksheet.getRange("B2:B3");
       worksheet.getScenarios().add("Discount Plan", range);
       Iterator<IScenario> scenarios = worksheet.getScenarios().iterator();
       if (scenarios.hasNext()) {
           IScenario scenario = scenarios.next();
       }
       
      Specified by:
      iterator in interface Iterable<IScenario>
      Returns:
      An iterator for traversing IScenario objects in this collection.