ChartSheet.Protect 方法

保护 Microsoft.Office.Tools.Excel.ChartSheet 以便不能对其进行修改。

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

语法

声明
Sub Protect ( _
    Password As Object, _
    DrawingObjects As Object, _
    Contents As Object, _
    Scenarios As Object, _
    UserInterfaceOnly As Object _
)
void Protect(
    Object Password,
    Object DrawingObjects,
    Object Contents,
    Object Scenarios,
    Object UserInterfaceOnly
)

参数

  • Password
    类型:System.Object
    一个字符串,指定工作表或工作簿的区分大小写的密码。如果省略此参数,则不使用密码就可以取消对工作表或工作簿的保护。否则,必须指定用来取消对工作表或工作簿的保护的密码。如果忘记了密码,则无法取消对工作表或工作簿的保护。最好将密码及其对应文档名的列表保存在安全的位置。
  • DrawingObjects
    类型:System.Object
    为 true 时保护形状。默认值为 false。
  • Contents
    类型:System.Object
    为 true 时保护内容。对于图表而言,这将保护整个图表。对于工作表而言,这将保护锁定的单元格。默认值为 true。
  • Scenarios
    类型:System.Object
    为 true 时保护方案。此参数仅对工作表有效。默认值为 true。
  • UserInterfaceOnly
    类型:System.Object
    为 true 可保护用户界面,但不保护宏。如果省略此参数,则同时对宏和用户界面应用保护。

备注

使用由大写字母和小写字母、数字以及符号组合而成的强密码。弱密码不混合使用这些元素。强密码:Y6dh!et5。弱密码:House27。使用一个方便记忆的强密码,这样就不必将它记在纸上。

可选参数

有关可选参数的信息,请参见Office 解决方案中的可选参数

示例

下面的代码示例使用 Protect 方法保护当前 Microsoft.Office.Tools.Excel.ChartSheet 的所有内容。然后,该示例使用 ProtectContents 属性验证该图表工作表是否受保护,然后提示用户使用 Unprotect 方法移除对该图表工作表的保护。

Private Sub ChartSheetProtection()
    Globals.Sheet1.Range("A1", "A5").Value2 = 22
    Globals.Sheet1.Range("B1", "B5").Value2 = 55

    Me.SetSourceData(Globals.Sheet1.Range("A1", "B5"), _
        Excel.XlRowCol.xlColumns)
    Me.ChartType = Excel.XlChartType.xl3DColumn

    Me.Protect(DrawingObjects:=True, Contents:=True, _
        Scenarios:=True, UserInterfaceOnly:=False)

    If Me.ProtectContents Then
        If DialogResult.Yes = MessageBox.Show("The chart sheet" & _
            " is protected. Unprotect the chart sheet?", _
            "Example", MessageBoxButtons.YesNo) Then
            Me.Unprotect()
        End If
    End If
End Sub
private void ChartSheetProtection()
{
    Globals.Sheet1.Range["A1", "A5"].Value2 = 22;
    Globals.Sheet1.Range["B1", "B5"].Value2 = 55;

    this.SetSourceData(Globals.Sheet1.Range["A1", "B5"],
        Excel.XlRowCol.xlColumns);
    this.ChartType = Excel.XlChartType.xl3DColumn;

    this.Protect(true, true, true, false);

    if (this.ProtectContents)
    {
        if (DialogResult.Yes ==
            MessageBox.Show("The chart sheet is protected. " +
            "Unprotect the chart sheet?", "Example", 
            MessageBoxButtons.YesNo))
        {
            this.Unprotect();
        }
    }
}

.NET Framework 安全性

请参见

参考

ChartSheet 接口

Microsoft.Office.Tools.Excel 命名空间