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 命名空間