Interface IScenarios
Represents the collection of What-If analysis scenarios in the worksheet.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Portable.dll
Syntax
public interface IScenarios
Properties
Count
Gets the number of the What-If analysis scenarios in scenarios collection.
Declaration
int Count { get; }
Property Value
Type |
---|
System.Int32 |
Examples
Following code illustrates how to get number of scenario in the scenarios collection.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
IScenarios scenarios = worksheet.Scenarios;
int count = worksheet.Scenarios.Count;
workbook.SaveAs("ScenarioManager.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Item[Int32]
Gets the scenario from the What-If analysis scenarios collection based on Index.
Declaration
IScenario this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Represent the index of the scenatrio |
Property Value
Type | Description |
---|---|
IScenario | Returns the created instance of IScenario |
Examples
Following code illustrates how to get scenario from scenarios collection based on Index.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
IScenarios scenarios = worksheet.Scenarios;
IScenario scenario = worksheet.Scenarios[0];
workbook.SaveAs("ScenarioManager.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Item[String]
Gets the scenario from from the What-If analysis collection based on scenario name.
Declaration
IScenario this[string name] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Represent the name of the scenatrio |
Property Value
Type | Description |
---|---|
IScenario | Returns the created instance of IScenario |
Examples
Following code illustrates how to get scenario from scenarios collection based on scenario name.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
IScenarios scenarios = worksheet.Scenarios;
IScenario scenario = worksheet.Scenarios["ScenarioName"];
workbook.SaveAs("ScenarioManager.xlsx");
workbook.Close();
excelEngine.Dispose();
}
ResultCells
Gets the Resultant cell range for the What-If analysis scenario.
Declaration
IRange ResultCells { get; }
Property Value
Type | Description |
---|---|
IRange | Returns the created instance of IRange |
Examples
Following code illustrates how to get resultant cells range for the worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
IScenarios scenarios = worksheet.Scenarios;
//Get the changnig cells range for the scenario
IRange resultantcellRange = scenarios.ResultantCells;
workbook.SaveAs("ScenarioManager.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Methods
Add(String, IRange, List<Object>)
Declaration
IScenario Add(string name, IRange changingCells, List<object> values)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | |
IRange | changingCells | |
System.Collections.Generic.List<System.Object> | values |
Returns
Type |
---|
IScenario |
Add(String, IRange, Object)
Creates a What-If analysis scenario and adds it to the What-If analysis scenarios collection for the current worksheet.
Declaration
IScenario Add(string name, IRange changingCells, object values)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Represent the name of the scenario |
IRange | changingCells | Represent the changingCell address of the scenario |
System.Object | values | Represent the value of the scenario |
Returns
Type | Description |
---|---|
IScenario | Returns the created instance of IScenario |
Examples
The following code illustrates how to add the scenario in the scenarios collection of the worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
//Add a new scenario to the worksheet.
IScenarios scenarios = sheet1.Scenarios;
IScenario scenario1 = scenarios.Add("Scenario1", sheet.Range["C4"], 100);
workbook.SaveAs("ScenarioManager.xlsx");
workbook.Close();
excelEngine.Dispose();
}
CreateSummary(IRange)
Creates a new worksheet that contains a summary report for the What-If analysis scenarios on the specified worksheet.
Declaration
void CreateSummary(IRange resultantCell)
Parameters
Type | Name | Description |
---|---|---|
IRange | resultantCell | Represent the resultantCell range for the scenarios |
Examples
The following code illustrates how to create a new worksheet that contains a summary report for the scenarios on the specified worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("ScenarioManager.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
//Add the scenarios in worksheet
IScenarios scenarios = sheet1.Scenarios;
IScenario scenario1 = scenarios.Add("scenario1", sheet.Range["C4"], 100);
IScenario scenario2 = scenarios.Add("scenario2", sheet.Range["C4"], 200);
IScenario scenario3 = scenarios.Add("scenario3", sheet.Range["C4"], 300);
//Create a summary for the worksheet
worksheet.Scenarios.CreateSummary(sheet.Range["C9"]);
workbook.SaveAs("ScenarioManager.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Merge(IWorksheet)
Declaration
IScenarios Merge(IWorksheet sheet)
Parameters
Type | Name | Description |
---|---|---|
IWorksheet | sheet |
Returns
Type |
---|
IScenarios |