Share via


WorkbookBase.ReadOnlyRecommended 屬性

取得或設定值,指出活頁簿是否儲存為唯讀建議的檔案。

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

語法

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

屬性值

型別:System.Boolean
如果活頁簿儲存為唯讀建議檔案則為 true,否則為 false。

備註

當您開啟儲存為唯讀建議檔案的活頁簿時,Microsoft Office Excel 會顯示訊息,建議您以唯讀方式開啟活頁簿。

使用 SaveAs 方法變更此屬性。

範例

在下列程式碼範例中,如果 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 命名空間