Back to Devexpress

ChartSheet.Protect(String, ChartSheetProtection) Method

officefileapi-devexpress-dot-spreadsheet-dot-chartsheet-dot-protect-x28-system-dot-string-devexpress-dot-spreadsheet-dot-chartsheetprotection-x29.md

latest5.2 KB
Original Source

ChartSheet.Protect(String, ChartSheetProtection) Method

Protects chart sheet elements to prevent them from being changed by the user.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void Protect(
    string password,
    ChartSheetProtection options
)
vb
Sub Protect(
    password As String,
    options As ChartSheetProtection
)

Parameters

NameTypeDescription
passwordString

A string that specifies a password for the chart sheet. If the password is an empty string, the chart sheet can be unprotected without using a password.

| | options | ChartSheetProtection |

A ChartSheetProtection enumeration member that allows you to specify chart sheet elements to protect.

|

Remarks

If a chart sheet is already protected, the Protect method throws an exception. Check the ChartSheet.IsProtected property before calling the method.

Example

View Example

csharp
Worksheet worksheet = workbook.Worksheets["chartTask1"];

// Create a chart sheet containing a pie chart.
ChartSheet chartSheet = workbook.ChartSheets.Add(ChartType.Pie, worksheet["B2:C7"]);

// Protect the chart sheet. Prevent end-users from making changes to chart elements.
if (!chartSheet.IsProtected)
    chartSheet.Protect("password", ChartSheetProtection.Default);

workbook.ChartSheets.ActiveChartSheet = chartSheet;
vb
Dim worksheet As Worksheet = workbook.Worksheets("chartTask1")

' Create a chart sheet containing a pie chart.
Dim chartSheet As ChartSheet = workbook.ChartSheets.Add(ChartType.Pie, worksheet("B2:C7"))

' Protect the chart sheet. Prevent end-users from making changes to chart elements.
If Not chartSheet.IsProtected Then
    chartSheet.Protect("password", ChartSheetProtection.Default)
End If

workbook.ChartSheets.ActiveChartSheet = chartSheet

The following code snippets (auto-collected from DevExpress Examples) contain references to the Protect(String, ChartSheetProtection) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-spreadsheet-chart-api/CS/SpreadsheetWPFChartAPISamples/CodeExamples/ChartSheetActions.cs#L129

csharp
if (!chartSheet.IsProtected)
    chartSheet.Protect("password", ChartSheetProtection.Default);

winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/CodeExamples/ChartSheetActions.cs#L129

csharp
if (!chartSheet.IsProtected)
    chartSheet.Protect("password", ChartSheetProtection.Default);

wpf-spreadsheet-chart-api/VB/SpreadsheetWPFChartAPISamples/CodeExamples/ChartSheetActions.vb#L124

vb
If Not chartSheet.IsProtected Then
    chartSheet.Protect("password", ChartSheetProtection.Default)
End If

winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/CodeExamples/ChartSheetActions.vb#L123

vb
If Not chartSheet.IsProtected Then
    chartSheet.Protect("password", ChartSheetProtection.Default)
End If

See Also

IsProtected

ChartSheet Interface

ChartSheet Members

DevExpress.Spreadsheet Namespace