WorkbookBase.ReadOnly 屬性

取得值,指出活頁簿是否以唯讀方式開啟。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel.v4.0.Utilities (在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

語法

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

屬性值

型別:System.Boolean
如果活頁簿以唯讀方式開啟則為 true,否則為 false。

備註

此屬性只適用於連結至 SharePoint 網站的清單。

範例

在下列程式碼範例中,如果 ReadOnlyRecommended 屬性為 true,且 ReadOnly 屬性為 false,則會顯示訊息,然後呼叫 ChangeFileAccess 方法,提示使用者將檔案的存取屬性設定為唯讀。

這是示範文件層級自訂的範例。

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 安全性

請參閱

參考

WorkbookBase 類別

Microsoft.Office.Tools.Excel 命名空間