[]
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");
add(String name,
IRange changingCells,
List<Object> values,
String comment,
boolean locked,
boolean hidden) get(int index) intgetCount()iterator()forEach, spliteratorThis 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();
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);
index - The index of the scenario to retrieve from the collection.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");
name - The scenario name.null if no matching scenario exists.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);
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));
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");
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.IScenario object.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);
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.IScenario object.IllegalArgumentException - if a scenario with the same name already exists, or if changingCells does not belong to 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();
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.IScenario object.IllegalArgumentException - if a scenario with the same name already exists, or if changingCells does not belong to the current worksheet.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();
}