Właściwość WorksheetBase.ProtectContents —
Pobiera wartość, która wskazuje, czy zawartość arkusza (poszczególnych komórek) są chronione.
Przestrzeń nazw: Microsoft.Office.Tools.Excel
Zestaw: Microsoft.Office.Tools.Excel.v4.0.Utilities (w Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)
Składnia
'Deklaracja
Public ReadOnly Property ProtectContents As Boolean
public bool ProtectContents { get; }
Wartość właściwości
Typ: System.Boolean
true Jeżeli zawartość arkusza jest chroniona; w przeciwnym razie false.
Przykłady
Poniższy kod pobiera wartość ProtectContents właściwości w celu określenia, czy zawartość arkusza jest chroniona.Jeśli zawartość jest niezabezpieczone, a następnie Protect wywoływana jest metoda Contents parametr ustawiony na true tak, aby zawartość są chronione.
Ten przykład dotyczy dostosowywania na poziomie dokumentu.
Private Sub ProtectCellContents()
If Not Me.ProtectContents Then
If DialogResult.Yes = MessageBox.Show("Cell contents in this " & _
"worksheet are not protected. Protect cell contents?", "Example", _
MessageBoxButtons.YesNo) Then
' Protect cell contents, but do not change any
' other protection type.
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)
End If
End If
End Sub
private void ProtectCellContents()
{
if (!this.ProtectContents)
{
if (DialogResult.Yes == MessageBox.Show("Cell contents in this " +
"worksheet are not protected. Protect cell contents?", "Example",
MessageBoxButtons.YesNo))
{
// Protect cell contents, but do not change any
// other protection type.
this.Protect(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);
}
}
}
Zabezpieczenia programu .NET Framework
- Pełne zaufanie do bezpośredniego wywołującego. Tego elementu członkowskiego nie można używać w kodzie częściowo zaufanym. Aby uzyskać więcej informacji, zobacz Używanie bibliotek pochodzących z częściowo zaufanego kodu.