[]
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");
voidchangeScenario(IRange changingCells) voidchangeScenario(IRange changingCells,
List<Object> values) voiddelete()IRange object that represents the changing cells for the scenario.booleanintgetIndex()booleangetName()voidsetComment(String comment) voidsetHidden(boolean hidden) voidsetLocked(boolean locked) voidvoidshow()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();
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();
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");
name - The scenario name.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();
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");
comment - The comment associated with the scenario.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();
worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
scenario.setHidden(true);
hidden - True if the scenario is hidden; otherwise, false.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();
worksheet.getRange("B2:B3").setValue(new Object[][] {{10}, {20}});
IScenario scenario = worksheet.getScenarios().add("Sales Plan", worksheet.getRange("B2:B3"), null);
scenario.setLocked(true);
locked - True if the scenario is locked; otherwise, false.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();
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();
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();
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();
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"));
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.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));
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.