ChartSheet.Unprotect 方法

Microsoft.Office.Tools.Excel.ChartSheet 中移除保护。 如果工作表或工作簿不受保护,则此方法无效。

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

语法

声明
Sub Unprotect ( _
    Password As Object _
)
void Unprotect(
    Object Password
)

参数

  • Password
    类型:System.Object
    用于取消保护工作表或工作簿的区分大小写的密码。如果未用密码保护工作表或工作簿,则省略此参数。如果对使用密码进行保护的工作表省略此参数,则您将被提示输入密码。如果对使用密码进行保护的工作簿省略此参数,则该方法将失败。

备注

如果忘记了密码,则无法取消对 Microsoft.Office.Tools.Excel.ChartSheet 的保护。 最好将密码及其对应文档名的列表保存在安全的位置。

可选参数

有关可选参数的信息,请参见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(missing, 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(missing);
        }
    }
}

.NET Framework 安全性

请参见

参考

ChartSheet 接口

Microsoft.Office.Tools.Excel 命名空间