How to open Excel file with Read Only protection?

28,662

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

See MSDN documentation :

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

Share:
28,662

Related videos on Youtube

Saravanan
Author by

Saravanan

I am Saravanan MCA Graduate.I am working as a Senior Developer in java environment. Email:[email protected]

Updated on July 05, 2022

Comments

  • Saravanan
    Saravanan almost 2 years

    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 excel file with read only protection.I have successfully done this for WORD Application like this

    Word.Document wordDoc = (Word.Document)axFramerControl1.ActiveDocument;
    Word.Application wordApp = wordDoc.Application;
    wordDoc.Protect(Word.WdProtectionType.wdAllowOnlyReading);
    

    In the same i want to do this work for Excel.But i couldn't able to protect Excel file on that way.

    string path = "C:\\test-wb.xlsx";
    axFramerControl1.Open(path, true,"excel.sheet", "", "");
    
    Excel._Workbook excelDoc   =(Microsoft.Office.Interop.Excel._Workbook)axFramerControl1.ActiveDocument;
    Excel.Application excelApp =excelDoc.Application;
    //What code should i write to protect Excel Workbook with read - only.
    excelDoc.Protect(misval, true, misval);//It is not working.
    
  • Saravanan
    Saravanan over 12 years
    :Thanks gdoron.Can you please tell where should i give that parameter in my above code that i mentioned in my question?
  • gdoron is supporting Monica
    gdoron is supporting Monica over 12 years
    @Saravanan. According to the MSDN, you should open with third param true. which .Net framework do you use? .Net 4?
  • Lukas
    Lukas about 10 years
    This helped me. Instead however I just added the password as the 6th parameter of the Open method.

Related