[]
Sheets.Scenarios.ScenarioManager
• new ScenarioManager(workbook)
Represents a scenario manager for retrieving, updating, removing, applying, restoring, and active, deactive scenarios in a workbook.
example
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var scenarioManager = spread.scenarioManager;
| Name | Type | Description |
|---|---|---|
workbook |
Workbook |
The workbook that owns the scenario manager. |
▸ all(): IScenario[]
Gets all scenarios in the workbook.
example
var scenarios = spread.scenarioManager.all();
console.log(scenarios.length);
All scenarios in the workbook.
▸ apply(name): boolean
Applies a scenario to the workbook.
example
spread.scenarioManager.apply("Optimistic");
| Name | Type | Description |
|---|---|---|
name |
string |
The scenario name. |
boolean
true if the scenario is applied successfully; otherwise, false.
▸ get(name): undefined | IScenario
Gets a scenario by name.
example
var scenario = spread.scenarioManager.get("Optimistic");
console.log(scenario);
| Name | Type | Description |
|---|---|---|
name |
string |
The scenario name. |
undefined | IScenario
The scenario with the specified name. Returns undefined if the scenario does not exist.
▸ getAppliedScenarios(): string[]
Gets the names of scenarios that are currently applied and not yet restored.
example
var appliedNames = spread.scenarioManager.getAppliedScenarios();
console.log(appliedNames);
string[]
The applied scenario names in application order.
▸ getBaseValues(): IOverrides[]
Gets a read-only snapshot of the current scenario base values.
example
var baseValues = spread.scenarioManager.getBaseValues();
console.log(baseValues);
The current base values.
▸ remove(name?): void
Removes a scenario by name. If no name is provided, all scenarios in the workbook are removed.
example
spread.scenarioManager.remove("Optimistic");
// Or remove all scenarios:
spread.scenarioManager.remove();
| Name | Type | Description |
|---|---|---|
name? |
string |
The scenario name. If omitted, all scenarios are removed. |
void
▸ restore(name?): void
Restores previously applied scenario values to their base values.
example
spread.scenarioManager.restore("Optimistic");
// Or restore all applied scenarios:
spread.scenarioManager.restore();
| Name | Type | Description |
|---|---|---|
name? |
string |
The scenario name. If omitted, all applied scenarios are restored. |
void
▸ set(scenario): void
Updates an existing scenario definition.
example
var scenario = spread.scenarioManager.get("Optimistic");
if (scenario) {
scenario.overrides[0].comment = "Updated sales growth assumption.";
spread.scenarioManager.set(scenario);
}
| Name | Type | Description |
|---|---|---|
scenario |
IScenario |
The scenario definition to update. |
void
▸ setActiveScenario(name): boolean
Activates a scenario to capture subsequent cell value edits, or deactivates the current active scenario.
example
spread.scenarioManager.setActiveScenario("Optimistic");
activeSheet.setValue(1, 1, 1200);
spread.scenarioManager.setActiveScenario(null);
| Name | Type | Description |
|---|---|---|
name |
null | string |
The scenario name. Pass null to deactivate the current active scenario. |
boolean
true if the operation succeeds; otherwise, false.