WorksheetBase.Protection Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Ruft ein Protection-Objekt ab, das die Schutzoptionen des Arbeitsblatts darstellt.
public Microsoft.Office.Interop.Excel.Protection Protection { get; }
Eigenschaftswert
Ein Protection-Objekt, das die Schutzoptionen des Arbeitsblatts darstellt.
Beispiele
Im folgenden Codebeispiel wird der Wert der- Protection Eigenschaft abgerufen, um zu bestimmen, ob die Zellen Formatierung derzeit zulässig ist. Wenn die Zellen Formatierung nicht zulässig ist, wird die- Protect Methode aufgerufen, und der- AllowFormattingCells Parameter wird auf festgelegt, true sodass Zellen formatiert werden können.
Dieses Beispiel gilt für eine Anpassung auf Dokument Ebene.
private void ProtectCellFormatting()
{
// Protect cell contents, but do not change any
// other protection type. This enables the Protection
// property to have effect.
this.Protect(missing, this.ProtectDrawingObjects,
true, this.ProtectScenarios, this.ProtectionMode,
this.Protection.AllowFormattingCells,
this.Protection.AllowFormattingColumns,
this.Protection.AllowFormattingRows,
this.Protection.AllowInsertingColumns,
this.Protection.AllowInsertingRows,
this.Protection.AllowInsertingHyperlinks,
this.Protection.AllowDeletingColumns,
this.Protection.AllowDeletingRows,
this.Protection.AllowSorting,
this.Protection.AllowFiltering,
this.Protection.AllowUsingPivotTables);
if (!this.Protection.AllowFormattingCells)
{
if (DialogResult.Yes == MessageBox.Show("Formatting cells is " +
"not allowed. Allow formatting cells?", "Example",
MessageBoxButtons.YesNo))
{
// Allow cell formatting, but do not change any other protection type.
this.Protect(this.ProtectDrawingObjects,
this.ProtectContents, this.ProtectScenarios,
this.ProtectionMode, true,
this.Protection.AllowFormattingColumns,
this.Protection.AllowFormattingRows,
this.Protection.AllowInsertingColumns,
this.Protection.AllowInsertingRows,
this.Protection.AllowInsertingHyperlinks,
this.Protection.AllowDeletingColumns,
this.Protection.AllowDeletingRows,
this.Protection.AllowSorting,
this.Protection.AllowFiltering,
this.Protection.AllowUsingPivotTables);
}
}
}
Private Sub ProtectCellFormatting()
' Protect cell contents, but do not change any
' other protection type. This enables the Protection
' property to have effect.
Me.Protect(DrawingObjects:=Me.ProtectDrawingObjects, _
Contents:=True, Scenarios:=Me.ProtectScenarios, _
UserInterfaceOnly:=Me.ProtectionMode, _
AllowFormattingCells:=Me.Protection.AllowFormattingCells, _
AllowFormattingColumns:=Me.Protection.AllowFormattingColumns, _
AllowFormattingRows:=Me.Protection.AllowFormattingRows, _
AllowInsertingColumns:=Me.Protection.AllowInsertingColumns, _
AllowInsertingRows:=Me.Protection.AllowInsertingRows, _
AllowInsertingHyperlinks:=Me.Protection.AllowInsertingHyperlinks, _
AllowDeletingColumns:=Me.Protection.AllowDeletingColumns, _
AllowDeletingRows:=Me.Protection.AllowDeletingRows, _
AllowSorting:=Me.Protection.AllowSorting, _
AllowFiltering:=Me.Protection.AllowFiltering, _
AllowUsingPivotTables:=Me.Protection.AllowUsingPivotTables)
If Not Me.Protection.AllowFormattingCells Then
If DialogResult.Yes = MessageBox.Show("Formatting cells is " & _
"not allowed. Allow formatting cells?", "Example", _
MessageBoxButtons.YesNo) Then
' Allow cell formatting, but do not change any other protection type.
Me.Protect(DrawingObjects:=Me.ProtectDrawingObjects, _
Contents:=Me.ProtectContents, Scenarios:=Me.ProtectScenarios, _
UserInterfaceOnly:=Me.ProtectionMode, _
AllowFormattingCells:=True, _
AllowFormattingColumns:=Me.Protection.AllowFormattingColumns, _
AllowFormattingRows:=Me.Protection.AllowFormattingRows, _
AllowInsertingColumns:=Me.Protection.AllowInsertingColumns, _
AllowInsertingRows:=Me.Protection.AllowInsertingRows, _
AllowInsertingHyperlinks:=Me.Protection.AllowInsertingHyperlinks, _
AllowDeletingColumns:=Me.Protection.AllowDeletingColumns, _
AllowDeletingRows:=Me.Protection.AllowDeletingRows, _
AllowSorting:=Me.Protection.AllowSorting, _
AllowFiltering:=Me.Protection.AllowFiltering, _
AllowUsingPivotTables:=Me.Protection.AllowUsingPivotTables)
End If
End If
End Sub