[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.IScenarios.Add

Add Method

Add(string, IRange, List<object>, string, bool, bool)

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.

Declaration
IScenario Add(string name, IRange changingCells, List<object> values = null, string comment = null, bool locked = true, bool hidden = false)
Function Add(name As String, changingCells As IRange, Optional values As List(Of Object) = Nothing, Optional comment As String = Nothing, Optional locked As Boolean = True, Optional hidden As Boolean = False) As IScenario
Parameters
Type Name Description
string name

The scenario name.

IRange changingCells

An IRange object that refers to the changing cells for the scenario.

List<object> values

A list that contains the scenario values for the cells in changingCells; null uses the current values in those cells.

string comment

A string that specifies comment text for the scenario; null adds the author name and date automatically.

bool locked true to lock the scenario to prevent changes; otherwise, false.
bool hidden true to hide the scenario; otherwise, false.
Returns
Type Description
IScenario

The new IScenario object.

Examples
worksheet.Range["B2"].Value = 0.1;
worksheet.Range["C2"].Value = 0.15;
IScenario scenario = worksheet.Scenarios.Add(
    "Target Revenue",
    worksheet.Range["B2:C2"],
    new List<object> { 0.12, 0.18 },
    "Discount assumptions",
    true,
    false);
worksheet.Range["B2:C2"].Value = new object[,] {{0.2, 0.25}};
scenario.Show();
object appliedValues = worksheet.Range["B2:C2"].Value;
Exceptions
Type Condition
ArgumentException

Thrown if a scenario with the same name already exists, or if changingCells does not belong to the current worksheet.