How to open Excel file with Read Only protection?

前端 未结 2 651
攒了一身酷
攒了一身酷 2021-01-23 06:13

I have opened Excel file in my C# WinForm Application adding reference to Microsoft.Office.Interop.Excel.dll and using DSO FRAMER CONTROL. But i want to open my exc

相关标签:
2条回答
  • 2021-01-23 06:30

    The WorkBook class has a Protect method, similar (but not identical) to the one supported by Word. I can't find the COM/interop documentation, but the VSTO documentation covers the same ground, and the method signatures are the same:

    Protect

    Protects a workbook so that it cannot be modified.

    public virtual void Protect (
        [OptionalAttribute] Object Password,
        [OptionalAttribute] Object Structure,
        [OptionalAttribute] Object Windows
    )
    

    (This all assumes that what you wanted to achieve was to protect the document, since that's what the Word code does, as opposed to opening the document read only, which is what your narrative seems to be saying, in which case, @gdoron's answer is more suitable

    0 讨论(0)
  • 2021-01-23 06:39

    Call theOpen method with third parameter (ReadOnly) = true.

    See MSDN documentation :

    ReadOnly
    Optional Object. True to open the workbook in read-only mode.

    0 讨论(0)
提交回复
热议问题