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