[]
        
(Showing Draft Content)

GC.Spread.Sheets.Scenarios.ScenarioManager

Class: ScenarioManager

Sheets.Scenarios.ScenarioManager

Table of contents

Constructors

Methods

Constructors

constructor

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;

Parameters

Name Type Description
workbook Workbook The workbook that owns the scenario manager.

Methods

all

all(): IScenario[]

Gets all scenarios in the workbook.

example

var scenarios = spread.scenarioManager.all();
console.log(scenarios.length);

Returns

IScenario[]

All scenarios in the workbook.


apply

apply(name): boolean

Applies a scenario to the workbook.

example

spread.scenarioManager.apply("Optimistic");

Parameters

Name Type Description
name string The scenario name.

Returns

boolean

true if the scenario is applied successfully; otherwise, false.


get

get(name): undefined | IScenario

Gets a scenario by name.

example

var scenario = spread.scenarioManager.get("Optimistic");
console.log(scenario);

Parameters

Name Type Description
name string The scenario name.

Returns

undefined | IScenario

The scenario with the specified name. Returns undefined if the scenario does not exist.


getAppliedScenarios

getAppliedScenarios(): string[]

Gets the names of scenarios that are currently applied and not yet restored.

example

var appliedNames = spread.scenarioManager.getAppliedScenarios();
console.log(appliedNames);

Returns

string[]

The applied scenario names in application order.


getBaseValues

getBaseValues(): IOverrides[]

Gets a read-only snapshot of the current scenario base values.

example

var baseValues = spread.scenarioManager.getBaseValues();
console.log(baseValues);

Returns

IOverrides[]

The current base values.


remove

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();

Parameters

Name Type Description
name? string The scenario name. If omitted, all scenarios are removed.

Returns

void


restore

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();

Parameters

Name Type Description
name? string The scenario name. If omitted, all applied scenarios are restored.

Returns

void


set

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);
}

Parameters

Name Type Description
scenario IScenario The scenario definition to update.

Returns

void


setActiveScenario

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);

Parameters

Name Type Description
name null | string The scenario name. Pass null to deactivate the current active scenario.

Returns

boolean

true if the operation succeeds; otherwise, false.