WorksheetBase.Scenarios 方法

获取一个对象,该对象表示工作表上的单个方案(一个 Microsoft.Office.Interop.Excel.Scenario 对象)或方案的集合(一个 Microsoft.Office.Interop.Excel.Scenarios 对象)。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

语法

声明
Public Function Scenarios ( _
    index As Object _
) As Object
public Object Scenarios(
    Object index
)

参数

  • index
    类型:System.Object
    方案的名称或编号。使用数组可指定多个方案。

返回值

类型:System.Object
一个对象,表示工作表上的单个方案(一个 Microsoft.Office.Interop.Excel.Scenario 对象)或方案的集合(一个 Microsoft.Office.Interop.Excel.Scenarios 对象)。

示例

下面的代码示例使用 Scenarios 方法向当前工作表添加一个新方案,然后显示**“方案管理器”**对话框来验证是否添加了该方案。

此示例针对的是文档级自定义项。

Private Sub CreateScenario()
    Dim range1 As Excel.Range = Me.Range("A1", "B10")
    range1.Formula = "=rand()"

    Dim scenarios1 As Excel.Scenarios = _
        CType(Me.Scenarios(), Excel.Scenarios)

    Dim newScenario As Excel.Scenario = _
        scenarios1.Add("New Scenario", range1)

    ' Show Scenario Manager dialog to verify that the scenario was added.
    Me.Application.Dialogs(Excel.XlBuiltInDialog.xlDialogScenarioCells).Show()
End Sub
private void CreateScenario()
{   
    Excel.Range range1 = this.Range["A1", "B10"];
    range1.Formula = "=rand()";

    Excel.Scenarios scenarios1 =
        (Excel.Scenarios)this.Scenarios(missing);

    Excel.Scenario newScenario = scenarios1.Add("New Scenario", 
        range1, missing, missing, missing, missing);

    // Show Scenario Manager dialog to verify that the scenario was added.
    this.Application.Dialogs[Excel.XlBuiltInDialog.xlDialogScenarioCells].Show(
        missing, missing, missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing);
}

.NET Framework 安全性

请参见

参考

WorksheetBase 类

Microsoft.Office.Tools.Excel 命名空间