Freigeben über


WorkbookBase.ReadOnly Property

Gets a value that indicates whether the workbook has been opened as read-only.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public ReadOnly Property ReadOnly As Boolean
public bool ReadOnly { get; }

Property Value

Type: System.Boolean
true if the workbook has been opened as read-only; otherwise, false.

Remarks

This property is used only for lists that are linked to a SharePoint site.

Examples

The following code example displays a message if the ReadOnlyRecommended property is true and the ReadOnly property is false, and then prompts the user to set the file access to read-only by calling the ChangeFileAccess method.

This example is for a document-level customization.

Private Sub MakeWorkbookReadOnly()
    If Me.ReadOnlyRecommended AndAlso Not Me.ReadOnly Then 
        ' Change the access level of the document to read-only   
        ' if the user clicks yes. 
        If MessageBox.Show("Set this document to read-only?", _
            "Sample", MessageBoxButtons.YesNo) = DialogResult.Yes Then 
            Me.ChangeFileAccess(Excel.XlFileAccess.xlReadOnly, Notify:=False)
        End If 
    End If 
End Sub
private void MakeWorkbookReadOnly()
{
    if (this.ReadOnlyRecommended && !this.ReadOnly)
    {
        // Change the access level of the document to read-only if the user  
        // clicks yes. 
        if (MessageBox.Show("Set this document to read-only?",
            "Sample", MessageBoxButtons.YesNo) == DialogResult.Yes)
        {
            this.ChangeFileAccess(Excel.XlFileAccess.xlReadOnly,
                 false);
        }
    }
}

.NET Framework Security

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace